• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.
Resource icon

AI+ v13.1

@Siesta Guru Would you be so kind and post a small guide on how to modify AI behavior? But not dry explanation of behavior node types or how tables are structured, but rather 2-3 practical examples. Let's say we want AI to do this and this, then this is how you do it. Etc.
 
Are you still working on improvements?

Not really these days. Without more access to new tools, there's not much that can be improved on still. I've also stopped playing civ, so don't really see the small tweaks that may still be improvements unless they're mentioned here.

@Siesta Guru Would you be so kind and post a small guide on how to modify AI behavior? But not dry explanation of behavior node types or how tables are structured, but rather 2-3 practical examples. Let's say we want AI to do this and this, then this is how you do it. Etc.

Hmm, well I'd say the best guide is probably in the AI+ files itself. Essentially though, the modding process here comes much more from the other side. Instead of starting with 'I want the ai to do x, let's find a way', you're generally looking more for 'what do these files allow me to do, and would any changes make the ai better'. The reason of course is that there's almost no 'clever' behavior that can be created through the tools here. And if I were you, I'd start by looking at those tools. Otherwise you'll get stuck very quickly, like wanting to make archers fire over skipping their turn, and then finding out that there's nothing with which individual unit behavior can be altered.

There's essentially two main areas in which you can meaningfully change things. Building preferences, and military operations.

For building preferences, here you'll probably want to start, we have the useful <PseudoYields> and <AiFavoredItems>. Changing pseudoyields allows you to alter large overall preferences for certain categories. For xample if you want to increase the desire of all AI players, regardless of circumstances to build military units, then you'd look at the current value in the base file yields.xml. PSEUDOYIELD_UNIT_COMBAT is 1.0, so we can increase it to say 1.5:
<Update>
<Set DefaultValue="1.5"></Set>
<Where PseudoYieldType="PSEUDOYIELD_UNIT_COMBAT"></Where>
</Update>

Alright great, they build more units now. Set it to 40 for some fun.

AiFavoredItems is a little more intelligent, and it allows you to alter multiple things. You start with creating an AiLists (andan AiListTypes). This list has a type (such as yields, which does a similar thing to pseudoyields, or buildings, which allows you to force the ai to make certain buildings), and it has some activation criteria. The activation criteria are found in other tables. When a list is activated, all of the AiFavoredItems which are attached to it start functioning. There's essentially two ways of activating a list, either you attach it to a trait, or to a strategy. Trait based lists are activated throughout the entire game, and can be attached to specific civs, all civs, all city states, etc.
Let's start with a trait based one. Say, if you want to force all civs, to build an industrial district whenever they can.

You start with defining a list:
<AiListTypes>
<Row ListType="DistrictForcer"/>
</AiListTypes>

Then you tell it what type/system of list it is, and to what trait it is attached, in this case, we want to deal with districts, and have it be attached to all civs.
<AiLists>
<Row ListType="DistrictForcer" LeaderType="TRAIT_LEADER_MAJOR_CIV" System="Districts"/>
</AiLists>

Then, we put an AiFavoredItems into the list, with the change we actually want:
<AiFavoredItems>
<Row ListType="DistrictForcer" Item="DISTRICT_INDUSTRIAL_ZONE" Favored="true"/>
</AiFavoredItems>

Now you'll see them all start building industrial districts.
Some of the favoreditems systems allow a Favored="true", which forces production. Sometimes a Favored="false" makes them avoid the object, sometimes if you set it to false, they just won't care about it in some special way. Others, allow finer control using values. The Yields system is one of those, which allows you to change a desire for science etc, for example, if we want cleopatra to build more science buildings:

<AiListTypes>
<Row ListType="sciencelover"/>
</AiListTypes>
<AiLists>
<Row ListType="sciencelover" LeaderType="TRAIT_LEADER_MEDITERRANEAN" System="Yields"/>
</AiLists>
<AiFavoredItems>
<Row ListType="sciencelover" Item="YIELD_SCIENCE" Value="10"/>
</AiFavoredItems>

You should now see cleo prioritize science higher. You're going to have to play with these types of values and do tests till you figure out how powerful they are and how much they impact things. Ill warn you, this is a very painful process when a simple test run takes 3 hours and you're never entirely sure whether a perceived change is the placebo effect or not. In fact, I'm still not sure myself on the yields system.

So, I mentioned strategies. Which is a more interesting thing to work with. Ailists can be attached to a couple of conditions (see victories.xml). One useful condition that is available is the amount of wars that a civ has going on. You can test whether a civ is at peace, and attach an ailist to it if it is. Let's say that we want the ai to build more wonders if it's at peace.

Create a strategy
<Strategies>
<Row StrategyType="STRATEGY_PEACETIME" NumConditionsNeeded="1" />
</Strategies>

Set the conditions at which this strategy will activate.
<StrategyConditions>
<Row StrategyType="STRATEGY_PEACETIME" ConditionFunction="Major Civ Wars" ThresholdValue="0" />
</StrategyConditions>

Create a list, with our increased wonder desire:

<AiListTypes>
<Row ListType="buildwonders"/>
</AiListTypes>

Note here that that this list shouldn't have the trait variable set:

<AiLists>
<Row ListType="buildwonders" System="PseudoYields"/>
</AiLists>

Psueodyields in favored items actually start affecting behavior somewhere around the 100-200 mark, whereas 1000 is nearly forcing them to always get something of this type. See the ai logs on building choices to get a bit of a grip on how high you want these values to be (it keeps picking the highest rated item)

<AiFavoredItems>
<Row ListType="buildwonders" Item="PSEUDOYIELD_WONDER" Value="200"/>
</AiFavoredItems>

Last step, attach the list to the strategy
<Strategy_Priorities>
<Row StrategyType="STRATEGY_PEACETIME" ListType="buildwonders"/>
</Strategy_Priorities>

Some of the strategy conditions can be a bit confusing. It's worth checking the logs to see whether your conditions are activating as expected. In the case of this war based one in particular, if you set the threshold value to 0, the strategy will activate if the civ is not at war, if it's set to 1, it will activate if the civ is in 1 or less wars. But strangely, there's no way to set it so your strategy only activates if the civ is at war.
A typical trick I use, is that if you want to increase some desire while a civ is at war by x, to raise the base desire by x, and the set the peace desire to -x.


So that about sums it up for building preferences. I'd encourage you to just look through the AI+ and base game files to find out what your options here are. Which strategies you can use, what things you can change, etc.

On (military) operations. Well, there's not as much of an easy way to describe this I'm afraid.. The process of changing this is much less organized.
Essentially you have a couple of tools to change this behavior. Inside of operations.xml you'll see most of the tools here. It allows you to have some control over the amount and type of troops send into war or as settle operations, and how quickly they are send. It for example allows you to set the ai to be much more/less warlike, by setting a different MinOddsOfSuccess on the AiOperationDefs for city attacks.

I'd encourage you to just look at the files (both operations.xml and my changes in military.xml) and play with the variables and prepare mentally for the fact that there's no smart ways of controlling which operations activate when, so that you also can't do things such as changing the required troop counts dynamically over time.
Oh right, it's important to keep in mind here too that these operations largely control the troops that civs will build. If there is no operation that requires them to build a siege unit, they will never build siege units.
A lot of my changes here are essentially 'dumbing' things down so they work better. For example by having less units dedicated to defense operations, since it would often mean that it wasnt actively using half of its army.


Besides this, you also have some control through behaviortrees. Changing these is a tedious process with lots of crashes in your future. They also miss a lot of conditionals and actions that you'd want/expect, so even if you try to really get into changing these, you'll probably discover you can't actually do that much better than what's already there. The main things I managed to improve through these, was that I just took something out that would often cause them to retreat needlessly (a recruit units tag), and I fixed some bugs where units would get stuck. For example originally, it required that all units get within 2 range of their target before moving on to the next step, which would sometimes never happen if their army was too big, they had stragglers, or the terrain doesn't allow it.
There should be a guide on behaviortrees out there somewhere by delnar


Lastly, you have some more minor tools lying about. You can do some diplomatic changes (see diplomaticactions.xml) that allow you to change how likely civs are to initiate some diplomatic actions. There's a few modifiers that can be changed, mostly to affect how friendly ais are to you (like agendas). This is the one area I feel I might've underutilized
Then lastly there's a few variables in globalparameters that deal with ai things.

I hope that helps! If there's anything specific you want to know more about you can always ask (although Im not very active here anymore). After months of testing there's quite a few quirks I found that aren't immediately obvious so I could probably help speed you up. But I'd first encourage you to just play with some things yourself and to rip whatever you want from the ai+ files. Good luck!
 
@Siesta Guru Thanks a lot, your post is extremely helpful! I've looked through all the files you mentioned, but I simply couldn't grasp what their purpose is and how they are connected. You explained it, so it's much more understandable right now. Thanks, again!
 
Some observations:
AI still not Building Aircrafts...
If AI lost his Army he is not rebuilding it...
CS do not have Armies from midgame on...
Still no fleets for AI generaly...

Hope you can find a solution for that - it makes game a Little bit boring ;-)
 
Some observations:
AI still not Building Aircrafts...
If AI lost his Army he is not rebuilding it...
CS do not have Armies from midgame on...
Still no fleets for AI generaly...

Hope you can find a solution for that - it makes game a Little bit boring ;-)

AI and aircrafts: At least partly fixed in the base game.
AI not rebuilding army: Never encountered this in recent games.
CS: No idea, but they don't seem to lack units in my games.
AI navy still bad.

Keep in mind that AI+ is not updated for the most recent patch and actually makes the AI worse in some areas because of that.
 
AI and aircrafts: At least partly fixed in the base game.
AI not rebuilding army: Never encountered this in recent games.
CS: No idea, but they don't seem to lack units in my games.
AI navy still bad.

Keep in mind that AI+ is not updated for the most recent patch and actually makes the AI worse in some areas because of that.

Well, I am actually playing England on Europemap.
Germany - after taking Amsterdam, was declaring war on me. Then lots of Knights and Crossbowmen tried to cross channel without any navy support - the outcome of that was clear with Royal Navy close.
After I destroyed all units of that army I crossed and liberated Amsterdam, then Paris...
No new German armies, some single Units and a lot of builders during the next 200 years.
A few days ago I played Russia: Hugh Scythian assault with 12 horsmen, a lot of horsearchers and some catapults. Destroyed all of them - no new army the next hundreds of years.

And I never saw a AI plane later in that 2 games.
 
Love this mod. Takes the game from unplayable to enjoyable, big improvement.

Quick feedback:

Pedro just built Stonehenge. Except all the prophets were already taken. Also he was the one who got one of those prophets. Surely there must have been something else he should have been spending his hammers on; Oracle and Hanging Gardens both aren't built yet.
 
I guess this may be because the mod is out of date, but I'm gonna report this anyway. Civs just don't build cities. or, rather, they hardly build cities, and only rarely do they have more than 4 on them at any time (one game was multiplayer where one AI had founded 6 cities, one founded 5 and conquered egypt's capital, the rest had 4 and under, and 2 civs only had their capital, although one of them did also conquer a city state [egypt]. which I later liberated. yerevan is MINE!) (another game was singleplayer with 9 AI, ynamp large map sizes, plenty of room to expand. largest civ was brazil at 4, until I took 2 of their cities, and those two cities are what rose my city count to 15. germany and france had only 1 city the entire game, although it is possible france actually had 2 and their 2nd city was captured by brazil. aside from brazil, no one had more than 3 cities. kongo, one of my 2 continental neighbors, and the only one that didn't spawn 5 tiles away from me, spawned in a wide open relatively empty area, and focused on science and culture, keeping me on my toes in the early game, and immediately jumped to 3 cities. I was worried they'd completely crowd out their side of the continent and spread up north to where I was expanding into... but not only did they not expand once since the ancient era, they actually somehow managed to lose a city in the late medieval era, almost certainly to barbarians, which shouldn't have been possible considering they had more military might than what I used to wrestle two cities from brazil with. aka over 300 military might. needless to say, I am currently at least twice as strong as my closest competitor in every field, meaning science or culture victories are now a shoo-in for me, and I've only just reached the renaissance era)

I'm considering just playing without AI+ to see if maybe the base AI will actually use the land that's around them for once, since I've heard the AI is better now than before, and others have stated on this page that AI+ may not actually be providing any benefit right now

...Stonehenge....

Stonehenge also supplies 2 faith. in the case of wondrous wonders, it also supplies a free monument in every city, and with quo's tweaks it does... other stuff, I forget. While I agree that they probably weren't thinking straight, it's not like their construction is entirely useless. I do recommend wondrous wonders, as it makes many wonders that are either only slightly useful (the "great"-but-not-so-great library) or only-temporarily useful (stonehenge) into wonders that you would actually want to build even if you can't get everything the wonder has to offer. while this doesn't change the AIs tendency to waste resources on buildings that have passed their expiration date in usefulness (or build petra on the only desert tile in their city, curse you russia for stealing it for no reason), it will make their waste of resources not really a waste.
 
I'm considering just playing without AI+ to see if maybe the base AI will actually use the land that's around them for once, since I've heard the AI is better now than before, and others have stated on this page that AI+ may not actually be providing any benefit right now
The people saying the AI is better are victims of confirmation bias. The AI has not been significantly changed at all since release.
Stonehenge also supplies 2 faith. in the case of wondrous wonders, it also supplies a free monument in every city, and with quo's tweaks it does... other stuff, I forget. While I agree that they probably weren't thinking straight, it's not like their construction is entirely useless. I do recommend wondrous wonders, as it makes many wonders that are either only slightly useful (the "great"-but-not-so-great library) or only-temporarily useful (stonehenge) into wonders that you would actually want to build even if you can't get everything the wonder has to offer. while this doesn't change the AIs tendency to waste resources on buildings that have passed their expiration date in usefulness (or build petra on the only desert tile in their city, curse you russia for stealing it for no reason), it will make their waste of resources not really a waste.
I'm not using any other mods, so all it did for them was give them +2 faith. It's highly unlikely that that was the best use of the AI's time.
 
I'm not using any other mods, so all it did for them was give them +2 faith. It's highly unlikely that that was the best use of the AI's time.

actually, I just reread your post, and you said brazil was one of the ones to get a great prophet. if the civ that builds stonehenge had already gotten a great prophet and founded a religion, they instead get an apostle of their religion. so free belief boost. so they actually did gain something more than 2 faith.

also, my comment was on how you can make their stupid actions not-so-stupid, not on how their actions aren't actually stupid. except in specific cases (like building petra in a city with only 1 desert tile, which was used to build petra), the wonders are viable even if one of the conditions isn't true. so in the case that brazil didn't found a religion and there are no prophets left to grab, they could still benefit from stonehenge aside from the 2 faith yield. you may not be able to stop them from being stupid, but you can certainly lessen the damage caused by their stupidity.

also, it's not really fair to throw out other users' complaints as just "falling for confirmation bias". on this page is a valid complaint that the AI will not build planes, yet do so without AI+ installed. that's not confirmation bias. it also doesn't take much change to make a significant difference. the mod creator has even admitted AI+ is mostly minor tweaks (mainly due to not being able to make any large, meaningful changes due to not having access to any modding tools. thanks, firaxis). his mod is an example of small changes making a difference. it hasn't been updated for the recent update anyway, so it might not actually be currently fully-functional. the last time the mod dev responded here was a month and a half ago, with the last update even further back. it's not unreasonable to question if it still works.
 
Last edited:
Right, the AI on base builds aerodomes, and not aircraft. I've fixed it in my mod so they build aircraft, simple to add to this one as well. Once they have aircraft, now they will fire on units, but I need more testing to know how often.

And the cities thing, is a struggle on base, and all of our mods. None of us have a perfect setup to get them to get cities out. I've tried so many damn variations, and none of them work properly. Drives me insane.
 
Is it possible to create a naval operations for AI, so they will be using stacks of ships instead of 1-2 random units? I would love to see a proper naval battle like it was in Civ 5.
 
Heya. Yeah it works with the summer patch. I mean, not optimally, but there are no crashes

For anyone curious, I've mostly stopped working on this mod (except for maintenance if needed) until we get access to some better tools. The available tools feel like they've mostly been exhausted and all that's really left to do is value tweaks. Which is something that's insanely hard to test because you can never tell whether an observed change is the placebo effect. I'd bet a large part of the suboptimal civ AI is because it's just so bloody hard and boring to debug.
 
Last edited:
Lol :p

So yeah it does seem some maintenance is required here. The AI has gotten weirdly passive and settling has gotten much worse again. I'll try to see if I can get something done. It might have something to do with the weird new pseudoyields..



Edit:
Yep. The new pseudoyields are crazily important in determining whether civs attempt to attack cities, declare war and build units. Keep them as set and there's like 2 attacks on city states during an entire game. Set them to 0, and it's continuous attempted capital attacks, not a single settler build and city states have 200 units. Will have to find some kind of a balance here... Whatever change was involved in adding these is almost certainly the main cause for the broken AI atm.

It also seems the city evaluation spot algorithm had some work done, they're not settling in the expected spots anymore. As in, worse spots..

Additionally some settle operations get "Operation Change Target INVALID" statuses now, whatever that means (on both the default and a custom behavior tree). It's stopping them from settling is all I know.
 
Last edited:
Back
Top Bottom