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

View File

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

View File

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

View File

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