diff --git a/lua/main.lua b/lua/main.lua index c7eee40a..2cb26c05 100644 --- a/lua/main.lua +++ b/lua/main.lua @@ -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 = "" @@ -1060,3 +1062,53 @@ function loti.util.list_attacks(unit) return has_attack 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 abilities = wml.get_child(unit, "abilities") + local latent_wrath_special = wml.get_child(abilities, "damage", "latent_wrath") + local 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 = 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 + 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 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 diff --git a/lua/stats.lua b/lua/stats.lua index 02fd0dfc..70478fa6 100644 --- a/lua/stats.lua +++ b/lua/stats.lua @@ -604,14 +604,15 @@ function wesnoth.update_stats(original) if best_backstab then table.insert(specials, best_backstab) end - local wrath_intensity = 0 - if vars.wrath == true then - wrath_intensity = vars.wrath_intensity - end - table.insert(specials, { "damage", { id = "latent_wrath", apply_to = "self", add = wrath_intensity }}) end - -- PART VIII: Apply visual effects + -- PART VIII: Abilities + 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 if #visual_effects > 0 then local visual_obj = { visual_provider = true } for i = 1,#visual_effects do @@ -649,7 +650,7 @@ function wesnoth.update_stats(original) table.insert(visible_modifications, overlays_object) - -- PART IX: Some final changes + -- PART X: Some final changes for i = #vars,1,-1 do if vars[i][1] == "disabled_defences" then local found = false @@ -682,7 +683,7 @@ function wesnoth.update_stats(original) end remade.advances_to = table.concat(new_advances_to, ",") - -- PART X: Call WML hooks + -- PART XI: Call WML hooks for i = 1,#events_to_fire do remade = call_event_on_unit(remade, events_to_fire[i]) end diff --git a/utils/abilities_events.cfg b/utils/abilities_events.cfg index 49b16f73..57986490 100644 --- a/utils/abilities_events.cfg +++ b/utils/abilities_events.cfg @@ -41,63 +41,63 @@ {CLEAR_VARIABLE resistance} #enddef #define EXPLOSIVE_UNIT_DIES BOMBER WEAPON_TYPE -# A unit hits with weapon special 'explosive detonation', or with trait 'unstable' and hit by impact weapon, explodes, killing self and damaging adjacent + # A unit hits with weapon special 'explosive detonation', or with trait 'unstable' and hit by impact weapon, explodes, killing self and damaging adjacent # add 1/4 damage at radius 1? # affected adjacent units with explosive detonation or unstable should probably light off as well- k>1 baby, chain reaction! - # Get units to harm after explosion (which kills the cause of all the trouble) - [store_unit] - [filter] - [filter_adjacent] - x,y=${BOMBER}.x,${BOMBER}.y - [/filter_adjacent] - [/filter] - variable=dont_stand_so_close_to_me - [/store_unit] - # Add animation to bomber and blow him up (assumes no death animation exists) - [object] - silent=yes - [filter] - id=${BOMBER}.id - [/filter] - [effect] - apply_to=new_animation - [death] - missile_start_time=0 - [missile_frame] - halo="projectiles/fireball-impact-[1~16].png:100" - sound=explosion.ogg - auto_vflip=no - [/missile_frame] - [/death] - [/effect] - [/object] - [harm_unit] - [filter] - id=${BOMBER}.id - [/filter] - amount=$(${BOMBER}.hitpoints * 1000) # sometimes you just have to be sure - damage_type=${WEAPON_TYPE} - fire_event=yes - animate=yes - kill=yes - [/harm_unit] - # Harm bomber's victims - [foreach] - array=dont_stand_so_close_to_me - [do] - [harm_unit] - [filter] - id=$this_item.id - [/filter] - amount=${BOMBER}.hitpoints - damage_type=${WEAPON_TYPE} - fire_event=yes - animate=yes - kill=yes - [/harm_unit] - [/do] - [/foreach] - {CLEAR_VARIABLE dont_stand_so_close_to_me} + # Get units to harm after explosion (which kills the cause of all the trouble) + [store_unit] + [filter] + [filter_adjacent] + x,y=${BOMBER}.x,${BOMBER}.y + [/filter_adjacent] + [/filter] + variable=dont_stand_so_close_to_me + [/store_unit] + # Add animation to bomber and blow him up (assumes no death animation exists) + [object] + silent=yes + [filter] + id=${BOMBER}.id + [/filter] + [effect] + apply_to=new_animation + [death] + missile_start_time=0 + [missile_frame] + halo="projectiles/fireball-impact-[1~16].png:100" + sound=explosion.ogg + auto_vflip=no + [/missile_frame] + [/death] + [/effect] + [/object] + [harm_unit] + [filter] + id=${BOMBER}.id + [/filter] + amount=$(${BOMBER}.hitpoints * 1000) # sometimes you just have to be sure + damage_type=${WEAPON_TYPE} + fire_event=yes + animate=yes + kill=yes + [/harm_unit] + # Harm bomber's victims + [foreach] + array=dont_stand_so_close_to_me + [do] + [harm_unit] + [filter] + id=$this_item.id + [/filter] + amount=${BOMBER}.hitpoints + damage_type=${WEAPON_TYPE} + fire_event=yes + animate=yes + kill=yes + [/harm_unit] + [/do] + [/foreach] + {CLEAR_VARIABLE dont_stand_so_close_to_me} #enddef #define ABILITIES_EVENTS @@ -828,44 +828,11 @@ 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] - [for] - array=unit.attack - variable=i - [do] - [for] - array=unit.attack[$i].specials.damage - variable=j - [do] - [if] - [variable] - name=unit.attack[$i].specials.damage[$j].id - equals=latent_wrath - [/variable] - [then] - {VARIABLE unit.attack[$i].specials.damage[$j].add $unit.variables.wrath_intensity} - [/then] - [/if] - [/do] - [/for] - [/do] - [/for] - [unstore_unit] - variable=unit - find_vacant=no - [/unstore_unit] + [set_wrath_intensity] + id=$unit.id + add=$second_unit.level + [/set_wrath_intensity] + [fire_event] name=force respec [primary_unit] @@ -5400,29 +5367,10 @@ [/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] - [unstore_unit] - variable=unit - find_vacant=no - [/unstore_unit] - [fire_event] - name=set wrath intensity - [primary_unit] - find_in=unit - [/primary_unit] - [/fire_event] + [set_wrath_intensity] + id=$unit.id + add=1 + [/set_wrath_intensity] [/event] [event] @@ -5458,29 +5406,10 @@ [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] - [unstore_unit] - variable=second_unit - find_vacant=no - [/unstore_unit] - [fire_event] - name=set wrath intensity - [primary_unit] - find_in=second_unit - [/primary_unit] - [/fire_event] + [set_wrath_intensity] + id=$second_unit.id + add=1 + [/set_wrath_intensity] [/event] [event] @@ -5503,29 +5432,10 @@ [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] - [unstore_unit] - variable=vindictors[$i] - find_vacant=no - [/unstore_unit] - [fire_event] - name=set wrath intensity - [primary_unit] - find_in=vindictors[$i] - [/primary_unit] - [/fire_event] + [set_wrath_intensity] + id=$vindictors[$i].id + add=1 + [/set_wrath_intensity] [/do] [/for] {CLEAR_VARIABLE vindictors} @@ -5679,30 +5589,10 @@ [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] - [unstore_unit] - variable=unit - find_vacant=no - advance=no - [/unstore_unit] - [fire_event] - name=set wrath intensity - [primary_unit] - find_in=unit - [/primary_unit] - [/fire_event] + [set_wrath_intensity] + id=$unit.id + sub=$lethargy_amount + [/set_wrath_intensity] [/event] [event] @@ -5747,77 +5637,21 @@ 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] - [unstore_unit] - variable=infuriated_unit - find_vacant=no - [/unstore_unit] - [fire_event] - name=set wrath intensity - [primary_unit] - find_in=infuriated_unit - [/primary_unit] - [/fire_event] + [set_wrath_intensity] + id=$infuriated_unit.id + add=1 + [/set_wrath_intensity] [/do] [/foreach] {CLEAR_VARIABLE infuriated} [/event] - - [event] - name=set wrath intensity - first_time_only=no - - [for] - array=unit.attack - variable=swi - [do] - [for] - array=unit.attack[$swi].specials.damage - variable=swj - [do] - [if] - [variable] - name=unit.attack[$swi].specials.damage[$swj].id - equals=latent_wrath - [/variable] - [then] - {VARIABLE unit.attack[$swi].specials.damage[$swj].add $unit.variables.wrath_intensity} - [/then] - [/if] - [/do] - [/for] - [/do] - [/for] - [unstore_unit] - variable=unit - find_vacant=no - advance=no - [/unstore_unit] - [/event] - [event] name=turn refresh first_time_only=no [store_unit] [filter] side=$side_number - [filter_wml] - [variables] - wrath=yes - [/variables] - [/filter_wml] + ability=latent_wrath [/filter] variable=wrathful [/store_unit] @@ -5825,90 +5659,10 @@ 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] - [for] - array=wrathful[$h].attack - variable=i - [do] - [for] - array=wrathful[$h].attack[$i].specials.damage - variable=j - [do] - [if] - [variable] - name=wrathful[$h].attack[$i].specials.damage[$j].id - equals=latent_wrath - [/variable] - [then] - {VARIABLE wrathful[$h].attack[$i].specials.damage[$j].add $wrathful[$h].variables.wrath_intensity} - [/then] - [/if] - [/do] - [/for] - [/do] - [/for] - [/then] - [else] - {CLEAR_VARIABLE wrathful[$h].variables.wrath,wrathful[$h].variables.wrath_intensity} - [for] - array=wrathful[$h].attack - variable=i - [do] - [for] - array=wrathful[$h].attack[$i].specials.damage - variable=j - [do] - [if] - [variable] - name=wrathful[$h].attack[$i].specials.damage[$j].id - equals=latent_wrath - [/variable] - [then] - {VARIABLE wrathful[$h].attack[$i].specials.damage[$j].add 0} - [/then] - [/if] - [/do] - [/for] - [/do] - [/for] - [/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] {CLEAR_VARIABLE wrathful} @@ -5969,29 +5723,10 @@ [/for] {CLEAR_VARIABLE drained} {VARIABLE_OP amount div 2} - [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] - [unstore_unit] - variable=fueled[$i] - find_vacant=no - [/unstore_unit] - [fire_event] - name=set wrath intensity - [primary_unit] - find_in=fueled[$i] - [/primary_unit] - [/fire_event] + [set_wrath_intensity] + id=$fueled[$i].id + add=$amount + [/set_wrath_intensity] {CLEAR_VARIABLE amount} [/do] [/for] @@ -6004,11 +5739,7 @@ [store_unit] [filter] - [filter_wml] - [variables] - wrath=yes - [/variables] - [/filter_wml] + ability=latent_wrath [/filter] variable=wrathful [/store_unit] @@ -6016,33 +5747,10 @@ variable=h array=wrathful [do] - {CLEAR_VARIABLE wrathful[$h].variables.wrath,wrathful[$h].variables.wrath_intensity} - [for] - variable=i - array=wrathful[$h].attack - [do] - [for] - variable=j - array=wrathful[$h].attack[$i].specials.damage - [do] - [if] - [variable] - name=wrathful[$h].attack[$i].specials.damage[$j].id - equals=latent_wrath - [/variable] - [then] - {VARIABLE wrathful[$h].attack[$i].specials.damage[$j].add 0} - [/then] - [/if] - [/do] - [/for] - [/do] - [/for] - [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] {CLEAR_VARIABLE wrathful}