From ce33ba394a689b173ed3cc0f933fde262a18c21d Mon Sep 17 00:00:00 2001 From: "Ignacio R. Morelle" Date: Sat, 21 Jun 2014 10:05:21 -0400 Subject: [PATCH] NR: Refactor the White Magi respawn location finding code into a macro This bit was subject to a particularly bad case of code copy-pasting when the only real variable is the id of the first respawn hub candidate. Added a statement to clear the respawn_hub WML variable after running the code since it's never used again afterwards. --- .../Northern_Rebirth/utils/herodeaths.cfg | 143 +++++++----------- 1 file changed, 55 insertions(+), 88 deletions(-) diff --git a/data/campaigns/Northern_Rebirth/utils/herodeaths.cfg b/data/campaigns/Northern_Rebirth/utils/herodeaths.cfg index 6ba049cf489a..d4e2e6d5b96b 100644 --- a/data/campaigns/Northern_Rebirth/utils/herodeaths.cfg +++ b/data/campaigns/Northern_Rebirth/utils/herodeaths.cfg @@ -214,6 +214,52 @@ {VARIABLE Eryssa_alive no} [/event] +#define FIND_NR_WHITE_MAGE_RESPAWN HUB_CANDIDATE + # Find a respawn point, start within 1 hex of the candidate, increase range if nothing suitable + # Search around Tallin if the candidate is still jailed + {VARIABLE current_radius 1} + [if] + [have_unit] + id={HUB_CANDIDATE} + [/have_unit] + [then] + {VARIABLE respawn_hub ({HUB_CANDIDATE})} + [/then] + [else] + {VARIABLE respawn_hub (Tallin)} + [/else] + [/if] + [while] + [variable] + name=respawn_point.length + equals=0 + [/variable] + [do] + [store_locations] + variable=respawn_point + [and] + [filter] + id=$respawn_hub + [/filter] + radius=$current_radius + [/and] + # Exclude hexes with units on them and impassable terrain + [and] + [not] + [filter] + [/filter] + [/not] + [not] + terrain=Wo,*^Xm,X*,Q* + [/not] + [/and] + [/store_locations] + {VARIABLE_OP current_radius add 1} + [/do] + [/while] + {CLEAR_VARIABLE current_radius,respawn_hub} +#enddef + # Sister Thera death, seven randomly chosen dialogues [event] name=last breath @@ -326,48 +372,9 @@ [/else] [/switch] {FLASH_WHITE ()} - # Find a respawn point, start within 1 hex of Father Morvin, increase range if nothing suitable - # Search around Tallin if Morvin is still jailed - {VARIABLE current_radius 1} - [if] - [have_unit] - id=Father Morvin - [/have_unit] - [then] - {VARIABLE respawn_hub "Father Morvin"} - [/then] - [else] - {VARIABLE respawn_hub "Tallin"} - [/else] - [/if] - [while] - [variable] - name=respawn_point.length - equals=0 - [/variable] - [do] - [store_locations] - variable=respawn_point - [and] - [filter] - id=$respawn_hub - [/filter] - radius=$current_radius - [/and] - # Exclude hexes with units on them and impassable terrain - [and] - [not] - [filter] - [/filter] - [/not] - [not] - terrain=Wo,*^Xm,X*,Q* - [/not] - [/and] - [/store_locations] - {VARIABLE_OP current_radius add 1} - [/do] - [/while] + + {FIND_NR_WHITE_MAGE_RESPAWN (Father Morvin)} + # Store unit to check if it advanced to mage of light [store_unit] [filter] @@ -392,9 +399,7 @@ [/modifications] {IS_LOYAL} [/unit] - {CLEAR_VARIABLE respawn_point} - {CLEAR_VARIABLE type_check} - {CLEAR_VARIABLE current_radius} + {CLEAR_VARIABLE respawn_point,type_check} [switch] variable=random [case] @@ -615,46 +620,8 @@ [/else] [/switch] - {VARIABLE current_radius 1} - [if] - [have_unit] - id=Sister Thera - [/have_unit] - [then] - {VARIABLE respawn_hub "Sister Thera"} - [/then] - [else] - {VARIABLE respawn_hub "Tallin"} - [/else] - [/if] - [while] - [variable] - name=respawn_point.length - equals=0 - [/variable] - [do] - [store_locations] - variable=respawn_point - [and] - [filter] - id=$respawn_hub - [/filter] - radius=$current_radius - [/and] - # Exclude hexes with units on them and impassable terrain - [and] - [not] - [filter] - [/filter] - [/not] - [not] - terrain=Wo,*^Xm,X*,Q* - [/not] - [/and] - [/store_locations] - {VARIABLE_OP current_radius add 1} - [/do] - [/while] + {FIND_NR_WHITE_MAGE_RESPAWN (Sister Thera)} + [store_unit] [filter] id=Father Morvin @@ -678,9 +645,7 @@ [/modifications] {IS_LOYAL} [/unit] - {CLEAR_VARIABLE type_check} - {CLEAR_VARIABLE respawn_point} - {CLEAR_VARIABLE current_radius} + {CLEAR_VARIABLE type_check,respawn_point} [switch] variable=random @@ -786,6 +751,8 @@ [/clear_variable] [/event] +#undef FIND_NR_WHITE_MAGE_RESPAWN + # Elenia death [event] name=last breath