Resource icon

AI+ v13.1

Thanks! I'll give it a shot to see what happens.

I noticed your comment that "Max is set because the AI cant handle logistics above a certain number of units"
While that comment is generally true, there's an important setting to control this you may not have found yet. So just in case:
In the behaviortrees there's a value set to 2 on the move units node right before they get into the attack city part (the name of the variable escapes me). This variable controls the minimum distance that units need to be at before the game allows moving past that node. It so happens that since it's set to 2, if armies get too big or if there are many mountains, it very frequently fails to get all of its units within that distance of 2. So it never moves past that node and it ends up just standing around the city with its armies while not doing anything. If you set this one to 3, it's much less likely to get stuck and ends up handling big armies a bit better.

I also noticed you haven't included a particular fix to operations which ends up making it significantly less likely that enemies attack in the lategame. Some of the operations (the city defense and the return worker operations IIRC) dont have an operation type set. This seems to end up interfering with the maximum limit of operation types. If you slap operationtypes on them it ends up launching more city attack operations late game.

Thanks for looking on this! I tried not to touch anything apart from Naval groups and just new operations but will definitely amend operations and behaviortree. Regarding behavior tree issue - how did you spot this in the game? I saw so many times AI not doing anything because of this issue and was always wondering whether they are trying to hire more units.

Thanks for the info. Okay, so I have not look at that yet since I really do not know what I am doing yet... I wanted to know if you or Siesta Guru were planning to update the changes in one of these mods?

I am now focusing on adding proper naval city attacks, AI is relatively okay with doing land combats in AI+ (even in base game it became better). I believe Siesta is waiting for a better modding tools but we can always try to ask him for an update...)

One other thing I have never seen the AI players make any carriers all game long, are the AI players able to use carriers and can the AI players be made to at least look into getting one or two carriers?

Yeah, same thing, I never saw AI using them. I believe AI just consider them "inefficient" because they cost a lot but cannot attack units or cities.
AI definitely can be made building them, there are several potential ways of doing it:

1. Simple way (not sure if it works): by adding it to AiFavoredItems and also checking that carrier unit belongs to Unit_Naval class.
2. More complicated: Creating separate class for these units (unit_naval_carrier), creating new team (Naval Base strike team) with minimum number of unit_naval_carrier at least one, creating new operation linked to this team (Naval base strike operation) with ideally its own operation type. Then you can give this operation type allowed limit and put it in favored items with the precondition of player reaching tech which allows building of carriers. There is a "ZergRush" type of operation done in AI+, you can create carrier operation using this as a template.
AI should build carriers and use them as part of naval formation (if you put siege city assault as behavior tree) however I believe it won't be putting airplanes into carriers and using them - this is where the whole behavior tree needs to be created. Siesta can better advise on this.
 
Yeah I'm just doing maintenance now really. Without better tools I don't feel I can add much more, inspiration for truly fundamental changes has run out so it's mostly just doing weight tweaks now. And while doing that can improve AI skills, it's too difficult to say to what extend they truly help the AI, especially since there's no way of having different players use different weights.

Regarding behavior tree issue - how did you spot this in the game? I saw so many times AI not doing anything because of this issue and was always wondering whether they are trying to hire more units.

Do you mean the issue where they get stuck around a city? Or the operations not being launched thing?
I noticed the 'stuck around city' thing by looking at the operation and behaviortree logs when I saw a particularly awful case where Scythia surrounded a city near mountains for hundreds of years and never attacked. It turned out they just got stuck in a movement node. I saw movement nodes has a variable for the minimum distance required, and saw that there were simply too many too units to be able to fit them all within a 2 tile radius (like 15 units for 7 tiles) so it could never get them all in range. Turns out there are actually 2 variables for distance. As far as I understand it now, there's basically a sort of 'center' (or leader?) of the operation. To complete a movement node, the center of the operation must be within a certain tile radius of the target goal, and all units must be within a tile radius of the center. Especially the latter is impactful.

Operations not being launched took me much longer and was one of the last genuinely impactful changes I did. For a while I had noticed that in late game, civs would build very few units. Later on I noticed in the logs that city attack operations would frequently just not start whatsoever, even if the civ in question has a sizeable army through upgrading medieval units. If operations don't even start, they never get to the recruiting phase, nor to the building contracts, which is their prime way of building military units. So the operations not starting seemed like the key, but I couldn't find a solution. For the longest time I thought it was that they simply felt too weak to attack cities lategame, possibly because of the large walls. Eventually though it became obvious that no matter what tweaks I did to minoddsofsucces, to min troop requirements, to unit combat strengths; the issue wouldn't disappear. Civs would also miss possible attacks on incredibly weak backwards civs.
After lots of looking through logs, I noticed one civ in particular that had 2 'return civilian' operations running, which for some reason didn't end for hundreds of turns. During the entire time, not a single city attack operation was launched. The pattern showed up in more games, so I had a look if there was anything special about the return civilian operation, and there was, no opeartiontype was set. The same ended up being true for the city defense operation, which was also frequently present in lategame. Adding proper operationtypes to both of them basically instantly did the trick and civs became way more active late.


One other thing I have never seen the AI players make any carriers all game long, are the AI players able to use carriers and can the AI players be made to at least look into getting one or two carriers?

Count me in as never having seen them make use out of carriers the proper way. Sometimes they build them, but use them only as melee ships. Any support units in general are generally either never build or nor handled well. Sometimes a battering ram or one of those scout balloons is carried along, but I've yet to see a great general, admiral or medic being used. And I've watched a lot of games...
 
At Siesta Guru and Lion King, anyway you two can combined your mods as I run a game using both on a duel map, set to immortal, starting in the Renaissance era and the AI player was able to take my city within like 15 to 20 turns (I was not really trying to hold them off to much for this test run) that was much faster than I have ever seen from the AI players (as they usually dance their units around my city), they also had a few ships that also attacked. The problem is when I run both of your mods the game becomes really unstable and starts to crash randomly a lot, so yeah I am hoping you two could make a more stable mod.
 
And Siesta Guru, can you check your mod (AI+) to make sure the AI players are using Bombers, Jet Bombers, Fighters and Jet Fighters correctly (I see them building them but not using them for anything). Right now the default fall patch AI is using them (not that good but is using them).
 
I am sorry to keep asking for help but where in the “BehaviorTrees.xml” and “Operations.xml” files or just wherever files would I go to fix the AI players units getting stuck around a city and late game wars not getting launched by the AI players? I have really looked and just do not know what I need to change.
 
I am sorry to keep asking for help but where in the “BehaviorTrees.xml” and “Operations.xml” files or just wherever files would I go to fix the AI players units getting stuck around a city and late game wars not getting launched by the AI players? I have really looked and just do not know what I need to change.

I'm pretty sure Siesta is at a loss regarding this as well...
 
Operations not being launched took me much longer and was one of the last genuinely impactful changes I did. For a while I had noticed that in late game, civs would build very few units. Later on I noticed in the logs that city attack operations would frequently just not start whatsoever, even if the civ in question has a sizeable army through upgrading medieval units. If operations don't even start, they never get to the recruiting phase, nor to the building contracts, which is their prime way of building military units. So the operations not starting seemed like the key, but I couldn't find a solution. For the longest time I thought it was that they simply felt too weak to attack cities lategame, possibly because of the large walls. Eventually though it became obvious that no matter what tweaks I did to minoddsofsucces, to min troop requirements, to unit combat strengths; the issue wouldn't disappear. Civs would also miss possible attacks on incredibly weak backwards civs.
After lots of looking through logs, I noticed one civ in particular that had 2 'return civilian' operations running, which for some reason didn't end for hundreds of turns. During the entire time, not a single city attack operation was launched. The pattern showed up in more games, so I had a look if there was anything special about the return civilian operation, and there was, no opeartiontype was set. The same ended up being true for the city defense operation, which was also frequently present in lategame. Adding proper operationtypes to both of them basically instantly did the trick and civs became way more active late.

I wish I knew more about the "operationtypes" I just keep poking at it. Also, are there any self help guides for Civ 6 AI modding yet?
 
And Siesta Guru, can you check your mod (AI+) to make sure the AI players are using Bombers, Jet Bombers, Fighters and Jet Fighters correctly (I see them building them but not using them for anything). Right now the default fall patch AI is using them (not that good but is using them).

Will test this, thanks for letting me know.

I am sorry to keep asking for help but where in the “BehaviorTrees.xml” and “Operations.xml” files or just wherever files would I go to fix the AI players units getting stuck around a city and late game wars not getting launched by the AI players? I have really looked and just do not know what I need to change.

So these fixes are already in AI+. But if you want to mimic them, you need to:


For the 'stuck around cities fix'
You can just rip the code in behaviortrees.xml out of AI+, but you'll get some other small changes along with it. So if you don't want that, here's a bit of an explanation that hopefully helps you figure out how the behaviortrees works

Find the <BehaviorTreeNodes> corresponding to : NodeType="Operation Move" for the relevant behaviortree. In particular, the one node thats relevant for city attacks is:

<Row NodeType="Operation Move" NodeId="39" TreeName="Siege City Assault" />

As its executed right before the bulk of the actual attacking logic
Then find the <TreeData> corresponding to the nodes you want to change. Which should be:
<Row DefnId="0" NodeId="39" TreeName="Siege City Assault" DefaultData="1" />
<Row DefnId="1" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />
<Row DefnId="2" NodeId="39" TreeName="Siege City Assault" DefaultData="false" />
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />

In the NodeDataDefinitions we can see what these mean:
<Row DataName="Move To (enum)" DefnId="0" DataType="int" NodeType="Operation Move" Required="False" UserData="True" />
<Row DataName="Range to goal" DefnId="1" DataType="int" NodeType="Operation Move" UserData="True" />
<Row DataName="Validate new units" DefnId="2" DataType="bool" NodeType="Operation Move" Required="False" UserData="True" />
<Row DataName="Unit distance" DefnId="3" DataType="int" NodeType="Operation Move" Required="False" UserData="True" />
<Row DataName="Leader Tag" DefnId="4" DataType="string" NodeType="Operation Move" Required="False" UserData="True" />

The node with id 3 (Unit Distance) is the one that determines the distance within which units need to be. As we can see it's currently set to 2. So all you need to do is change it to 3.

So turn
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />
into
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="3" />
You can do this either by updating it, or by deleting it and creating a new one or by using sql. I like doing the latter on the entire tree in AI+ because it minimizes the risk that a civ patch causes everything to crash (if ids ends up changing, an update would override data of the wrong node). Its also pretty easy in case of behaviortrees. Just delete all nodedata and all behaviortreenodes inside some tree, then copy paste the original tree in while altering what you want.


For the 'operationtypes' fix, note that these operations:
<Row OperationName="City Defense" TargetType="TARGET_FRIENDLY_CITY" TargetParameter="1" BehaviorTree="Simple City Defense" Priority="4" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
<Row OperationName="Civilian Builder Capture" TargetType="TARGET_FRIENDLY_CITY" BehaviorTree="Escort Worker To Camp" Priority="1" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />

Don't have an OperationType set, while all other (non-barb) operations do have something set there.
Strangely enough, the xml does provide two defined operationtypes which were supposedly intended for these two:
<Row OperationType="OP_ESCORT" Value="2" />
<Row OperationType="OP_DEFENSE" Value="4" />

So just set the operationtypes to these. You can do this through a delete + new create or an update or by using sql
In AI+ I'm using an update here. Basically just add these lines to your mod inside of an AiOperationDefs xml block:

<Update>
<Set OperationType="OP_ESCORT"></Set>
<Where OperationName="Civilian Builder Capture"></Where>
</Update>
<Update>
<Set OperationType="OP_DEFENSE"></Set>
<Where OperationName="City Defense"></Where>
</Update>
 
Will test this, thanks for letting me know.



So these fixes are already in AI+. But if you want to mimic them, you need to:


For the 'stuck around cities fix'
You can just rip the code in behaviortrees.xml out of AI+, but you'll get some other small changes along with it. So if you don't want that, here's a bit of an explanation that hopefully helps you figure out how the behaviortrees works

Find the <BehaviorTreeNodes> corresponding to : NodeType="Operation Move" for the relevant behaviortree. In particular, the one node thats relevant for city attacks is:

<Row NodeType="Operation Move" NodeId="39" TreeName="Siege City Assault" />

As its executed right before the bulk of the actual attacking logic
Then find the <TreeData> corresponding to the nodes you want to change. Which should be:
<Row DefnId="0" NodeId="39" TreeName="Siege City Assault" DefaultData="1" />
<Row DefnId="1" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />
<Row DefnId="2" NodeId="39" TreeName="Siege City Assault" DefaultData="false" />
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />

In the NodeDataDefinitions we can see what these mean:
<Row DataName="Move To (enum)" DefnId="0" DataType="int" NodeType="Operation Move" Required="False" UserData="True" />
<Row DataName="Range to goal" DefnId="1" DataType="int" NodeType="Operation Move" UserData="True" />
<Row DataName="Validate new units" DefnId="2" DataType="bool" NodeType="Operation Move" Required="False" UserData="True" />
<Row DataName="Unit distance" DefnId="3" DataType="int" NodeType="Operation Move" Required="False" UserData="True" />
<Row DataName="Leader Tag" DefnId="4" DataType="string" NodeType="Operation Move" Required="False" UserData="True" />

The node with id 3 (Unit Distance) is the one that determines the distance within which units need to be. As we can see it's currently set to 2. So all you need to do is change it to 3.

So turn
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />
into
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="3" />
You can do this either by updating it, or by deleting it and creating a new one or by using sql. I like doing the latter on the entire tree in AI+ because it minimizes the risk that a civ patch causes everything to crash (if ids ends up changing, an update would override data of the wrong node). Its also pretty easy in case of behaviortrees. Just delete all nodedata and all behaviortreenodes inside some tree, then copy paste the original tree in while altering what you want.


For the 'operationtypes' fix, note that these operations:
<Row OperationName="City Defense" TargetType="TARGET_FRIENDLY_CITY" TargetParameter="1" BehaviorTree="Simple City Defense" Priority="4" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
<Row OperationName="Civilian Builder Capture" TargetType="TARGET_FRIENDLY_CITY" BehaviorTree="Escort Worker To Camp" Priority="1" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />

Don't have an OperationType set, while all other (non-barb) operations do have something set there.
Strangely enough, the xml does provide two defined operationtypes which were supposedly intended for these two:
<Row OperationType="OP_ESCORT" Value="2" />
<Row OperationType="OP_DEFENSE" Value="4" />

So just set the operationtypes to these. You can do this through a delete + new create or an update or by using sql
In AI+ I'm using an update here. Basically just add these lines to your mod inside of an AiOperationDefs xml block:

<Update>
<Set OperationType="OP_ESCORT"></Set>
<Where OperationName="Civilian Builder Capture"></Where>
</Update>
<Update>
<Set OperationType="OP_DEFENSE"></Set>
<Where OperationName="City Defense"></Where>
</Update>

:( I am still having issues... I have never used sql (I tried I just do not know how to work it and I did see a YouTube video or two so I will watch them later and try doing a sql again) and I am not sure how you do a "delete + new create" and I tried to insert "<Update>" using your mod (after deleting everything in your mod so I could use it as a template) but still did not work. Lastly, I want to the "BehaviorTrees.XML" in Base\Assets\Gameplay\Data and changed
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />
into
<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="3" /> but after that the AI player just started moving their units back and forth not even going near my city (so, that just made it worse). I had a backup and have undone that change. I did each of these attempts separately too. Yeah, modding is not easy and I really do appreciate your help and I hope I can still get this.
 
So for an example of delete + a new create, see the behaviortrees.xml file in AI+.
I do a delete on all <TreeData> of the tree Siege City assault using: <Delete TreeName="Siege City Assault"/>
Then I recreate the same tree by just defining new tredata elements. There's a lot of them in there, and that's because it's mostly just a duplicate of the original behaviortrees with some changes
You do need to be inside of a mod to do this.

Your way -changing the base files- also works though, and in theory your change should've been the correct one. The fact that the behavior seems worse probably doesn't mean that much. It's a very chaotic/random game, so small positive changes don't necessarily mean that the end result will be better in every single game.
Changes to the mods used etc on an already saved game are not handled very well, and it's recommended to start with a clean game after mod changes.
 
So I've done some digging: the file delnars_fixes.xml is superfluous. All the changes inside of it have been added to the Vanilla game, the file doesn't even load at the moment because the SQL constraints fail. All it does is clutter up the logs with a bunch of errors, which is rather bad form. You can just get rid of the entire file without side effects.

* The only thing it does do is give an AIUnitType to spies. As spies are not units that can move, this almost certainly does nothing at all.

So I've noticed that this file is still in the mod, probably best to remove it at the next update.
 
At Siesta Guru: So, I want back to the "BehaviorTrees.XML" in Base\Assets\Gameplay\Data and changed <Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="2" />

into

<Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="4" /> and the AI player is at least attacking and taking all my cities but it is taking them forever to do that as they still waste a lot of time just moving back and forth with their units. This is an improvement to what was happened before, in games with no modifications/mods to the AI player who would sometimes never take any cities doing the late game (note I have only done 2 test games and will do some more to make sure the changes I made are really making a difference).





So, how do I do modifications to the Base\Assets\Gameplay\Data files to add

<Update>
<Set OperationType="OP_ESCORT"></Set>
<Where OperationName="Civilian Builder Capture"></Where>
</Update>
<Update>
<Set OperationType="OP_DEFENSE"></Set>
<Where OperationName="City Defense"></Where>
</Update>

the fix for the “operationtypes” as me and making mods is not really working out, please? Like, in what lines should I paste and/or change and so on?
 
Last edited:
Turn these two lines in operations.xml:
<Row OperationName="Civilian Builder Capture" TargetType="TARGET_FRIENDLY_CITY" BehaviorTree="Escort Worker To Camp" Priority="1" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
<Row OperationName="City Defense" TargetType="TARGET_FRIENDLY_CITY" TargetParameter="1" BehaviorTree="Simple City Defense" Priority="4" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
Into:
<Row OperationName="Civilian Builder Capture" OperationType="OP_ESCORT" TargetType="TARGET_FRIENDLY_CITY" BehaviorTree="Escort Worker To Camp" Priority="1" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
<Row OperationName="City Defense" OperationType="OP_DEFENSE" TargetType="TARGET_FRIENDLY_CITY" TargetParameter="1" BehaviorTree="Simple City Defense" Priority="4" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />


Btw from testing I'm pretty sure DefaultData="3" is better than DefaultData="4". 4 looses it up so much that armies become way too spread out.


So I've noticed that this file is still in the mod, probably best to remove it at the next update.

Ah yes, thanks for reminding me, I deleted it now in my local version. So it should be gone next patch.
 
Turn these two lines in operations.xml:
<Row OperationName="Civilian Builder Capture" TargetType="TARGET_FRIENDLY_CITY" BehaviorTree="Escort Worker To Camp" Priority="1" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
<Row OperationName="City Defense" TargetType="TARGET_FRIENDLY_CITY" TargetParameter="1" BehaviorTree="Simple City Defense" Priority="4" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
Into:
<Row OperationName="Civilian Builder Capture" OperationType="OP_ESCORT" TargetType="TARGET_FRIENDLY_CITY" BehaviorTree="Escort Worker To Camp" Priority="1" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />
<Row OperationName="City Defense" OperationType="OP_DEFENSE" TargetType="TARGET_FRIENDLY_CITY" TargetParameter="1" BehaviorTree="Simple City Defense" Priority="4" MaxTargetDistInRegion="-1" MaxTargetDistInArea="-1" MaxTargetDistInWorld="0" />


Btw from testing I'm pretty sure DefaultData="3" is better than DefaultData="4". 4 looses it up so much that armies become way too spread out.




Ah yes, thanks for reminding me, I deleted it now in my local version. So it should be gone next patch.


... next patch you say!?
 
Thank you Siesta Guru! That seems to have fixed it making those changes; the AI players are more aggressive with taking cities doing the late game. Just need to run a few more test games.



I am still keeping <Row DefnId="3" NodeId="39" TreeName="Siege City Assault" DefaultData="2" /> at set DefaultData="4" because when I have it at 3 the AI players seem to act weird and not attack my cities or any cities… what settings are you using when you run your test with it set to DefaultData="3" maybe I have to many changes made to the Base\Assets\Gameplay\Data and/or mods and that is why “3” seems to not work for me? And the only changes to the Base\Assets\Gameplay\Data are the fixes for the stuck around a city and AI not being aggressive late game.
 
Something, else I saw doing some of my test games on giant map sizes (most of my test games have been on small or duel size maps too), the AI players would not attack me a lot if I was on one side of the map and them on the other side. I was the only person they were at war with but still they did not generally launch any attacks (send units to try and take my cites), anyway to make the AI players more willing launch attacks against someone they are at war with on the other side of the map (like on giant maps), especially if the target is about to win one of the victory conditions?
 
Last edited:
Plus, when the AI players starts using nukes they tend to move their units towards the city that got nuked and stop… anyhow their units keep dying in the radiation and they never take the city (they keeping nuking the same city until they capture it, at least in my games). Anyway, to force the AI player to just sacrifice a unit that has enough movement to get to and take a city in radiation so at least they hopefully stop killing all their own units trying to surround a city in radiation (they keep nuking)?
 
Last edited:
Hey Siesta, when are you looking at updating "AI+" again? Also did you ever check to make the AI players are using air units correctly are at least using them for something in the "AI+" mod? Lastly, is the "AI+" mod compatible with the "Warfare Expanded (for MOAR)" like will the AI players build the new air units (like the "Great War Bomber" and others) in that mod and use them?
 
Hey guys, tiny question - is this AI improvement compatible with October updates (Khmer and Indonesia)?
 
Top Bottom