Skip to content

Commit

Permalink
remove variables.wrath*
Browse files Browse the repository at this point in the history
  • Loading branch information
white-haired-uncle committed May 11, 2024
1 parent 043c7f1 commit f366404
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 92 deletions.
69 changes: 38 additions & 31 deletions lua/main.lua
Expand Up @@ -351,7 +351,9 @@ local function unit_information_part_1()
local starving = wml.variables["unit.variables.starving"]
local from_the_ashes_used = wml.variables["unit.variables.from_the_ashes_used"]
local from_the_ashes_cooldown = wml.variables["unit.variables.from_the_ashes_cooldown"]
local wrath = wml.variables["unit.variables.wrath_intensity"]
local wrath = nil
local latent_wrath = wml.get_child(wml.get_child(wml.variables["unit"], "abilities"), "damage", "latent_wrath")
if latent_wrath ~= nil then wrath = latent_wrath.add end

local result = ""
local span = "<span font_weight='bold'>"
Expand Down Expand Up @@ -1065,43 +1067,48 @@ 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 latent_wrath_special = wml.get_child(abilities, "damage", "latent_wrath")
local wrath_intensity = 0
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
if latent_wrath_special ~= nil then
wrath_intensity = latent_wrath_special.add
end
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: 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 = wrath_intensity / cfg.div
if wrath_intensity > 0 then
wrath_intensity = math.floor(wrath_intensity)
else
wrath_intensity = math.ceil(wrath_intensity)
end
wrath_intensity = math.ceil(wrath_intensity)
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
if debug then wesnoth.interface.add_chat_message(string.format("Didn't find latent_wrath_special, creating with add = %d",wrath_intensity)) end
table.insert(abilities, { "damage", { id = "latent_wrath", apply_to = "self", add = wrath_intensity }})
if cfg.add ~= nil then wrath_intensity = wrath_intensity + cfg.add end
if cfg.sub ~= nil then wrath_intensity = wrath_intensity - cfg.sub end
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: \twrath_intensity is %d",wrath_intensity)) end
if wrath_intensity == 0 then
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: wrath_intensity == %d, removing ability",wrath_intensity)) end
local _,index = wml.find_child(abilities, "damage", { id = "latent_wrath" })
if debug then
if index ~= nil then
wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: found id=latent_wrath at position %d",index))
table.remove(abilities,index)
else
wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: no id=latent_wrath found"))
end
end
else
if debug then wesnoth.interface.add_chat_message(string.format("Found latent_wrath_special, setting latent_wrath_special.add = %d",wrath_intensity)) end
latent_wrath_special.add = wrath_intensity
if latent_wrath_special == nil then
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: Didn't find latent_wrath_special, creating with add = %d",wrath_intensity)) end
table.insert(abilities, { "damage", { id = "latent_wrath", apply_to = "self", add = wrath_intensity }})
else
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: Found latent_wrath_special, setting add = %d",wrath_intensity)) end
latent_wrath_special.add = wrath_intensity
end
end
wesnoth.units.to_map(unit)
end
10 changes: 3 additions & 7 deletions lua/stats.lua
Expand Up @@ -607,13 +607,9 @@ function wesnoth.update_stats(original)
end

-- PART VIII: Abilities
local abilities = wml.get_child(remade, "abilities")
-- add latent_wrath to apply wrath/lethargy to all attacks
local latent_wrath_special = wml.get_child(abilities, "damage", "latent_wrath")
if latent_wrath_special == nil then
local wrath_intensity = 0
if vars.wrath == true then wrath_intensity = vars.wrath_intensity end
table.insert(abilities, { "damage", { id = "latent_wrath", apply_to = "self", add = wrath_intensity }})
local latent_wrath_special = wml.get_child(wml.get_child(original, "abilities"), "damage", "latent_wrath")
if latent_wrath_special ~= nil then
table.insert(wml.get_child(remade, "abilities"), { "damage", latent_wrath_special })
end

-- PART IX: Apply visual effects
Expand Down
58 changes: 4 additions & 54 deletions utils/abilities_events.cfg
Expand Up @@ -828,11 +828,6 @@
animate=no
fire_attacker_hits=true
[/harm_unit_loti]
{VARIABLE unit.variables.wrath yes}
[unstore_unit]
variable=unit
find_vacant=no
[/unstore_unit]
[set_wrath_intensity]
id=$unit.id
add=$second_unit.level
Expand Down Expand Up @@ -5372,11 +5367,6 @@
[/filter_adjacent]
[/or]
[/filter]
{VARIABLE unit.variables.wrath yes}
[unstore_unit]
variable=unit
find_vacant=no
[/unstore_unit]
[set_wrath_intensity]
id=$unit.id
add=1
Expand Down Expand Up @@ -5416,11 +5406,6 @@
[filter_second]
ability=triggerable
[/filter_second]
{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
Expand All @@ -5447,11 +5432,6 @@
[for]
array=vindictors
[do]
{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
Expand Down Expand Up @@ -5609,12 +5589,6 @@
[event]
name=lethargy x
first_time_only=no
{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
Expand Down Expand Up @@ -5663,11 +5637,6 @@
array=infuriated
variable=infuriated_unit
[do]
{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
Expand All @@ -5682,15 +5651,11 @@
[store_unit]
[filter]
side=$side_number
[filter_wml]
[variables]
wrath=yes
[/variables]
[/filter_wml]
ability=latent_wrath
[/filter]
variable=wrathful
[/store_unit]
[for] # Change [set_wrath_intensity] to accept find_in=wrathful and skip this loop?
[for]
array=wrathful
variable=h
[do]
Expand Down Expand Up @@ -5758,12 +5723,6 @@
[/for]
{CLEAR_VARIABLE drained}
{VARIABLE_OP amount div 2}
{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
Expand All @@ -5780,26 +5739,17 @@

[store_unit]
[filter]
[filter_wml]
[variables]
wrath=yes
[/variables]
[/filter_wml]
ability=latent_wrath
[/filter]
variable=wrathful
[/store_unit]
[for]
variable=h
array=wrathful
[do]
{CLEAR_VARIABLE wrathful[$h].variables.wrath,wrathful[$h].variables.wrath_intensity}
[unstore_unit]
variable=wrathful[$h]
find_vacant=no
advance=no
[/unstore_unit]
[set_wrath_intensity]
id=$wrathful[$h].id
set=0
[/set_wrath_intensity]
[/do]
[/for]
Expand Down

0 comments on commit f366404

Please sign in to comment.