| General | Hosted Sites | Civ5 | CivRev | Civ4Col | Civ4 | Civ3 | Civ2 | Civ1 | Misc | Marketplace |
![]() |
|
|
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. |
|
|||||||
![]() |
|
|
Thread Tools |
|
|
#1 |
|
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 ... |
|
|
|
|
|
#2 |
|
The White Wizard
|
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 |
|
|
|
|
|
#3 |
|
Emperor
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.
__________________
|
|
|
|
|
|
#4 |
|
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 ... |
|
|
|
|
|
#5 |
|
The White Wizard
|
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 |
|
|
|
|
|
#6 |
|
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 ... |
|
|
|
|
|
#7 |
|
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. |
|
|
|
|
|
#8 |
|
Deity
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! |
|
|
|
|
|
#9 |
|
Say No 2 Net Validations
![]() ![]() |
The code looks perfect
.How do you know, that the AI doesn't get the benefits? |
|
|
|
|
|
#10 |
|
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 ... |
|
|
|
|
|
#11 | |
|
Emperor
Join Date: Jun 2007
Posts: 1,453
|
Quote:
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.
|
|
|
|
|
![]() |
| Bookmarks |
|
| Thread Tools | |
|
|
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 |