Skip to content

1.3 An Example

XeoNovaDan edited this page Sep 6, 2018 · 4 revisions

This section of the document will quickly go through the creation of the XML for the Machine Gun Emplacement in TE Turret Expansion, a mod which utilizes the framework extensions offered by Turret Extensions.

The Base XML

First off, we must create the actual turret building ThingDef. For now, we'll do a standard non-TE def which looks like this:

<ThingDef ParentName="BuildingBase">
    <defName>Turret_MGEmplacement</defName>
    <label>machine gun emplacement</label>
    <description>A fixed gun emplacement with a heavy machine gun mounted on top. Lethal, but offers inferior cover to sandbags.</description>
    <thingClass>Building_TurretGun</thingClass>
    <statBases>
        <MaxHitPoints>250</MaxHitPoints>
        <Flammability>0.7</Flammability>
        <WorkToBuild>11000</WorkToBuild>
        <Beauty>-60</Beauty>
    </statBases>
    <uiIconPath>Things/Building/Security/MachineGunEmplacement_MenuIcon</uiIconPath>
    <uiIconScale>1.80</uiIconScale>
    <constructionSkillPrerequisite>6</constructionSkillPrerequisite>
    <researchPrerequisites>
        <li>GasOperation</li>
    </researchPrerequisites>
    <terrainAffordanceNeeded>Heavy</terrainAffordanceNeeded>
    <designationCategory>Security</designationCategory>
    <costList>
        <Steel>100</Steel>
        <ComponentIndustrial>6</ComponentIndustrial>
    </costList>
    <costStuffCount>110</costStuffCount>
    <stuffCategories>
        <li>Metallic</li>
    </stuffCategories>
    <placeWorkers>
        <li>PlaceWorker_TurretTop</li>
    </placeWorkers>
    <graphicData>
        <texPath>Things/Building/Security/MachineGunEmplacement/MachineGunEmplacement</texPath>
        <graphicClass>Graphic_Multi</graphicClass>
        <drawSize>(3.5,1.5)</drawSize>
        <damageData>
            <cornerTL>Damage/Corner</cornerTL>
            <cornerTR>Damage/Corner</cornerTR>
            <cornerBL>Damage/Corner</cornerBL>
            <cornerBR>Damage/Corner</cornerBR>
        </damageData>
    </graphicData>
    <altitudeLayer>Building</altitudeLayer>
    <tickerType>Normal</tickerType>
    <comps>
        <li Class="CompProperties_Mannable">
            <manWorkType>Violent</manWorkType>
        </li>
        <li Class="CompProperties_Forbiddable"/>
        <li Class="CompProperties_Refuelable">
            <fuelLabel>Shots until barrel change</fuelLabel>
            <fuelGizmoLabel>Barrel durability</fuelGizmoLabel>
            <fuelFilter>
                <thingDefs>
                    <li>Steel</li>
                </thingDefs>
            </fuelFilter>
            <fuelCapacity>300</fuelCapacity>
            <initialFuelPercent>1</initialFuelPercent>
            <autoRefuelPercent>0.25</autoRefuelPercent>
            <showFuelGizmo>true</showFuelGizmo>
            <fuelMultiplier>3.75</fuelMultiplier>
            <consumeFuelOnlyWhenUsed>true</consumeFuelOnlyWhenUsed>
            <outOfFuelMessage>Cannot shoot: Needs new barrel</outOfFuelMessage>
            <fuelIconPath>UI/Overlays/Barrel</fuelIconPath>
        </li>
    </comps>
    <passability>PassThroughOnly</passability>
    <pathCost>70</pathCost>
    <size>(3,1)</size>
    <hasInteractionCell>True</hasInteractionCell>
    <interactionCellOffset>(0,0,-1)</interactionCellOffset>
    <fillPercent>0.5</fillPercent>
    <castEdgeShadows>true</castEdgeShadows>
    <hasTooltip>true</hasTooltip>
    <specialDisplayRadius>30.9</specialDisplayRadius>
    <building>
        <turretGunDef>Gun_TurretMGEmplacement</turretGunDef>
        <turretBurstCooldownTime>3.6</turretBurstCooldownTime>
        <turretBurstWarmupTime>1.8</turretBurstWarmupTime>
        <turretTopGraphicPath>Things/Building/Security/MachineGunEmplacement_Top</turretTopGraphicPath>
    </building>
</ThingDef>

Utilizing Turret Extensions

Now that the standard building def has been created for the machine gun emplacement, it's possible to have it actually utilize the framework extensions offered by Turret Extensions.

In this particular building's case, it was given the useMannerShootingAccuracy and useMannerAimingDelayFactor tags so that it actually factors in the manning colonist's Shooting Accuracy and Aiming Time stats. Without these tags, the machine gun emplacement would always behave as if a baseline level 8 shooter was manning it, regardless of how effective at ranged combat the manning person actually was.

The following XML was added to the end of the ThingDef as a result:

    <modExtensions>
        <li Class="TurretExtensions.TurretFrameworkExtension">
            <useMannerShootingAccuracy>true</useMannerShootingAccuracy>
            <useMannerAimingDelayFactor>true</useMannerAimingDelayFactor>
        </li>
    </modExtensions>

The Final XML

Now that the manned turret modifications have been made, this is what the entire XML for the turret looks like when everything gets tied together:

<ThingDef ParentName="BuildingBase">
    <defName>Turret_MGEmplacement</defName>
    <label>machine gun emplacement</label>
    <description>A fixed gun emplacement with a heavy machine gun mounted on top. Lethal, but offers inferior cover to sandbags.</description>
    <thingClass>Building_TurretGun</thingClass>
    <statBases>
        <MaxHitPoints>250</MaxHitPoints>
        <Flammability>0.7</Flammability>
        <WorkToBuild>11000</WorkToBuild>
        <Beauty>-60</Beauty>
    </statBases>
    <uiIconPath>Things/Building/Security/MachineGunEmplacement_MenuIcon</uiIconPath>
    <uiIconScale>1.80</uiIconScale>
    <constructionSkillPrerequisite>6</constructionSkillPrerequisite>
    <researchPrerequisites>
        <li>GasOperation</li>
    </researchPrerequisites>
    <terrainAffordanceNeeded>Heavy</terrainAffordanceNeeded>
    <designationCategory>Security</designationCategory>
    <costList>
        <Steel>100</Steel>
        <ComponentIndustrial>6</ComponentIndustrial>
    </costList>
    <costStuffCount>110</costStuffCount>
    <stuffCategories>
        <li>Metallic</li>
    </stuffCategories>
    <placeWorkers>
        <li>PlaceWorker_TurretTop</li>
    </placeWorkers>
    <graphicData>
        <texPath>Things/Building/Security/MachineGunEmplacement/MachineGunEmplacement</texPath>
        <graphicClass>Graphic_Multi</graphicClass>
        <drawSize>(3.5,1.5)</drawSize>
        <damageData>
            <cornerTL>Damage/Corner</cornerTL>
            <cornerTR>Damage/Corner</cornerTR>
            <cornerBL>Damage/Corner</cornerBL>
            <cornerBR>Damage/Corner</cornerBR>
        </damageData>
    </graphicData>
    <altitudeLayer>Building</altitudeLayer>
    <tickerType>Normal</tickerType>
    <comps>
        <li Class="CompProperties_Mannable">
            <manWorkType>Violent</manWorkType>
        </li>
        <li Class="CompProperties_Forbiddable"/>
        <li Class="CompProperties_Refuelable">
            <fuelLabel>Shots until barrel change</fuelLabel>
            <fuelGizmoLabel>Barrel durability</fuelGizmoLabel>
            <fuelFilter>
                <thingDefs>
                    <li>Steel</li>
                </thingDefs>
            </fuelFilter>
            <fuelCapacity>300</fuelCapacity>
            <initialFuelPercent>1</initialFuelPercent>
            <autoRefuelPercent>0.25</autoRefuelPercent>
            <showFuelGizmo>true</showFuelGizmo>
            <fuelMultiplier>3.75</fuelMultiplier>
            <consumeFuelOnlyWhenUsed>true</consumeFuelOnlyWhenUsed>
            <outOfFuelMessage>Cannot shoot: Needs new barrel</outOfFuelMessage>
            <fuelIconPath>UI/Overlays/Barrel</fuelIconPath>
        </li>
    </comps>
    <passability>PassThroughOnly</passability>
    <pathCost>70</pathCost>
    <size>(3,1)</size>
    <hasInteractionCell>True</hasInteractionCell>
    <interactionCellOffset>(0,0,-1)</interactionCellOffset>
    <fillPercent>0.5</fillPercent>
    <castEdgeShadows>true</castEdgeShadows>
    <hasTooltip>true</hasTooltip>
    <specialDisplayRadius>30.9</specialDisplayRadius>
    <building>
        <turretGunDef>Gun_TurretMGEmplacement</turretGunDef>
        <turretBurstCooldownTime>3.6</turretBurstCooldownTime>
        <turretBurstWarmupTime>1.8</turretBurstWarmupTime>
        <turretTopGraphicPath>Things/Building/Security/MachineGunEmplacement_Top</turretTopGraphicPath>
    </building>
    <modExtensions>
        <li Class="TurretExtensions.TurretFrameworkExtension">
            <useMannerShootingAccuracy>true</useMannerShootingAccuracy>
            <useMannerAimingDelayFactor>true</useMannerAimingDelayFactor>
        </li>
    </modExtensions>
</ThingDef>

And that concludes how to make a turret use TurretFrameworkExtension!

To learn how to make a turret upgradable, see here.

Clone this wiki locally