Armordefs.lua: Difference between revisions

From Spring
Jump to navigationJump to search
Flozi (talk | contribs)
m 1cat
Flozi (talk | contribs)
→More efficient with Lua: delete this section
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
==Location==
This file sorts units into different armor classes. Weapons can deal different amount of damage to different armor classes.
 
=Location=
<code>armordefs.lua</code> is a file in the <code>Gamedata/</code> directory of a Spring Game.
<code>armordefs.lua</code> is a file in the <code>Gamedata/</code> directory of a Spring Game.


==Purpose==
=Source=
This file sorts units into different armor classes. Weapons can deal different amount of damage to different armor classes.
 
==Source==
The engine source code which parses the data from this file is viewable here:
The engine source code which parses the data from this file is viewable here:


* {{sourcelink|file=rts/Sim/Misc/DamageArrayHandler.cpp}}
* {{sourcelink|file=rts/Sim/Misc/DamageArrayHandler.cpp}}


==Details==
=Details=
By default a damage class named "default" exists and every unit is in it.
By default a damage class named "default" exists and every unit is in it.
So if all your weapons only deal "default" damage then this file is not needed.
So if all your weapons only deal "default" damage then this file is not needed.


==Example==
=Example=
<code><pre>
<code><pre>
local armorDefs = {
local armorDefs = {
tanks = {
tanks = {
"supertank",
"supertank",
"megatank",
"megatank",
},
},


infantry = {
infantry = {
"dude",
"dude",
},
},
}


for categoryName, categoryTable in pairs(armorDefs) do
--NOTE: only needed for <95.0 (before engine was expecting a cryptic format)
  local t = {}
if not(Game) or not(Game.version) then
  for _, unitName in pairs(categoryTable) do
  for categoryName, categoryTable in pairs(armorDefs) do
    t[unitName] = 1
    local t = {}
    for _, unitName in pairs(categoryTable) do
      t[unitName] = 1
    end
    armorDefs[categoryName] = t
   end
   end
  armorDefs[categoryName] = t
end
end


return armorDefs</pre></code>
return armorDefs</pre></code>


Note:<br>
=Weapon Example=
The cryptic looking loop at the end is required to convert the table to a different format. Just copy & paste it.
 
==weapon example==
Goes with above example, a weapon that deals 60 damage to infantry but only 5 damage to tanks:
Goes with above example, a weapon that deals 60 damage to infantry but only 5 damage to tanks:
<code><pre>
<code><pre>
...
...
damage = {
damage = {
infantry = 60,
infantry = 60,
tanks = 5,
tanks = 5,
},
},
...
...
</pre></code>
</pre></code>


==links to more examples==
=Shields=
In engine versions =< 96.0 the damage dealt to shields is the weapon's ''default'' value.
This [https://springrts.com/mantis/view.php?id=4450 changed] in v98.0
 
Putting a shield into an armor class is analogical to units, ie. the armorDefs entry is its weaponDef name:
<code><pre>
armorDefs = {
  units = { "shieldbot" },
  shields = { "shieldbot_shield" }
}</pre></code>
 
Then in some damage table:
<code><pre>damage = {
  default = 123,
  units = 456,
  shields = 789
}</pre></code>
 
=Links to more Examples=
[http://code.google.com/p/zero-k/source/browse/trunk/mods/zk/gamedata/armordefs.lua zero-K]<br>
[http://code.google.com/p/zero-k/source/browse/trunk/mods/zk/gamedata/armordefs.lua zero-K]<br>
contains scripting to take into account various things like EMP damage.
Contains scripting to take into account various things like EMP damage.


[http://code.google.com/p/springtutorialgame/source/browse/trunk/SpringTutorialGame.sdd/Gamedata/armordefs.lua|Spring Tutorial Game]<br>
[http://code.google.com/p/springtutorialgame/source/browse/trunk/SpringTutorialGame.sdd/Gamedata/armordefs.lua|Spring Tutorial Game]<br>
uses default damage class, except for one unit that is "armored."
Uses default damage class, except for one unit that is "armored."
 
[http://sourceforge.net/p/mwspring/code/899/tree/Gamedata/armordefs.lua MechCommander: Legacy]<br>
Automatically assigns units to an armor class based on [[Gamedev:UnitDefs|UnitDef]] tags and custom params.


[[Category:gamedata]]
[[Category:gamedata]]

Latest revision as of 13:27, 23 January 2021

This file sorts units into different armor classes. Weapons can deal different amount of damage to different armor classes.

Location

armordefs.lua is a file in the Gamedata/ directory of a Spring Game.

Source

The engine source code which parses the data from this file is viewable here:

Details

By default a damage class named "default" exists and every unit is in it. So if all your weapons only deal "default" damage then this file is not needed.

Example

local armorDefs = {
	tanks = {
		"supertank",
		"megatank",
	},

	infantry = {
		"dude",
	},
}

--NOTE: only needed for <95.0 (before engine was expecting a cryptic format)
if not(Game) or not(Game.version) then
  for categoryName, categoryTable in pairs(armorDefs) do
    local t = {}
    for _, unitName in pairs(categoryTable) do
      t[unitName] = 1
    end
    armorDefs[categoryName] = t
  end
end

return armorDefs

Weapon Example

Goes with above example, a weapon that deals 60 damage to infantry but only 5 damage to tanks:

...
damage = {
	infantry = 60,
	tanks = 5,
},
...

Shields

In engine versions =< 96.0 the damage dealt to shields is the weapon's default value. This changed in v98.0

Putting a shield into an armor class is analogical to units, ie. the armorDefs entry is its weaponDef name:

armorDefs = {
  units = { "shieldbot" },
  shields = { "shieldbot_shield" }
}

Then in some damage table:

damage = {
  default = 123,
  units = 456,
  shields = 789
}

Links to more Examples

zero-K
Contains scripting to take into account various things like EMP damage.

Tutorial Game
Uses default damage class, except for one unit that is "armored."

MechCommander: Legacy
Automatically assigns units to an armor class based on UnitDef tags and custom params.