Python - City Production Relocation

Lplate

Esus (Allegedly)
Joined
Feb 8, 2011
Messages
578
Location
Ireland
Hi,

I'm working on a spell which transfers population, food, certain completed buildings and also the current building production.

I have most of it working but can not get the current production to transfer across with everything else. Below is an example of what I've been trying in Python (without success):

Spoiler :

eCurrentB = pCity.getProductionBuilding()
iCurrentB = gc.getInfoForType(eCurrentB)
iCurrentBProd = pCity.getBuildingProduction()

pTargetCity.setBuildingProduction(iCurrentB, iCurrentBProd)



Should I be using getProduction() rather than getBuildingProduction()?
Any suggestions as to how I'd make this work?

yours,
LPlate
 
I wouldn't know about getProduction() vs getBuildingProduction(), but I do however believe that you've messed up the enum/ID for the building. Because CyCity.getProductionBuilding() returns the BuildingType you need for the CyCity.setBuildingProduction() method. While the CyGlobalContext.getInfoTypeForString() method wouldn't be valid if you pass it a non-string value as the parameter. So you skip that step and go:
Code:
pTargetCity.setBuildingProduction(pCity.getProductionBuilding(), pCity.getBuildingProduction())
 
First, your "getInfoForType" thing is useless. There is no such function. Presumably you meant gc.getInfoTypeForString or somethign along those lines. You don't need that either.

CyCity.getBuildingProduction takes an argument, specifically the type of building you are getting the production for (i.e. CyCity.getBuildingProduction(iBuilding)). Every city remembers how much it has spent on a building of each type, which is why you can change what you are building and then come back to what you were building and find that it already has the production you already spent on it. (Ditto for units. Probably projects too)

I'd try (give or take proper indentation):
Code:
if pCity.isProductionBuilding() : 
	# city is producing a building, if this test was false then it is not (it was a unit, project, or process (like culture))
	pTargetCity.setBuildingProduction(pCity.getProductionBuilding(), pCity.getProduction())

If you want to copy the complete list of stored amounts of production for buildings to a new city you can do that too. (Say, for example, the source city was half done with a forge when you switched to building an axeman due to an approaching barbarian being spotted so it is not currently producing a building but a unit instead, but there is a half built forge in the works.)

The code for that should look something like this:
Code:
for iBuilding in range(iNumBuildingTypes):
	pTargetCity.setBuildingProduction(iBuilding, pCity.getBuildingProduction(iBuilding))
 
Hi,

Sorted. Thank you both for your help.

LPlate
 
Back
Top Bottom