/
alldefs_post.lua
422 lines (370 loc) · 14.7 KB
/
alldefs_post.lua
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
--------------------------
-- DOCUMENTATION
-------------------------
-- Evolution RTS contains weapondefs in its unitdef files
-- Standalone weapondefs are only loaded by Spring after unitdefs are loaded
-- So, if we want to do post processing and include all the unit+weapon defs, and have the ability to bake these changes into files, we must do it after both have been loaded
-- That means, ALL UNIT AND WEAPON DEF POST PROCESSING IS DONE HERE
-- What happens:
-- unitdefs_post.lua calls the _Post functions for unitDefs and any weaponDefs that are contained in the unitdef files
-- unitdefs_post.lua writes the corresponding unitDefs to customparams (if wanted)
-- weapondefs_post.lua fetches any weapondefs from the unitdefs,
-- weapondefs_post.lua fetches the standlaone weapondefs, calls the _post functions for them, writes them to customparams (if wanted)
-- strictly speaking, alldefs.lua is a misnomer since this file does not handle armordefs, featuredefs or movedefs
-- Switch for when we want to save defs into customparams as strings (so as a widget can then write them to file)
-- The widget to do so can be found in 'etc/Lua/bake_unitdefs_post'
SaveDefsToCustomParams = false
-------------------------
-- DEFS POST PROCESSING
-------------------------
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
-- process unitdef
function UnitDef_Post(name, uDef)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Utility
--
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 disableunits(unitlist)
for name, ud in pairs(UnitDefs) do
if (ud.buildoptions) then
for _, toremovename in ipairs(unitlist) do
for index, unitname in pairs(ud.buildoptions) do
if (unitname == toremovename) then
table.remove(ud.buildoptions, index)
end
end
end
end
end
end
-- Allow all unit to see planes high above
-- This ties in with the global Cylinder Targetting
-- Default airsightdistance is sightdistance * 1.5
uDef.airsightdistance = uDef.sightdistance * 2
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Set building Mask 0 for all mobile units
--
if uDef.customparams and uDef.customparams.unittype == "mobile" then
uDef.buildingmask = 0
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- 3dbuildrange for all none plane builders
--
--[[
for name, ud in pairs(UnitDefs) do
if (tobool(ud.isBuilder) and not tobool(ud.canfly)) then
ud.buildrange3d = true
end
end
--]]
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- turn off unit collision check for planes
--
if uDef.canfly and not uDef.istransport then
uDef.collide = false
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Calculate mincloakdistance based on unit footprint size
--
local sqrt = math.sqrt
if uDef.cancloak == true then
local fx = uDef.footprintx and tonumber(uDef.footprintx) or 1
local fz = uDef.footprintz and tonumber(uDef.footprintz) or 1
local radius = 8 * sqrt((fx * fx) + (fz * fz))
if uDef.customparams and uDef.customparams.decloakradiusmodifier then
uDef.mincloakdistance = (radius * uDef.customparams.decloakradiusmodifier)
else
uDef.mincloakdistance = (radius * 6)
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Spring Kludge Removal
--
uDef.activateWhenBuilt = true
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--Set reverse velocity automatically
if uDef.maxvelocity then
uDef.maxreversevelocity = uDef.maxvelocity * 0.75
end
--Override groundplate used
if uDef.usegrounddecal == true then
uDef.buildinggrounddecaltype = "groundplate.dds"
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Turn off nanospray globally
if uDef.shownanospray then
uDef.shownanospray = false
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- process weapondef
function WeaponDef_Post(name, wDef)
-- Cylinder Targeting for everything
wDef.cylindertargeting = 128
-- weapon reloadTime and stockpileTime were seperated in 77b1
if (tobool(wDef.stockpile) and (wDef.stockpiletime==nil)) then
wDef.stockpiletime = wDef.reloadtime
--wDef.reloadtime = 2 -- 2 seconds
end
if (tobool(wDef.ballistic) or tobool(wDef.dropped)) then
wDef.gravityaffected = true
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Set up params for Point Defense turrets
if wDef.customparams and wDef.customparams.ispointdefenselaser == true then
if wDef.customparams.primaryweaponrange ~= nil then
primaryWeaponRange = tonumber(wDef.customparams.primaryweaponrange)
else
primaryWeaponRange = 0
end
wDef.areaofeffect = 0
wDef.avoidfeature = false
wDef.avoidfriendly = false
wDef.collidefeature = false
wDef.collidefriendly = false
wDef.corethickness = 0.2
wDef.duration = 0.2
wDef.explosiongenerator = [[custom:genericshellexplosion-small-sparks-burn]]
wDef.falloffrate = 1
wDef.impulsefactor = 0
wDef.interceptedbyshieldtype = 4
wDef.minintensity = 1
wDef.name = [[Point Defense Laser]]
wDef.projectiles = 1
wDef.range = primaryWeaponRange
wDef.reloadtime = 0.25
wDef.weapontype = [[LaserCannon]]
wDef.rgbcolor = [[0 0.5 1]]
wDef.rgbcolor2 = [[1 1 1]]
wDef.soundtrigger = true
wDef.soundstart = [[weapons/pointdefensefire.wav]]
wDef.texture1 = [[shot]]
wDef.texture2 = [[empty]]
wDef.thickness = 2
wDef.tolerance = 1000
wDef.turret = true
wDef.weaponvelocity = 1500
wDef.customparams.damagetype = [[pdlaser]]
wDef.damage.default = 6.25
wDef.energypershot = math.floor(wDef.damage.default * 0.05 * wDef.projectiles * ((wDef.areaofeffect * 0.001) + 1) * wDef.range^0.25 * 0.5 * 10 + 0.5) * 0.1
end
end
--------------------------
-- MODOPTIONS
-------------------------
-- process modoptions (last, because they should not get baked)
function ModOptions_Post (UnitDefs, WeaponDefs)
if (Spring.GetModOptions) then
local modOptions = Spring.GetModOptions()
--------------------------------------------------------------------------------
-- Process Upgrades --
--------------------------------------------------------------------------------
for id,uDef in pairs(UnitDefs) do
-- Handle upgraded units HP and Max Speed
if uDef.customparams and uDef.customparams.isupgraded == "1" then
uDef.maxdamage = uDef.maxdamage * 1.20
uDef.maxvelocity = uDef.maxvelocity * 0.95
end
if uDef.customparams and uDef.customparams.isupgraded == "2" then
uDef.maxdamage = uDef.maxdamage * 1.35
uDef.maxvelocity = uDef.maxvelocity * 0.90
end
if uDef.customparams and uDef.customparams.isupgraded == "3" then
uDef.maxdamage = uDef.maxdamage * 1.50
uDef.maxvelocity = uDef.maxvelocity * 0.85
end
end
for id,wDef in pairs(WeaponDefs) do
-- Handle upgraded units weapon reload times
if wDef.customparams and wDef.customparams.isupgraded == "1" then
wDef.reloadtime = wDef.reloadtime * 0.85
wDef.damage.default = wDef.damage.default * 1.20
if wDef.exteriorshield == true and wDef.shieldpower < 0 then
wDef.shieldpower = wDef.shieldpower * 1.20
end
end
if wDef.customparams and wDef.customparams.isupgraded == "2" then
wDef.reloadtime = wDef.reloadtime * 0.70
wDef.damage.default = wDef.damage.default * 1.35
if wDef.exteriorshield == true and wDef.shieldpower < 0 then
wDef.shieldpower = wDef.shieldpower * 1.35
end
end
if wDef.customparams and wDef.customparams.isupgraded == "3" then
wDef.reloadtime = wDef.reloadtime * 0.65
wDef.damage.default = wDef.damage.default * 1.50
if wDef.exteriorshield == true and wDef.shieldpower < 0 then
wDef.shieldpower = wDef.shieldpower * 1.50
end
end
--Handle Shields
if wDef.customparams and wDef.customparams.isshieldupgraded == "1" then
if wDef.exteriorshield == true then
wDef.shieldpower = wDef.shieldpower * 1.20
end
end
if wDef.customparams and wDef.customparams.isshieldupgraded == "2" then
if wDef.exteriorshield == true then
wDef.shieldpower = wDef.shieldpower * 1.35
end
end
if wDef.customparams and wDef.customparams.isshieldupgraded == "3" then
if wDef.exteriorshield == true then
wDef.shieldpower = wDef.shieldpower * 1.50
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Process Armortypes --
--------------------------------------------------------------------------------
local damageClasses = VFS.Include("gamedata/configs/damageTypes.lua")
local damageTypes = damageClasses.damageTypes
local defaultClass = damageClasses.default
weapondamage = tonumber(wDef.damage.default)
if (weapondamage > 0) then
if (wDef.customparams) then
local damagetypelower
if wDef.customparams.damagetype ~=nil then
damagetypelower = string.lower(wDef.customparams.damagetype)
end
if damagetypelower == '' or damagetypelower == nil then
damagetypelower = defaultClass
end
--Spring.Echo(damagetypelower)
--Spring.Echo(" ")
if damageTypes[damagetypelower] then
for armorClass, armorMultiplier in pairs(damageTypes[damagetypelower]) do
--Spring.Echo(wd.name, armorClass, weapondamage*armorMultiplier )
wDef.damage[armorClass] = weapondamage*armorMultiplier
end
else
Spring.Echo("!!WARNING!! Invalid damagetype: " .. damagetypelower)
end
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Set energy cost to fire automatically
-- There are 2 weapondef customparams used to control this
-- oldcosttofireformula = true, will result in the original formula that did not account for weapon range to be used
-- nocosttofire == true, will result in cost to fire being set at 0
local weaponDefaultDamage = wDef.damage.default
local weaponAreaOfEffect = wDef.areaofeffect or 0
local weaponRange = wDef.range or 0
local weaponProjectiles = wDef.projectiles or 1
if wDef.customparams and wDef.customparams.nocosttofire == true then
wDef.energypershot = 0
elseif wDef.customparams and wDef.customparams.oldcosttofireforumula == true then
local energycosttofire = math.floor(weaponDefaultDamage * 0.1 * weaponProjectiles * ((weaponAreaOfEffect * 0.001) + 1)*10 + 0.5)*0.1
wDef.energypershot = energycosttofire
else
--energycosttofire = weaponDefaultDamage * 0.05 * weaponProjectiles * ((weaponAreaOfEffect * 0.001) + 1) * weaponRange^0.5 * 0.1
local energycosttofire = math.floor(weaponDefaultDamage * 0.05 * weaponProjectiles * ((weaponAreaOfEffect * 0.001) + 1) * weaponRange^0.25 * 0.5*10 + 0.5)*0.1
wDef.energypershot = energycosttofire
end
--Set shield energy cost to recharge
if wDef.exteriorshield == true then
if wDef.customparams and wDef.customparams.nocosttofire == true then
wDef.shieldpowerregenenergy = 0
else
wDef.shieldpowerregenenergy = math.floor(wDef.shieldpowerregen * 0.05 * wDef.shieldradius^0.25 * 0.5 * 10 + 0.5) * 0.1
--Spring.Echo("Energy usage is " .. wDef.shieldpowerregenenergy)
end
end
end
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
for id,unitDef in pairs(UnitDefs) do
for id,weaponDef in pairs(WeaponDefs) do
weaponDef.name = unitDef.name .. [[ Weapon]]
--Spring.Echo(weaponDef.name)
end
end
--------------------------------------------------------------------------------
-- Gameplay Speed (Classic RTS Mode) --
--------------------------------------------------------------------------------
local gamePlaySpeed = modOptions.gameplayspeed or "normal"
Spring.Echo("[Gameplay Speed] Set to " .. gamePlaySpeed)
for id,unitDef in pairs(UnitDefs) do
unitDef.buildtime = unitDef.buildcostmetal / 4
end
if gamePlaySpeed == "veryslow" then
for id,unitDef in pairs(UnitDefs) do
if unitDef.maxvelocity then
unitDef.maxvelocity = unitDef.maxvelocity * 0.5
end
if unitDef.buildcostmetal then
unitDef.buildcostmetal = unitDef.buildcostmetal * 1.5
end
end
for id,weaponDef in pairs(WeaponDefs) do
if weaponDef.weaponvelocity then
--Spring.Echo ("//")
--Spring.Echo (weaponDef.name)
--Spring.Echo (weaponDef.weaponvelocity)
weaponDef.weaponvelocity = weaponDef.weaponvelocity * 0.5
--Spring.Echo ("••")
--Spring.Echo (weaponDef.name)
--Spring.Echo (weaponDef.weaponvelocity)
--Spring.Echo ("\\")
end
end
end
if gamePlaySpeed == "slow" then
for id,unitDef in pairs(UnitDefs) do
if unitDef.maxvelocity then
unitDef.maxvelocity = unitDef.maxvelocity * 0.75
end
if unitDef.buildcostmetal then
unitDef.buildcostmetal = unitDef.buildcostmetal * 1.25
end
end
for id,weaponDef in pairs(WeaponDefs) do
if weaponDef.weaponvelocity then
weaponDef.weaponvelocity = weaponDef.weaponvelocity * 0.75
end
end
end
if gamePlaySpeed == "fast" then
for id,unitDef in pairs(UnitDefs) do
-- Spring.Echo(unitDef.buildcostmetal)
unitDef.buildtime = 5
end
end
end
end