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 - Project & Mod Development > Civ4 - Fall from Heaven > FfH2 Modmods, Scenarios, and Maps

Notices

Reply
 
Thread Tools
Old Jun 07, 2009, 04:38 PM   #1
Turinturambar
Prince
 
Join Date: Dec 2005
Posts: 368
Better economic AI (V. 0.7 updated!)

This mod fixes most of the bad AI economic behavior by forcing them to make good decisions. It consists 4 updated files: CvGameUtils.py, CvSpellInterface.py, CIV4SpellInfos.xml and PythonCallBackDefines.xml .

Installation Instructions: Simply unzip the zip file into your beyond the sword/mods folder. If you have modified your game, you should make a backup copy of your CvGameUtils.py, CvSpellInterface.py, CIV4SpellInfos.xml and your PythonCallBackDefines.xml files first.

The mod is compatible with FFH2 patch 041g and earlier.

Suggested settings:
For best AI performance I recommend playing with aggressive AI, no Acheron and a Continents-, Lakes- or Pangeae- style map.

Features:
AI will efficiently spend its available hammers.
AI will research Religion Founding techs if appropriate/worthwile.
AI will optimally research worker techs in the early game.
AI will use efficient civics/ is fully capable of running an aristocracy economy.
AI will be forced to research midgame economic techs when appropriate.
AI will no longer build forts or build workshops.
AI will build a sufficient amount of warriors to defend itself in the very early game.
AI will not suffer an economic crash anymore.
AI will intelligently use advanced religion beelines to late game heroes.
AI will be better able to capture cities
AI will better use unique buildings ( Warrens and Governors Manors in particular)
Luchuirp tech and build AI improved (hello fireball spamming golems)
AI will build mana nodes somewhat intelligently

New in 0.7
AI world spell casting improved
AI will somewhat adjust its research/production decisions if they are at war.
AI can now cast most spells properly, most notably: Crew promotions, feasting, Pirate Coves
AI research decisions greatly improved
AI production improved, AI will now build heroes and wonders very quickly.
AI military production improved, AI will now build one tier2 enabling building in each city
AI will build appropriate numbers of adepts (depending on available spells and traits)
AI worker building tweaked, AI improves its land now very quickly.
AI will aggressively spread and adopt religions of which it has the holy city

Civ specific:
Illian AI understands when to build their temple of the hand
Kuriotates AI will not build settlers after they have reached their max number of allowed cities, drastically improving their AI.

It should be easy to use the changes for other mods as I have only modified the following functions in CvGameUtils.py:

1. canbuild
2. cannotResearch
3. cannotDoCivic
4. cannotTrain
5. cannotConstruct
6. cannotCreate
7. AI_chooseTech
8. AI_chooseProduction (new in 0.6)

The changes to the Spellfiles should be easily findable with winmerge. The main part of the mod is in CvGameutils.py anyway.
Of course I also needed to activate the canbuild and cannotDoCivic functions in PythonCallBackDefines.xml.


How much do these changes improve the AI? Check out this screenshots of a Pangeae noble game with aggressive AI, all unique features and no Acheron enabled:

Without Changes:
Spoiler:



With Changes:
Spoiler:



Note the religious diversity (Sandolphon follows Esus), the rather scary Calabim stack and the scores of the top3 civs.
Attached Files
File Type: zip Better Economic AI 07.zip (58.5 KB, 184 views)

Last edited by Turinturambar; Sep 12, 2009 at 08:39 AM. Reason: Updated!
Turinturambar is offline   Reply With Quote
Old Jun 07, 2009, 06:29 PM   #2
cyther
Lord of the Dance
 
cyther's Avatar
 
Join Date: Jun 2008
Location: Fane of Lessers
Posts: 1,033
I just tested out a game and the AI looks pretty good. Could I use this in Rise of Darkness?
__________________
Rise of Darkness Plus Ruins of Amur: A Dungeon Adventure
Member: Fallen Ages - A Journey through the Ages
FFH (Download) (Forum) (Wiki)

"*Applause.* Aye, there you go! The floor is yours! Please, don't hurt anyone. Too much. Unless it'd be funny."-KillerClowns
cyther is offline   Reply With Quote
Old Jun 08, 2009, 12:46 AM   #3
Turinturambar
Prince
 
Join Date: Dec 2005
Posts: 368
Sure!
I just looked over the changelog for your mod and I couldn't see any compatibilty issues with the changes I made.
Turinturambar is offline   Reply With Quote
Old Jun 08, 2009, 01:54 AM   #4
[to_xp]Gekko
WM junkie
 
[to_xp]Gekko's Avatar
 
Join Date: Dec 2005
Location: Seyda Neen, Vvardenfell
Posts: 7,090
awesome!
__________________
" Sheelba does what Charadon't " - Senethro
[to_xp]Gekko is offline   Reply With Quote
Old Jun 08, 2009, 03:12 AM   #5
Skyre Noktis
Warlord
 
Skyre Noktis's Avatar
 
Join Date: Apr 2009
Posts: 271
Extremely good work, especially as I was going to be looking at this next (early worker techs in particular) and was trying to figure out a good way to do it. Looks like your results are rather impressive (though it would be nice to be able to see the leaders' scores on the right hand side).
Skyre Noktis is offline   Reply With Quote
Old Jun 08, 2009, 05:04 AM   #6
Senethro
Overlord
 
Senethro's Avatar
 
Join Date: Mar 2007
Location: The cutest of cephalopods
Posts: 1,726
Monarch, Normal Speed, turn 200:
Top 3 are Beeri Bawl: 1350
Decius of Bannor: 925
Ethne: 800

They're so good at getting gold I would suggest making a custom difficulty level which has raised unit maintenance and unit upgrade costs (i.e. 50% instead of 25%) just to soak up some of their excess.
Senethro is offline   Reply With Quote
Old Jun 08, 2009, 05:48 AM   #7
Skyre Noktis
Warlord
 
Skyre Noktis's Avatar
 
Join Date: Apr 2009
Posts: 271
A minor criticism:

Code:
if eBonus == gc.getInfoTypeForString('BONUS_GOLD'):
	imining = imining +1
if eBonus == gc.getInfoTypeForString('BONUS_GEMS') :
	imining = imining +1
if eBonus == gc.getInfoTypeForString('BONUS_DYE') :
	icalendar = icalendar +1
if eBonus == gc.getInfoTypeForString('BONUS_INCENSE') :
	icalendar = icalendar +1
Why are only dye and incense considered for calendar resources? Why not cotton, for example? This seems somewhat limited. Also, if you have wine in your initial fat cross, there's no real need to rush for either tech for the commerce benefits.

You're also not taking into account whether the bonus is blocked by a terrain feature. If you're not an elven civ and you have a calendar resource in a forest, you'll need mining first regardless. If the resource is in a jungle square (common with both dyes and gems), you'll need bronze working before it's useful.
Skyre Noktis is offline   Reply With Quote
Old Jun 08, 2009, 06:07 AM   #8
Turinturambar
Prince
 
Join Date: Dec 2005
Posts: 368
Quote:
Originally Posted by Skyre Noktis View Post
A minor criticism:

Code:
if eBonus == gc.getInfoTypeForString('BONUS_GOLD'):
	imining = imining +1
if eBonus == gc.getInfoTypeForString('BONUS_GEMS') :
	imining = imining +1
if eBonus == gc.getInfoTypeForString('BONUS_DYE') :
	icalendar = icalendar +1
if eBonus == gc.getInfoTypeForString('BONUS_INCENSE') :
	icalendar = icalendar +1
Why are only dye and incense considered for calendar resources? Why not cotton, for example? This seems somewhat limited. Also, if you have wine in your initial fat cross, there's no real need to rush for either tech for the commerce benefits.

You're also not taking into account whether the bonus is blocked by a terrain feature. If you're not an elven civ and you have a calendar resource in a forest, you'll need mining first regardless. If the resource is in a jungle square (common with both dyes and gems), you'll need bronze working before it's useful.
Only Incense and Dye are included because the others are either marginal (Cotton) or
covered by Forest (Silk). Elven civs default to researching calendar before mining anyway (unless gold/gems are present).

Since the code only checks for the Capital and the Capital gets dejunglified in standard mapscripts I don't need to check for features.

Wine is also only a marginal resource commercewise. +2 commerce does not make a noticeable difference, however I could see that beelining crafting could be sensible for 2+ wine. However crafting is forced very early anyway in the mining beeline, so it's not as if it goes unimproved for long.

Edit: Come to think of it beelining Crafting makes sense as both a food and a commerce tech, so I will include a check for wine resources and force it as first tech if there are 2+ wine resources.

Last edited by Turinturambar; Jun 08, 2009 at 06:23 AM.
Turinturambar is offline   Reply With Quote
Old Jun 08, 2009, 06:57 AM   #9
Opera
Deity
 
Opera's Avatar
 
Join Date: Sep 2008
Posts: 4,284
Very interesting changes. I'm eager to start a game with those
(as Cyther, I may end up using them in my own modmod... which, being Orbis, will need a bit of tweak; I hope you wouldn't mind?)
Opera is offline   Reply With Quote
Old Jun 08, 2009, 07:56 AM   #10
Skyre Noktis
Warlord
 
Skyre Noktis's Avatar
 
Join Date: Apr 2009
Posts: 271
Quote:
Originally Posted by Turinturambar View Post
Only Incense and Dye are included because the others are either marginal (Cotton) or
covered by Forest (Silk). Elven civs default to researching calendar before mining anyway (unless gold/gems are present).
Why is cotton marginal? If there's only one, I agree that it's going to be relatively low priority, but they often come in clumps, in my experience, and it's worth getting hooked up if there are two or three near your capital. Provided you have a decent food supply, the +1 happiness can be extremely useful as well.

Also, from a brief look at your code, only the Ljosalfar are hardcoded to pick calendar over mining, not the Svarts (unless I'm missing something obvious).

Quote:
Since the code only checks for the Capital and the Capital gets dejunglified in standard mapscripts I don't need to check for features.
Isn't it possible for the AI to move its initial settler in FfH? I'm sure I've seen it do that, so there's an outside chance of jungle in the fat cross, although it's probably not too likely on most maps.

Quote:
Wine is also only a marginal resource commercewise. +2 commerce does not make a noticeable difference, however I could see that beelining crafting could be sensible for 2+ wine. However crafting is forced very early anyway in the mining beeline, so it's not as if it goes unimproved for long.
The low commerce bonus is offset by the fact that crafting is so cheap and that it also gives a food bonus. And almost any resource is worth it if there's at least two of them.

Quote:
Edit: Come to think of it beelining Crafting makes sense as both a food and a commerce tech, so I will include a check for wine resources and force it as first tech if there are 2+ wine resources.
This sounds sensible.
Skyre Noktis is offline   Reply With Quote
Old Jun 08, 2009, 10:11 AM   #11
Turinturambar
Prince
 
Join Date: Dec 2005
Posts: 368
Quote:
Originally Posted by Opera View Post
Very interesting changes. I'm eager to start a game with those
(as Cyther, I may end up using them in my own modmod... which, being Orbis, will need a bit of tweak; I hope you wouldn't mind?)
Sure go ahead and only take the parts you like/modify it to your hearts content.

Quote:
Originally Posted by Skyre Noktis View Post
Why is cotton marginal? If there's only one, I agree that it's going to be relatively low priority, but they often come in clumps, in my experience, and it's worth getting hooked up if there are two or three near your capital. Provided you have a decent food supply, the +1 happiness can be extremely useful as well.
It gets hooked up rather early anyway, calendar is one of the first techs regardless of resources since it unlocks festivals and the agrarianism civic. The only decision is whether to go for mining or claendar first. An improved cotton only adds 2 commerce to the tile. Compare this to a mine on a standard hill, which adds +2 hammers and possible chop boni.

If you farm the cotton resources before aquiring calendar and chop forests/build mines earlier, you will have get your settlers/warriors/workers out faster and work more and better tiles than 2/0/3 cottons.

Quote:
Originally Posted by Skyre Noktis View Post
Also, from a brief look at your code, only the Ljosalfar are hardcoded to pick calendar over mining, not the Svarts (unless I'm missing something obvious).
Good catch, I must have forgotten to include them.

Quote:
Originally Posted by Skyre Noktis View Post
Isn't it possible for the AI to move its initial settler in FfH? I'm sure I've seen it do that, so there's an outside chance of jungle in the fat cross, although it's probably not too likely on most maps.
I have never seen this and I think I read somewhere that the AI is hardcoded to settle its first city immediately. Regardless it would be such a rare case and would not have especially bad consequences if it happens that I don't think adding more checks is sensible.
Turinturambar is offline   Reply With Quote
Old Jun 08, 2009, 10:23 AM   #12
Quetz
The Tallest Lilliputian
 
Quetz's Avatar
 
Join Date: Aug 2006
Location: Heavensent
Posts: 650
I see no improvement in Life Expectancy with these changes! Useless!

I mean, great work XD

Going to dump this into an FFPlus install and see what happens.
__________________
“Let the future tell the truth, and evaluate each one according to his work and accomplishments. The present is theirs; the future, for which I have really worked, is mine.” - A very ironic statement by Nikola Tesla, the real inventor of electricity!

"In war, truth must always be accompanied by a bodyguard of lies." -- Winston Churchill

Last edited by Quetz; Jun 08, 2009 at 10:26 AM.
Quetz is offline   Reply With Quote
Old Jun 08, 2009, 11:09 AM   #13
Skyre Noktis
Warlord
 
Skyre Noktis's Avatar
 
Join Date: Apr 2009
Posts: 271
Quote:
Originally Posted by Turinturambar View Post
I have never seen this and I think I read somewhere that the AI is hardcoded to settle its first city immediately. Regardless it would be such a rare case and would not have especially bad consequences if it happens that I don't think adding more checks is sensible.
Agreed it's an edge case. Just to clear this up, though, I've seen the AI move its initial settler quite often, although it always settles on the first turn.
Skyre Noktis is offline   Reply With Quote
Old Jun 08, 2009, 12:08 PM   #14
Opera
Deity
 
Opera's Avatar
 
Join Date: Sep 2008
Posts: 4,284
Can I suggest that you comment your changes? It's a bit hard to see what's part of vanilla and what's yours. Of course, using WinMerge, for example, is useful but... commenting is handy too
Opera is offline   Reply With Quote
Old Jun 08, 2009, 12:30 PM   #15
Opera
Deity
 
Opera's Avatar
 
Join Date: Sep 2008
Posts: 4,284
Line 303: SHEIAM instead of SHEAIM
In fact, it seems you did this mistake more than once... I begin to doubt it's a mistake, now...

Why only prevent some civs to build disciples? I mean, if you have a religion Holy City, even though you're not Sheaim, Bannor or whatever, you should spread it, no?

Okay, done reading thoroughly your code. Really interesting things in it. It will be a bit tricky to adapt it to Orbis but I'll do it.

Congratulations for that, you thought of many things
Opera is offline   Reply With Quote
Old Jun 08, 2009, 01:24 PM   #16
Turinturambar
Prince
 
Join Date: Dec 2005
Posts: 368
Quote:
Originally Posted by Opera View Post
Line 303: SHEIAM instead of SHEAIM
In fact, it seems you did this mistake more than once... I begin to doubt it's a mistake, now...
Why only prevent some civs to build disciples? I mean, if you have a religion Holy City, even though you're not Sheaim, Bannor or whatever, you should spread it, no?
Hah I just noticed that that part of the code is still messed up. Thanks for pointing it out.

I wanted to make it so that only civs with the Holy cities or the civs which are attuned to the religion build disciples, so that everyone else doesn't waste hammers. In addition this should slow down the spread of religions, leading to more diversity.

Corrected Code looks like this:
Code:
if eUnitClass == gc.getInfoTypeForString('UNITCLASS_DISCIPLE_THE_ASHEN_VEIL'):
				if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_DISCIPLE_THE_ASHEN_VEIL')) > 3:
					return True
				if pPlayer.hasHolyCity(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL')) == False :
					if not pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SHEAIM') :
						return True

Last edited by Turinturambar; Jun 08, 2009 at 01:29 PM.
Turinturambar is offline   Reply With Quote
Old Jun 08, 2009, 01:35 PM   #17
Opera
Deity
 
Opera's Avatar
 
Join Date: Sep 2008
Posts: 4,284
Oh, right. So you want that no civ (apart from attuned ones and holy-city ones) manually spread religions? That's interesting. I remember this, manual spreading through disciples, being a huge factor in non-religiously-diverse games. Thanks for explaining that

By the way, it's really hard to import this to a modmod which change many techs Cartography is much less valuable in Orbis (it's Writing that leads to Open Borders) and Exploration just doesn't exists!
Opera is offline   Reply With Quote
Old Jun 09, 2009, 04:32 AM   #18
Opera
Deity
 
Opera's Avatar
 
Join Date: Sep 2008
Posts: 4,284
I've been tweaking your religions check in AI_chooseReligion and came up with that:
Code:
		####-----###
		## Religion beelines
		####-----###
		iLeader = gc.getLeaderHeadInfo(pPlayer.getLeaderType())
		iFlavor = ileader.getFlavorValue(gc.getInfoTypeForString('FLAVOR_RELIGION'))
		iFoL = gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES')
		
		## FoL
		if iLeader.getReligionWeightModifier(iFoL) >= 0:
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_MYSTICISM')) \
			or eTeam.isHasTech(gc.getInfoTypeForString('TECH_TRACKING')) \
			or pPlayer.getNumCities() > 3:
				iDiceFoL = CyGame().getSorenRandNum(100, "FoL")
				if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR'):
					iDiceFoL += 30
				if iLeader.getFavoriteReligion() == iFoL:
					iDiceFoL += 30
				if iFlavor != 0:
					iDiceFoL += iFlavor
				if iDiceFoL <= iLeader.getReligionWeightModifier(iFoL):
					iTech = gc.getInfoTypeForString('TECH_WAY_OF_THE_FORESTS')
I tried doing something flexible, so you have bonus for things like being Ljos or having a high religion flavor, you're not just given the possibility of founding the religion only if you are Ljos. Not sure if it's worth it, though...
Opera is offline   Reply With Quote
Old Jun 09, 2009, 02:48 PM   #19
Turinturambar
Prince
 
Join Date: Dec 2005
Posts: 368
I really like how religionfounding turned out in my mod. All civs have the possibility of founding religions, not just the attuned ones. In fact they regularly get beaten, but will still research the appropriate techs.

It works like this:
If the AI has researched the proper economic techs for its current economic situation and has researched Mysticism (Philosophy for the advanced religions) and has established initial settling (>= 3 cities), the AI will beeline one of the early religions under the following conditions:
1) It does not have a holy city already (doing so under these circumstances would be wasteful and would lead to less religious diversity)
2) The religion has not been founded yet. (again to promote diversity)
3) The civ is not attuned to a specific religion (e. g. the Sheaim don't waste their research on chasing octopus overlords, because they will research Ashen Veil later on anyway.)
4) The civ rolls a 5 or 6 on a six-sided die. (This ensures that different religions get chased by the nonattuned civs,leading to more efficiency and diversity)
5) The alignment fits, meaning no civ will research a religion that shifts it alignment by 2 steps (from good to evil or vice versa) or shifts the alignment to neutral.

Each religion has one civ that is attuned to it for flavour/gameplay reasons. Those civs can research the other religious techs, but they are never forced to do so. Once they pass the requirements for their preferred religion they will beeline it.

Adding religious flavours to the random roll could be desirable, but I'm not sure if it will have a noticeable effect.
Turinturambar is offline   Reply With Quote
Old Jun 09, 2009, 04:50 PM   #20
UNIT 666
One of Many
 
UNIT 666's Avatar
 
Join Date: Mar 2008
Location: Classified.
Posts: 340
I've just gotta say, Turin, you've done a GREAT job with this AI mod! Now I can finally get better at Civ while still staying at Noble difficulty!

Thank you, Turin!
UNIT 666 is offline   Reply With Quote
Reply

Bookmarks

Tags
ai improvement, ffh2, mod

Go Back Civilization Fanatics' Forums > CIVILIZATION IV > Civ4 - Creation & Customization > Civ4 - Project & Mod Development > Civ4 - Fall from Heaven > FfH2 Modmods, Scenarios, and Maps > Better economic AI (V. 0.5)

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
AI commits economic suicide Thalassicus Civ4 - Bug Reports 1 Aug 13, 2007 09:21 PM
What's going to be the fifth economic civic? kolpo Civ4 - General Discussions 35 Oct 21, 2005 06:27 PM
Economic Victory? DrMadd Civ - Ideas & Suggestions 20 Oct 19, 2005 05:56 AM
Economic Systems Teabeard Civ - Ideas & Suggestions 5 Oct 28, 2004 06:18 PM
The Economic Miracle blitzy Civ2 - Strategy & Tips 12 Nov 14, 2000 08:28 AM


Advertisement

All times are GMT -6. The time now is 06:28 AM.


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