Skip to content

Commit

Permalink
move wrath_intensity adjustments to lua
Browse files Browse the repository at this point in the history
  • Loading branch information
white-haired-uncle committed May 10, 2024
1 parent 20cc982 commit 78029b1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 139 deletions.
33 changes: 30 additions & 3 deletions lua/main.lua
Expand Up @@ -1062,18 +1062,45 @@ function loti.util.list_attacks(unit)
end

function wesnoth.wml_actions.set_wrath_intensity(cfg)
local debug = cfg.debug or false
local unit_id = cfg.id or wml.error("[set_wrath_intensity]: missing required id=")
local unit = wesnoth.units.get(unit_id).__cfg
local vars = wml.get_child(unit, "variables")
local abilities = wml.get_child(unit, "abilities")

local wrath_intensity = 0
if vars.wrath == true then wrath_intensity = vars.wrath_intensity end
if vars.wrath == true then
wrath_intensity = vars.wrath_intensity or 0 -- Do these still need to be separate?
if debug then wesnoth.interface.add_chat_message(string.format("wrath_intensity was %d",wrath_intensity)) end
if cfg.set ~= nil then wrath_intensity = cfg.set end
if cfg.div ~= nil then
if math.abs(wrath_intensity) <= 1 then
wrath_intensity = 0
else
wrath_intensity = wrath_intensity / cfg.div
if wrath_intensity > 0 then
wrath_intensity = math.floor(wrath_intensity)
else
wrath_intensity = math.ceil(wrath_intensity)
end
end
end
if cfg.add ~= nil then wrath_intensity = wrath_intensity + cfg.add end
if cfg.sub ~= nil then wrath_intensity = wrath_intensity - cfg.sub end
vars.wrath_intensity = wrath_intensity
if debug then wesnoth.interface.add_chat_message(string.format("\twrath_intensity is %d",wrath_intensity)) end
if vars.wrath_intensity == 0 then
vars.wrath_intensity = nil
vars.wrath = nil
end
end

local latent_wrath_special = wml.get_child(abilities, "damage", "latent_wrath")
if latent_wrath_special == nil then
--wesnoth.interface.add_chat_message("Didn't find latent_wrath_special, creating")
--wesnoth.interface.add_chat_message(string.format("Didn't find latent_wrath_special, creating with add = %d",wrath_intensity))
table.insert(abilities, { "damage", { id = "latent_wrath", apply_to = "self", add = wrath_intensity }})
else
--wesnoth.interface.add_chat_message(string.format("Found latent_wrath_special, adding latent_wrath_special.add = %d",wrath_intensity))
--wesnoth.interface.add_chat_message(string.format("Found latent_wrath_special, setting latent_wrath_special.add = %d",wrath_intensity))
latent_wrath_special.add = wrath_intensity
end
wesnoth.units.to_map(unit)
Expand Down
152 changes: 16 additions & 136 deletions utils/abilities_events.cfg
Expand Up @@ -828,25 +828,14 @@
animate=no
fire_attacker_hits=true
[/harm_unit_loti]
[if]
[variable]
name=unit.variables.wrath
equals=yes
[/variable]
[then]
{VARIABLE_OP unit.variables.wrath_intensity add $second_unit.level}
[/then]
[else]
{VARIABLE unit.variables.wrath yes}
{VARIABLE unit.variables.wrath_intensity $second_unit.level}
[/else]
[/if]
{VARIABLE unit.variables.wrath yes}
[unstore_unit]
variable=unit
find_vacant=no
[/unstore_unit]
[set_wrath_intensity]
id=$unit.id
add=$second_unit.level
[/set_wrath_intensity]

[fire_event]
Expand Down Expand Up @@ -5383,25 +5372,14 @@
[/filter_adjacent]
[/or]
[/filter]
[if]
[variable]
name=unit.variables.wrath
equals=yes
[/variable]
[then]
{VARIABLE_OP unit.variables.wrath_intensity add 1}
[/then]
[else]
{VARIABLE unit.variables.wrath yes}
{VARIABLE unit.variables.wrath_intensity 1}
[/else]
[/if]
{VARIABLE unit.variables.wrath yes}
[unstore_unit]
variable=unit
find_vacant=no
[/unstore_unit]
[set_wrath_intensity]
id=$unit.id
add=1
[/set_wrath_intensity]
[/event]

Expand Down Expand Up @@ -5438,25 +5416,14 @@
[filter_second]
ability=triggerable
[/filter_second]
[if]
[variable]
name=second_unit.variables.wrath
equals=yes
[/variable]
[then]
{VARIABLE_OP second_unit.variables.wrath_intensity add 1}
[/then]
[else]
{VARIABLE second_unit.variables.wrath yes}
{VARIABLE second_unit.variables.wrath_intensity 1}
[/else]
[/if]
{VARIABLE second_unit.variables.wrath yes}
[unstore_unit]
variable=second_unit
find_vacant=no
[/unstore_unit]
[set_wrath_intensity]
id=$second_unit.id
add=1
[/set_wrath_intensity]
[/event]

Expand All @@ -5480,25 +5447,14 @@
[for]
array=vindictors
[do]
[if]
[variable]
name=vindictors[$i].variables.wrath
equals=yes
[/variable]
[then]
{VARIABLE_OP vindictors[$i].variables.wrath_intensity add 1}
[/then]
[else]
{VARIABLE vindictors[$i].variables.wrath yes}
{VARIABLE vindictors[$i].variables.wrath_intensity 1}
[/else]
[/if]
{VARIABLE vindictors[$i].variables.wrath yes}
[unstore_unit]
variable=vindictors[$i]
find_vacant=no
[/unstore_unit]
[set_wrath_intensity]
id=$vindictors[$i].id
add=1
[/set_wrath_intensity]
[/do]
[/for]
Expand Down Expand Up @@ -5653,26 +5609,15 @@
[event]
name=lethargy x
first_time_only=no
[if]
[variable]
name=unit.variables.wrath
equals=yes
[/variable]
[then]
{VARIABLE_OP unit.variables.wrath_intensity sub $lethargy_amount}
[/then]
[else]
{VARIABLE unit.variables.wrath yes}
{VARIABLE unit.variables.wrath_intensity "$(-1*$lethargy_amount)"}
[/else]
[/if]
{VARIABLE unit.variables.wrath yes}
[unstore_unit]
variable=unit
find_vacant=no
advance=no
[/unstore_unit]
[set_wrath_intensity]
id=$unit.id
sub=$lethargy_amount
[/set_wrath_intensity]
[/event]

Expand Down Expand Up @@ -5718,25 +5663,14 @@
array=infuriated
variable=infuriated_unit
[do]
[if]
[variable]
name=infuriated_unit.variables.wrath_intensity
greater_than_equal_to=1
[/variable]
[then]
{VARIABLE_OP infuriated_unit.variables.wrath_intensity add 1}
[/then]
[else]
{VARIABLE infuriated_unit.variables.wrath yes}
{VARIABLE infuriated_unit.variables.wrath_intensity 1}
[/else]
[/if]
{VARIABLE infuriated_unit.variables.wrath yes}
[unstore_unit]
variable=infuriated_unit
find_vacant=no
[/unstore_unit]
[set_wrath_intensity]
id=$infuriated_unit.id
add=1
[/set_wrath_intensity]
[/do]
[/foreach]
Expand All @@ -5756,55 +5690,13 @@
[/filter]
variable=wrathful
[/store_unit]
[for]
[for] # Change [set_wrath_intensity] to accept find_in=wrathful and skip this loop?
array=wrathful
variable=h
[do]
[if]
[variable]
name=wrathful[$h].variables.wrath_intensity
greater_than=1
[/variable]
[or]
[variable]
name=wrathful[$h].variables.wrath_intensity
less_than=-1
[/variable]
[/or]
[then]
[if]
[variable]
name=wrathful[$h].variables.wrath_intensity
greater_than=0
[/variable]
[then]
[set_variable]
name=wrathful[$h].variables.wrath_intensity
divide=2
round=floor
[/set_variable]
[/then]
[else]
[set_variable]
name=wrathful[$h].variables.wrath_intensity
divide=2
round=ceil
[/set_variable]
[/else]
[/if]
[/then]
[else]
{CLEAR_VARIABLE wrathful[$h].variables.wrath,wrathful[$h].variables.wrath_intensity}
[/else]
[/if]
[unstore_unit]
variable=wrathful[$h]
find_vacant=no
advance=no
[/unstore_unit]

[set_wrath_intensity]
id=$wrathful[$h].id
div=2
[/set_wrath_intensity]
[/do]
[/for]
Expand Down Expand Up @@ -5866,27 +5758,15 @@
[/for]
{CLEAR_VARIABLE drained}
{VARIABLE_OP amount div 2}
# move to [s_w_i]?
[if]
[variable]
name=fueled[$i].variables.wrath_intensity
greater_than_equal_to=1
[/variable]
[then]
{VARIABLE_OP fueled[$i].variables.wrath_intensity add $amount}
[/then]
[else]
{VARIABLE fueled[$i].variables.wrath yes}
{VARIABLE fueled[$i].variables.wrath_intensity $amount}
[/else]
[/if]
{VARIABLE fueled[$i].variables.wrath yes}
[unstore_unit]
variable=fueled[$i]
find_vacant=no
advance=no
[/unstore_unit]
[set_wrath_intensity]
id=$fueled[$i].id
add=$amount
[/set_wrath_intensity]
{CLEAR_VARIABLE amount}
[/do]
Expand Down

0 comments on commit 78029b1

Please sign in to comment.