Skip to content
This repository has been archived by the owner on Apr 14, 2020. It is now read-only.

Creating a caliber

NoImageAvailable edited this page Jul 9, 2017 · 7 revisions

If your weapon is using an ammo type that is not yet part of the CE core mod you will need to create your own. Several things are need to create a completely new caliber and we'll go through them one by one using CE's .50 BMG as an example.

Creating the file

For readability, every caliber should have its own XML file named after the shared part of the def names, e.g. 50BMG.xml, 14x114mmSoviet.xml, etc.

ThingCategoryDef

    <ThingCategoryDef>
      <defName>Ammo50BMG</defName>
      <label>.50 BMG</label>
      <parent>AmmoHighCaliber</parent>
    </ThingCategoryDef>

This is what your caliber shows up on in a stockpile's storage tab. Every caliber should have its own category. The parent should be the general category the caliber falls into. See /Defs/Ammo/ThingCategories.xml for all the available parent categories.

AmmoSet

  <CombatExtended.AmmoSetDef>
    <defName>AmmoSet_50BMG</defName>
    <label>.50 BMG</label>
    <ammoTypes>
      <Ammo_50BMG_FMJ>Bullet_50BMG_FMJ</Ammo_50BMG_FMJ>
      <Ammo_50BMG_Sabot>Bullet_50BMG_Sabot</Ammo_50BMG_Sabot>
      <Ammo_50BMG_HE>Bullet_50BMG_HE</Ammo_50BMG_HE>
      <Ammo_50BMG_Incendiary>Bullet_50BMG_Incendiary</Ammo_50BMG_Incendiary>
    </ammoTypes>
  </CombatExtended.AmmoSetDef>

This is what you will put into CompAmmoUser when setting what caliber a weapon uses.

label: this will be what is listed in a gun's info tab under what caliber it uses.

ammoTypes: this maps an AmmoThing (what is actually spawned in the world, carried in inventory, etc.) to a projectile (what is fired when this ammo is loaded). The format for these is <AmmoThingDefName>ProjectileDefName</AmmoThingDefName>.

Note that when the ammo system is toggled of every gun using this caliber will default to whichever projectile is defined first in this list, in this case that'd be FMJ ammo.

Tip: you can have multiple AmmoSets map the same AmmoThing to different projectiles. For example if your mod adds Old-West rifles and pistols using the same caliber, you can define two AmmoSets. Both use the same AmmoThing but the rifle one has faster/more damaging projectiles.

Ammo

  <ThingDef Name="Ammo50BMGBase" ParentName="SmallAmmoBase" Abstract="True">
    <description>Large caliber bullet used by many heavy machine guns and anti-materiel rifles.</description>
    <statBases>
      <Mass>0.12</Mass>
      <Bulk>0.16</Bulk>
    </statBases>
    <tradeTags>
      <li>CE_AutoEnableTrade</li>
      <li>CE_AutoEnableCrafting</li>
    </tradeTags>
    <thingCategories>
      <li>Ammo50BMG</li>
    </thingCategories>
    <stackLimit>200</stackLimit>
  </ThingDef>

  <ThingDef ParentName="Ammo50BMGBase">
    <defName>Ammo_50BMG_FMJ</defName>
    <label>.50 BMG cartridge (FMJ)</label>
    <graphicData>
      <texPath>Things/Ammo/HighCaliber/FMJ</texPath>
      <graphicClass>Graphic_StackCount</graphicClass>
    </graphicData>
    <statBases>
      <MarketValue>0.42</MarketValue>
    </statBases>
    <ammoClass>FullMetalJacket</ammoClass>
    <cookOffProjectile>Bullet_50BMG_FMJ</cookOffProjectile>
  </ThingDef>

This is the actual object that will show up on the game map and can be bought from traders, carried in your inventory, etc. and consumed on reloading. It is good form to have one base class and then derive all your different ammo types (FMJ, AP, HP, etc.) from that.

tradeTags: if you want traders to stock your ammo, use CE_AutoEnableTrade. If you want players to be able to craft your ammo, use CE_AutoEnableCrafting.

Note: CE_AutoEnableCrafting will automatically look for a recipe with defName = Make[ammoThingDefName], e.g. MakeAmmo_50BMG_FMJ.

By default all recipes are added to the loading bench, if you want your recipe to go to a different work bench you need to append the defName to the tag, e.g. CE_AutoEnableCrafting_TableMachining would add your recipe to the machining table. If you want the recipe to be available at multiple benches you can specify multiple tags for each.

ammoClass: the general class of ammo. For all currently possible types see the files in Defs/Ammo/AmmoCategoryDefs

cookOffProjectile: when bullet stacks take damage they cook off and start spraying bullets everywhere. This determines what projectile is fired on cook-off. For explosive shells leave this blank and use CompExplosiveCE instead.

Note: the above example derives from CE's own abstract def "SmallAmmoBase". These base classes contain shared data all CE ammo needs and you should derive from the same bases when making your own defs. This also applies to all the defs listed down below.

Projectile

  <ThingDef Name="Base50BMGBullet" ParentName="BaseBullet" Abstract="true">
    <graphicData>
      <texPath>Things/Projectile/Bullet_Big</texPath>
      <graphicClass>Graphic_Single</graphicClass>
    </graphicData>
    <projectile>
      <damageDef>Bullet</damageDef>
      <speed>222</speed>
      <dropsCasings>true</dropsCasings>
    </projectile>
  </ThingDef>

  <ThingDef ParentName="Base50BMGBullet">
    <defName>Bullet_50BMG_HE</defName>
    <label>.50 BMG bullet (HE)</label>
    <projectile>
      <damageAmountBase>28</damageAmountBase>
      <armorPenetration>1.059</armorPenetration>
      <secondaryDamage>
        <li>
          <def>Bomb_Secondary</def>
          <amount>18</amount>
        </li>
      </secondaryDamage>
    </projectile>
  </ThingDef>

dropsCasings: whether this will generate a bullet casing mote on being fired.

armorPenetration: this determines how well this projectile does against armor. As a rule, if a bullet's penetration matches the armor's deflection stat it will have a 50% chance to be deflected.

secondaryDamage: this is applied alongside the primary damage.

Note that CE uses secondary damage types with harmAllLayersUntilOutside set to false. This means that a bullet that penetrates the torso to hit the kidney will apply primary damage to both the torso and kidney, but secondary damage only to the kidney. This might or might not make sense for your type of ammo, so you'll have to decide for yourself.

Note: if your projectile is supposed to cause an explosion (e.g. cannon shell) it will need to have CompProperties_ExplosiveCE defined for it. Do not use vanilla CompExplosive.

Recipes

  <RecipeDef ParentName="AmmoRecipeBase">
    <defName>MakeAmmo_50BMG_FMJ</defName>
    <label>make .50 BMG (FMJ) cartridge x200</label>
    <description>Craft 200 .50 BMG (FMJ) cartridges.</description>
    <jobString>Making .50 BMG (FMJ) cartridges.</jobString>
    <ingredients>
      <li>
        <filter>
          <thingDefs>
            <li>Steel</li>
          </thingDefs>
        </filter>
        <count>31</count>
      </li>
    </ingredients>
    <fixedIngredientFilter>
      <thingDefs>
        <li>Steel</li>
      </thingDefs>
    </fixedIngredientFilter>
    <products>
      <Ammo_50BMG_FMJ>200</Ammo_50BMG_FMJ>
    </products>
    <workAmount>5250</workAmount>
  </RecipeDef>

These aren't changed from vanilla. However it is important that the name is exactly Make[YourAmmoDefName] or else the system won't be able to properly recognize it. Do not include recipe users, these are added automatically on game load.

The output count should be different depending on the type of ammo, e.g. pistol and rifle ammo produces stacks of 500, high caliber ammo like the .50 BMG only 200, etc. Use CE's included recipes for a guideline on what makes sense for your caliber.

Determining ammo and projectile stats

Use this spreadsheet (make a local copy or download it, then edit on your end). Simply fill in your projectile's data in the input tab and use the stats tabs to calculate your values.

Submitting the caliber

After you're done creating your caliber, submit it to the CE team on the Rimworld forums or here on GitHub. DO NOT package it with your mod.

The reason for this is if for example a user installs mod A which adds an AK-47 and mod B which adds an RPD, they will end up with two different 7.62x39mm calibers, which can both be fired only from either an AK or an RPD. To avoid this CE starts all ammo types disabled and selectively enables them if it detects a gun using it.