Skip to content

Commit

Permalink
Replace remaining uses of FOREACH macro
Browse files Browse the repository at this point in the history
(cherry-picked from commit 66b9e11)
  • Loading branch information
mattsc committed Oct 7, 2018
1 parent 32dc3cc commit 841e5c6
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 45 deletions.
17 changes: 10 additions & 7 deletions data/campaigns/Delfadors_Memoirs/utils/sides.cfg
Expand Up @@ -516,13 +516,16 @@
y=18
[/unstore_unit]
{CLEAR_VARIABLE chantal_store}
{FOREACH delfador_elvish_veterans i}
[unstore_unit]
variable=delfador_elvish_veterans[$i]
find_vacant=yes
x,y=2,19
[/unstore_unit]
{NEXT i}
[foreach]
array=delfador_elvish_veterans
[do]
[unstore_unit]
variable=this_item
find_vacant=yes
x,y=2,19
[/unstore_unit]
[/do]
[/foreach]
[clear_variable]
name=delfador_elvish_veterans
[/clear_variable]
Expand Down
75 changes: 45 additions & 30 deletions data/scenario-test.cfg
Expand Up @@ -1312,22 +1312,28 @@ My best advancement costs $next_cost gold and I’m $experience|% there."
variable=unit_reach
[/store_reachable_locations]

{FOREACH unit_reach i}
[item]
x,y=$unit_reach[$i].x,$unit_reach[$i].y
image=misc/waypoint.png
[/item]
{NEXT i}
[foreach]
array=unit_reach
[do]
[item]
x,y=$this_item.x,$this_item.y
image=misc/waypoint.png
[/item]
[/do]
[/foreach]

[event]
name=select,side turn,moveto

{FOREACH unit_reach i}
[remove_item]
x,y=$unit_reach[$i].x,$unit_reach[$i].y
image="misc/waypoint.png"
[/remove_item]
{NEXT i}
[foreach]
array=unit_reach
[do]
[remove_item]
x,y=$this_item.x,$this_item.y
image=misc/waypoint.png
[/remove_item]
[/do]
[/foreach]

[redraw]
[/redraw]
Expand Down Expand Up @@ -1368,12 +1374,15 @@ My best advancement costs $next_cost gold and I’m $experience|% there."
[event]
name=select,side turn,moveto

{FOREACH unit_reach i}
[remove_item]
x,y=$unit_reach[$i].x,$unit_reach[$i].y
image="misc/waypoint.png~CS(255,-127,-127)"
[/remove_item]
{NEXT i}
[foreach]
array=unit_reach
[do]
[remove_item]
x,y=$this_item.x,$this_item.y
image="misc/waypoint.png~CS(255,-127,-127)"
[/remove_item]
[/do]
[/foreach]

[redraw]
[/redraw]
Expand Down Expand Up @@ -1720,12 +1729,15 @@ Also, 0..9 = $below_ten, one,two,three = $ascii and the bonus answer is $mixed."
[/variable]
[/not]
[then]
{FOREACH territory i}
[capture_village]
side=$territory[$i].owner_side
x,y=$territory[$i].x,$territory[$i].y
[/capture_village]
{NEXT i}
[foreach]
array=territory
[do]
[capture_village]
side=$this_item.owner_side
x,y=$this_item.x,$this_item.y
[/capture_village]
[/do]
[/foreach]
[/then]
[/if]
{CLEAR_VARIABLE store}
Expand Down Expand Up @@ -3652,12 +3664,15 @@ unplagueable: $wml_unit.status.unplagueable"
variable=temp_villages_area
[/store_locations]

{FOREACH temp_villages_area i}
[capture_village]
side=2
x,y=$temp_villages_area[$i].x,$temp_villages_area[$i].y
[/capture_village]
{NEXT i}
[foreach]
array=temp_villages_area
[do]
[capture_village]
side=2
x,y=$this_item.x,$this_item.y
[/capture_village]
[/do]
[/foreach]

# Then put goblins on the northernmost villages

Expand Down
22 changes: 14 additions & 8 deletions data/test/scenarios/characterize_pathfinding.cfg
Expand Up @@ -92,10 +92,13 @@
[else]
{CHECK_ANSWER path.movement_cost}
#{CHECK_ANSWER path.required_turns} Comment this out -- there may be multiple shortest paths, so finding a different shortest path is okay.
#{FOREACH path.steps step}
# {CHECK_ANSWER (path.steps[$step|].x)}
# {CHECK_ANSWER (path.steps[$step|].y)}
#{NEXT step}
#[foreach]
# array=path.steps
# [do]
# {CHECK_ANSWER (this_item.x)}
# {CHECK_ANSWER (this_item.y)}
# [do]
#[foreach]
[/else]
)}
#enddef
Expand Down Expand Up @@ -380,10 +383,13 @@
[/store_reachable_locations]
{VARIABLE nlocs $r.length}
{CHECK_ANSWER nlocs}
{FOREACH r i}
{CHECK_ANSWER (r[$i|].x)}
{CHECK_ANSWER (r[$i|].y)}
{NEXT i}
[foreach]
array=r
[do]
{CHECK_ANSWER (this_item.x)}
{CHECK_ANSWER (this_item.y)}
[/do]
[/foreach]
#enddef

#define MAKE_SHORT_TEST ID MACRO INIT_MACRO INIT_COUNTER
Expand Down

0 comments on commit 841e5c6

Please sign in to comment.