1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- file: weapondefs_post.lua
-- brief: weaponDef post processing
-- author: Dave Rodgers
--
-- Copyright (C) 2008.
-- Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
-- Per-unitDef weaponDefs
--
local function isbool(x) return (type(x) == 'boolean') end
local function istable(x) return (type(x) == 'table') end
local function isnumber(x) return (type(x) == 'number') end
local function isstring(x) return (type(x) == 'string') end
local function tobool(val)
local t = type(val)
if (t == 'nil') then
return false
elseif (t == 'boolean') then
return val
elseif (t == 'number') then
return (val ~= 0)
elseif (t == 'string') then
return ((val ~= '0') and (val ~= 'false'))
end
return false
end
--------------------------------------------------------------------------------
local function BackwardCompability(wdName,wd)
-- weapon reloadTime and stockpileTime were seperated in 77b1
if (tobool(wd.stockpile) and (wd.stockpiletime==nil)) then
wd.stockpiletime = wd.reloadtime
wd.reloadtime = 2 -- 2 seconds
end
-- auto detect ota weapontypes
if (wd.weapontype==nil) then
local rendertype = tonumber(wd.rendertype) or 0
if (tobool(wd.dropped)) then
wd.weapontype = "AircraftBomb";
elseif (tobool(wd.vlaunch)) then
wd.weapontype = "StarburstLauncher";
elseif (tobool(wd.beamlaser)) then
wd.weapontype = "BeamLaser";
elseif (tobool(wd.isshield)) then
wd.weapontype = "Shield";
elseif (tobool(wd.waterweapon)) then
wd.weapontype = "TorpedoLauncher";
elseif (wdName:lower():find("disintegrator",1,true)) then
wd.weaponType = "DGun"
elseif (tobool(wd.lineofsight)) then
if (rendertype==7) then
wd.weapontype = "LightningCannon";
-- swta fix (outdated?)
elseif (wd.model and wd.model:lower():find("laser",1,true)) then
wd.weapontype = "LaserCannon";
elseif (tobool(wd.beamweapon)) then
wd.weapontype = "LaserCannon";
elseif (tobool(wd.smoketrail)) then
wd.weapontype = "MissileLauncher";
elseif (rendertype==4 and tonumber(wd.color)==2) then
wd.weapontype = "EmgCannon";
elseif (rendertype==5) then
wd.weapontype = "Flame";
--elseif(rendertype==1) then
-- wd.weapontype = "MissileLauncher";
else
wd.weapontype = "Cannon";
end
else
wd.weapontype = "Cannon";
end
if (wd.weapontype == "LightingCannon") then
wd.weapontype = "LightningCannon";
end
end
--
if (tobool(wd.ballistic) or tobool(wd.dropped)) then
wd.gravityaffected = true
end
end
--------------------------------------------------------------------------------
local function ProcessUnitDef(udName, ud)
local wds = ud.weapondefs
if (not istable(wds)) then
return
end
-- add this unitDef's weaponDefs
for wdName, wd in pairs(wds) do
if (isstring(wdName) and istable(wd)) then
local fullName = udName .. '_' .. wdName
WeaponDefs[fullName] = wd
end
end
-- convert the weapon names
local weapons = ud.weapons
if (istable(weapons)) then
for i = 1, 32 do
local w = weapons[i]
if (istable(w)) then
if (isstring(w.def)) then
local ldef = string.lower(w.def)
local fullName = udName .. '_' .. ldef
local wd = WeaponDefs[fullName]
if (istable(wd)) then
w.name = fullName
end
end
w.def = nil
end
end
end
-- convert the death explosions
if (isstring(ud.explodeas)) then
local fullName = udName .. '_' .. ud.explodeas
if (WeaponDefs[fullName]) then
ud.explodeas = fullName
end
end
if (isstring(ud.selfdestructas)) then
local fullName = udName .. '_' .. ud.selfdestructas
if (WeaponDefs[fullName]) then
ud.selfdestructas = fullName
end
end
end
--------------------------------------------------------------------------------
local function ProcessWeaponDef(wdName, wd)
-- backward compability
BackwardCompability(wdName,wd)
end
--------------------------------------------------------------------------------
-- Process the unitDefs
local UnitDefs = DEFS.unitDefs
for udName, ud in pairs(UnitDefs) do
if (isstring(udName) and istable(ud)) then
ProcessUnitDef(udName, ud)
end
end
for wdName, wd in pairs(WeaponDefs) do
if (isstring(wdName) and istable(wd)) then
ProcessWeaponDef(wdName, wd)
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
|