Python Question: Button Events, Click Events? WTH Magic?

Woil

Chieftain
Joined
May 27, 2006
Messages
12
So I'm trying to make this mod that will do the seemingly simple task of allowing a user to take a super specialist / great specialist back out of a city after it has joined. Thus allowing a user to store the great person in the city while waiting for that wonder completion / tech research option, then pull back out of the city and use.

I've figured out how to spawn new great people in any city, and figured out how events like onCityBuilt work. What I can't figure out is how is how to actually get interface functions. I'm a long time c++ / c# programmer, so python isn't that tough. I'm just missing some major link between where we make the specialist buttons (CvMainInterface.py or so it would seem) and where the code is that actually increases / decreases the specialist count in the cities.


So question one:

For all you modders who add buttons to the interface: how do you link where you add the button (in your individual screens interface file) and where the button's functionality code executes? Is there some magic XML thing I'm missing where it says "this one goes there, that one goes there"?

--


So I bust out the c++ sdk code for the city (CvCity.cpp / .h) and I can clearly see that there is an exposed "getNumGreatPeople()" and a clearly not exposed "changeNumGreatPeople(int)" Obviously I'd want to expose this to implement my mod. But pretending I bothered, and figured out how to call it (see question one) I can't figure out how the city stores WHICH great people it has. Its an int, and there doesn't appear to be a data structure storing which great people are in the city, only how many. As the different kinds of great people do different things.... WTH?

Is there some other file that provides a global tracking for all great people? (That'd be a horrible way to do this, but I'm reaching here...)

Any guesses out there on where this information is stored?
 
Woil said:
So I'm trying to make this mod that will do the seemingly simple task of allowing a user to take a super specialist / great specialist back out of a city after it has joined. Thus allowing a user to store the great person in the city while waiting for that wonder completion / tech research option, then pull back out of the city and use.

I've figured out how to spawn new great people in any city, and figured out how events like onCityBuilt work. What I can't figure out is how is how to actually get interface functions. I'm a long time c++ / c# programmer, so python isn't that tough. I'm just missing some major link between where we make the specialist buttons (CvMainInterface.py or so it would seem) and where the code is that actually increases / decreases the specialist count in the cities.


So question one:

For all you modders who add buttons to the interface: how do you link where you add the button (in your individual screens interface file) and where the button's functionality code executes? Is there some magic XML thing I'm missing where it says "this one goes there, that one goes there"?

--


So I bust out the c++ sdk code for the city (CvCity.cpp / .h) and I can clearly see that there is an exposed "getNumGreatPeople()" and a clearly not exposed "changeNumGreatPeople(int)" Obviously I'd want to expose this to implement my mod. But pretending I bothered, and figured out how to call it (see question one) I can't figure out how the city stores WHICH great people it has. Its an int, and there doesn't appear to be a data structure storing which great people are in the city, only how many. As the different kinds of great people do different things.... WTH?

Is there some other file that provides a global tracking for all great people? (That'd be a horrible way to do this, but I'm reaching here...)

Any guesses out there on where this information is stored?

Question1: I'm assuming you're speaking about the little +/- buttons next to the specialists pictures in the city? I'm not sure, but a quick search of the CyMainInterface.py shows up what appears to be increase/decrease buttons at around line 394. They're part of a custom widget that looks to call the function CvDLLWidgetData::executeAction. You might be able to take a look at the contents of the CvWidgetDataStruct structure and find out what is happening when each gets clicked. I'm going to assume that one of the data fields holds the integer value of the enumerated type that is the specialist that was increased/decreased. If you want to do some SDK modding, you might be able to mod that function to do what you want. However, I'd wait for someone more in tune with python mods reads this, as that's probably not the most ideal solution for a quick-fix.

Question2: The variable you're probably looking at in CvCity (m_iSpecialistPopulation) is only one part, there is also an integer array (m_paiSpecialistCount) that holds an array of integers indexed by their enumerated value, where each integer value holds the number of that specialist. You're right through, the...

void changeSpecialistCount(SpecialistTypes eIndex, int iChange);

...function doesn't seem to be exposed to python, but the alterSpecialistCount (with the same arguments) does. It may appear to be the same thing, but changeSpecialistCount does the change with no regard for rules, whereas alterSpecialistCount looks like it makes checks. You can check out the code to see more what it does.


Hope that helps.
 
Woil said:
So I'm trying to make this mod that will do the seemingly simple task of allowing a user to take a super specialist / great specialist back out of a city after it has joined. Thus allowing a user to store the great person in the city while waiting for that wonder completion / tech research option, then pull back out of the city and use.

I've figured out how to spawn new great people in any city, and figured out how events like onCityBuilt work. What I can't figure out is how is how to actually get interface functions. I'm a long time c++ / c# programmer, so python isn't that tough. I'm just missing some major link between where we make the specialist buttons (CvMainInterface.py or so it would seem) and where the code is that actually increases / decreases the specialist count in the cities.

Whoa--way to jump right in!

The button itself is placed by the python code in CvMainInterface.py -- you have to place references in a few different places because the buttons appear and dissapear when you enter a city/leave a city, so the python code needs to know to create and delete the widgets at the right time.

As to the second part of your question: I don't know! I've never tried to manipulate the specialists per se. I'm an old C++ guy myself and I just started wading through the SDK last weekend. I remember the city code pretty clearly because I've been looking at the AI, and I think the AI sets it's specialists every turn, but I can't remember off the top of my head where that data was kept. You could go through the CityAI file and see--I know it's in there, but you might be able to do it from Python alone as Roger Bacon suggests.

Good luck!
 
Back
Top Bottom