CyCity Question

Vadus

pretend the impossible
Joined
Nov 23, 2003
Messages
374
Location
Northern Germany
Hi all,

I want to change the production of a city from script. (e.g. change from a Warrior-Production to Spearmen-Production )
Therefore I found the following methods of CyCity :

VOID setProduction(INT iNewValue)
not documented
VOID changeUnitProduction(UnitType iIndex, INT iChange)
adjusts production towards UnitID by iChange
VOID chooseProduction(UnitType eTrainUnit, BuildingType eConstructBuilding, ProjectType eCreateProject, BOOL bFinish)
Chooses production for a city

so, which one is the right method for that ?
And what for an integer value should I take as iNewValue resp. iChange ?
If the third method is the right one : what for a value do I have to take for eConstructBuilding and eCreateProject when I just want to choose a unit ( e.g. Spearmen ) ?? :hmm:
 
Vadus said:
Hi all,

I want to change the production of a city from script. (e.g. change from a Warrior-Production to Spearmen-Production )
Therefore I found the following methods of CyCity :

VOID setProduction(INT iNewValue)
not documented
VOID changeUnitProduction(UnitType iIndex, INT iChange)
adjusts production towards UnitID by iChange
VOID chooseProduction(UnitType eTrainUnit, BuildingType eConstructBuilding, ProjectType eCreateProject, BOOL bFinish)
Chooses production for a city

so, which one is the right method for that ?
And what for an integer value should I take as iNewValue resp. iChange ?

If the third method is the right one : what for a value do I have to take for eConstructBuilding and eCreateProject when I just want to choose a unit ( e.g. Spearmen ) ?? :hmm:

The frist two adjust the product amount (so changing from X amount of hammers) which isn't what you want. I haven't played with chooseProduction but I usually use a -1 for things like this when I don't want to pass any data in that variable.
 
Kael said:
The frist two adjust the product amount (so changing from X amount of hammers) which isn't what you want. I haven't played with chooseProduction but I usually use a -1 for things like this when I don't want to pass any data in that variable.
Hmm.. chooseProduction does nothing , whether True or False as bFinish..
I tried this line in a key-event, which works normally.
Code:
gc.getPlayer(0).getCity(0).chooseProduction(6, -1, -1, True)
This should change the production of the capital to a worker, but the only result I get is the sound, which appears normally when another player found a new religion. ( so this "event-sound" ... )
 
Vadus said:
Hmm.. chooseProduction does nothing , whether True or False as bFinish..
I tried this line in a key-event, which works normally.
Code:
gc.getPlayer(0).getCity(0).chooseProduction(6, -1, -1, True)
This should change the production of the capital to a worker, but the only result I get is the sound, which appears normally when another player found a new religion. ( so this "event-sound" ... )

Do you have debugging turned on, do you get an error?
 
yes , debugging is on. There is no error. (only, that unittype 6 is the indian worker, but this shouldn't matter )
now I tried
Code:
gc.getPlayer(0).getCity(0).changeUnitProduction(5, 0)
So, Nr 5 is the normal worker. But I don't know, what the iChange value should mean.. I guessed, this stands for a boolean switch, so that 0 is true and 1 is false. But also this line here does nothing :confused:

EDIT :
also
Code:
gc.getPlayer(0).getCity(0).changeUnitProduction(5, 1)
isn't working. No error, nothing
 
Vadus said:
yes , debugging is on. There is no error. (only, that unittype 6 is the indian worker, but this shouldn't matter )
now I tried
Code:
gc.getPlayer(0).getCity(0).changeUnitProduction(5, 0)
So, Nr 5 is the normal worker. But I don't know, what the iChange value should mean.. I guessed, this stands for a boolean switch, so that 0 is true and 1 is false. But also this line here does nothing :confused:

EDIT :
also
Code:
gc.getPlayer(0).getCity(0).changeUnitProduction(5, 1)
isn't working. No error, nothing

changeUnitProduction should just give you X credit toward that unit. It shouldn't switch your production to that unit. You know how you can earn credit toward techs and stuff even when you aren't researching them, this should be the same.

Let me play with the function a little bit and see what it does for me.
 
I have no idea what it does either. I did notice that their are 2 boolean functions on it, not one. But I dont know what the second one is. I got it to run without errors (just as you did), but like you it didn't seem to do anything.

I'll post back if I think of anything, but Im as confused as you are.
 
It looks like chooseProduction is the control on the popup window. I dont think you are going to be able to use it to control what the city is currently doing.
 
Kael said:
It looks like chooseProduction is the control on the popup window. I dont think you are going to be able to use it to control what the city is currently doing.
You mean, you don't think it's possible to change the city production ?
hmm.. maybe the
CyCity.doTask() - void (int eTaskTypes, int iData1, int iData2, bool bOption) - Enacts the TaskType passed
does something.. I will have to try much .. :sad:
 
I think you want to push an order on to the city's order queue:

Code:
VOID pushOrder(OrderType eOrder, INT iData1, INT iData2, BOOL bSave, BOOL bPop, BOOL bAppend)

Try something like (see CvWBDesc.py):

Code:
pushOrder(OrderTypes.ORDER_TRAIN, 5, -1, False, False, False)
 
Vadus said:
You mean, you don't think it's possible to change the city production ?
hmm.. maybe the
CyCity.doTask() - void (int eTaskTypes, int iData1, int iData2, bool bOption) - Enacts the TaskType passed
does something.. I will have to try much .. :sad:

I dont think that will work either.

The only way I can think to do this is to drop a building in the city that is checked for in cannotTrain, cannotConstruct, and cannotCreate that checks to see if the building is there. If it is it denies any build except the unit you want to make.

It not elegant, and its certainly not very versitile, but it should work. It should cancel the current production and offer human players a build list with only one unit on it.

Then of course in the unit creation you have it remove the building.
 
pushOrder does the trick. there are four boolean values. first is to set it to make it forever, like Alt-clicking on the unit's button. second boolean means to replace the current production. third is to put the new production on bottom of the queue. fourth is to force the production even if you can't normally make it. however, the AI checks this at the beginning of the next turn and may discontinue it if you cannot build it.
 
PeteT said:
I think you want to push an order on to the city's order queue:

Code:
VOID pushOrder(OrderType eOrder, INT iData1, INT iData2, BOOL bSave, BOOL bPop, BOOL bAppend)

Try something like (see CvWBDesc.py):

Code:
pushOrder(OrderTypes.ORDER_TRAIN, 5, -1, False, False, False)

It oooowns !! :goodjob:
But actually the interpreter requires a pushOrder(OrderType, INT, INT , BOOL, BOOL, BOOL, BOOL) ( so 4 instead of 3 bools ) though this method is documented here with 3 bools :hmm:
but anyway, it works with ... False, False, False, False ;)

EDIT: Oh, Chinese American told already ;)
 
Back
Top Bottom