FfH2 AI Mod (Highly Experimental!)

Skyre Noktis

Warlord
Joined
Apr 28, 2009
Messages
271
Download Links

Fall from Heaven 2 Better AI v0.3.1 (for BTS v3.17/FfH2 v0.41a)

Fall from Heaven 2 Better AI v0.3.1 (for BTS v3.19/FfH2 v0.41b) - Coming soon!

Installation

1. Create a copy of your Fall from Heaven 2 folder.

2. Overwrite the following files and folders with files from the ZIP archive:
- Assets/python (folder)
- Assets/XML (folder)
- Assets/CvGameCoreDLL.dll (file)

3. Load up the mod from within BTS or using a shortcut

Change Log

v0.3.1 (21st June 2009)

- Bug Fix: Barbarian AI will no longer declare nationality on its animal units (caused animals to appear to be at peace with Barbarian trait leaders)
- Barbarian trait explorers will seek out graveyards (they can still be robbed when at peace with barbs)

v0.3 (19th June 2009)

- Merged many of Turinturambar's AI changes for better tech, building and civic (Aristocracy!) handling
- Refined AI religious behaviour - AI players with high religion weights but favour later religions will no longer rush Runes/FoL
- AI civs will beeline Sailing if they run out of space to expand on their current landmass (common on tiny island maps)
- AI will do its best to avoid Minister Koun splits (they only harm it)
- Revised algorithm for determining city specialisation (i.e. commerce/production)
- Workers will build over old improvements to connect bonus tiles (though at a lower priority than 'bare' tiles)
- AI civs don't attempt to pick new techs while research is disabled due to Stasis (this could previously lead to some strange decisions)
- Improved worker/work boat build order logic for seafood starts
- Merged Xienwolf's Fall Further fix, allowing Hidden Nationality units to group
- Trade weight modifiers from mana bonuses removed - they're no longer considered ridiculously valuable by the AI
- AI units will attempt to seek out any dropped equipment within their immediate vicinity
- Barbarian AI: Barbarians can no longer trigger Seven Pines and make peace with everyone
- Calabim AI: Vampires will feast on unhappy citizens
- Illian AI: Temples of the Hand now better prioritised in city build queues (considered as food-producing buildings)
- Infernal AI: Hyborem will no longer adopt Agrarianism
- Khazad AI: Reworked economic AI and tech priorities
- Khazad AI: AI no longer spends all its vault money when running civics that allow rush-buying
- Kuriotate AI: Improvements no longer built for settlements on non-bonus tiles (saves on worker time + time spent producing workers in core cities)
- Lanun AI: AI builds Pirate Coves in its coastal cities
- Luchuirp AI: AI protects Mud Golems as it would regular workers, instead of regarding them as combat units (which resulted in a lot of deaths to barbarians, etc.)
- Luchuirp AI: Garrim and Beeri now favour melee units (more Sculptor's Studios and Golems)
- Bug Fix: Typos in reqKidnap fixed (no longer throws Python exception when Svartalfar try to kidnap someone)
- Various other minor tweaks and modifications

Older changes:
Spoiler :
v0.2.2 (8th June 2009, updated 10th June 2009) - [Requires FfH2 v0.41 or v0.41a]

- AI players will now seek out and explore lairs and other important landmarks
- AI players won't build rituals unless certain preconditions are met (varies for each one)
- Adaptive players pick their trait based on the current game state
- Slightly altered city placement algorithm in early game to ensure AI still settles new cities on maps with less than ideal terrain
- Calabim value Governor's Manor as a production building (not just maintenance/Vampire prereq.)
- Fixed a bug in area power calculations (it was using the base XML value, not the modified value taking into account promotions, etc.)

v0.2.1 (30th May 2009) - [Requires FfH2 v0.41 or v0.41a]

- HIGH PRIORITY: Fixed bug introduced by AI Autoplay mod that stopped certain (quite important) events from firing
- AI makes more sensible use of certain spells and world spells (e.g. Sanctuary, Arcane Lacuna)
- AI workers will build the improvement on a bonus tile before building a road (instead of the other way around, which it did before)
-Inappropriate AI types blocked for disciples and scouts/lightbringers
- Added 'rapid expansion' strategy to encourage AI to expand more in early stages
- Beginnings of a basic city specialisation system (very, very unfinished)
- Infernal war script increases aggression when they first spawn
- Some small tweaks to AI favourite techs
- Priesthood no longer blocked for civs without state religions
- AI won't research the basic tech for an already founded religion unless it likes it better than its current state religion (Empyrean and CoE excepted, as these give the Overcouncil/Undercouncil civics)
- Changed the way unit building prerequisites are chosen to be built (now grouped in with Command Posts, etc.)
- AI places much higher priority on gold-generating buildings when in financial trouble
- Unit groups including settlers respond more intelligently to danger and won't retreat if they are stronger (this could cause AI settlers passing by goblin forts, etc. to get trapped in a loop before and never go anywhere)
- AI no longer takes the spread of disliked religions religions into account when picking a state religion (e.g. Sabathiel with 5 Ashen Veil cities and 1 Order city will have no problem in picking Order)

v0.2.0 (20th May 2009) - [Requires FfH2 v0.41; Will break saved games]:

- Merged with Fall from Heaven v0.41
- Leaders' FavoriteTechs adjusted slightly + their effect on research priorities greatly increased
- AI will now raze barbarian cities that are too far away (instead of burdening its economy with the maintenance)
- Using a fairer calculation to determine values of military buildings (based on unit tiers)
- Adjusted AI weights for various buildings
- Re-adjusted power values for all land units
- Added iPowerBonus and iPowerModifier values for promotions (allows distinguishing between positive/negative promotions, etc.)
- Fixed bug from v1 where AI would not attempt to found religions if it already had a state religion (Oops!)
- AIs that rely on a particular religion for their overall game plan (Elves -> FoL, Khazad -> RoK, Sheaim -> AV, etc.) will now still research it even if they are beaten by another civ
- AI will no longer research Priesthood when it does not have a state religion
- AI places much more emphasis on researching Exploration in the early game
- Re-adjusted unit AI values for all land units
- AI will use the Great Bard from the harpy event to create a great work (before, it was letting its only city go into 15 turns of disorder)
- Infernal AI: Added much greater weight on Manes' 'Add to City' spell
- Infernal AI: Removed food from a number of calculations where it was still being considered (including technology choices and civics)
- Kuriotate AI: AI no longer places settlements right next to its main cities
+ Small changes/tweaks to tech priorities, etc.

v0.1.1 (8th May 2009):
- Merged with Better BTS AI v0.70
- Fixed bug with power graph due to unit power not being saved/loaded
- Reduced AI weight for Freaks

v0.1.0 (5th May 2009):
- Merged with Better BTS AI v0.60
- Numerous tweaks to research priorities (mainly economy-related)
- AI builds more early defenders
- AI values commerce much more (in general)
- Civs pay more attention to religion weights when choosing whether to found/adopt
- Stopped AI from purposely growing cities into unhappiness (pre-slavery!)
- Units no longer consider a single barbarian on a spawn tile to be a danger
- Vastly improved naval AI for settling (use of skeleton crews, etc.)
- AI more likely to raze far away cities
- Corrected a number of calculations relying on a numerical value for the current era (FfH eras are not linear)
- AI will no longer send large (but inadequate) stacks against Acheron
- AI no longer spams forts all over its territory
- Number of Scouts built by AI players greatly reduced
- AI players won't attempt to construct wonders/rituals before they build their second city
- New power algorithm that takes into account promotions and weapons (still needs some refining + more accurate weights in XML file)
- Amurites will trade techs at Pleased
- Illians will build Temples of the Hand
- Khazad understand Dwarven Vault mechanic to some extent (and expand!)
- Kuriotates place cities and settlements sensibly
- Plus various other minor/half-implemented fixes and improvements
 

Attachments

Very interesting, could you also post the relevant code you changed for the items with an unclear description( i.e. tweaks to research priorities, More Value for Commerce etc)

Btw growing into unhappiness is not always a bad thing. More population gives you more trade route income and if you build worker/settlers the unhappy pop does not eat.
 
Very interesting, could you also post the relevant code you changed for the items with an unclear description( i.e. tweaks to research priorities, More Value for Commerce etc)
Unfortunately, not easy, as a huge amount of different things have been changed here - some just numbers/weightings and some a bit more advanced. In particular, the CvPlayerAI::AI_bestTech function has been messed with quite a bit. Your best option is probably to diff my code against the code for the main mod with WinMerge or something similar.

(This is the same reason I decided not to comment all of my changes. Some parts of the code would be mostly comments. I'm using source control to track changes, though, and may make that public soon.)

Btw growing into unhappiness is not always a bad thing. More population gives you more trade route income and if you build worker/settlers the unhappy pop does not eat.
Sounds like a very specific case. I'm not sure the AI is smart enough yet to use its unhappiness 'tactically'.

What I was seeing was early in the game, where food is high but happiness resources are limited, where the AI had three or four cities that it was growing past the happy cap for no real reason. I doubt there was any masterplan involved there.
 
Is the Archeron change in a specific function?

I think it was a very good decision to change the CvPlayerAI::AI_bestTech function as it really doesn't fit FFH that well. Do you have civ-specific values in it? For example go Luchuirp for sorcery once they have a good economy?

what really helps the AI from my experience are changes to how it decides what to produce. Not sure what you can achieve there with simple changes but good luck :)
 
Is the Archeron change in a specific function?
CvPlayerAI::AI_targetBarbCity

As mentioned in another thread, it's a bit of a hack. Basically, it ignores any barbarian city where:

- The best defender has fear
- The best attacker in your stack does not have courage
- Your best attacker's offensive strength is less than the best defender's defensive strength

I wanted to make it so that it's possible some supremely powerful AI might take on Acheron later on if it had the units to do so (e.g. maybe another dragon). It probably could do with some refining, but it's such an edge case that I'm not sure it's worth spending too much time on it. The main thing is that the AI doesn't waste hammers on units that just sit outside the city doing nothing.

I think it was a very good decision to change the CvPlayerAI::AI_bestTech function as it really doesn't fit FFH that well. Do you have civ-specific values in it? For example go Luchuirp for sorcery once they have a good economy?
Kael has a change listed to give AI leaders a favourite tech for v0.41. If the new version comes out soon, I'll probably integrate that, otherwise I'll add it myself. There are only a few civs that need pushing more towards certain techs, though, in my opinion (Hippus being the main ones). Civs already place a very high priority on their favourite religions - most extreme example being the Khazad, who go for Way of the Earthmother pretty much straight away 99% of the time at the moment.

what really helps the AI from my experience are changes to how it decides what to produce. Not sure what you can achieve there with simple changes but good luck :)
First priority there is to get it to build civ-specific buildings it normally ignores (e.g. blasting houses, based on a conversation in another thread). Then I guess I can take a closer look at how it determines what to build in which situations. Any feedback would be helpful.

Kael has mentioned making some changes to improve worker build choices, so hopefully that'll make it into the main mod soon enough. The ultimate scenario would be if the AI could be made to specialise its cities in the same way a good human player would, but I'm not 100% sure how to go about it, not least because I'm pretty crap at that side of things myself. :)
 
As mentioned in another thread, it's a bit of a hack. Basically, it ignores any barbarian city where:

- The best defender has fear
- The best attacker in your stack does not have courage
- Your best attacker's offensive strength is less than the best defender's defensive strength

I wanted to make it so that it's possible some supremely powerful AI might take on Acheron later on if it had the units to do so (e.g. maybe another dragon). It probably could do with some refining, but it's such an edge case that I'm not sure it's worth spending too much time on it. The main thing is that the AI doesn't waste hammers on units that just sit outside the city doing nothing.
I guess you mean CvUnitAI::AI_targetBarbCity ;). I like your solution, modified it a little bit by tier to protect hunters with courage, etc.:
Code:
                   if (pBestDefender == NULL ||
                                !pBestDefender->isFear() ||
                                (this->isImmuneToFear() && this->m_pUnitInfo->getTier()>2))
First priority there is to get it to build civ-specific buildings it normally ignores (e.g. blasting houses, based on a conversation in another thread). Then I guess I can take a closer look at how it determines what to build in which situations. Any feedback would be helpful.
Probably nothing new to you but the easiest way would be to kind of cheat and give the UB 0.001% production boost and a high AIWeight. Ok, doesn't work for blasting houses since they need fire mana. I rewrote AI_chooseProduction or whatever it is called to also solve the UB issue. Looking forward to see if you find a better way.
 
Probably nothing new to you but the easiest way would be to kind of cheat and give the UB 0.001% production boost and a high AIWeight. Ok, doesn't work for blasting houses since they need fire mana. I rewrote AI_chooseProduction or whatever it is called to also solve the UB issue. Looking forward to see if you find a better way.
The problems are with buildings where the effects are entirely coded in Python and there's nothing in the XML to indicate that it does a particular thing. That means the DLL code doesn't get any indication that the building might be valuable. So the choice seems to be between adding new (trivial, one time use only) XML fields or hardcoding things.

Edit: FWIW, these are my ideas for favourite techs for AI civs (bearing in mind that technologies that actually found religions are already valued highly by the more fanatical leaders). Some of them need a bit of a nudge in terms of military, etc. Any input is appreciated. :)

Amurites - Sorcery
Balseraphs - Festivals
Bannor - Fanaticism
Calabim - Feudalism
Clan of Embers - Masonry
Hippus - Horseback Riding
Illians - Way of the Wicked (for The White Hand?)
Khazad - Arete (or something else?)
Ljosalfar - Guardian of Nature
Luchuirp - Sorcery (or Construction?)
Sheaim - Infernal Pact
Svartalfar - Poisons (possibly?)

There's always the possiblity of having multiple favoured techs if necessary.
 
By favourite techs, you mean techs that said civilization will research if it can? If so, then Svartalfar -> Poisons may be a bit much. I mean, usually, I delay this tech because of its high cost... there's usually more useful techs to grab before. That said, I may not see the full potential of grabing it earlier :)
 
No, more that the weight of the tech gets increased when making its decision. The AI takes tech costs into account when picking its research, so it'll still grab cheaper ones first.
 
The trick you can use to flavor the buildings which have "only used once" python tricks associated is that typically these are Unique Buildings, so you ramp up the natural weighting which the AI places on a unique building, regardless of stats. So far nobody has a Unique Version of a building which is meant to make it WORSE, so this works nicely in the final results.
 
sweet! is this the first modmod to come out for FFH 0.41? cheers :D

I'm pretty sure I'll play a couple games with this in the upcoming days :)
 
Good job !!

Installed it along with .41, and frankly the AIs seemed to do averall better than they used to.
At least the discrepancies between AIs were smaller, making for more balanced games.

Keep up the good work !
 
Yes. I've run a lot of autoplay games to test out various things and I've definitely noticed the average AI player score has gone waaay up. On Noble/Continents/Huge/Standard, the average score tends to be around 1000 (with the occasional civ breaking 2000) by turn 300, whereas it tended to be closer to 500 on average with the base mod. It's mostly down to having a much more effective economy (the AI still sucks at fighting).

It doesn't do so well on island/archipelago maps, but they're also much harder for human players, too. I'd be interested to hear some feedback from anyone who tries one out.

I'd also be interested in ideas on how to improve the Infernals. In the base mod, they tend to just sit around with one or two cities and do nothing the whole game (besides spreading Hell terrain, of course). I made them more aggressive (as they really need to be warmongers to do well, perhaps more than any other civ), but now their usual game plan seems to go like this:

1. Get summoned sometime between turns 200 and 300 (usually by Keelyn or one of the Sheaim leaders)
2. Found Dis
3. Possibly found a second city nearby
4. Declare war on a well developed neighbour who has 10+ cities and a large army of tier 2/3 units
5. Get squished

They just don't seem to be very effective. It's possible that they're just not strong enough (relative to the other civs) by the time they appear in the game, and you could theoretically summon them earlier, but it doesn't make sense for the Sheaim/Balseraphs to compromise their own game by beelining Infernal Pact ahead of defensive/economic techs.

Basium does much better, but then he inevitably has a permanent alliance with one of the game leaders.
 
Some feedback:

Your block on priesthood is not good, since it does not check for agnostic civs and is a prereq for certain useful techs. It sometimes makes sense to research the tech even without a religion and you deny Cassiel his Druids.

An easy improvement for the AI is to block building the purge the unfaithful wonder. That one is terrible even in human hands, for the AI it is simply a lot of wasted production to remove something positive from your cities.

Another easy improvement is to block the Illians from building Samhain until they get at least a few cities.

As for Hyborem I gave him a lot more possible spawns in my version, but made each spawned troop dependent on a random roll that has to pass a certain threshold (the better the troop the higher the threshold). Each turn adds to the random roll, so if more game time passes before Hyborem spawns, he gets better and more troops. To keep him from bankrupting himself I also gave him gold depending on the gameturn.
That seems to work quite well to counter his weakness if he arrives too late.


Now I also have a question:
I tried to insert forced economic and religious beelines into your AI_ChooseTech function in CvGameUtil.py, similar to the 0.40z version. The game keeps giving me python exceptions, which point to cvgameinterface.py. If I use them in the base mod they work without problems. Any idea why?
 
To improve poor little weak Hybo, I gave him a multitude of traits. That slightly improved him, and he was able to conquer one third of the moderately powerful Lanun empire in my game so far. But he was still weak for the powerful demonic guy he's supposed to be, so I made the Infernal Palace give large bonuses, while adding the fallow trait as a prerequisite to building it (so that the Elohim wouldn't be able to build it).
 
Your block on priesthood is not good, since it does not check for agnostic civs and is a prereq for certain useful techs. It sometimes makes sense to research the tech even without a religion and you deny Cassiel his Druids.
Agreed. I'll relax it.

An easy improvement for the AI is to block building the purge the unfaithful wonder. That one is terrible even in human hands, for the AI it is simply a lot of wasted production to remove something positive from your cities.

Another easy improvement is to block the Illians from building Samhain until they get at least a few cities.
I'm definitely planning to help give the AI a better understanding of when to build rituals at some point. Right now, it's more or less random for most of them since their effects are all handled by Python code. Since they're basically just big spells (that are cast by cities rather than by units), something like the 'req' function system used in CvSpellInterface would work well.

As for Hyborem I gave him a lot more possible spawns in my version, but made each spawned troop dependent on a random roll that has to pass a certain threshold (the better the troop the higher the threshold). Each turn adds to the random roll, so if more game time passes before Hyborem spawns, he gets better and more troops. To keep him from bankrupting himself I also gave him gold depending on the gameturn.
That seems to work quite well to counter his weakness if he arrives too late.
I'm not too fond of the idea of changing the core game mechanics just to help out the AI, otherwise I'd give it a go. In my opinion, the AI should be playing the same game as the human player and the job of an AI mod should be to help it play within the rules (in other words, if I was developing a chess AI, I wouldn't let it spawn extra pieces randomly to help it out :)). Yes, I'm aware that makes things much more difficult. :P

Anyway, if Hyborem appears too late, I guess that's hard luck for him, but he should be able to be fairly effective if he arrives at a reasonable time -- at least, he should be able to capture one or two cities and not get destroyed immediately. Probably a lot of this has to do with how the chooses targets and attacks cities. I'm thinking that perhaps they should be more willing to attack with their Hyborem unit (instead of only attacking with 95%+ odds, as with other world units) early on, making their game take more of an all-or-nothing angle. Might be worthwhile taking some other risks, too.

Now I also have a question:
I tried to insert forced economic and religious beelines into your AI_ChooseTech function in CvGameUtil.py, similar to the 0.40z version. The game keeps giving me python exceptions, which point to cvgameinterface.py. If I use them in the base mod they work without problems. Any idea why?
No idea. I'll have to try it and get back to you. What beelines are you trying to add?
 
I'm not too fond of the idea of changing the core game mechanics just to help out the AI, otherwise I'd give it a go. In my opinion, the AI should be playing the same game as the human player and the job of an AI mod should be to help it play within the rules

Wouldn't that proposal also apply to human Infernals?
 
Back
Top Bottom