SoF: Replace FOREACH

This commit is contained in:
fendrin 2016-08-06 00:54:39 +02:00
parent a4e366d2da
commit 418c9656a5
4 changed files with 218 additions and 168 deletions

View File

@ -314,102 +314,111 @@
[/value] [/value]
[/set_variables] [/set_variables]
{FOREACH glyphs i} [foreach]
[item] array=glyphs
x,y=$glyphs[$i].x,$glyphs[$i].y [do]
image=$glyphs[$i].image_off [item]
[/item] x,y=$this_item.x,$this_item.y
{NEXT i} image=$this_item.image_off
[/item]
[/do]
[/foreach]
[/event] [/event]
# These macros toggle a glyph on the given location on or off # These macros toggle a glyph on the given location on or off
#define GLYPH_ON X Y #define GLYPH_ON X Y
{FOREACH glyphs glyph_i} [foreach]
[if] array=glyphs
[variable] [do]
name=glyphs[$glyph_i].x [if]
numerical_equals={X} [variable]
[/variable] name=this_item.x
[variable] numerical_equals={X}
name=glyphs[$glyph_i].y [/variable]
numerical_equals={Y} [variable]
[/variable] name=this_item.y
numerical_equals={Y}
[/variable]
[then] [then]
[remove_item] [remove_item]
x,y={X},{Y} x,y={X},{Y}
image=$glyphs[$glyph_i].image_off image=$this_item.image_off
[/remove_item] [/remove_item]
[item] [item]
x,y={X},{Y} x,y={X},{Y}
image=$glyphs[$glyph_i].image_on image=$this_item.image_on
[/item] [/item]
[if] [if]
[variable] [variable]
name=glyphs[$glyph_i].toggles_x name=this_item.toggles_x
not_equals=$empty not_equals=$empty
[/variable] [/variable]
[then] [then]
[sound] [sound]
name=rumble.ogg name=rumble.ogg
[/sound] [/sound]
[terrain] [terrain]
x,y=$glyphs[$glyph_i].toggles_x,$glyphs[$glyph_i].toggles_y x,y=$this_item.toggles_x,$this_item.toggles_y
terrain=Xu terrain=Xu
[/terrain] [/terrain]
[/then] [/then]
[/if] [/if]
[/then] [/then]
[/if] [/if]
{NEXT glyph_i} [/do]
[/foreach]
#enddef #enddef
#define GLYPH_OFF X Y #define GLYPH_OFF X Y
{FOREACH glyphs glyph_i} [foreach]
[if] array=glyphs
[variable] [do]
name=glyphs[$glyph_i].x [if]
numerical_equals={X} [variable]
[/variable] name=this_item.x
[variable] numerical_equals={X}
name=glyphs[$glyph_i].y [/variable]
numerical_equals={Y} [variable]
[/variable] name=this_item.y
numerical_equals={Y}
[/variable]
[then] [then]
[remove_item] [remove_item]
x,y={X},{Y} x,y={X},{Y}
image=$glyphs[$glyph_i].image_on image=$this_item.image_on
[/remove_item] [/remove_item]
[item] [item]
x,y={X},{Y} x,y={X},{Y}
image=$glyphs[$glyph_i].image_off image=$this_item.image_off
[/item] [/item]
[if] [if]
[variable] [variable]
name=glyphs[$glyph_i].toggles_x name=this_item.toggles_x
not_equals=$empty not_equals=$empty
[/variable] [/variable]
[then] [then]
[sound] [sound]
name=rumble.ogg name=rumble.ogg
[/sound] [/sound]
[terrain] [terrain]
x,y=$glyphs[$glyph_i].toggles_x,$glyphs[$glyph_i].toggles_y x,y=$this_item.toggles_x,$this_item.toggles_y
terrain=Cud terrain=Cud
[/terrain] [/terrain]
[/then] [/then]
[/if] [/if]
[/then] [/then]
[/if] [/if]
{NEXT glyph_i} [/do]
[/foreach]
#enddef #enddef
# We reach the northern side entrance # We reach the northern side entrance

View File

@ -94,12 +94,15 @@
variable=adjacent_cavewall variable=adjacent_cavewall
[/store_locations] [/store_locations]
{FOREACH adjacent_cavewall i} [foreach]
[terrain] array=adjacent_cavewall
x,y=$adjacent_cavewall[$i].x,$adjacent_cavewall[$i].y [do]
terrain=Uu [terrain]
[/terrain] x,y=$this_item.x,$this_item.y
{NEXT i} terrain=Uu
[/terrain]
[/do]
[/foreach]
{CLEAR_VARIABLE adjacent_cavewall} {CLEAR_VARIABLE adjacent_cavewall}

View File

@ -328,20 +328,23 @@
[/not] [/not]
side=1 side=1
[/kill] [/kill]
{FOREACH dwarves i} [foreach]
{VARIABLE dwarves[$i].x "recall"} array=dwarves
{VARIABLE dwarves[$i].y "recall"} [do]
# to heal them {VARIABLE this_item.x "recall"}
{VARIABLE dwarves[$i].hitpoints ($dwarves[$i].max_hitpoints)} {VARIABLE this_item.y "recall"}
{VARIABLE dwarves[$i].moves ($dwarves[$i].max_moves)} # to heal them
{VARIABLE dwarves[$i].attacks_left ($dwarves[$i].max_attacks)} {VARIABLE this_item.hitpoints ($this_item.max_hitpoints)}
{CLEAR_VARIABLE dwarves[$i].status.slowed} {VARIABLE this_item.moves ($this_item.max_moves)}
# no need for poisoned and petrified, as Elves do not have units with such abilities {VARIABLE this_item.attacks_left ($this_item.max_attacks)}
{CLEAR_VARIABLE this_item.status.slowed}
# no need for poisoned and petrified, as Elves do not have units with such abilities
[unstore_unit] [unstore_unit]
variable=dwarves[$i] variable=this_item
[/unstore_unit] [/unstore_unit]
{NEXT i} [/do]
[/foreach]
{CLEAR_VARIABLE dwarves} {CLEAR_VARIABLE dwarves}
{CLEAR_VARIABLE stored_Rugnur_side} {CLEAR_VARIABLE stored_Rugnur_side}
[/event] [/event]

View File

@ -223,11 +223,14 @@
variable=to_be_recalled variable=to_be_recalled
[/store_unit] [/store_unit]
{FOREACH to_be_recalled i} [foreach]
[recall] array=to_be_recalled
id=$to_be_recalled[$i].id [do]
[/recall] [recall]
{NEXT i} id=$this_item.id
[/recall]
[/do]
[/foreach]
{CLEAR_VARIABLE to_be_recalled} {CLEAR_VARIABLE to_be_recalled}
@ -644,14 +647,17 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
fire_event=yes y=$this_item.y
[/kill] animate=yes
{NEXT i} fire_event=yes
[/kill]
[/do]
[/foreach]
[clear_variable] [clear_variable]
name=lavadead name=lavadead
[/clear_variable] [/clear_variable]
@ -717,13 +723,17 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
fire_event=yes
[/kill]
[/do]
[/foreach]
#lava 4 #lava 4
[terrain_mask] [terrain_mask]
x,y=1,1 x,y=1,1
@ -742,13 +752,17 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
fire_event=yes
[/kill]
[/do]
[/foreach]
#lava 5 #lava 5
[terrain_mask] [terrain_mask]
x,y=1,1 x,y=1,1
@ -767,13 +781,17 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
fire_event=yes
[/kill]
[/do]
[/foreach]
#lava 6 #lava 6
[terrain_mask] [terrain_mask]
x,y=1,1 x,y=1,1
@ -792,13 +810,17 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
fire_event=yes
[/kill]
[/do]
[/foreach]
#lava 7 #lava 7
[terrain_mask] [terrain_mask]
x,y=1,1 x,y=1,1
@ -817,13 +839,17 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
fire_event=yes
[/kill]
[/do]
[/foreach]
#and then you win #and then you win
[endlevel] [endlevel]
result=victory result=victory
@ -879,13 +905,16 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
[/kill]
[/do]
[/foreach]
#lava 9 #lava 9
[terrain_mask] [terrain_mask]
x,y=1,1 x,y=1,1
@ -904,13 +933,16 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
[/kill]
[/do]
[/foreach]
#lava final #lava final
[terrain_mask] [terrain_mask]
x,y=1,1 x,y=1,1
@ -929,13 +961,16 @@
terrain=Chw,Ql terrain=Chw,Ql
variable=lavadead variable=lavadead
[/store_locations] [/store_locations]
{FOREACH lavadead i} [foreach]
[kill] array=lavadead
x=$lavadead[$i].x [do]
y=$lavadead[$i].y [kill]
animate=yes x=$this_item.x
[/kill] y=$this_item.y
{NEXT i} animate=yes
[/kill]
[/do]
[/foreach]
#clear the variable #clear the variable
[clear_variable] [clear_variable]
name=lavadead name=lavadead