customizing the granting of independence - a popup

antaine

King
Joined
Aug 1, 2005
Messages
737
Know how you can grant independence to a continent and spin off a new civ as long as the maximum number of civs are not already active?

Well, I'd like to script a Python popup that allows a human player to define a custom name/shortname/adjective (and leadername?) for the new civilization at the time you grant independence. I know you can change your own set of information using the Options menu, but it would be handy (especially on earth maps) to not have the Egyptian civilization becoming Australia or the Persians the new Canada. I'm not looking to force the use of a particular leader or civ, just to change the xml names.

Is this possible to do with Python? I'm imagining so, but I could be way off base...

conversely, is it possible to define areas and a custom name for each one (like any civ being granted independence on australia will be called australia, regardless of what civ it "really" is) using only Python? If it is, that may be simpler than the popup...I can just define five or six areas that are likely to happen (Australia, Brazil, Argentina, Mexico, Canada, etc).
 
As for the first question I haven't been able to find a CyPlayer.setName() method or anything like it in the API. There is supposedly a CvPlayer.setName() in the SDK, but that is of course C++ and not Python. In order to enable this for Python you'd have to "enable" this for Python which means that you have to compile a custom DLL file. (The boost Python is basically mirroring the SDK but doesn't have all the tools available.) I was actually doing something similar with Python just the other week and had to abandon it in the end.

For the second question pretty much anything that has to do with logic can be done in Python as in any other programming language. So you would definitely be able to, say, lookup which landmass something is located on. By, for example, checking the coordinates of the capital against some values. But, you still need to be able to change the Civ name dynamically and I don't think this can be achieved with anything found in the Python API.
 
that is indeed an accurate assessment of my predicament, save that I'm waiting for double-confirmation on the not being able to change the name thing. If that truly is the case, then you're right, I've just got to hang up that idea (because I'm doing my project without touching the dll).

What is the function that allows me to change my own name through the options?

Also, if I can figure out how to do this I can implement it for the dead-civ respawns (if they happen) so the Romans would become the Italians, the Celts would become the Irish, etc.
 
that is indeed an accurate assessment of my predicament, save that I'm waiting for double-confirmation on the not being able to change the name thing. If that truly is the case, then you're right, I've just got to hang up that idea (because I'm doing my project without touching the dll).
I would be very happy if this was possible...

What is the function that allows me to change my own name through the options?
I don't quite follow...

Also, if I can figure out how to do this I can implement it for the dead-civ respawns (if they happen) so the Romans would become the Italians, the Celts would become the Irish, etc.
This is pretty much exactly what I was trying to do myself, but unfortunately it wasn't gonna happen without a SDK mod. :p
 
I don't quite follow...


Well, the game already has a popup that allows you to edit your information at any time after the game has already started. I think it's MainMenu->Options->Edit My Info (or something like that)...I can change my leader name, as well as all the names associated with my civ.

So I figure that surely must be a python thing right there, no? If I can choose to do it during the game with a popup through the options menu, must I not be able to access that same feature with some python code and run it for an AI when independence is granted (I haven't looked to see what that's called in event manager yet)?
 
Ah, don't count on it though. It would have to be some undocumented stuff in the Python API in that case.

But lets just wait for confirmation from someone who knows. You would probably be able to find CvPlayer.setName() in the SDK and confirm that it isn't forwarded to Python. That would mean that the functionality isn't available with Python, making this a dead-end.
 
I'm thinking this is not possible in Python unless DLL changes are made to make it possible.

The reason is that a player, as in CvPlayer type object, has a civilization type that just says which CvCivilizationInfo it is using. The CvCivilizationInfo objects have various methods like "getAdjective()" but nothing like "setAdjective()" (in fact, the CyPlayer object has various civilization related getCivilizationSomethingOrOther() methods that would get them directly without having to get the CvCivilizationInfo in Python that needs them - I haven't checked but I expect that it is just looking up the info from the CvCivilizationInfo every time, not storing the data separately). The result is that from Python you can retrieve the information, but you can't set it.

Well, OK - there is a very slim chance that there may be one way to do it. If you were to go into all of the Python files that display information on the screen and change it from looking up the info the way it does now to getting the info from some list that you define instead (set to the original values and changed to user defined values via some popup at the appropriate time) then it might, in effect, do what you want. But it might not since there is a good chance that there are places the civilization name appears in text that is composed in the DLL instead of in Python and those places would use the original value. Having a player's civ's name change depending on where the text came from would be bad. If that does not actually ever happen and this did therefore happen to work, you'd have to save the new name data in the savegame file and load it when the file is read (probably via one of the various scriptdata locations), which is probably the easiest part of this whole operation.
 
Well, OK - there is a very slim chance that there may be one way to do it. If you were to go into all of the Python files that display information on the screen and change it from looking up the info the way it does now to getting the info from some list that you define instead (set to the original values and changed to user defined values via some popup at the appropriate time) then it might, in effect, do what you want. But it might not since there is a good chance that there are places the civilization name appears in text that is composed in the DLL instead of in Python and those places would use the original value. Having a player's civ's name change depending on where the text came from would be bad. If that does not actually ever happen and this did therefore happen to work, you'd have to save the new name data in the savegame file and load it when the file is read (probably via one of the various scriptdata locations), which is probably the easiest part of this whole operation.
Since the CyPlayer.setScriptData() method takes a string as the input value it would be easy enough to store all three forms in the form of a string, making pickling and other nonsense on save/load superfluous. (You'd probably wanna have a separator character of some sort, or simply rely on Capital letters for parsing the names.)

But you're probably right - it would be pretty messy, prone to errors and require a lot of work. Changing Civ names is a SDK job, as simple as that. Unless you supply a custom DLL that enables this functionality for Python, but that is of course a C++ hack.
 
Alright, but how does it allow a change when using the "Your Details" popup (just fired up the game, that's what it's called)? Surely it must store that somewhere in the savegame (I imagine it's the same basic mechanism that allows you to define custom values where you're starting the scenario).

Now, when I grant independence to someone, it always picks a dead civ from the scenario, but a random leader which wasn't in there to begin with. I can't seem to find the code where that's handled, either.

I'm not telling you you're wrong on any of your points, but if it's not being handled the way I think it is, I'm interested to know how it is being handled...
 
Boy was I slow. One post in the thread when I start, 6 when I post.
Yeah, both me and antaine have been updating every other minuter or so and more or less used this thread as a text chat. :lol:
 
Alright, but how does it allow a change when using the "Your Details" popup (just fired up the game, that's what it's called)? Surely it must store that somewhere in the savegame (I imagine it's the same basic mechanism that allows you to define custom values where you're starting the scenario).
If its not in the SDK it would be in the executable. I doubt that the Options menu is done in Python.

Now, when I grant independence to someone, it always picks a dead civ from the scenario, but a random leader which wasn't in there to begin with. I can't seem to find the code where that's handled, either.
Oh, leaders can be hand-picked and set with Python. (This happens in RFC also.) I think that the hard part would be to figure out how to run Python code on independence - is there such an event defined in the SDK?

But almost anything can be done - its just a matter of how complicated it has to get. Sometimes you really should edit the SDK instead of relying on Python.
 
I looked it up and the method is CyPlayer.setPersonalityType(). I believe RFC uses some outdated method for this, though, but obviously it works none-the-less.

But the problem is to detect when independence is declared, so that the method can be used. The simple approach would be to check CyPlayer.isAlive() on each game turn and set the desired leader. But this is far from optimal.
 
having an appropriately named leader would be icing, but having an appropriately named civ is the cake. Oh, well...mayhaps it's just too unwieldy for a minor cosmetic adjustment
 
I'd say that the ability to change the name(s) of a Civ/player is a missing feature in the Python API. It should be there - and it can be added.

But then again, there are other features missing also... Python simply isn't very good for modding the game. Its convenient for some stuff, like manipulating individual city/unit/plot objects, but not nearly powerful or complete enough to change the rules of the game (like how cities/units/plots work). If it can be done with Python, then it can also be done better, faster and more efficiently in the SDK. So learning C++ is definitely a priority of mine... :p
 
Back
Top Bottom