Gamedev:WeaponDefs
Location
WeaponDef files are .lua files stored in the Weapons/ directory of a Spring Game. Alternatively they can be integrated into UnitDefs.
Purpose
WeaponDef files have one purpose; to define the properties of weapons. They are the main description file for what attributes your weapon should have and how it should behave.
Source
The engine source code which loads the tags from these files is viewable here:rts/Sim/Weapons/WeaponDefHandler.cpp
Data Types
Tags may be one of the following data types:
int- An integer numberfloat- A number with decimals.bool- A value which can betrueorfalse.string- Text, or more precisely a string of alphanumeric characters.float[3]- A vector, with threefloatcomponents, 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. The WeaponTags are shown in order of usefullness, which is the ability to modify most of its values. Also, if some weaponfunctions is not provided (for example rocket controll in midflight), its often easier to code a replacement in lua (e.g. creating a kamikazeplan, assign it the look of a rocket). Some weapon require some tags to be activated.
WeaponTypes
MissileLauncher (lineofsight=1 and smoketrail=1)
Shoots a smoke-emitting projectile. It can use acceleration, etc. The projectile's lifetime depends on range/maxspeed so a slowly accelerating missile will fall short. It can also use trajectoryheight to have the shot arc but that has trouble with aiming at targets higher or lower than the shooter (see bug report, this REALLY could use some fixing). Pretty versatile weapon overall, if the laser rendering code was ported into this we could pretty much axe the LaserCannon completely.
LaserCannon (lineofsight=1 and either beamweapon=1 or weaponname contains "laser"
The OTA-style laser. Probably one of the least annoying weapons in the engine. Its length is defined by the duration tag (together with the speed), BTW.
Cannon (this is the default weapon, the engine returns to if it couldnt identify another type)
Aka plasma. Shoots a ballistic projectile. Unlike the DGun it aims properly. Can't be emit-sfxed properly, maybe a ballistic DGun can fill that role.
It is usual to name the returned WeaponDef table the internal weaponName desired for the weapon.
General
float tagToCopyPaste default: 0.0
- Lorem ipsum dolor sit amet.
Sub Tables
customParams
The customParams subtable of a WeaponDef allows the game designer to give their weapons 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
'Balanced Annihilation' WeaponDefs
'Conflict Terra' WeaponDefs (Most are integrated into their UnitDefs)
'Evolution RTS' WeaponDefs (Most are integrated into their UnitDefs)
'Spring: 1944' WeaponDefs (Implements an OOP paradigm with inheritance)