Can someone help with this python issue

Martin Curwen

Chieftain
Joined
Jan 26, 2008
Messages
5
Hi can someone tell me how to do this..

i need to search the players cities one by one and find out how many defenders there is.

if it comes to a city that has over 6 defenders i want to to give me the unit id of one of them at random.

hope someon can help as im a bit of a noob trying to learn as i go

im trying to build on the Mercenaries Mod to get the computer to contract out units it doesnt need if it needs the money as id like to get rid of the randomly gen ones and just have computer player contracted units that way ud be able to buy UU from other civs that arnt random generated barb units.
 
I don't know if you need to loop all players too. I assume that.
I try to write the code right here... there COULD be errors!! I hope not!! :)

Code:
[INDENT]
for i in range(gc.getMAX_CIV_PLAYERS()):
[INDENT]
if gc.getPlayer(i).isAlive and not gc.getPlayer(i).isBarbarian():
[INDENT]
(loopCity,iter)=gc.getPlayer(i).firstCity(false)
while(loopCity):
[INDENT]
if loopCity.plot().getNumUnits()>6:
[INDENT]
rnd = gc.getGame().getSorenRandomNumber(loopCity.plot().getNumUnits(),"Pick unit")
return loopCity.plot().getUnitByIndex(rnd)
[/INDENT]
(loopCity,iter)=gc.getPlayer(i).nextCity(iter,false)
[/INDENT]
[/INDENT]
[/INDENT]
[/INDENT]
 
Back
Top Bottom