Skip to content

How To Use

Matthew Seal edited this page Apr 6, 2020 · 11 revisions

How To Use

We'll walk through an example here, and explain how to add each of the available features to a mod. Let's start with a new animal, a Sand Worm.

Adding a Speed stat

The idea is that on desert maps this animal should move faster through sand than other terrain, while other pawns should move slower through sand.

To start let's copy MoveSpeed's definition and replace the defName, label, description defaultBaseValue, and minValue fields. We'll place this file in Defs/Stats/Stats_Sand.xml.

<?xml version="1.0" encoding="utf-8" ?>
<Defs>
  <StatDef>
    <defName>SandSpeed</defName>
    <label>sand speed</label>
    <description>Speed of movement in cells per second through sand.</description>
    <category>BasicsPawn</category>
    <defaultBaseValue>0</defaultBaseValue>
    <minValue>0</minValue>
    <hideAtValue>0</hideAtValue>
    <toStringStyle>FloatTwo</toStringStyle>
    <formatString>{0} c/s</formatString>
    <displayPriorityInCategory>90</displayPriorityInCategory>
    <capacityFactors>
      <li>
        <capacity>Moving</capacity>
        <weight>1</weight>
      </li>
    </capacityFactors>
    <parts>
      <li Class="StatPart_Glow">
        <humanlikeOnly>true</humanlikeOnly>
        <factorFromGlowCurve>
          <points>
            <li>(0,0.80)</li>
            <li>(0.30,1.00)</li>
          </points>
        </factorFromGlowCurve>
      </li>
    </parts>
    <scenarioRandomizable>true</scenarioRandomizable>
  </StatDef>
</Defs>

This add a SandSpeed stat which we'll make matter later on.

Applying SandSpeed to a pawn

With a new stat we'll want to add this stat to our pawn in Defs/ThingDefs_Races/SandWorm.xml.

<ThingDef ParentName="AnimalThingBase">
  <defName>Sand Worm</defName>
  <label>worm</label>
  <description>A large predatory worm that only lurks in sands.</description>
  <statBases>
    <MoveSpeed>1.0</MoveSpeed>
    <SandSpeed>8.0</SandSpeed>
  </statBases>
  ...

We made the Sand Worm have a MoveSpeed of 1 but a SandSpeed of 8, meaning we intend for this guy to be quite fast in sand.

Adding a pathCost stat

Clone this wiki locally