Gamedev:UnitDefs: Difference between revisions

From Spring
Jump to navigationJump to search
Flozi (talk | contribs)
m →General: match wording of other tags
Flozi (talk | contribs)
m →General: cross reference
Line 1: Line 1:
==Location==
<h2>Location</h2>
UnitDef files are .lua files stored in the <code>Units/</code> directory of a Spring Game.
<p>UnitDef files are .lua files stored in the <code>Units/</code> directory of a Spring Game.
 
</p>
==Purpose==
<h2>Purpose</h2>
UnitDef files have one purpose; to define the properties of units. They are the main description file for what attributes your unit should have and how it should behave.
<p>UnitDef files have one purpose; to define the properties of units. They are the main description file for what attributes your unit should have and how it should behave.
 
</p>
==Source==
<h2>Source</h2>
The engine source code which loads the tags from these files is viewable here:{{sourcelink|file=rts/Sim/Units/UnitDef.cpp}}
<p>The engine source code which loads the tags from these files is viewable here:<span class="fck_mw_template">{{sourcelink|file=rts/Sim/Units/UnitDef.cpp}}</span>
 
</p><p><br />
 
The engine source which reads the <a _fcknotitle="true" href="#sounds">#sounds</a> subtable can be found here:<span class="fck_mw_template">{{sourcelink|file=rts/Sim/Units/UnitDefHandler.cpp}}</span>
The engine source which reads the [[#sounds]] subtable can be found here:{{sourcelink|file=rts/Sim/Units/UnitDefHandler.cpp}}
</p>
 
<h2>Data Types</h2>
==Data Types==
<p>Tags may be one of the following data types:
Tags may be one of the following data types:
</p>
* <code>int</code> - An integer number
<ul><li> <code>int</code> - An integer number
* <code>float</code> - A number with decimals.
</li><li> <code>float</code> - A number with decimals.
* <code>bool</code> - A value which can be <code>true</code> or <code>false</code>.
</li><li> <code>bool</code> - A value which can be <code>true</code> or <code>false</code>.
* <code>string</code> - Text, or more precisely a string of alphanumeric characters.
</li><li> <code>string</code> - Text, or more precisely a string of alphanumeric characters.
* <code>float[3]</code> - A vector, with three <code>float</code> components, representing x, y and z axes (y is 'up').
</li><li> <code>float[3]</code> - A vector, with three <code>float</code> components, representing x, y and z axes (y is 'up').
 
</li></ul>
==Details==
<h2>Details</h2>
There follows a comprehensive (certain deprecated tags are not present) list of the tags available, their data type, default value and a brief description of what they do. Bear in mind that the source code linked above is the ultimate reference when dealing with these tags.  
<p>There follows a comprehensive (certain deprecated tags are not present) list of the tags available, their data type, default value and a brief description of what they do. Bear in mind that the source code linked above is the ultimate reference when dealing with these tags.  
 
</p><p>In lua tables keys (i.e. the tags) should be lower case, here they are represented in camelCase for readability. In your files you may use the <code>lowerkeys</code> function on your final table to ensure the keys are properly cased.
In lua tables keys (i.e. the tags) should be lower case, here they are represented in camelCase for readability. In your files you may use the <code>lowerkeys</code> function on your final table to ensure the keys are properly cased.
</p><p>It is usual to name the returned UnitDef table the internal <code>unitName</code> desired for the unit.
 
</p>
It is usual to name the returned UnitDef table the internal <code>unitName</code> desired for the unit.
<h3>General</h3>
 
<p><span class="fck_mw_template">{{tagfckLR|name = namefckLR|type = stringfckLR|default = &quot;&quot;fckLR|description = This is simply the name of the unit as it appears to the player.}}</span>
===General===
</p><p><span class="fck_mw_template">{{tagfckLR|name = descriptionfckLR|type = stringfckLR|default = namefckLR|description = This is the tooltip description of the unit seen by the player. It defaults to the &lt;code&gt;name&lt;/code&gt; of the unit.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = buildPicfckLR|type = stringfckLR|default = &quot;&quot;fckLR|description = The filename of the image to be used as the build picture, assumes &lt;code&gt;Unitpics/&lt;/code&gt; directory.}}</span>
|name = name
</p><p><span class="fck_mw_template">{{tagfckLR|name = objectNamefckLR|type = stringfckLR|default = &quot;&quot;fckLR|description = The filename of the 3D model file for this unit, assumes &lt;code&gt;Objects3D/&lt;/code&gt; directory.}}</span>
|type = string
</p><p><span class="fck_mw_template">{{tagfckLR|name = scriptfckLR|type = stringfckLR|default = unitName + &quot;.cob&quot;fckLR|description = The filename of the animation script file for this unit, assumes &lt;code&gt;Scripts/&lt;/code&gt; directory. Default assumes .cob file but [[Animation-LuaScripting | LUS]] should be preferred.}}</span>
|default = ""
</p><p><span class="fck_mw_template">{{tagfckLR|name = maxDamagefckLR|type = floatfckLR|default = 0.0fckLR|description = The base 'hitpoints' the unit will have.}}</span>
|description = This is simply the name of the unit as it appears to the player.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = autoHealfckLR|type = floatfckLR|default = 0.0fckLR|description = How much health the unit will regain every second.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = idleAutoHealfckLR|type = floatfckLR|default = 10.0fckLR|description = How much health the unit will regain every second whilst it is idle.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = idleTimefckLR|type = intfckLR|default = 600fckLR|description = The time in [[frames]] taken until a unit is considered to be idle.}}</span>
|name = description
</p><p><span class="fck_mw_template">{{tagfckLR|name = buildCostMetalfckLR|type = floatfckLR|default = 1.0fckLR|description = The amount of metal resource the unit costs to build. Cannot be below &lt;code&gt;1.0&lt;/code&gt;.}}</span>
|type = string
</p><p><span class="fck_mw_template">{{tagfckLR|name = buildCostEnergyfckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of energy resource the unit costs to build.}}</span>
|default = name
</p><p><span class="fck_mw_template">{{tagfckLR|name = buildTimefckLR|type = floatfckLR|default = 0.0fckLR|description = The time taken to build the unit, in conjunction with the &lt;code&gt;workerTime&lt;/code&gt; of the constructor. Effectively, ''Time to build = unit &lt;code&gt;buildTime&lt;/code&gt; / constructor &lt;code&gt;workerTime&lt;/code&gt;''. Defaults to &lt;code&gt;0.0&lt;/code&gt; but cannot actually be below &lt;code&gt;1.0&lt;/code&gt;.}}</span>
|description = This is the tooltip description of the unit seen by the player. It defaults to the <code>name</code> of the unit.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = massfckLR|type = floatfckLR|default = buildCostMetalfckLR|description = The mass of the unit, used in weapon impulse calculations. Cannot be less than &lt;code&gt;1.0&lt;/code&gt;.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = reclaimablefckLR|type = boolfckLR|default = truefckLR|description = Can the unit be reclaimed by a builder?}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = capturablefckLR|type = boolfckLR|default = truefckLR|description = Can a unit be stolen by a builder using the capture command?}}</span>
|name = buildPic
</p><p><span class="fck_mw_template">{{tagfckLR|name = repairablefckLR|type = boolfckLR|default = truefckLR|description = Can the unit be repaired by a builder?}}</span>
|type = string
</p><p><span class="fck_mw_template">{{tagfckLR|name = maxRepairSpeedfckLR|type = floatfckLR|default = 1e20fckLR|description = The maximum cumulative speed at which this unit can be repaired.}}</span>
|default = ""
</p><p><span class="fck_mw_template">{{tagfckLR|name = iconTypefckLR|type = stringfckLR|default = &quot;default&quot;fckLR|description = The name of the radar icon type this unit should use. See [[Icontypes.lua]].}}</span>
|description = The filename of the image to be used as the build picture, assumes <code>Unitpics/</code> directory.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = corpsefckLR|type = stringfckLR|default = &quot;&quot;fckLR|description = The name of the feature this unit should leave behind as a wreck when it dies (See [[Units-FeatureDefs]]).}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = explodeAsfckLR|type = stringfckLR|default = &quot;&quot;fckLR|description = The name of the weapon this unit should explode as when it is killed (See [[Units-WeaponDefs]]).}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = selfDestructAsfckLR|type = stringfckLR|default = &quot;&quot;fckLR|description = The name of the weapon this unit should explode as when it self destructs (See [[Units-WeaponDefs]]). Also used as the &lt;code&gt;kamikaze&lt;/code&gt; weapon.}}</span>
|name = objectName
</p>
|type = string
<h3>Resources</h3>
|default = ""
<p><span class="fck_mw_template">{{tagfckLR|name = metalStoragefckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the metal resource storage the unit contributes.}}</span>
|description = The filename of the 3D model file for this unit, assumes <code>Objects3D/</code> directory.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = energyStoragefckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the energy resource storage the unit contributes.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = extractsMetalfckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the metal resource the unit extracts from the ground. The amount extracted depends on the metal map defined in the map itself. Works only for structures.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = extractSquarefckLR|type = boolfckLR|default = falsefckLR|description = Is the metal extractors extraction area circular or square?}}</span>
|name = script
</p><p><span class="fck_mw_template">{{tagfckLR|name = windGeneratorfckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the energy resource the unit generates which is dependant on the map wind. Works only for structures.}}</span>
|type = string
</p><p><span class="fck_mw_template">{{tagfckLR|name = tidalGeneratorfckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the energy resource the unit generates which is dependant on the maps tidal power. Clearly, this only works on water structures.}}</span>
|default = unitName + ".cob"
</p><p><span class="fck_mw_template">{{tagfckLR|name = metalUsefckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the metal resource the unit consumes per game 'tick'.}}</span>
|description = The filename of the animation script file for this unit, assumes <code>Scripts/</code> directory. Default assumes .cob file but [[Animation-LuaScripting | LUS]] should be preferred.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = energyUsefckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the energy resource the unit consumes per game 'tick'.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = metalMakefckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the metal resource the unit generates unconditionally per game 'tick'.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = energyMakefckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the energy resource the unit generates unconditionally per game 'tick'.}}</span>
|name = maxDamage
</p><p><span class="fck_mw_template">{{tagfckLR|name = makesMetalfckLR|type = floatfckLR|default = 0.0fckLR|description = The amount of the energy resource the unit turns into the metal resource per game 'tick'.}}</span>
|type = float
</p>
|default = 0.0
<h3>Sensors</h3>
|description = The base 'hitpoints' the unit will have.}}
<p><span class="fck_mw_template">{{tagfckLR|name = onoffablefckLR|type = boolfckLR|default = falsefckLR|description = Does the unit have an on/off button? Currently the activation status tied to this button also turns sensors (other than LOS) on and off.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = activateWhenBuiltfckLR|type = boolfckLR|default = falsefckLR|description = Should the unit's activation status be on or off when it is created?}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = sightDistancefckLR|type = floatfckLR|default = 0.0fckLR|description = The radius of the units sight (LOS is circular in Spring)}}</span>
|name = autoHeal
</p><p><span class="fck_mw_template">{{tagfckLR|name = airSightDistancefckLR|type = floatfckLR|default = 1.5 * sightDistancefckLR|description = How far away the unit can see aircraft (and some FX).}}</span>
|type = float
</p><p><span class="fck_mw_template">{{tagfckLR|name = losEmitHeightfckLR|type = floatfckLR|default = 20.0fckLR|special={{new|83.0}}fckLR|description = How high up the unit is the point used to calculate it's LOS vs. the terrain?}}</span>
|default = 0.0
</p><p><span class="fck_mw_template">{{tagfckLR|name = radarEmitHeightfckLR|type = floatfckLR|default = 20.0fckLR|special={{new|83.0}}fckLR|description = How high up the unit is the point used to calculate it's radar vs. the terrain?}}</span>
|description = How much health the unit will regain every second.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = radarDistancefckLR|type = intfckLR|default = 0fckLR|description = The radius of the units radar.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = sonarDistancefckLR|type = intfckLR|default = 0fckLR|description = The radius of the units sonar.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = radarDistanceJamfckLR|type = intfckLR|default = 0fckLR|description = The radius of the units radar jamming.}}</span>
|name = idleAutoHeal
</p><p><span class="fck_mw_template">{{tagfckLR|name = sonarDistancefckLR|type = intfckLR|default = 0fckLR|description = The radius of the units sonar jamming.}}</span>
|type = float
</p><p><span class="fck_mw_template">{{tagfckLR|name = stealthfckLR|type = boolfckLR|default = falsefckLR|description = Is the unit undetectable by radar?}}</span>
|default = 10.0
</p><p><span class="fck_mw_template">{{tagfckLR|name = sonarStealthfckLR|type = boolfckLR|default = falsefckLR|description = Is the unit undetectable by sonar?}}</span>
|description = How much health the unit will regain every second whilst it is idle.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = seismicDistancefckLR|type = intfckLR|default = 0fckLR|description = The radius of the unit's seismic (movement) sensor.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = seismicSignaturefckLR|type = floatfckLR|default = 0 for units with &lt;code&gt;floater&lt;/code&gt;, &lt;code&gt;canHover&lt;/code&gt; or &lt;code&gt;canFly&lt;/code&gt;, otherwise sqrt(mass / 100.0)fckLR|description = How fast the seismic ring expands in [[Units-UnitsOfMeasurement | elmos per frame]]. Each ping always lasts 15 [[frames]], so this also determines the maximum radius of the seismic ring.}}</span>
{{tag
</p>
|name = idleTime
<h4>Cloaking</h4>
|type = int
<p>For units with <a href="Units-UnitDefs#Commands">canCloak</a> set to <code>true</code>:
|default = 600
<span class="fck_mw_template">{{tagfckLR|name = cloakCostfckLR|type = floatfckLR|default = 0.0fckLR|description = The energy cost per tick to cloak the unit while it is stationary.}}</span>
|description = The time in [[frames]] taken until a unit is considered to be idle.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = cloakCostMovingfckLR|type = floatfckLR|default = cloakCostfckLR|description = The energy cost per tick to cloak the unit while it is moving.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = initCloakedfckLR|type = boolfckLR|default = falsefckLR|description = Is the unit cloaked as soon as it is created?}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = minCloakDistancefckLR|type = floatfckLR|default = 0.0fckLR|description = The minimum distance (radius) which the unit must be from any enemy units to remain cloaked.}}</span>
|name = buildCostMetal
</p><p><span class="fck_mw_template">{{tagfckLR|name = decloakSphericalfckLR|type = boolfckLR|default = truefckLR|description = Does &lt;code&gt;minCloakDistance&lt;/code&gt; apply in 3D or only 2D? i.e. can aircraft flying above the unit decloak it?}}</span>
|type = float
</p><p><span class="fck_mw_template">{{tagfckLR|name = decloakOnFirefckLR|type = boolfckLR|default = truefckLR|description = Does the unit deloak when it fires a weapon?}}</span>
|default = 1.0
</p><p><span class="fck_mw_template">{{tagfckLR|name = cloakTimeoutfckLR|type = intfckLR|default = 128fckLR|description = The minimum time, in [[frames]], between a decloak and subsequent re-cloak.}}</span>
|description = The amount of metal resource the unit costs to build. Cannot be below <code>1.0</code>.}}
</p>
 
<h3>Commands</h3>
{{tag
<p><span class="fck_mw_template">{{tagfckLR|name = canMovefckLR|type = boolfckLR|default = falsefckLR|description = Can the unit be issued Move orders?}}</span>
|name = buildCostEnergy
</p><p><span class="fck_mw_template">{{tagfckLR|name = canAttackfckLR|type = boolfckLR|default = truefckLR|description = Can the unit be issued Attack orders?}}</span>
|type = float
</p><p><span class="fck_mw_template">{{tagfckLR|name = canFightfckLR|type = boolfckLR|default = truefckLR|description = Can the unit be issued Fight orders?}}</span>
|default = 0.0
</p><p><span class="fck_mw_template">{{tagfckLR|name = canPatrolfckLR|type = boolfckLR|default = truefckLR|description = Can the unit be issued Patrol orders?}}</span>
|description = The amount of energy resource the unit costs to build.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = canGuardfckLR|type = boolfckLR|default = truefckLR|description = Can the unit be issued Guard orders?}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR| name = canCloakfckLR| type = boolfckLR| default = falsefckLR| description =fckLRCan the unit be issued Cloak orders?}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = canRepeatfckLR|type = boolfckLR|default = truefckLR|description = Can the unit be issued Repeat orders?}}</span>
|name = buildTime
</p><p><span class="fck_mw_template">{{tagfckLR|name = canSelfDestructfckLR|type = boolfckLR|default = truefckLR|description = Can the unit be issued a self destruct order?}}</span>
|type = float
</p><p><span class="fck_mw_template">{{tagfckLR|name = moveStatefckLR|type = intfckLR|default = -1 for mobile units, &lt;code&gt;1&lt;/code&gt; for structuresfckLR|description = The initial movement state for the unit. Can be &lt;code&gt;-1&lt;/code&gt; - Inherits from factory, &lt;code&gt;0&lt;/code&gt; - Hold Position, &lt;code&gt;1&lt;/code&gt; - Manoeuvre or &lt;code&gt;2&lt;/code&gt; - Roam.}}</span>
|default = 0.0
</p><p><span class="fck_mw_template">{{tagfckLR|name = fireStatefckLR|type = intfckLR|default = -1 for units without &lt;code&gt;noAutoFire&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt; otherwisefckLR|description = The initial firing state for the unit. Can be &lt;code&gt;-1&lt;/code&gt; - Inherits from factory, &lt;code&gt;0&lt;/code&gt; - Hold Fire, &lt;code&gt;1&lt;/code&gt; - Return Fire or &lt;code&gt;2&lt;/code&gt; - Fire At Will.}}</span>
|description = The time taken to build the unit, in conjunction with the <code>workerTime</code> of the constructor. Effectively, ''Time to build = unit <code>buildTime</code> / constructor <code>workerTime</code>''. Defaults to <code>0.0</code> but cannot actually be below <code>1.0</code>.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = noAutoFirefckLR|type = boolfckLR|default = falsefckLR|description = Controls whether or not the unit has a fire state button.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = canManualFirefckLR|type = boolfckLR|default = falsefckLR|description = Can the unit be issued ManualFire commands? A ManualFire command will fire any weapons with the &lt;code&gt;commandfire&lt;/code&gt; tag (See [[Units-WeaponDefs]]).}}</span>
{{tag
</p>
|name = mass
<h4>Builder Commands</h4>
|type = float
<p><span class="fck_mw_template">{{tagfckLR|name = canRestorefckLR|type = boolfckLR|default = builderfckLR|description = Can the unit be issued restore terrain commands? For builders only.}}</span>
|default = buildCostMetal
</p><p><span class="fck_mw_template">{{tagfckLR|name = canRepairfckLR|type = boolfckLR|default = builderfckLR|description = Can the unit be issued repair commands? For builders only.}}</span>
|description = The mass of the unit, used in weapon impulse calculations. Cannot be less than <code>1.0</code>.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = canReclaimfckLR|type = boolfckLR|default = builderfckLR|description = Can the unit be issued reclaim commands? For builders only.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = canResurrectfckLR|type = boolfckLR|default = falsefckLR|description = Can the unit be issued resurrection commands? For builders only.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = canCapturefckLR|type = boolfckLR|default = falsefckLR|description = Can the unit be issued capture commands? For builders only.}}</span>
|name = reclaimable
</p>
|type = bool
<h3>Builder</h3>
|default = true
<p><span class="fck_mw_template">{{tagfckLR|name = builderfckLR|type = boolfckLR|default = falsefckLR|description = Is the unit a builder?}}</span>
|description = Can the unit be reclaimed by a builder?}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = buildDistancefckLR|type = floatfckLR|default = 128.0fckLR|description = How far away from itself the unit can build, measured to the centre of the unit being built. The minimum value is &lt;code&gt;38.0&lt;/code&gt;.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = buildRange3DfckLR|type = boolfckLR|default = falsefckLR|description = Does the builders &lt;code&gt;buildDistance&lt;/code&gt; apply in all 3 dimensions or only 2?}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = workerTimefckLR|type = floatfckLR|default = 0.0fckLR|description = How fast the builder builds, used in conjunction with the &lt;code&gt;buildTime&lt;/code&gt; of the unit being built. Effectively, ''Time to build = unit &lt;code&gt;buildTime&lt;/code&gt; / constructor &lt;code&gt;workerTime&lt;/code&gt;''. If this value is &lt;= &lt;code&gt;0.0&lt;/code&gt; then &lt;code&gt;builder&lt;/code&gt; is set to false.}}</span>
|name = capturable
</p><p><span class="fck_mw_template">{{tagfckLR|name = repairSpeedfckLR|type = floatfckLR|default = workerTimefckLR|description = How fast the builder can repair other units.}}</span>
|type = bool
</p><p><span class="fck_mw_template">{{tagfckLR|name = reclaimSpeedfckLR|type = floatfckLR|default = workerTimefckLR|description = How fast the builder can reclaim other units and features.}}</span>
|default = true
</p><p><span class="fck_mw_template">{{tagfckLR|name = resurrectSpeedfckLR|type = floatfckLR|default = workerTimefckLR|description = How fast the builder can resurrect corpse features back into living units.}}</span>
|description = Can a unit be stolen by a builder using the capture command?}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = captureSpeedfckLR|type = floatfckLR|default = workerTimefckLR|description = How fast the builder can capture other units.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = terraformSpeedfckLR|type = floatfckLR|default = workerTimefckLR|description = How fast the builder levels and restores terrain.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = canAssistfckLR|type = boolfckLR|default = builderfckLR|description = Can the builder assist other constructions?}}</span>
|name = repairable
</p><p><span class="fck_mw_template">{{tagfckLR|name = canBeAssistedfckLR|type = boolfckLR|default = truefckLR|description = Can the builder be assisted by other builders?}}</span>
|type = bool
</p><p><span class="fck_mw_template">{{tagfckLR|name = canSelfRepairfckLR|type = boolfckLR|default = falsefckLR|description = Can the builder repair itself?}}</span>
|default = true
</p><p><span class="fck_mw_template">{{tagfckLR|name = showNanoSprayfckLR|type = boolfckLR|default = truefckLR|description = Does the builder emit OTA-style nanospray whilst constructing?}}</span>
|description = Can the unit be repaired by a builder?}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = nanoColorfckLR|type = float[3]fckLR|default = {0.2, 0.7, 0.2} aka greenfckLR|description = The RGB colour of a builders' emitted nano particles if &lt;code&gt;showNanoSpray&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;. Also controls the RBG colour of a unit's own nanoframe if &lt;code&gt;showNanoFrame&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;.}}</span>
 
</p><p><span class="fck_mw_template">{{tagfckLR|name = fullHealthFactoryfckLR|type = boolfckLR|default = falsefckLR|description = If &lt;code&gt;true&lt;/code&gt;, units are repaired before they are allowed to leave the factory i.e. units from this factory will be healed back to 100% health if they are damaged during construction.}}</span>
{{tag
</p><p><span class="fck_mw_template">{{tagfckLR|name = isAirbasefckLR|type = boolfckLR|default = falsefckLR|description = Is this unit an airbase? Aircraft may land and repair on units which are airbases.}}</span>
|name = maxRepairSpeed
</p>
|type = float
<h3>Movement &amp; Placement</h3>
|default = 1e20
<p><span class="fck_mw_template">{{tagfckLR|name = footprintXfckLR|type = intfckLR|default = 1fckLR|description = fckLRHow wide the unit is in footprint units, left to right. 1 footprint unit = 16 [[elmos]]. Cannot be below &lt;code&gt;1&lt;/code&gt;. For mobile units this should be the same as the &lt;code&gt;footprintX&lt;/code&gt; of its &lt;code&gt;movementClass&lt;/code&gt;. Also used for obstacle avoidance.}}</span>
|description = The maximum cumulative speed at which this unit can be repaired.}}
</p><p><span class="fck_mw_template">{{tagfckLR|name = footprintZfckLR|type = intfckLR|default = 1fckLR|description = fckLRHow wide the unit is in footprint units, top to bottom. 1 footprint unit = 16 [[elmos]]. Cannot be below &lt;code&gt;1&lt;/code&gt;. For mobile units this should be the same as the &lt;code&gt;footprintZ&lt;/code&gt; of its &lt;code&gt;movementClass&lt;/code&gt;. Also used for obstacle avoidance.}}</span>
 
</p><p>{{tag
{{tag
|name = iconType
|type = string
|default = "default"
|description = The name of the radar icon type this unit should use. See [[Icontypes.lua]].}}
 
{{tag
|name = corpse
|type = string
|default = ""
|description = The name of the feature this unit should leave behind as a wreck when it dies (See [[Units-FeatureDefs]]).}}
 
{{tag
|name = explodeAs
|type = string
|default = ""
|description = The name of the weapon this unit should explode as when it is killed (See [[Units-WeaponDefs]]).}}
 
{{tag
|name = selfDestructAs
|type = string
|default = ""
|description = The name of the weapon this unit should explode as when it self destructs (See [[Units-WeaponDefs]]). Also used as the <code>kamikaze</code> weapon.}}
 
===Resources===
{{tag
|name = metalStorage
|type = float
|default = 0.0
|description = The amount of the metal resource storage the unit contributes.}}
 
{{tag
|name = energyStorage
|type = float
|default = 0.0
|description = The amount of the energy resource storage the unit contributes.}}
 
{{tag
|name = extractsMetal
|type = float
|default = 0.0
|description = The amount of the metal resource the unit extracts from the ground. The amount extracted depends on the metal map defined in the map itself. Works only for structures.}}
 
{{tag
|name = extractSquare
|type = bool
|default = false
|description = Is the metal extractors extraction area circular or square?}}
 
{{tag
|name = windGenerator
|type = float
|default = 0.0
|description = The amount of the energy resource the unit generates which is dependant on the map wind. Works only for structures.}}
 
{{tag
|name = tidalGenerator
|type = float
|default = 0.0
|description = The amount of the energy resource the unit generates which is dependant on the maps tidal power. Clearly, this only works on water structures.}}
 
{{tag
|name = metalUse
|type = float
|default = 0.0
|description = The amount of the metal resource the unit consumes per game 'tick'.}}
 
{{tag
|name = energyUse
|type = float
|default = 0.0
|description = The amount of the energy resource the unit consumes per game 'tick'.}}
 
{{tag
|name = metalMake
|type = float
|default = 0.0
|description = The amount of the metal resource the unit generates unconditionally per game 'tick'.}}
 
{{tag
|name = energyMake
|type = float
|default = 0.0
|description = The amount of the energy resource the unit generates unconditionally per game 'tick'.}}
 
{{tag
|name = makesMetal
|type = float
|default = 0.0
|description = The amount of the energy resource the unit turns into the metal resource per game 'tick'.}}
 
===Sensors===
{{tag
|name = onoffable
|type = bool
|default = false
|description = Does the unit have an on/off button? Currently the activation status tied to this button also turns sensors (other than LOS) on and off.}}
 
{{tag
|name = activateWhenBuilt
|type = bool
|default = false
|description = Should the unit's activation status be on or off when it is created?}}
 
{{tag
|name = sightDistance
|type = float
|default = 0.0
|description = The radius of the units sight (LOS is circular in Spring)}}
 
{{tag
|name = airSightDistance
|type = float
|default = 1.5 * sightDistance
|description = How far away the unit can see aircraft (and some FX).}}
 
{{tag
|name = losEmitHeight
|type = float
|default = 20.0
|special={{new|83.0}}
|description = How high up the unit is the point used to calculate it's LOS vs. the terrain?}}
 
{{tag
|name = radarEmitHeight
|type = float
|default = 20.0
|special={{new|83.0}}
|description = How high up the unit is the point used to calculate it's radar vs. the terrain?}}
 
{{tag
|name = radarDistance
|type = int
|default = 0
|description = The radius of the units radar.}}
 
{{tag
|name = sonarDistance
|type = int
|default = 0
|description = The radius of the units sonar.}}
 
{{tag
|name = radarDistanceJam
|type = int
|default = 0
|description = The radius of the units radar jamming.}}
 
{{tag
|name = sonarDistance
|type = int
|default = 0
|description = The radius of the units sonar jamming.}}
 
{{tag
|name = stealth
|type = bool
|default = false
|description = Is the unit undetectable by radar?}}
 
{{tag
|name = sonarStealth
|type = bool
|default = false
|description = Is the unit undetectable by sonar?}}
 
{{tag
|name = seismicDistance
|type = int
|default = 0
|description = The radius of the unit's seismic (movement) sensor.}}
 
{{tag
|name = seismicSignature
|type = float
|default = 0 for units with <code>floater</code>, <code>canHover</code> or <code>canFly</code>, otherwise sqrt(mass / 100.0)
|description = How fast the seismic ring expands in [[Units-UnitsOfMeasurement | elmos per frame]]. Each ping always lasts 15 [[frames]], so this also determines the maximum radius of the seismic ring.}}
 
====Cloaking====
For units with [[Units-UnitDefs#Commands|canCloak]] set to <code>true</code>:
{{tag
|name = cloakCost
|type = float
|default = 0.0
|description = The energy cost per tick to cloak the unit while it is stationary.}}
 
{{tag
|name = cloakCostMoving
|type = float
|default = cloakCost
|description = The energy cost per tick to cloak the unit while it is moving.}}
 
{{tag
|name = initCloaked
|type = bool
|default = false
|description = Is the unit cloaked as soon as it is created?}}
 
{{tag
|name = minCloakDistance
|type = float
|default = 0.0
|description = The minimum distance (radius) which the unit must be from any enemy units to remain cloaked.}}
 
{{tag
|name = decloakSpherical
|type = bool
|default = true
|description = Does <code>minCloakDistance</code> apply in 3D or only 2D? i.e. can aircraft flying above the unit decloak it?}}
 
{{tag
|name = decloakOnFire
|type = bool
|default = true
|description = Does the unit deloak when it fires a weapon?}}
 
{{tag
|name = cloakTimeout
|type = int
|default = 128
|description = The minimum time, in [[frames]], between a decloak and subsequent re-cloak.}}
 
===Commands===
{{tag
|name = canMove
|type = bool
|default = false
|description = Can the unit be issued Move orders?}}
 
{{tag
|name = canAttack
|type = bool
|default = true
|description = Can the unit be issued Attack orders?}}
 
{{tag
|name = canFight
|type = bool
|default = true
|description = Can the unit be issued Fight orders?}}
 
{{tag
|name = canPatrol
|type = bool
|default = true
|description = Can the unit be issued Patrol orders?}}
 
{{tag
|name = canGuard
|type = bool
|default = true
|description = Can the unit be issued Guard orders?}}
 
{{tag
| name = canCloak
| type = bool
| default = false
| description =
Can the unit be issued Cloak orders?}}
 
{{tag
|name = canRepeat
|type = bool
|default = true
|description = Can the unit be issued Repeat orders?}}
 
{{tag
|name = canSelfDestruct
|type = bool
|default = true
|description = Can the unit be issued a self destruct order?}}
 
{{tag
|name = moveState
|type = int
|default = -1 for mobile units, <code>1</code> for structures
|description = The initial movement state for the unit. Can be <code>-1</code> - Inherits from factory, <code>0</code> - Hold Position, <code>1</code> - Manoeuvre or <code>2</code> - Roam.}}
 
{{tag
|name = fireState
|type = int
|default = -1 for units without <code>noAutoFire</code>, <code>2</code> otherwise
|description = The initial firing state for the unit. Can be <code>-1</code> - Inherits from factory, <code>0</code> - Hold Fire, <code>1</code> - Return Fire or <code>2</code> - Fire At Will.}}
 
{{tag
|name = noAutoFire
|type = bool
|default = false
|description = Controls whether or not the unit has a fire state button.}}
 
{{tag
|name = canManualFire
|type = bool
|default = false
|description = Can the unit be issued ManualFire commands? A ManualFire command will fire any weapons with the <code>commandfire</code> tag (See [[Units-WeaponDefs]]).}}
 
====Builder Commands====
{{tag
|name = canRestore
|type = bool
|default = builder
|description = Can the unit be issued restore terrain commands? For builders only.}}
 
{{tag
|name = canRepair
|type = bool
|default = builder
|description = Can the unit be issued repair commands? For builders only.}}
 
{{tag
|name = canReclaim
|type = bool
|default = builder
|description = Can the unit be issued reclaim commands? For builders only.}}
 
{{tag
|name = canResurrect
|type = bool
|default = false
|description = Can the unit be issued resurrection commands? For builders only.}}
 
{{tag
|name = canCapture
|type = bool
|default = false
|description = Can the unit be issued capture commands? For builders only.}}
 
===Builder===
{{tag
|name = builder
|type = bool
|default = false
|description = Is the unit a builder?}}
 
{{tag
|name = buildDistance
|type = float
|default = 128.0
|description = How far away from itself the unit can build, measured to the centre of the unit being built. The minimum value is <code>38.0</code>.}}
 
{{tag
|name = buildRange3D
|type = bool
|default = false
|description = Does the builders <code>buildDistance</code> apply in all 3 dimensions or only 2?}}
 
{{tag
|name = workerTime
|type = float
|default = 0.0
|description = How fast the builder builds, used in conjunction with the <code>buildTime</code> of the unit being built. Effectively, ''Time to build = unit <code>buildTime</code> / constructor <code>workerTime</code>''. If this value is <= <code>0.0</code> then <code>builder</code> is set to false.}}
 
{{tag
|name = repairSpeed
|type = float
|default = workerTime
|description = How fast the builder can repair other units.}}
 
{{tag
|name = reclaimSpeed
|type = float
|default = workerTime
|description = How fast the builder can reclaim other units and features.}}
 
{{tag
|name = resurrectSpeed
|type = float
|default = workerTime
|description = How fast the builder can resurrect corpse features back into living units.}}
 
{{tag
|name = captureSpeed
|type = float
|default = workerTime
|description = How fast the builder can capture other units.}}
 
{{tag
|name = terraformSpeed
|type = float
|default = workerTime
|description = How fast the builder levels and restores terrain.}}
 
{{tag
|name = canAssist
|type = bool
|default = builder
|description = Can the builder assist other constructions?}}
 
{{tag
|name = canBeAssisted
|type = bool
|default = true
|description = Can the builder be assisted by other builders?}}
 
{{tag
|name = canSelfRepair
|type = bool
|default = false
|description = Can the builder repair itself?}}
 
{{tag
|name = showNanoSpray
|type = bool
|default = true
|description = Does the builder emit OTA-style nanospray whilst constructing?}}
 
{{tag
|name = nanoColor
|type = float[3]
|default = {0.2, 0.7, 0.2} aka green
|description = The RGB colour of a builders' emitted nano particles if <code>showNanoSpray</code> is <code>true</code>. Also controls the RBG colour of a unit's own nanoframe if <code>showNanoFrame</code> is <code>true</code>.}}
 
{{tag
|name = fullHealthFactory
|type = bool
|default = false
|description = If <code>true</code>, units are repaired before they are allowed to leave the factory i.e. units from this factory will be healed back to 100% health if they are damaged during construction.}}
 
{{tag
|name = isAirbase
|type = bool
|default = false
|description = Is this unit an airbase? Aircraft may land and repair on units which are airbases.}}
 
===Movement & Placement===
{{tag
|name = footprintX
|type = int
|default = 1
|description =  
How wide the unit is in footprint units, left to right. 1 footprint unit = 16 [[elmos]]. Cannot be below <code>1</code>. For mobile units this should be the same as the <code>footprintX</code> of its <code>movementClass</code>. Also used for obstacle avoidance.}}
 
{{tag
|name = footprintZ
|type = int
|default = 1
|description =  
How wide the unit is in footprint units, top to bottom. 1 footprint unit = 16 [[elmos]]. Cannot be below <code>1</code>. For mobile units this should be the same as the <code>footprintZ</code> of its <code>movementClass</code>. Also used for obstacle avoidance.}}
 
{{tag
|name = yardmap
|name = yardmap
|type = string
|type = string
Line 574: Line 134:
|description =  
|description =  
Used to determine a structure from a mobile unit. A string of characters which defines in detail each 'footprint square' of the structure. Each footprint square may be:  
Used to determine a structure from a mobile unit. A string of characters which defines in detail each 'footprint square' of the structure. Each footprint square may be:  
:: <code>y</code> - 'Yard' - Always open, unblocking,
</p>
:: <code>c</code> - 'Construction' - Open and unblocking only while constructing (for factories, controlled via <code>COB.YARD_OPEN</code> see [[Animation-LuaCallouts#Other]]),
<dl><dd><dl><dd> <code>y</code> - 'Yard' - Always open, unblocking,
:: <code>i</code> - 'Inversed Construction' - Closed and blocking only while constructing (for factories, controlled via <code>COB.YARD_OPEN</code> see [[Animation-LuaCallouts#Other]]) ({{new|89.0}}),
</dd><dd> <code>c</code> - 'Construction' - Open and unblocking only while constructing (for factories, controlled via <code>COB.YARD_OPEN</code> see <a _fcknotitle="true" href="Animation-LuaCallouts#Other">Animation-LuaCallouts#Other</a>),
:: <code>g</code> - 'Geothermal' - Flags that the unit must be placed over a <code>geoThermal</code> feature, does not actually count as a square (See [[Units-FeatureDefs]]),
</dd><dd> <code>i</code> - 'Inversed Construction' - Closed and blocking only while constructing (for factories, controlled via <code>COB.YARD_OPEN</code> see <a _fcknotitle="true" href=
::<code>o</code> - 'Obstacle' - Always closed, blocking, all other chars are treated the same way.
: Tip: 'Draw' out the yardmap over multiple lines. Prior to <span class=warning>89.0</span> newlines should be replaced with spaces as newlines are treated as <code>o</code>.
 
 
{{tag
|name = levelGround
|type = bool
|default = false
|description = For structures. Does the constructor have to level the ground underneath the build area before beginning to build the structure?}}
 
{{tag
|name = movementClass
|type = string
|default = ""
|description = The name of the movement type a mobile, non aircraft, unit should use. See [[Movedefs.lua]]. Other tag usage should be consistent with this i.e. <code>canHover = true</code> IFF using a <code>HOVER</code> based movetype.}}
 
{{tag
|name = canHover
|type = bool
|default = false
|description = Is the unit a hovercraft? Hovercraft can cross water of any depth without a speed penalty. Hover's must also have <code>HOVER</code> within the name of their <code>movementClass</code> (see [[Movedefs.lua]]).}}
 
{{tag
|name = floater
|type = bool
|default = true if the unit has the <code>waterline</code> tag, <code>false</code> otherwise
|description = When a mobile unit is crossing water, or a structure is placed on water, does it float on top of the water or crawl / lay on the sea bed?}}
 
{{tag
|name = upright
|type = bool
|default = false
|description = Does the unit follow the terrain or always remain upright? Generally used for walkers.}}
 
{{tag
|name = maxSlope
|type = float
|default = 0.0
|description = The maximum slope a building can be placed on. Mobile unit's use the <code>maxSlope</code> set in their <code>movementClass</code> (see [[Movedefs.lua]]). The value is in degrees and is clamped between <code>0.0</code> and <code>89.0</code>. This value is converted to a "maximum allowed height difference" (call it M), which involves a hard-coded constant. When a building gets placed,
It is a simple array (number indexed table) of <code>unitName</code>s (not the human readable <code>name</code>!).
It is a simple array (number indexed table) of <code>unitName</code>s (not the human readable <code>name</code>!).
 
</p><p>There are no additional tags specific to this subtable.
There are no additional tags specific to this subtable.
</p>
 
<h3>SFXTypes</h3>
===SFXTypes===
<p>The <code>SFXTypes</code> subtable of a UnitDef tells Spring which <a _fcknotitle="true" href="CEG">CEG</a> effects are associated with the unit. It consists of two further subtables, with no additional tags specific to them.
The <code>SFXTypes</code> subtable of a UnitDef tells Spring which [[CEG]] effects are associated with the unit. It consists of two further subtables, with no additional tags specific to them.
</p>
 
<h4>explosionGenerators</h4>
====explosionGenerators====
<p>The <code>explosionGenerators</code> subtable of <code>SFXTypes</code> tells Spring which <a _fcknotitle="true" href="CEG">CEG</a>s the unit's script can call, via the <code>EmitSFX()</code> callout (See <a _fcknotitle="true" href="Animation-LuaCallouts#Effects">Animation-LuaCallouts#Effects</a>). It is a simple array (number indexed table) of CEG names, prefaced by the string <code>"custom:"</code>.  
 
</p>
The <code>explosionGenerators</code> subtable of <code>SFXTypes</code> tells Spring which [[CEG]]s the unit's script can call, via the <code>EmitSFX()</code> callout (See [[Animation-LuaCallouts#Effects]]). It is a simple array (number indexed table) of CEG names, prefaced by the string <code>"custom:"</code>.  
<h4>pieceExplosionGenerators</h4>
 
<p><span class="fck_mw_template">{{new|83.0}}</span>
====pieceExplosionGenerators====
</p><p>The <code>pieceExplosionGenerators</code> subtable of <code>SFXTypes</code> tells Spring which <a _fcknotitle="true" href="CEG">CEG</a>s the unit's script can pick at random to attach to a flying unit piece, created from the <code>Explode()</code> callout (See <a _fcknotitle="true" href="Animation-LuaCallouts#Effects">Animation-LuaCallouts#Effects</a>). It is a simple array (number indexed table) of CEG names, with no prefix.
{{new|83.0}}
</p><p>Forum thread (with examples): <span class="fck_mw_template">{{forumlink|topic=27554|title=pieceExplosionGenerators}}</span>
 
</p>
The <code>pieceExplosionGenerators</code> subtable of <code>SFXTypes</code> tells Spring which [[CEG]]s the unit's script can pick at random to attach to a flying unit piece, created from the <code>Explode()</code> callout (See [[Animation-LuaCallouts#Effects]]). It is a simple array (number indexed table) of CEG names, with no prefix.
<h3>sounds</h3>
 
<p>The <code>sounds</code> subtable of a UnitDef tells Spring which sound files to play when the unit triggers various events.
Forum thread (with examples): {{forumlink|topic=27554|title=pieceExplosionGenerators}}
</p><p>Files are assumed to be in the <code>Sounds/</code> directory; accepted formats are .wav and .ogg, the former being assumed if no extension is given.
 
</p><p>Sounds can be defined in one of three ways:
===sounds===
</p>
 
<ol><li> Each event can be used as though it were a <code>string</code> tag referring to the filename.
The <code>sounds</code> subtable of a UnitDef tells Spring which sound files to play when the unit triggers various events.
</li><li> Each event can be the name of a subtable, which is a simple array containing the filenames. One sound is picked at random from the list each time the event occurs.
 
</li><li> Each event can be the name of a subtable, which is a simple array containing further tables, which contain the following tags:
Files are assumed to be in the <code>Sounds/</code> directory; accepted formats are .wav and .ogg, the former being assumed if no extension is given.
</li></ol>
 
<p><span class="fck_mw_template">{{tagfckLR|name = filefckLR|type = stringfckLR|default = &quot;&quot;fckLR|description = The filename of the sound to play.}}</span>
Sounds can be defined in one of three ways:
</p><p><span class="fck_mw_template">{{tagfckLR|name = volumefckLR|type = floatfckLR|default = 1.0fckLR|description = The default volume of the sound.}}</span>
 
</p><p>Spring checks any referenced sound filename to see if a SoundItem has been created, which allows greater control over how it is played (See <a _fcknotitle="true" href="Sounds.lua">Sounds.lua</a>).
# Each event can be used as though it were a <code>string</code> tag referring to the filename.
</p>
# Each event can be the name of a subtable, which is a simple array containing the filenames. One sound is picked at random from the list each time the event occurs.
<h4>sounds Example</h4>
# Each event can be the name of a subtable, which is a simple array containing further tables, which contain the following tags:
<p>For clarification, here is an example of all three methods:
{{tag
</p>
|name = file
|type = string
|default = ""
|description = The filename of the sound to play.}}
 
{{tag
|name = volume
|type = float
|default = 1.0
|description = The default volume of the sound.}}
 
Spring checks any referenced sound filename to see if a SoundItem has been created, which allows greater control over how it is played (See [[Sounds.lua]]).
 
====sounds Example====
 
For clarification, here is an example of all three methods:
 
<code><pre>sounds = {
<code><pre>sounds = {
   -- Method 1
   -- Method 1
Line 1,378: Line 339:
   },
   },
}</pre></code>
}</pre></code>
 
<h4>sounds Events</h4>
====sounds Events====
<p>The events called by the engine are as follows:
 
</p>
The events called by the engine are as follows:
<ul><li> <b><code>ok</code></b>
 
</li></ul>
* '''<code>ok</code>'''
<dl><dd> Unit is issued a command.
: Unit is issued a command.
</dd></dl>
 
<ul><li> <b><code>select</code></b>
* '''<code>select</code>'''
</li></ul>
: Unit is selected by the player.
<dl><dd> Unit is selected by the player.
 
</dd></dl>
* '''<code>arrived</code>
<ul><li> <b><code>arrived</code></b>
: Unit has arrived at its destination. Mobile ground units only.
</li></ul>
 
<dl><dd> Unit has arrived at its destination. Mobile ground units only.
* '''<code>build</code>'''
</dd></dl>
: Unit begins building. Called for both factories and mobile construction units.
<ul><li> <b><code>build</code></b>
 
</li></ul>
* '''<code>activate</code>'''
<dl><dd> Unit begins building. Called for both factories and mobile construction units.
: Unit is activated, i.e. Is turned on. Also called when a mobile ground unit starts moving.
</dd></dl>
 
<ul><li> <b><code>activate</code></b>
* '''<code>deactivate</code>'''
</li></ul>
: Unit deactivates, i.e. Is turned off.
<dl><dd> Unit is activated, i.e. Is turned on. Also called when a mobile ground unit starts moving.
 
</dd></dl>
* '''<code>cant</code>'''
<ul><li> <b><code>deactivate</code></b>
: Unit cannot carry out this order. Loaded but not currently called by the engine.
</li></ul>
 
<dl><dd> Unit deactivates, i.e. Is turned off.
* '''<code>underattack</code>'''
</dd></dl>
: Unit gets attacked. Loaded but not currently called by the engine.
<ul><li> <b><code>cant</code></b>
 
</li></ul>
===customParams===
<dl><dd> Unit cannot carry out this order. Loaded but not currently called by the engine.
The <code>customParams</code> subtable of a UnitDef allows the game designer to give their units custom attributes, which can then be accessed via lua gadgets and widgets. It is a map (key-value pair indexed table) of strings. When accessing these attributes in lua the strings can be turned back into numbers, bools or even tables. This gives great control to game designers to essentially implement their own behaviour tags.
</dd></dl>
 
<ul><li> <b><code>underattack</code></b>
There are no additional tags specific to this subtable
</li></ul>
 
<dl><dd> Unit gets attacked. Loaded but not currently called by the engine.
==Examples==
</dd></dl>
[http://imolarpg.dyndns.org/trac/balatest/browser/trunk/units 'Balanced Annihilation' UnitDefs]
<h3>customParams</h3>
 
<p>The <code>customParams</code> subtable of a UnitDef allows the game designer to give their units custom attributes, which can then be accessed via lua gadgets and widgets. It is a map (key-value pair indexed table) of strings. When accessing these attributes in lua the strings can be turned back into numbers, bools or even tables. This gives great control to game designers to essentially implement their own behaviour tags.
[http://trac.caspring.org/browser/trunk/mods/ca/units 'Complete Annihilation' UnitDefs]
</p><p>There are no additional tags specific to this subtable
 
</p>
[http://code.google.com/p/conflictterra/source/browse/#svn%2Fgames%2FCT%2Funits 'Conflict Terra' UnitDefs]
<h2>Examples</h2>
 
<p><a href="http://imolarpg.dyndns.org/trac/balatest/browser/trunk/units">'Balanced Annihilation' UnitDefs</a>
[https://code.google.com/p/evolutionrts/source/browse/#svn%2Ftrunk%2Fevolutiondev.sdd%2FUnits 'Evolution RTS' UnitDefs]
</p><p><a href="http://trac.caspring.org/browser/trunk/mods/ca/units">'Complete Annihilation' UnitDefs</a>
 
</p><p><a href="http://code.google.com/p/conflictterra/source/browse/#svn%2Fgames%2FCT%2Funits">'Conflict Terra' UnitDefs</a>
[http://code.google.com/p/springtutorialgame/source/browse/#svn%2Ftrunk%2FSpringTutorialGame.sdd%2FUnits 'Spring Tutorial Game' UnitDefs]
</p><p><a href="https://code.google.com/p/evolutionrts/source/browse/#svn%2Ftrunk%2Fevolutiondev.sdd%2FUnits">'Evolution RTS' UnitDefs</a>
 
</p><p><a href="http://code.google.com/p/springtutorialgame/source/browse/#svn%2Ftrunk%2FSpringTutorialGame.sdd%2FUnits">'Spring Tutorial Game' UnitDefs</a>
[http://code.google.com/p/zero-k/source/browse/trunk#trunk%2Fmods%2Fzk%2Funits 'ZeroK' UnitDefs]
</p><p><a href="http://code.google.com/p/zero-k/source/browse/trunk#trunk%2Fmods%2Fzk%2Funits">'ZeroK' UnitDefs</a>
 
</p><br/><span _fcknotitle="true" class="fck_mw_category" sort="Unit_development">Unit development</span> <br/><span _fcknotitle="true" class="fck_mw_category" sort="Game_development">Game development</span> <br/>
 
[[Category: Unit_development]]
[[Category: Game development]]

Revision as of 14:43, 9 July 2012

Location

UnitDef files are .lua files stored in the Units/ directory of a Spring Game.

Purpose

UnitDef files have one purpose; to define the properties of units. They are the main description file for what attributes your unit should have and how it should behave.

Source

The engine source code which loads the tags from these files is viewable here:rts/Sim/Units/UnitDef.cpp


The engine source which reads the <a _fcknotitle="true" href="#sounds">#sounds</a> subtable can be found here:rts/Sim/Units/UnitDefHandler.cpp

Data Types

Tags may be one of the following data types:

  • int - An integer number
  • float - A number with decimals.
  • bool - A value which can be true or false.
  • string - Text, or more precisely a string of alphanumeric characters.
  • float[3] - A vector, with three float components, representing x, y and z axes (y is 'up').

Details

There follows a comprehensive (certain deprecated tags are not present) list of the tags available, their data type, default value and a brief description of what they do. Bear in mind that the source code linked above is the ultimate reference when dealing with these tags.

In lua tables keys (i.e. the tags) should be lower case, here they are represented in camelCase for readability. In your files you may use the lowerkeys function on your final table to ensure the keys are properly cased.

It is usual to name the returned UnitDef table the internal unitName desired for the unit.

General

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Resources

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Sensors

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Cloaking

For units with <a href="Units-UnitDefs#Commands">canCloak</a> set to true: Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Commands

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Builder Commands

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Builder

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Movement & Placement

Template:TagfckLR

Template:TagfckLR

{{tag

|name = yardmap |type = string |default = "" |description = Used to determine a structure from a mobile unit. A string of characters which defines in detail each 'footprint square' of the structure. Each footprint square may be:

y - 'Yard' - Always open, unblocking,
c - 'Construction' - Open and unblocking only while constructing (for factories, controlled via COB.YARD_OPEN see <a _fcknotitle="true" href="Animation-LuaCallouts#Other">Animation-LuaCallouts#Other</a>),
i - 'Inversed Construction' - Closed and blocking only while constructing (for factories, controlled via COB.YARD_OPEN see <a _fcknotitle="true" href="Animation-LuaCallouts#Other">Animation-LuaCallouts#Other</a>) (New in version 89.0),
g - 'Geothermal' - Flags that the unit must be placed over a geoThermal feature, does not actually count as a square (See <a _fcknotitle="true" href="Units-FeatureDefs">Units-FeatureDefs</a>),
o - 'Obstacle' - Always closed, blocking, all other chars are treated the same way.
Tip: 'Draw' out the yardmap over multiple lines. Prior to 89.0 newlines should be replaced with spaces as newlines are treated as o.


Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Flanking

For a deeper explanation of these tags, see <a _fcknotitle="true" href="Units:FlankingBonus">Units:FlankingBonus</a>.

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Aircraft

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Advanced Air Tags

The following set of tags are not well understood and using non-default values can lead to undesired flight behaviours. Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Flares

The following set of tags are rarely used and are hardcoded to only work vs. missile weapons. The texture is hardcoded to be flareprojectiletexture defined in <a _fcknotitle="true" href="Resources.lua">Resources.lua</a>. Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Transports

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Categories

For a deeper explanation of these tags, see <a _fcknotitle="true" href="Unit Categories">Unit Categories</a>. Template:TagfckLR

Template:TagfckLR

Decals

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Collision Volumes

For a deeper explanation of these tags, see <a href="Unit collision volumes"> Unit Collision Volumes</a>. Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Attack Behaviours

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Other

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Sub Tables

weapons

The weapons subtable of a UnitDef tells Spring which weapons the unit has. It is a simple array (number indexed table) of weaponNames (not the human readable name!).

The following additional tags are associated with this subtable:

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

Template:TagfckLR

buildOptions

The buildOptions subtable of a UnitDef tells Spring which other units the unit can build (in the case of a builder) or produce (in the case of a factory). It is a simple array (number indexed table) of unitNames (not the human readable name!).

There are no additional tags specific to this subtable.

SFXTypes

The SFXTypes subtable of a UnitDef tells Spring which <a _fcknotitle="true" href="CEG">CEG</a> effects are associated with the unit. It consists of two further subtables, with no additional tags specific to them.

explosionGenerators

The explosionGenerators subtable of SFXTypes tells Spring which <a _fcknotitle="true" href="CEG">CEG</a>s the unit's script can call, via the EmitSFX() callout (See <a _fcknotitle="true" href="Animation-LuaCallouts#Effects">Animation-LuaCallouts#Effects</a>). It is a simple array (number indexed table) of CEG names, prefaced by the string "custom:".

pieceExplosionGenerators

New in version 83.0

The pieceExplosionGenerators subtable of SFXTypes tells Spring which <a _fcknotitle="true" href="CEG">CEG</a>s the unit's script can pick at random to attach to a flying unit piece, created from the Explode() callout (See <a _fcknotitle="true" href="Animation-LuaCallouts#Effects">Animation-LuaCallouts#Effects</a>). It is a simple array (number indexed table) of CEG names, with no prefix.

Forum thread (with examples): pieceExplosionGenerators

sounds

The sounds subtable of a UnitDef tells Spring which sound files to play when the unit triggers various events.

Files are assumed to be in the Sounds/ directory; accepted formats are .wav and .ogg, the former being assumed if no extension is given.

Sounds can be defined in one of three ways:

  1. Each event can be used as though it were a string tag referring to the filename.
  2. Each event can be the name of a subtable, which is a simple array containing the filenames. One sound is picked at random from the list each time the event occurs.
  3. Each event can be the name of a subtable, which is a simple array containing further tables, which contain the following tags:

Template:TagfckLR

Template:TagfckLR

Spring checks any referenced sound filename to see if a SoundItem has been created, which allows greater control over how it is played (See <a _fcknotitle="true" href="Sounds.lua">Sounds.lua</a>).

sounds Example

For clarification, here is an example of all three methods:

sounds = {
  -- Method 1
  ok = 'oksound', -- .wav appended
  -- Method 2
  arrived = {
    'arrived1.wav',
    'arrived2.wav',
  },
  -- Method 3
  select = {
    { file = 'selsound1.ogg', volume = 2.0 },
    { file = 'selsound2.ogg', volume = 2.5 },
  },
}

sounds Events

The events called by the engine are as follows:

  • ok
Unit is issued a command.
  • select
Unit is selected by the player.
  • arrived
Unit has arrived at its destination. Mobile ground units only.
  • build
Unit begins building. Called for both factories and mobile construction units.
  • activate
Unit is activated, i.e. Is turned on. Also called when a mobile ground unit starts moving.
  • deactivate
Unit deactivates, i.e. Is turned off.
  • cant
Unit cannot carry out this order. Loaded but not currently called by the engine.
  • underattack
Unit gets attacked. Loaded but not currently called by the engine.

customParams

The customParams subtable of a UnitDef allows the game designer to give their units custom attributes, which can then be accessed via lua gadgets and widgets. It is a map (key-value pair indexed table) of strings. When accessing these attributes in lua the strings can be turned back into numbers, bools or even tables. This gives great control to game designers to essentially implement their own behaviour tags.

There are no additional tags specific to this subtable

Examples

<a href="http://imolarpg.dyndns.org/trac/balatest/browser/trunk/units">'Balanced Annihilation' UnitDefs</a>

<a href="http://trac.caspring.org/browser/trunk/mods/ca/units">'Complete Annihilation' UnitDefs</a>

<a href="http://code.google.com/p/conflictterra/source/browse/#svn%2Fgames%2FCT%2Funits">'Conflict Terra' UnitDefs</a>

<a href="https://code.google.com/p/evolutionrts/source/browse/#svn%2Ftrunk%2Fevolutiondev.sdd%2FUnits">'Evolution RTS' UnitDefs</a>

<a href="http://code.google.com/p/springtutorialgame/source/browse/#svn%2Ftrunk%2FSpringTutorialGame.sdd%2FUnits">'Spring Tutorial Game' UnitDefs</a>

<a href="http://code.google.com/p/zero-k/source/browse/trunk#trunk%2Fmods%2Fzk%2Funits">'ZeroK' UnitDefs</a>


Unit development
Game development