Skip to content

Commit 0621daa

Browse files
committed
Add fire and slow because it seemed easy enough to do.
1 parent 7fe0414 commit 0621daa

4 files changed

Lines changed: 125 additions & 80 deletions

File tree

LuaRules/Configs/fire_defs.lua

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
local flamerWeaponDefs = {}
3+
local fireproof = {}
4+
5+
local function cpv(value)
6+
return value and tonumber(value)
7+
end
8+
9+
local DEFAULT_BURN_TIME = 450
10+
local DEFAULT_BURN_TIME_RANDOMNESS = 0.3
11+
local DEFAULT_BURN_DAMAGE = 0.5
12+
13+
-- NOTE: fireStarter is divided by 100 somewhere in the engine between weapon defs and here.
14+
for i = 1, #WeaponDefs do
15+
local wcp = WeaponDefs[i].customParams or {}
16+
if (wcp.setunitsonfire) then -- stupid tdf
17+
--// (fireStarter-tag: 1.0->always flame trees, 2.0->always flame units/buildings too) -- citation needed
18+
19+
flamerWeaponDefs[i] = {
20+
burnTime = cpv(wcp.burntime) or WeaponDefs[i].fireStarter*DEFAULT_BURN_TIME,
21+
burnTimeRand = cpv(wcp.burntimerand) or DEFAULT_BURN_TIME_RANDOMNESS,
22+
burnTimeBase = 1 - (cpv(wcp.burntimerand) or DEFAULT_BURN_TIME_RANDOMNESS),
23+
burnChance = cpv(wcp.burnchance) or WeaponDefs[i].fireStarter/10,
24+
burnDamage = cpv(wcp.burndamage) or DEFAULT_BURN_DAMAGE,
25+
}
26+
27+
flamerWeaponDefs[i].maxDamage = flamerWeaponDefs[i].burnDamage*flamerWeaponDefs[i].burnTime
28+
end
29+
end
30+
31+
for i = 1, #UnitDefs do
32+
fireproof[i] = (UnitDefs[i].customParams.fireproof == "1")
33+
end
34+
35+
return flamerWeaponDefs, fireproof

LuaRules/Gadgets/api_widget_events.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ local scriptUnitDestroyedByTeam = Script.LuaUI.UnitDestroyedByTeam
2323
local scriptUnitLeftRadar = Script.LuaUI.UnitLeftRadar
2424

2525
local disarmWeapons = VFS.Include("LuaRules/Configs/disarm_defs.lua")
26+
local slowWeapons = include("LuaRules/Configs/timeslow_defs.lua")
27+
local fireWeapons = VFS.Include("LuaRules/Configs/fire_defs.lua")
2628

2729
local _, fullview = Spring.GetSpectatingState()
2830
local myAllyTeamID = spGetMyAllyTeamID()
@@ -77,7 +79,7 @@ end
7779

7880
function gadget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weaponDefID, attackerID, attackerDefID, attackerTeam)
7981
--Spring.Echo("gadget:UnitDamaged",unitID, unitDefID, unitTeam, damage, paralyzer)
80-
if paralyzer or disarmWeapons[weaponDefID] then
82+
if paralyzer or disarmWeapons[weaponDefID] or slowWeapons[weaponDefID] or fireWeapons[weaponDefID] then
8183
if not fullview and not Spring.IsUnitInLos(unitID, myAllyTeamID) then
8284
return
8385
end
@@ -87,5 +89,11 @@ function gadget:UnitDamaged(unitID, unitDefID, unitTeam, damage, paralyzer, weap
8789
elseif disarmWeapons[weaponDefID] and Script.LuaUI("UnitDisarmDamageEffect") then
8890
Script.LuaUI.UnitDisarmDamageEffect(unitID, unitDefID)
8991
end
92+
if slowWeapons[weaponDefID] and Script.LuaUI("UnitSlowDamageEffect") then
93+
Script.LuaUI.UnitSlowDamageEffect(unitID, unitDefID)
94+
end
95+
if fireWeapons[weaponDefID] and Script.LuaUI("UnitFireDamageEffect") then
96+
Script.LuaUI.UnitFireDamageEffect(unitID, unitDefID)
97+
end
9098
end
9199
end

LuaRules/Gadgets/unit_is_on_fire.lua

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ if (gadgetHandler:IsSyncedCode()) then
4040

4141
--//SETTINGS
4242

43-
local DEFAULT_BURN_TIME = 450
44-
local DEFAULT_BURN_TIME_RANDOMNESS = 0.3
45-
local DEFAULT_BURN_DAMAGE = 0.5
4643
local MIN_IMMERSION_FOR_EXTINGUISH = 0.8
4744

4845
local CHECK_INTERVAL = 6
@@ -69,34 +66,7 @@ local SetUnitCloak = Spring.SetUnitCloak
6966
--------------------------------------------------------------------------------
7067
--------------------------------------------------------------------------------
7168

72-
local function cpv(value)
73-
return value and tonumber(value)
74-
end
75-
76-
-- NOTE: fireStarter is divided by 100 somewhere in the engine between weapon defs and here.
77-
78-
local flamerWeaponDefs = {}
79-
for i = 1, #WeaponDefs do
80-
local wcp = WeaponDefs[i].customParams or {}
81-
if (wcp.setunitsonfire) then -- stupid tdf
82-
--// (fireStarter-tag: 1.0->always flame trees, 2.0->always flame units/buildings too) -- citation needed
83-
84-
flamerWeaponDefs[i] = {
85-
burnTime = cpv(wcp.burntime) or WeaponDefs[i].fireStarter*DEFAULT_BURN_TIME,
86-
burnTimeRand = cpv(wcp.burntimerand) or DEFAULT_BURN_TIME_RANDOMNESS,
87-
burnTimeBase = 1 - (cpv(wcp.burntimerand) or DEFAULT_BURN_TIME_RANDOMNESS),
88-
burnChance = cpv(wcp.burnchance) or WeaponDefs[i].fireStarter/10,
89-
burnDamage = cpv(wcp.burndamage) or DEFAULT_BURN_DAMAGE,
90-
}
91-
92-
flamerWeaponDefs[i].maxDamage = flamerWeaponDefs[i].burnDamage*flamerWeaponDefs[i].burnTime
93-
end
94-
end
95-
96-
local fireproof = {}
97-
for i = 1, #UnitDefs do
98-
fireproof[i] = (UnitDefs[i].customParams.fireproof == "1")
99-
end
69+
local flamerWeaponDefs, fireproof = VFS.Include("LuaRules/Configs/fire_defs.lua")
10070

10171
local unitsOnFire = {}
10272
local inWater = {}

LuaUI/Widgets/gfx_paralyze_effect.lua

Lines changed: 80 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,7 @@ void main() {
191191
#endif
192192
193193
v_endcolor_alpha.rgba = endcolor_endgameframe.rgba;
194-
v_endcolor_alpha.a = clamp( (v_endcolor_alpha.a - (timeInfo.x + timeInfo.w) + 100) * 0.01, 0.0, 1.0); // fade out for end time
195-
196-
float paralyzestrength = uni[instData.y].userDefined[1].x; // this (paralyzedamage/maxhealth), so >=1.0 is paralyzed
197-
v_endcolor_alpha.a = clamp(pow(paralyzestrength, 2.0), 0.0, 1.1);
198-
v_endcolor_alpha.r = uni[instData.y].userDefined[1].y;
194+
v_endcolor_alpha.a = uni[instData.y].userDefined[1].x;
199195
200196
// this checks the drawFlag of wether the unit is actually being drawn (this is ==1 when then unit is both visible and drawn as a full model (not icon))
201197
if ((uni[instData.y].composite & 0x00000003u) < 1u ) {
@@ -324,8 +320,20 @@ in vec4 v_endcolor_alpha;
324320
out vec4 fragColor;
325321
#line 25000
326322
void main() {
327-
float paralysis_level = v_endcolor_alpha.a; // values of 1 are fully paralyzed
328-
float disarmed = v_endcolor_alpha.r; // can be 1 or 0
323+
float input_data = v_endcolor_alpha.a; // 1: para, 2: disarm, 4: fire, fraction: slow
324+
bool fire = (input_data > 3.75);
325+
if (fire) {
326+
input_data -= 4.0;
327+
}
328+
bool disarm = (input_data > 1.75);
329+
if (disarm) {
330+
input_data -= 2.0;
331+
}
332+
bool emp = (input_data > 0.75);
333+
if (emp) {
334+
input_data -= 1.0;
335+
}
336+
float slowed = input_data;
329337
330338
float noisescale;
331339
float persistance;
@@ -337,12 +345,12 @@ void main() {
337345
float lighting_sharpness;
338346
float lighting_width;
339347
float lightning_speed;
340-
float effect_level;
348+
float effect_level = 0.0;
341349
342350
// ------------------ CONFIG START --------------------
343351
344-
if (paralysis_level > 0.98) { // not fully paralyzed
345-
effect_level = paralysis_level;
352+
if (emp) {
353+
effect_level = 1.0;
346354
noisescale = 0.31;
347355
persistance = 0.45;
348356
lacunarity = 2.5;
@@ -353,7 +361,7 @@ void main() {
353361
lighting_sharpness = 4.8;
354362
lighting_width = 3.8;
355363
lightning_speed = 0.95;
356-
} else if (disarmed > 0.5) {
364+
} else if (disarm) {
357365
effect_level = 0.996;
358366
noisescale = 0.31;
359367
persistance = 0.45;
@@ -365,37 +373,51 @@ void main() {
365373
lighting_sharpness = 4.8;
366374
lighting_width = 3.8;
367375
lightning_speed = 0.95;
368-
} else {
369-
fragColor = vec4(0);
370-
return;
371376
}
372377
// ------------------ CONFIG END --------------------
373378
374-
vec4 noiseposition = noisescale * vec4(v_modelPosOrig, (timeInfo.x + timeInfo.w) * lightning_speed);
375-
float noise4 = 0;
376-
noise4 += pow(persistance, 1.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 1.0));
377-
noise4 += pow(persistance, 2.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 2.0));
378-
noise4 += pow(persistance, 3.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 3.0));
379-
noise4 += pow(persistance, 4.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 4.0));
380-
noise4 = (1.0 * noise4 + 0.5);
381-
float electricity = clamp(1.0 - abs(noise4 - 0.5) * lighting_width, 0.0, 1.0);
382-
electricity = clamp(pow(electricity, lighting_sharpness), 0.0, 1.0);
383-
384-
vec3 lightningcolor;
385-
float effectalpha;
386-
lightningcolor = mix(minlightningcolor, maxlightningcolor, electricity);
387-
effectalpha = clamp(effect_level * lightningalpha, 0.0, 1.0);
379+
fragColor = vec4(1.0, 1.0, 1.0, 0.0);
388380
float flash = abs((2.0 * fract((timeInfo.x + timeInfo.w) * 0.07)) - 1.0);
389-
390-
fragColor = vec4(lightningcolor, electricity*effectalpha);
391-
float baseItensity = snoise(0.032 * vec4(v_modelPosOrig, 1.7*(timeInfo.x + timeInfo.w))) +
392-
snoise(0.02 * vec4(v_modelPosOrig, 1.3*(timeInfo.x + timeInfo.w)));
393-
baseItensity = sqrt(abs(baseItensity) + 0.2) * (0.5 * flash + 0.2) + clamp(baseItensity * (flash - 0.5) * 0.5, -0.2, 1.0);
394-
wholeunitbasecolor.a = wholeunitbasecolor.a * (0.4 + baseItensity * 0.5);
395-
wholeunitbasecolor.r = wholeunitbasecolor.r + baseItensity * 0.33;
396-
wholeunitbasecolor.g = wholeunitbasecolor.g + baseItensity * 0.45;
397-
fragColor = max(wholeunitbasecolor, fragColor); // apply whole unit base color
398-
fragColor.a *= clamp((effect_level - 0.98) * 50.0, 0.0, 1.0);
381+
if (effect_level > 0.5) {
382+
vec4 noiseposition = noisescale * vec4(v_modelPosOrig, (timeInfo.x + timeInfo.w) * lightning_speed);
383+
float noise4 = 0;
384+
noise4 += pow(persistance, 1.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 1.0));
385+
noise4 += pow(persistance, 2.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 2.0));
386+
noise4 += pow(persistance, 3.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 3.0));
387+
noise4 += pow(persistance, 4.0) * snoise(noiseposition * 0.025 * pow(lacunarity, 4.0));
388+
noise4 = (1.0 * noise4 + 0.5);
389+
float electricity = clamp(1.0 - abs(noise4 - 0.5) * lighting_width, 0.0, 1.0);
390+
electricity = clamp(pow(electricity, lighting_sharpness), 0.0, 1.0);
391+
392+
vec3 lightningcolor;
393+
float effectalpha;
394+
lightningcolor = mix(minlightningcolor, maxlightningcolor, electricity);
395+
effectalpha = clamp(effect_level * lightningalpha, 0.0, 1.0);
396+
397+
fragColor = vec4(lightningcolor, electricity*effectalpha);
398+
float baseItensity = snoise(0.032 * vec4(v_modelPosOrig, 1.7*(timeInfo.x + timeInfo.w))) +
399+
snoise(0.02 * vec4(v_modelPosOrig, 1.3*(timeInfo.x + timeInfo.w)));
400+
baseItensity = sqrt(abs(baseItensity) + 0.2) * (0.5 * flash + 0.2) + clamp(baseItensity * (flash - 0.5) * 0.5, -0.2, 1.0);
401+
wholeunitbasecolor.a = wholeunitbasecolor.a * (0.4 + baseItensity * 0.5);
402+
wholeunitbasecolor.r = wholeunitbasecolor.r + baseItensity * 0.33;
403+
wholeunitbasecolor.g = wholeunitbasecolor.g + baseItensity * 0.45;
404+
fragColor = max(wholeunitbasecolor, fragColor); // apply whole unit base color
405+
fragColor.a *= clamp((effect_level - 0.98) * 50.0, 0.0, 1.0);
406+
}
407+
if (slowed > 0.001) {
408+
float baseItensity = snoise(0.032 * vec4(v_modelPosOrig, -1.7*(timeInfo.x + timeInfo.w))) +
409+
snoise(0.02 * vec4(v_modelPosOrig, -1.3*(timeInfo.x + timeInfo.w)));
410+
baseItensity = sqrt(abs(baseItensity) + 0.2);
411+
vec4 slowcolor = vec4(0.9, 0.1, 0.9, baseItensity) * sqrt(slowed) * 2.0;
412+
fragColor = mix(slowcolor, fragColor, 0.5 + 0.3 * clamp(effect_level, 0.0, 1.0));
413+
}
414+
if (fire) {
415+
flash = 1.0 - flash;
416+
float baseItensity = snoise(0.06 * vec4(v_modelPosOrig, 1.1*(timeInfo.x + timeInfo.w))) +
417+
snoise(0.073 * vec4(v_modelPosOrig, 2.2*(timeInfo.x + timeInfo.w)));
418+
vec4 firecolor = vec4(1.0, 0.3, 0.0, (0.4 + 0.3*flash) * (0.3 + 0.5 * baseItensity) + 0.2 * baseItensity + 0.4 + 0.6*flash);
419+
fragColor = mix(firecolor, fragColor, 0.65 + 0.2 * clamp(effect_level + slowed, 0.0, 1.0));
420+
}
399421
}
400422
]]
401423

@@ -524,7 +546,9 @@ function widget:UnitCreated(unitID, unitDefID)
524546

525547
local health,maxHealth,paralyzeDamage,capture,build = spGetUnitHealth(unitID)
526548
local disarmed = spGetUnitRulesParam(unitID, "disarmed")
527-
if (paralyzeDamage and paralyzeDamage > 0) or (disarmed == 1) then
549+
local slow = spGetUnitRulesParam(unitID, "slowState")
550+
local fire = (spGetUnitRulesParam(unitID, "on_fire") == 1)
551+
if (paralyzeDamage and paralyzeDamage > 0) or (disarmed == 1) or (slow or 0) > 0 or fire then
528552
DrawParalyzedUnitGL4(unitID, unitDefID)
529553
end
530554
end
@@ -542,7 +566,7 @@ function widget:UnitEnteredLos(unitID)
542566
widget:UnitCreated(unitID, spGetUnitDefID(unitID))
543567
end
544568

545-
local function UnitParalyzeOrDisarmDamageEffect(unitID, unitDefID) -- called from Healthbars Widget Forwarding GADGET!!!
569+
local function UnitStatusDamageEffect(unitID, unitDefID) -- called from Healthbars Widget Forwarding GADGET!!!
546570
widget:UnitCreated(unitID, unitDefID)
547571
end
548572

@@ -555,14 +579,18 @@ function widget:GameFrame(n)
555579
for unitID, index in pairs(paralyzedDrawUnitVBOTable.instanceIDtoIndex) do
556580
local health, maxHealth, paralyzeDamage, capture, build = spGetUnitHealth(unitID)
557581
local disarmed = spGetUnitRulesParam(unitID, "disarmed")
558-
if (not paralyzeDamage or paralyzeDamage == 0) and disarmed ~= 1 then
582+
local slow = spGetUnitRulesParam(unitID, "slowState")
583+
local fire = (spGetUnitRulesParam(unitID, "on_fire") == 1)
584+
if (not paralyzeDamage or paralyzeDamage == 0) and disarmed ~= 1 and (slow or 0) <= 0 and not fire then
559585
toremove[unitID] = true
560586
else
561587
local para = (paralyzeDamage or 0) / (maxHealth or 1)
562-
uniformcache[1] = para -- 1 to avoid div0
588+
local val = (slow or 0)
589+
val = val + (((para >= 1) and 1) or 0)
590+
val = val + (((disarmed == 1) and 2) or 0)
591+
val = val + ((fire and 4) or 0)
592+
uniformcache[1] = val
563593
gl.SetUnitBufferUniforms(unitID, uniformcache, 4)
564-
uniformcache[1] = disarmed
565-
gl.SetUnitBufferUniforms(unitID, uniformcache, 5)
566594
end
567595
end
568596
end
@@ -588,15 +616,19 @@ function widget:Initialize()
588616
end
589617
WG['DrawParalyzedUnitGL4'] = DrawParalyzedUnitGL4
590618
WG['StopDrawParalyzedUnitGL4'] = StopDrawParalyzedUnitGL4
591-
widgetHandler:RegisterGlobal("UnitParalyzeDamageEffect", UnitParalyzeOrDisarmDamageEffect)
592-
widgetHandler:RegisterGlobal("UnitDisarmDamageEffect", UnitParalyzeOrDisarmDamageEffect)
619+
widgetHandler:RegisterGlobal("UnitParalyzeDamageEffect", UnitStatusDamageEffect)
620+
widgetHandler:RegisterGlobal("UnitDisarmDamageEffect", UnitStatusDamageEffect)
621+
widgetHandler:RegisterGlobal("UnitSlowDamageEffect", UnitStatusDamageEffect)
622+
widgetHandler:RegisterGlobal("UnitFireDamageEffect", UnitStatusDamageEffect)
593623
end
594624

595625
function widget:Shutdown()
596626
WG['DrawParalyzedUnitGL4'] = nil
597627
WG['StopDrawParalyzedUnitGL4'] = nil
598-
widgetHandler:DeregisterGlobal("UnitParalyzeDamageEffect" )
599-
widgetHandler:DeregisterGlobal("UnitDisarmDamageEffect" )
628+
widgetHandler:DeregisterGlobal("UnitParalyzeDamageEffect")
629+
widgetHandler:DeregisterGlobal("UnitDisarmDamageEffect")
630+
widgetHandler:DeregisterGlobal("UnitSlowDamageEffect")
631+
widgetHandler:DeregisterGlobal("UnitFireDamageEffect")
600632
end
601633

602634
function widget:DrawWorld()

0 commit comments

Comments
 (0)