Replace remaining uses of FOREACH macro

(cherry-picked from commit 66b9e11a2d)
This commit is contained in:
mattsc 2018-05-14 17:12:01 -07:00
parent 32dc3cc953
commit 841e5c6b06
3 changed files with 69 additions and 45 deletions

View file

@ -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]

View file

@ -1312,22 +1312,28 @@ My best advancement costs $next_cost gold and Im $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]
@ -1368,12 +1374,15 @@ My best advancement costs $next_cost gold and Im $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]
@ -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}
@ -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

View file

@ -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
@ -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