Changing AI Priorities¶
In this tutorial, the AI priorities of mudraptors will be changed.
The files used are available separately or zipped. You can see the output here.
First, we’ll need to build the folder for the Mod Generator to use as input. Make new files and folders until you have the following:
AIMod
├── filelist.xml
└── Content
└── Characters
└── Mudraptor
└── Mudraptor.xml
Since we’re only changing the AI priorities here, we don’t need to include the ragdoll or any of the assets.
Now populate filelist.xml with the mod files:
<?xml version="1.0" encoding="utf-8"?>
<contentpackage name="AI Mod" path="Mods/AIMod/filelist.xml" corepackage="false" gameversion="0.10.4.0">
<Character file="Mods/AIMod/Content/Characters/Mudraptor/Mudraptor.xml"/>
</contentpackage>
We can begin writing our diff (Mudraptor.xml) now.
Let’s start by taking a look at the vanilla mudraptor’s XML.
<Character speciesname="Mudraptor" humanoid="False" group="" husk="False" needsair="False" canspeak="False" noise="100" visibility="100" blooddecal="blood" eatingspeed="10">
...
<ai combatstrength="250" sight="0.75" hearing="1" aggressiveboarding="True" fleehealththreshold="0" aggressiongreed="30" aggressionhurt="200" attackwhenprovoked="False">
<latchonto attachtowalls="true" attachtosub="false" attachlimb="HeadArmor" />
<target tag="decoy" state="Attack" priority="600" />
<target tag="provocative" state="Attack" priority="200" />
<target tag="weapon" state="Attack" priority="200" />
<target tag="nasonov" state="Attack" priority="200" />
<target tag="stronger" state="Avoid" priority="110" reactdistance="2000"/>
<target tag="human" state="Attack" priority="100" />
<target tag="tool" state="Aggressive" priority="80" reactdistance="1000"/>
<target tag="dead" state="Eat" priority="60" />
<target tag="weaker" state="Attack" priority="60" />
<target tag="sonar" state="Attack" priority="60" />
<target tag="door" state="Attack" priority="30" />
<target tag="wall" state="Attack" priority="20" />
<target tag="room" state="Attack" priority="10" />
<target tag="turret" state="Attack" priority="1" />
</ai>
</Character>
Some of the file has been omitted to make reading the relevant parts easier.
We can edit the priority of an existing target with a simple patch operation:
<replace sel="/Character/ai/target[@tag='door']/@priority">90</replace>
Working out what each part of this xpath is straightforward: /Character/ai select the mudraptor’s ai element, then target[@tag='door'] finds the target element with tag attribute door, and finally @priority selects the priority attribute of that element.
It’s also possible to use a more concise xpath:
<replace sel="//target[@tag='door']/@priority">90</replace>
Here, the // selects any element in the entire tree that meets the conditions - in this case, its tag attribute must be door.
Whichever of these you use is down to preference - in a small file like Mudraptor.xml, it’s easy to check that there’s no other elements that are accidentally edited, however in larger files (such as files with items) using // can cause unwanted edits.
If you’re unsure, just check the output of the Mod Generator to confirm.
This same method can also be used to change what action the mudraptor should take:
<replace sel="//target[@tag='stronger']/@state">Attack</replace>
Removing a target from the list is also easy:
<remove sel="//target[@tag='turret']"/>
Note here how the element has no value.
That’s because remove operations just need to know the selection of the element(s) to remove.
Finally, adding a target is also fairly trivial:
<add sel="//ai">
<target tag="leucocyte" state="Avoid" priority="50" reactdistance="2000"/>
</add>
Combining all these changes into one diff, we get:
<?xml version="1.0" encoding="utf-8"?>
<Diff file="Content/Characters/Mudraptor/Mudraptor.xml" override="root" cleanup="false">
<replace sel="//target[@tag='door']/@priority">90</replace>
<replace sel="//target[@tag='stronger']/@state">Attack</replace>
<remove sel="//target[@tag='turret']"/>
<add sel="//ai">
<target tag="leucocyte" state="Avoid" priority="50" reactdistance="2000"/>
</add>
</Diff>
Since we’re editing a character file, we have to override the root element.
Furthermore, cleanup is false since we don’t want to delete the rest of the mudraptor’s character file.
Here’s the output in full:
<?xml version="1.0" encoding="utf-8"?>
<Override>
<Character speciesname="Mudraptor" humanoid="False" group="" husk="False" needsair="False" canspeak="False" noise="100" visibility="100" blooddecal="blood" eatingspeed="10">
<ragdolls />
<animations />
<health vitality="120" doesbleed="True" crushdepth="-Infinity" usehealthwindow="False" bleedingreduction="1" burnreduction="0" constanthealthregeneration="0" healthregenerationwheneating="1">
<Limb name="Torso" />
<Limb name="Head" />
<Limb name="LeftLeg" />
<Limb name="RightLeg" />
</health>
<bloodemitter particle="blood" particleamount="1" anglemin="0" anglemax="0" scalemin="1" scalemax="1" velocitymin="0" velocitymax="0" emitinterval="0" particlespersecond="0" highqualitycollisiondetection="False" copyentityangle="False" />
<bloodemitter particle="waterblood" particleamount="1" anglemin="0" anglemax="0" scalemin="1" scalemax="1" velocitymin="0" velocitymax="0" emitinterval="0" particlespersecond="0" highqualitycollisiondetection="False" copyentityangle="False" />
<damageemitter particle="brownchunks" particleamount="10" velocitymin="50" velocitymax="300" anglemin="0" anglemax="360" scalemin="0.1" scalemax="0.3" />
<gibemitter particle="gib" particleamount="20" velocitymin="200" velocitymax="700" anglemin="0" anglemax="360" scalemin="1" scalemax="1" emitinterval="0" particlespersecond="0" highqualitycollisiondetection="False" copyentityangle="False" />
<gibemitter particle="heavygib" particleamount="10" velocitymin="50" velocitymax="500" anglemin="0" anglemax="360" scalemin="1" scalemax="1" emitinterval="0" particlespersecond="0" highqualitycollisiondetection="False" copyentityangle="False" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_attack1.ogg" state="Attack" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_attack2.ogg" state="Attack" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_attack3.ogg" state="Attack" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_damage1.ogg" state="Damage" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_damage2.ogg" state="Damage" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_damage3.ogg" state="Damage" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_idle1.ogg" state="Idle" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_idle2.ogg" state="Idle" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_idle3.ogg" state="Idle" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_death1.ogg" state="Die" range="1000" volume="1" gender="None" />
<sound file="Content/Characters/Mudraptor/MUDRAPTOR_death2.ogg" state="Die" range="1000" volume="1" gender="None" />
<Inventory slots="Any, Any" accessiblewhenalive="False" commonness="15">
<Item identifier="hydroxyapatite" />
</Inventory>
<Inventory slots="Any, Any" accessiblewhenalive="False" commonness="1">
<Item identifier="hydroxyapatite" />
<Item identifier="mudraptorshell" />
</Inventory>
<Inventory slots="Any, Any" accessiblewhenalive="False" commonness="1">
<Item identifier="hydroxyapatite" />
<Item identifier="smallmudraptoregg" />
</Inventory>
<ai combatstrength="250" sight="0.75" hearing="1" aggressiveboarding="True" fleehealththreshold="0" aggressiongreed="30" aggressionhurt="200" attackwhenprovoked="False">
<latchonto attachtowalls="true" attachtosub="false" attachlimb="HeadArmor" />
<target tag="decoy" state="Attack" priority="600" />
<target tag="provocative" state="Attack" priority="200" />
<target tag="weapon" state="Attack" priority="200" />
<target tag="nasonov" state="Attack" priority="200" />
<target tag="stronger" state="Attack" priority="110" reactdistance="2000" />
<target tag="human" state="Attack" priority="100" />
<target tag="tool" state="Aggressive" priority="80" reactdistance="1000" />
<target tag="dead" state="Eat" priority="60" />
<target tag="weaker" state="Attack" priority="60" />
<target tag="sonar" state="Attack" priority="60" />
<target tag="door" state="Attack" priority="90" />
<target tag="wall" state="Attack" priority="20" />
<target tag="room" state="Attack" priority="10" />
<target tag="leucocyte" state="Avoid" priority="50" reactdistance="2000" />
</ai>
</Character>
</Override>
As you can see, the turret target is also gone.
This concludes the AI Priorities tutorial.