[HELP PYTHON] Get & set City Production...

Fabrysse

Charming-snake learner
Joined
Sep 11, 2006
Messages
430
Location
Toulouse - France
Here is what I want to do :
  • Player1 is producting something in a city.
  • At a turn, via python, Player2 acquires the city. Just before this, the city was producting something, and the progression was "some int"...
  • If Player2 is Human, I want to put back the same production and the progression.

I've tried 2 ways (with 1 + 2 = 3 tries).


First method is something like that (when I saw that it doesn't work, I erased it : I try here to give you the idea) :
Code:
for pyCity in apCityList:
	pCity = pyCity.GetCy()
	#Get Production
	if(pCity.isProductionUnit ()):
		iProdUnit = pCity.getProductionUnit ()
		iProdBuilding = -1
		iProdProject = -1
		iProgressProd = pCity.getProduction ()
	elif(pCity.isProductionBuilding ()):
		iProdUnit = -1
		iProdBuilding = pCity.getProductionBuilding ()
		iProdProject = -1
		iProgressProd = pCity.getProduction ()
	elif(pCity.isProductionBuilding ()):
		iProdUnit = -1
		iProdBuilding = -1
		iProdProject = pCity.getProductionBuilding ()
		iProgressProd = pCity.getProduction ()
	else:
		iProdUnit = gc.getInfoTypeForString ("UNIT_INFANTRY")
		iProdBuilding = -1
		iProdProject = -1
		iProgressProd = 0

	newPlayer.acquireCity( pCity, False, False )
	#Here, I add some units in the city : not interesting here, so I cut.

	#Set Production
	pCity.chooseProduction (iProdUnit, iProdBuilding, iProdProject, False, True)
	pCity.setProduction (iProgressProd)
Result : no python error, but there is not any city producing something !!


Second method is exactly (first try) :
Code:
for pyCity in apCityList:
	pCity = pyCity.GetCy()
	#Get Production
	lOrder = []
	for iOrder in range (pCity.getOrderQueueLength() ):
		lOrder.append(pCity.getOrderFromQueue(iOrder))

	newPlayer.acquireCity( pCity, False, False )
	#Here, I add some units in the city : not interesting here, so I cut.

	#Set Production
	if(len(lOrder) > 0):
		for iOrder in range( len(lOrder) ):
			pCity.pushOrder (lOrder[iOrder].eOrderType, lOrder[iOrder].iData1, lOrder[iOrder].iData2, lOrder[iOrder].bSave, False, True, True)
Result : 2 cities are producing ManhattanProject, 1 is producing a Palace, all others product nothing !
Note that nobody was producing Manhattan Project or Palace before acquireCity()...


Second method again (second try) :
Code:
for pyCity in apCityList:
	pCity = pyCity.GetCy()
	#Get Production
	lOrder = []
	if(pCity.getOrderFromQueue(0)):
		lOrder.append(pCity.getOrderFromQueue(0))
	elif(pCity.getOrderFromQueue(1)):
		lOrder.append(pCity.getOrderFromQueue(1))

	newPlayer.acquireCity( pCity, False, False )
	#Here, I add some units in the city : not interesting here, so I cut.

	#Set Production
	if(len(lOrder) > 0):
		for iOrder in range( len(lOrder) ):
			pCity.pushOrder (lOrder[iOrder].eOrderType, lOrder[iOrder].iData1, lOrder[iOrder].iData2, lOrder[iOrder].bSave, True, True, True)
Result : several cities are producing Manhattan Project (about 50% of the cities), one is producing a Palace.
Note the same than previous.

:crazyeye:
PLEASE HEEEEEELP !!!!!
 
I've just scratching the surface with python, but I've done other languages and think I can help. You're creating a variable that is the same of the city. Then, you're changing the variable. You'd have to make the original the same as the duplicate, if it's like other situations that I've messed with.
 
newPlayer.acquireCity( pCity, False, False )
This line cause the game to delete the city. Then create a new one belonging to newPlayer. After that you try to change the production of the OLD city. But the old city is no more. Try finding the new city instead and changing the production of that one.
 
newPlayer.acquireCity( pCity, False, False )
This line cause the game to delete the city. Then create a new one belonging to newPlayer. After that you try to change the production of the OLD city. But the old city is no more. Try finding the new city instead and changing the production of that one.

Yes, but before this line, I have stored the production.
1- I get old production
2- I give city to new player
3- I put back the production
Isn't it good ? I can't understand...
 
Yes, but before this line, I have stored the production.
1- I get old production
2- I give city to new player
3- I put back the production
Isn't it good ? I can't understand...
The problem is #3. You are putting the production back in the old city. But the game deleted the old city. You have to put it in the NEW city. pCity and the city belonging to newPlayer are two completly different cities.
 
Back
Top Bottom