adding free buildings when settling

Chrill

Chieftain
Joined
Aug 19, 2002
Messages
26
Location
Sweden
so i made alittle python function to automatically add buildings to newly founded cities depending on some prereqs... It works perfectly fine for human players, however AI players doesn't seem to get the benefit of this ... And I'm kindow clueless to why... Any help would be appreciated!

here's how the code looks like under: OnCityBuilt in CvEventManager

Code:
# SETTLERS EXTRA STUFF XUUL! ##
		pPlayer = gc.getPlayer(city.getOwner())
		iTeam = gc.getTeam(pPlayer.getTeam())
		if iTeam.isHasTech(gc.getInfoTypeForString('TECH_CARTHOGRAPHY'))  == true:
			city.setNumRealBuilding(gc.getInfoTypeForString("BUILDING_MILITARY_ENCAMPMENT"), 1)
			if (pPlayer.getCivilizationType() == gc.getInfoTypeForString("CIVILIZATION_INCA")):
				city.setNumRealBuilding(gc.getInfoTypeForString("BUILDING_INCAN_TERRACE"), 1)
			elif (pPlayer.getCivilizationType() != gc.getInfoTypeForString("CIVILIZATION_INCA")):
				city.setNumRealBuilding(gc.getInfoTypeForString("BUILDING_GRANARY"), 1)
 
The AI don't see nor understand python. You would need to modify their AI logic in the SDK.
 
Well I'm not actually very familliar with python, but as far as know your code is like:
Code:
When you settle and you have receive tech A and if you are Inca you receive building B but if you aren't Inca then you receive building C.
I don't see any reason why there have to mod AI. OR then I have misunderstood something. Chrill, how do you know that the AI doesn't receive the buildings?
 
it's not the logic that is flawed, it is that the function doesn't seem to affect the computer players at all.

I.e. a human player settles and get buildings under the right conditions. The AI player under same condition do not get this effect, and I cannot figure out why at all, but my asumption is that is to have something to do with how 'city' is referenced...

I've also enabled AIautoplay as in the BetterBTSAi 0.80 but after some testing it doesn't seem to be what is interfering...
 
Take a look at Rise of Mankind. They have some python code in there for colonists and pioneers, which give free buildings to starting cities.
 
I've already looked the RoM code over and so, however there's nothing there that tells me what wouln't make my code work ;( i just find it really strange that the code under OnCityBuilt only affect a human player... Again I'm a python amateur so ...
 
This doesn't actually address your existing issue, but that elif really should just be an else - you would get the same results with faster execution time.

Anyway, I would suggest sticking some debugging output in/around your code.
Have it dump something to a log just before the test ("CityName founded, checking techs for free buildings")
Then after the test ("TechX found, adding buildings")
Then if a building is added ("BuildingX added")
and once you are done ("All checks completed")

From that you should be able to find out how far into the process it is going and work from there to figure out why it is failing.
 
Perhaps this typo is not in the actual code but you have "CARTHOGRAPHY" as a tech. As zyphyr has suggested, load up the code with print statements till you see the problem. I usually have a local function like:
Code:
def mydebug(s):
   f = open ("c:\\mylog.txt", "a")
   f.write(s)
   f.close()
 
After alot of fix trixing i got it to work. I loaded up the code in a new mod and the code worked, so i asumed there was some other interfering code...

It appeared that the AIAutoPlay function that came with BetterBTSAi interfered with this code, in a way that it affected all computer players (all players under AI control).

So i removed all instances of OnCityBuilt in AIAutoPlay.py and now my whole code works. The only drawback afaik is under AiAutoPlay a popup comes up when a new city is founded, which isn't that significant. Otherwise everything appears to work.
 
it's not the logic that is flawed, it is that the function doesn't seem to affect the computer players at all.

I.e. a human player settles and get buildings under the right conditions. The AI player under same condition do not get this effect, and I cannot figure out why at all, but my asumption is that is to have something to do with how 'city' is referenced...

I've also enabled AIautoplay as in the BetterBTSAi 0.80 but after some testing it doesn't seem to be what is interfering...


You have to modify AIAutoplay.py. That's all. Do not do anything else. Cut the code and paste it in AIAutoplay.py. This file has an onCityBuilt event.


//edit: Did not read your last posting. ;)
 
Back
Top Bottom