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

Manual Patching with Vanilla


Each individual weapon gets 3 Patches, safety check, reloading code, then animal behaviors.

Safety Check

The first patch just checks to see if the comps node is there and adds it if it isn't. This is just there to solve compatibility problems, and if there is a problem with this in the future it's likely because the other mod needs a safety check too or needs to be loaded before Simple Ammo.

  <Operation Class="PatchOperationConditional">
    <xpath>Defs/ThingDef[defName="Your_Def"]/comps</xpath>
    <nomatch Class="PatchOperationAdd">
      <xpath>Defs/ThingDef[defName="Your_Def"]</xpath>
      <value>
        <comps />
      </value>
    </nomatch>
  </Operation>

Reloading Code

Note:This is NOT an official wiki for the Reloading code form VEF, when one is written for 1.3 a link will be provided and this information will be rewritten to reference official documentation. Old 1.2 Wiki

Most of the nodes available are straight forward, but to help clarify everything:

  • compClass - Supports Reloading.CompReloadable and Reloading.CompChangeableAmmo, you probably want the first one, the second is advanced usage
  • MaxShots - As it says, this multiplied by ItemsPerShot gives the total ammo needed to reload. Typically you want this to be a multiple of the burstShotCount, and needs to be at least the burstShotCount or else it will refuse to shoot. Note: burstShotCount comes from the weapon itself, and will default to one if not specified.
  • ItemsPerShot - Amount of ammo used per shot. Ammo per burst is not yet supported.
  • ReloadTimePerShot - This multiplied by MaxShots will give reload time in real life seconds.
  • ReloadSound - Sound played when reloading
  • AmmoFilter - Supports both thingDefs and categories, and will handle multiple types of ammo. For the purposes of Simple Ammo we only use thingDef and one ammo type at a time, but this info can be handy if using CompChangeableAmmo.
  • GenerateAmmo - This node is optional, how much ammo for npc's to spawn with, can support multiple items which can be useful if using CompChangeableAmmo.
  • NewVerbClass - This node is optional, it will replace the verb with the one you specify. Makes one less patch operation if making a single use weapon reloadable, like rocket launchers.
  • GenerateBackupWeapon - This node is optional, and accepts a boolean(true/false). I still need to play with this one, but the name is obvious enough. Check out Reloadable Rockets to see a functional example of how to use this.

Note: Comments are where I put reference notes while I write patches.

    <Operation Class="PatchOperationAdd">
        <xpath>Defs/ThingDef[defName="Your_Def"]/comps</xpath>
        <value>
            <li Class="Reloading.CompProperties_Reloadable">
                <compClass>Reloading.CompReloadable</compClass>
                <MaxShots>#</MaxShots> <!-- burstShotCount # reference -->
                <ItemsPerShot>#</ItemsPerShot>
                <ReloadTimePerShot>#</ReloadTimePerShot>
                <ReloadSound>Sound</ReloadSound>
                <AmmoFilter>
                    <thingDefs> <!-- Real Life ammo for reference -->
                        <li>RawPotatoes</li>
                    </thingDefs>
                </AmmoFilter>
                <GenerateAmmo>
                    <RawPotatoes>
                      <Min>#</Min>
                      <Max>#</Max>
                    </RawPotatoes>
                </GenerateAmmo>
                <NewVerbClass>Verb</NewVerbClass>
                <GenerateBackupWeapon>booleen</GenerateBackupWeapon>
            </li>
        </value>
    </Operation>

Proper Shotguns

If the weapon you're patching is supported then you're likely going to use the following patch to offer different balance, the PatchOperationAdd's are abbreviated for space and copy the Reloading patch above.

  <Operation Class="PatchOperationFindMod">
    <mods>
      <li>[XND] Proper Shotguns (Continued)</li>
    </mods>
    <match Class="PatchOperationAdd" />
    <nomatch Class="PatchOperationAdd" />
  </Operation>

Animal Behaviors

VEF Wiki Page

Reference this file for language information

As it turns out this one part of Animal Behaviors from VEF can be applied almost anywhere, so I used it here to add what ammo weapons use to their info screens. PatchOperationAddModExtension itself has a safety check built in so we don't need one like the comps node, which ironically leads into the next section.

  <Operation Class="PatchOperationAddModExtension">
    <xpath>Defs/ThingDef[defName="Your_Def"]</xpath>
    <value>
      <li Class="AnimalBehaviours.AnimalStatExtension">
        <statToAdd>
          <li>FF_Ammo_Type</li>	
        </statToAdd>
        <statValues>
          <li>FF_Potato_Ammo</li>
        </statValues>
        <statDescriptions>
          <li>FF_Potato_Desc</li>
        </statDescriptions>
      </li>
    </value>
  </Operation>

Manual Patching with XML Extensions


XmlExtensions.PatchOperationSafeAdd

Using vanilla patch operations gets the job done, but with XML Extensions we can add everything in one patch operation. Adding another dependency for one patch operation seems silly, but one day we may add it.

  <Operation Class="XmlExtensions.PatchOperationSafeAdd">
    <xpath>Defs/ThingDef[defName="Gun_ChargeRifle"]</xpath>
    <safetyDepth>1</safetyDepth>
    <value>
      <comps>
        <li Class="Reloading.CompProperties_Reloadable">
          <compClass>Reloading.CompReloadable</compClass>
          <MaxShots>45</MaxShots>
          <AmmoFilter>
            <thingDefs>
              <li>FF_Ammunition_Spacer</li>
            </thingDefs>
          </AmmoFilter>
          <ItemsPerShot>1</ItemsPerShot>
          <ReloadTimePerShot>0.03</ReloadTimePerShot>
          <ReloadSound>Standard_Reload</ReloadSound>
          <GenerateAmmo>
            <FF_Ammunition_Spacer>90~135</FF_Ammunition_Spacer>
          </GenerateAmmo>
        </li>
      </comps>
      <modExtensions>
        <li Class="AnimalBehaviours.AnimalStatExtension">
          <statToAdd>
            <li>FF_Ammo_Type</li>	
          </statToAdd>
          <statValues>
            <li>FF_Spacer_Ammo</li>
          </statValues>
          <statDescriptions>
            <li>FF_Spacer_Desc</li>
          </statDescriptions>
        </li>
      </modExtensions>
    </value>
  </Operation>

Using PatchDefs from XML Extensions


XmlExtensions.PatchDef

XmlExtensions.ApplyPatch

Still not compact enough? Let's write some PatchDefs and feed them variables from patches. First we're going to need to add a def:

<XmlExtensions.PatchDef Name="XYZ_Spacer_Patch" Abstract="True">
  <parameters>
    <li>XYZ_Spacer_Patch_defName</li>
    <li>XYZ_Spacer_Patch_MaxShots</li>
    <li>XYZ_Spacer_Patch_ItemsPerShot</li>
    <li>XYZ_Spacer_Patch_ReloadTimePerShot</li>
    <li>XYZ_Spacer_Patch_ReloadSound</li>
    <li>XYZ_Spacer_Patch_GenerateAmmo_min</li>
    <li>XYZ_Spacer_Patch_GenerateAmmo_max</li>
  </parameters>
  <apply>
   <Operation Class="XmlExtensions.PatchOperationSafeAdd">
    <xpath>Defs/ThingDef[defName="{XYZ_Spacer_Patch_defName}"]</xpath>
    <safetyDepth>1</safetyDepth>
    <value>
      <comps>
        <li Class="Reloading.CompProperties_Reloadable">
          <compClass>Reloading.CompReloadable</compClass>
          <MaxShots>{XYZ_Spacer_Patch_MaxShots}</MaxShots>
          <AmmoFilter>
            <thingDefs>
              <li>FF_Ammunition_Spacer</li>
            </thingDefs>
          </AmmoFilter>
          <ItemsPerShot>{XYZ_Spacer_Patch_ItemsPerShot}</ItemsPerShot>
          <ReloadTimePerShot>{XYZ_Spacer_Patch_ReloadTimePerShot}</ReloadTimePerShot>
          <ReloadSound>{XYZ_Spacer_Patch_ReloadSound}</ReloadSound>
          <GenerateAmmo>
            <FF_Ammunition_Spacer>
              <min>{XYZ_Spacer_Patch_GenerateAmmo_min}</min>
              <max>{XYZ_Spacer_Patch_GenerateAmmo_max}</max>
            </FF_Ammunition_Spacer>
          </GenerateAmmo>
        </li>
      </comps>
      <modExtensions>
        <li Class="AnimalBehaviours.AnimalStatExtension">
          <statToAdd>
            <li>FF_Ammo_Type</li>	
          </statToAdd>
          <statValues>
            <li>FF_Spacer_Ammo</li>
          </statValues>
          <statDescriptions>
            <li>FF_Spacer_Desc</li>
          </statDescriptions>
        </li>
      </modExtensions>
    </value>
   </Operation>
  </apply>
</XmlExtensions.PatchDef>

Then we just use XmlExtensions.ApplyPatch for each weapon:

<Operation Class="XmlExtensions.ApplyPatch">
    <patchName>XYZ_Spacer_Patch</patchName>
    <arguments>
        <li>Gun_ChargeRifle</li>
        <li>45</li>
        <li>1</li>
        <li>0.03</li>
        <li>90</li>
        <li>135</li>
        <li>Standard_Reload</li>
    </arguments>
</Operation>

Auto Patching with XML Extensions


Todo, the example for this one is complex.

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