DW: Replace FOREACH

This commit is contained in:
fendrin 2016-08-05 23:26:57 +02:00
parent deb56e0fe6
commit aa8b541757
4 changed files with 76 additions and 59 deletions

View file

@ -484,21 +484,24 @@
# Loop through the zombified villages to see if that
# location has already been stored:
{FOREACH zombified_villages loop}
[if]
[variable]
name=village_location
equals=$zombified_villages[$loop].location
[/variable]
[foreach]
array=zombified_villages
[do]
[if]
[variable]
name=village_location
equals=$this_item.location
[/variable]
[then]
[set_variable]
name=already_zombified
value=yes
[/set_variable]
[/then]
[/if]
{NEXT loop}
[then]
[set_variable]
name=already_zombified
value=yes
[/set_variable]
[/then]
[/if]
[/do]
[/foreach]
# If the village's location was not found in the
# array, it hasn't been taken over yet, so zombify

View file

@ -334,12 +334,15 @@
[/filter]
variable=undead
[/store_unit]
{FOREACH undead loop}
[set_variable]
name=number_of_undead
add=1
[/set_variable]
{NEXT loop}
[foreach]
array=undead
[do]
[set_variable]
name=number_of_undead
add=1
[/set_variable]
[/do]
[/foreach]
[clear_variable]
name=undead
[/clear_variable]
@ -602,15 +605,18 @@
kill=yes
variable=orcs
[/store_unit]
{FOREACH orcs orc}
[set_variable]
name=orcs[$orc].moves
value=0
[/set_variable]
[unstore_unit]
variable=orcs[$orc]
[/unstore_unit]
{NEXT orc}
[foreach]
array=orcs
[do]
[set_variable]
name=this_item.moves
value=0
[/set_variable]
[unstore_unit]
variable=this_item
[/unstore_unit]
[/do]
[/foreach]
[clear_variable]
name=orcs
[/clear_variable]

View file

@ -178,19 +178,21 @@
[/store_locations]
# Put a bat into each chasm hex.
{FOREACH chasm_hexes hex}
{RANDOM ({BAT_TYPES_VALUE})}
[unit]
type=$random
x=$chasm_hexes[$hex].x
y=$chasm_hexes[$hex].y
side=2
animate=yes # The animation fades in, which looks good. If the animation is ever changed to something else, this might have to be changed.
[/unit]
{NEXT hex}
[foreach]
array=chasm_hexes
[do]
{RANDOM ({BAT_TYPES_VALUE})}
[unit]
type=$random
x=$this_item.x
y=$this_item.y
side=2
animate=yes # The animation fades in, which looks good. If the animation is ever changed to something else, this might have to be changed.
[/unit]
[/do]
[/foreach]
{CLEAR_VARIABLE chasm_hexes}
{CLEAR_VARIABLE hex}
#enddef
#define BATS_ENTER_CAVE
@ -227,19 +229,22 @@
variable=bats
[/store_unit]
{FOREACH bats bat}
{NEAREST_HEX $bats[$bat].x $bats[$bat].y 99 (terrain=Qx*) chasm_hex}
[kill]
id=$bats[$bat].id
animate=no
[/kill]
[move_unit_fake]
type=$bats[$bat].type
x=$bats[$bat].x, $chasm_hex.x
y=$bats[$bat].y, $chasm_hex.y
side=2
[/move_unit_fake]
{NEXT bat}
[foreach]
array=bats
[do]
{NEAREST_HEX $this_item.x $this_item.y 99 (terrain=Qx*) chasm_hex}
[kill]
id=$this_item.id
animate=no
[/kill]
[move_unit_fake]
type=$this_item.type
x=$this_item.x, $chasm_hex.x
y=$this_item.y, $chasm_hex.y
side=2
[/move_unit_fake]
[/do]
[/foreach]
{CLEAR_VARIABLE bats}
{CLEAR_VARIABLE chasm_hex}

View file

@ -210,13 +210,16 @@
variable=stunned
[/store_unit]
{FOREACH stunned i}
{CLEAR_VARIABLE stunned[$i].status.stunned}
[foreach]
array=stunned
[do]
{CLEAR_VARIABLE this_item.status.stunned}
[unstore_unit]
variable=stunned[$i]
[/unstore_unit]
{NEXT i}
[unstore_unit]
variable=this_item
[/unstore_unit]
[/do]
[/foreach]
{CLEAR_VARIABLE stunned}
[/event]