Skip to content

Commit

Permalink
NR: Refactor the White Magi respawn location finding code into a macro
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
irydacea committed Jun 21, 2014
1 parent 87b3ba5 commit 00d7b06
Showing 1 changed file with 55 additions and 88 deletions.
143 changes: 55 additions & 88 deletions data/campaigns/Northern_Rebirth/utils/herodeaths.cfg
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -786,6 +751,8 @@
[/clear_variable]
[/event]

#undef FIND_NR_WHITE_MAGE_RESPAWN

# Elenia death
[event]
name=last breath
Expand Down

0 comments on commit 00d7b06

Please sign in to comment.