Making a moving city.

If the city is never in a "packed up" state, meaning each time it moves one tile the city is created anew with all the buildings, there's no reason to ever pickle its attributes.
 
My own suggestion was that the city would only reform if it was founded with a unit action. So it could be "packed up" for any amount of game turns.

But you are of course right: If the city always reforms once the unit moves one tile, then the data could be stored as a global variable or whatever. But if there is an opportunity for the game to be saved the data needs to be stored in a Cy instance of some sort. This could happen if the new city was formed after the player's turn or at the end of the game turn (autosave).

So it would be a matter of implementation then.

Just out of curiosity: How hard would it be to make something like a simplified CyCity class in the SDK? Because I've always wanted to have colonies as proto-cities - without population points, food bar, culture, only a few possible building classes, et cetera. Like a CyColony class, I guess.
 
baldyr said:
Yeah, you should only pickle onPreSave and unpickle onPreLoad (or whatever). The data needs to be stored somewhere in the meanwhile though.

You have come to a slightly wrong conclusion based on what I said. You should only pickle/unpickle very rarely. But it does not have to be limited to save,load functions. My suggestion is to use a string; but using a pickle is fine too. The key point is that you create the string or pickle the data only when the special settler unit is created. And you parse the string or unpickle the data only when the special settler is destroyed.
 
Just out of curiosity: How hard would it be to make something like a simplified CyCity class in the SDK? Because I've always wanted to have colonies as proto-cities - without population points, food bar, culture, only a few possible building classes, et cetera. Like a CyColony class, I guess.

This is possible without a new CvColony class (would be Cv, not Cy- Cy is the stuff exposed to Python). I think it's also pretty easy. You would add two booleans, one to CvCity and one to CvBuildingInfo. The one in CvCity declares a city as a colony, the one in CvBuildingInfo would be a new tag for buildings that declares a building buildable in a colony.

Then you would edit various CvCity functions and stop certain things from happening if the city is a colony.

I guess you would probably want a third boolean, in CvUnitInfo (new unit tag) that causes a city build by the unit to be a colony and not a city.


Although, I'm not seeing how this is relevant... :confused:
 
This is possible without a new CvColony class (would be Cv, not Cy- Cy is the stuff exposed to Python). I think it's also pretty easy. You would add two booleans, one to CvCity and one to CvBuildingInfo. The one in CvCity declares a city as a colony, the one in CvBuildingInfo would be a new tag for buildings that declares a building buildable in a colony.
Yeah, I used the wrong prefix. What exactly is Cv and Cy short for?

Although, I'm not seeing how this is relevant... :confused:
Its not.
 
That was actually my guess also. :D
 
So would the code start out like this?

getNumBuilding (BuildingType iIndex)
getNumGreatPeople ()
getPopulation ()



And then for when the build city order is given, would I do this?
getScriptData ()
isCapital ()


Or something like that?
 
Its good that you're looking in the API - its a start. But there is obviously quite a few things yet to learn.

Take another look at the API and lookup the methods you suggested. Each entry starts with a label of sorts - VOID methods are used to manipulate the class instance (like a CyCity instance - an actual city in the game), the other methods return something - BOOL methods returns a boolean value (True/False), INT methods return a integer value, STRING methods return a string value, and so on. Some methods return class instances, like CyCity (again).

Also, each of the methods you suggested has to be invoked on a class instance. So all methods belonging to the CyCity class has to be used with a CyCity instance. Classes and class instances are part of Object-Oriented Programming and it probably doesn't make much sense right now.

Class instances are regularly assigned to variables and these variables are normally given the "p" prefix (for "pointer" I guess). Variables that "point" to CyCity objects are usually called pCity - you might have seen examples of this in actual code. So if that is a CyCity reference - then you can invoke any method belonging to the CyCity class on it!
Code:
pCity.getNumBuilding()
pCity.getNumGreatPeople()
pCity.getPopulation()
pCity.getScriptData()
pCity.isCapital()
But note that pCity really has to point to a CyCity instance - actually the city that you wanna work with. Also, all the methods above return a value of some sort, so you probably wanna assign them to variables:
Code:
iNumBuiding = pCity.getNumBuilding()
iNumGreatPeople = pCity.getNumGreatPeople()
iPopulation = pCity.getPopulation()
scriptData = pCity.getScriptData()
bIsCapital = pCity.isCapital()
The best advice anyone could give you at this point is to learn as much Python as you can stomach. You'll need any and all you can get in order to do much of anything with programming. But once you do - the sky is the limit! :king:
 
For learning Python I have been recommending How to Think Like a Computer Scientist, a free online book that uses Python to teach beginning programming. This project of yours is pretty ambitious. It's not too complicated, but it is quite different from the other mods I've seen. As such you won't be able to modify existing code to do it, so you're best off learning some Python first. Take a weekend and go through what you can in the book, post some questions, and see where you land.
 
For learning Python I have been recommending How to Think Like a Computer Scientist, a free online book that uses Python to teach beginning programming. This project of yours is pretty ambitious. It's not too complicated, but it is quite different from the other mods I've seen. As such you won't be able to modify existing code to do it, so you're best off learning some Python first. Take a weekend and go through what you can in the book, post some questions, and see where you land.
Excellent advice, as always. :goodjob: I try to listen whenever the EmperorFool is handing out advice.

I can also vouch for the textbook mentioned - I learned all the things about Python that EmperorFool didn't teach me himself from it. :king: Its also available online in html.

But, the textbook will only teach you the Python language as such - it won't teach anything about modding. So that is the next phase then. But if you know your Python you could probably find my tutorial easy enough to follow. It goes into some detail on many of the things you wanna know for your project.
 
Top Bottom