Scenarios - Freefolk-Rimworld-Modding/FF-Simple-Ammunition-Remastered-2.0 GitHub Wiki

Manual Patching with Vanilla


Manually patching scenarios is straight forward

  <Operation Class="PatchOperationAdd">
    <xpath>Defs/ScenarioDef[defName="Crashlanded"]/scenario/parts</xpath>
    <value>
      <li Class="ScenPart_StartingThing_Defined">
        <def>StartingThing_Defined</def>
        <thingDef>FF_Ammunition_Industrial</thingDef>
        <count>300</count>
      </li>
    </value>
  </Operation>

Auto Patching with Vanilla


I still need to test this bit of code, but it should be straight forward. Every scenario with a revolver should have ammo added to it.

  <Operation Class="PatchOperationAdd">
    <xpath>Defs/ScenarioDef/scenario/parts[li/thingDef="Gun_Revolver"]</xpath>
    <value>
      <li Class="ScenPart_StartingThing_Defined">
        <def>StartingThing_Defined</def>
        <thingDef>FF_Ammunition_Industrial</thingDef>
        <count>150</count>
      </li>
    </value>
  </Operation>

This maybe faster, again I need to do some testing.

  <Operation Class="PatchOperationAdd">
    <xpath>Defs/ScenarioDef[scenario/parts/li/thingDef="Gun_Revolver"]/scenario/parts</xpath>
    <value>
      <li Class="ScenPart_StartingThing_Defined">
        <def>StartingThing_Defined</def>
        <thingDef>FF_Ammunition_Industrial</thingDef>
        <count>150</count>
      </li>
    </value>
  </Operation>

Auto Patching with XML Extensions


XmlExtensions.ForEach

XmlExtensions.CreateVariable

This example still needs testing.

The above examples will work fine, but with CreateVariable we can be more precise and add more ammo if there is a count defined for the weapon. Even if we hit all vanilla weapons there will still be plenty of edge cases that will be easier to manually patch.

  <Operation Class="XmlExtensions.ForEach"> <!-- Runs this for each ScenarioDef, filtering out ones without Gun_Revolver -->
    <xpath>Defs/ScenarioDef/scenario/parts/li[thingDef="Gun_Revolver"]</xpath>
    <storeIn>ScenarioDef_Path</storeIn>
    <prefixLength>4</prefixLength>
    <apply> 
      <Operation Class="XmlExtensions.CreateVariable"> <!-- Creates a variable based on the count node of revolver -->
        <storeIn>Count_Gun_Revolver</storeIn>
        <value>{ScenarioDef_Path}/li[thingDef="Gun_Revolver"]/count</value>
        <value2>150</value2>
        <fromXml>true</fromXml>
        <defaultValue>1</defaultValue> <!-- Defaults to 1 if there is not a count node -->
        <operation>*</operation>
        <apply>
          <Operation Class="PatchOperationAdd"> <!-- Adds ammo using variable we created -->
            <xpath>{ScenarioDef_Path}</xpath>
            <value>
              <li Class="ScenPart_StartingThing_Defined">
                <def>StartingThing_Defined</def>
                <thingDef>FF_Ammunition_Industrial</thingDef>
                <count>{Count_Gun_Revolver}</count>
              </li>
            </value>
          </Operation>
        </apply>
      </Operation>
    </apply>
  </Operation>

Functional example for Yayo's Combat 3

⚠️ **GitHub.com Fallback** ⚠️