Advertisement
Civilization Fanatics' Center  

Welcome to Civilization Fanatics' Center.

You are currently viewing our site as a guest which gives you limited access to our site features. By joining our free community, you will be able to participate in the discussions, search the forum, send private messages, vote in polls, upload your own screenshots to the gallery, and access many other special features. Registration is fast, simple and absolutely free, so sign up today! If you have any problems with the registration process or your account login, please contact support.

Go Back   Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python

Notices

Reply
 
Thread Tools
Old Sep 01, 2009, 03:18 AM   #1
Chrill
Chieftain
 
Join Date: Aug 2002
Location: Sweden
Posts: 26
adding free buildings when settling

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)
__________________
... Enjoy ...
Chrill is offline   Reply With Quote
Old Sep 01, 2009, 07:05 AM   #2
Afforess
The White Wizard
 
Afforess's Avatar
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 10,652
Images: 8
The AI don't see nor understand python. You would need to modify their AI logic in the SDK.
__________________
"A Witty Saying Proves Nothing"
-Voltaire

Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75
Civilization 5 Mods: Active City Defense, Tech Diffusion
Minecraft Mods: Spout & Spoutcraft Lead Developer
Afforess is offline   Reply With Quote
Old Sep 01, 2009, 10:33 AM   #3
NotSoGood
Emperor
 
NotSoGood's Avatar
 
Join Date: Jan 2009
Location: Finland
Posts: 1,077
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?
__________________
1st Champion of the Somnium League!
19th and 20th Century mod Download
NotSoGood is offline   Reply With Quote
Old Sep 01, 2009, 10:35 AM   #4
Chrill
Chieftain
 
Join Date: Aug 2002
Location: Sweden
Posts: 26
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...
__________________
... Enjoy ...
Chrill is offline   Reply With Quote
Old Sep 01, 2009, 10:37 AM   #5
Afforess
The White Wizard
 
Afforess's Avatar
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 10,652
Images: 8
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.
__________________
"A Witty Saying Proves Nothing"
-Voltaire

Civilization 4 Mods: Rise of Mankind - A New Dawn 1.75
Civilization 5 Mods: Active City Defense, Tech Diffusion
Minecraft Mods: Spout & Spoutcraft Lead Developer
Afforess is offline   Reply With Quote
Old Sep 01, 2009, 10:45 AM   #6
Chrill
Chieftain
 
Join Date: Aug 2002
Location: Sweden
Posts: 26
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 ...
__________________
... Enjoy ...
Chrill is offline   Reply With Quote
Old Sep 01, 2009, 10:49 AM   #7
zyphyr
Prince
 
Join Date: Oct 2005
Posts: 461
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.
zyphyr is offline   Reply With Quote
Old Sep 01, 2009, 01:43 PM   #8
davidlallen
Deity
 
davidlallen's Avatar
 
Join Date: Apr 2008
Location: California
Posts: 4,728
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()
__________________
Come see the Fury Road sub-forum! Everybody wants post-apocalyptic desert warfare with crossbows!
davidlallen is offline   Reply With Quote
Old Sep 01, 2009, 03:54 PM   #9
The_J
Say No 2 Net Validations

 
The_J's Avatar
 
Join Date: Oct 2008
Location: Germany / Netherlands
Posts: 25,002
Images: 51
The code looks perfect .

How do you know, that the AI doesn't get the benefits?
__________________
Civ4-BtS-Mod "Mars, Now!"


Steam eats the souls of little gamers!!!
The_J is offline   Reply With Quote
Old Sep 03, 2009, 05:13 AM   #10
Chrill
Chieftain
 
Join Date: Aug 2002
Location: Sweden
Posts: 26
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.
__________________
... Enjoy ...
Chrill is offline   Reply With Quote
Old Sep 04, 2009, 12:12 PM   #11
Cybah
Emperor
 
Cybah's Avatar
 
Join Date: Jun 2007
Posts: 1,453
Quote:
Originally Posted by Chrill View Post
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.
Cybah is offline   Reply With Quote
Reply

Bookmarks

Go Back Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - SDK/Python > [PYTHON] adding free buildings when settling

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
FREE Settling Plan Empiremaker Team FREE 22 Mar 07, 2007 12:08 PM
Adding Buildings? Thasis Civ4 - Creation & Customization 5 Mar 15, 2006 05:42 PM
Adding Buildings Azmorg Civ3 - Creation & Customization 2 Jan 24, 2005 08:15 AM
Adding new buildings Red Threat Civ3 - Creation & Customization 4 Jun 21, 2004 08:38 PM
Adding buildings help MarineCorps Civ3 - Creation & Customization 48 Dec 05, 2003 06:59 PM


Advertisement

All times are GMT -6. The time now is 03:25 PM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
This site is copyright © Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR