wml cleanups, add terrain= attribute to [random_placement] loc

replacing some [while] with [repeat] or [random_placement]

Adding  terrain= attribute to the variable generated by [random_placement] this mkaes it easier to use [random_placement] as a replacement for [store_locations] + [while] since [store_locations] also generates the [terrain] attribute:
This commit is contained in:
gfgtdf 2016-12-10 14:07:13 +01:00 committed by GitHub
parent 3c498eb0e4
commit a53090d648
9 changed files with 86 additions and 261 deletions

View file

@ -543,23 +543,8 @@
[/if]
# Get the number of zombies from the list of numbers:
[set_variable]
name=index
value=$($number_of_captured_villages % 5)
[/set_variable]
[set_variable]
name=number_of_zombies
value=$zombie_number_pattern[ $($number_of_captured_villages % 5) ].number
[/set_variable]
#{DEBUG_MSG zombie_number_pattern[$index]
# Now place the zombies. For each one,
# decrease the number until it reaches 0
[while]
[variable]
name=number_of_zombies
greater_than=0
[/variable]
[repeat]
times=$zombie_number_pattern[ $($number_of_captured_villages % 5) ].number
[do]
#ifdef HARD
[if]
@ -591,13 +576,8 @@
attacks_left=0
animate=yes
[/unit]
[set_variable]
name=number_of_zombies
sub=1
[/set_variable]
[/do]
[/while]
[/repeat]
[set_variable]
name=number_of_captured_villages

View file

@ -128,23 +128,6 @@
random_traits=no
[/unit]
# Place manor guards in hallways at random locations
[store_locations]
terrain=Iwr
[not]
x,y=20,20
radius=6
[/not]
[not]
x=1-5
y=1-5
[/not]
[not]
[filter][/filter]
[/not]
variable=possible_guard_locations
[/store_locations]
[set_variables]
name=guardtypetable
[value]
@ -170,66 +153,30 @@
[/value]
[/set_variables]
{VARIABLE guardtypetable_i 0}
{VARIABLE guards_to_place 8}
[random_placement]
num_items=8
variable=loc
min_distance=4
[filter_location]
terrain=Iwr
[not]
x,y=20,20
radius=6
[/not]
[not]
x=1-5
y=1-5
[/not]
[not]
[filter][/filter]
[/not]
[/filter_location]
[command]
{NAMED_NOTRAIT_UNIT 2 $guardtypetable[$($loc.n % $guardtypetable.length)].type $loc.x $loc.y () (_ "Guard")} {GUARDIAN}
[/command]
[/random_placement]
[while]
[variable]
name=guards_to_place
greater_than=0
[/variable]
[do]
{RANDOM 1..$possible_guard_locations.length}
{VARIABLE_OP random sub 1}
{NAMED_NOTRAIT_UNIT 2 $guardtypetable[$guardtypetable_i].type $possible_guard_locations[$random].x $possible_guard_locations[$random].y () (_ "Guard")} {GUARDIAN}
[store_locations]
find_in=possible_guard_locations
[not]
x,y=$possible_guard_locations[$random].x,$possible_guard_locations[$random].y
radius=4
[/not]
variable=possible_guard_locations
[/store_locations]
{VARIABLE_OP guardtypetable_i add 1}
[if]
[variable]
name=guardtypetable_i
numerical_equals=$guardtypetable.length
[/variable]
[then]
{VARIABLE guardtypetable_i 0}
[/then]
[/if]
{VARIABLE_OP guards_to_place sub 1}
[/do]
[/while]
{CLEAR_VARIABLE guardtypetable,guardtypetable_i,possible_guard_locations}
[store_locations]
terrain=Iwr
[not]
x,y=20,20
radius=6
[/not]
[not]
x=1-5
y=1-5
[/not]
[not]
[filter_adjacent_location]
terrain=!,Iwr
[/filter_adjacent_location]
[/not]
variable=possible_mage_locations
[/store_locations]
{CLEAR_VARIABLE guardtypetable}
[set_variables]
name=magetypetable
@ -258,57 +205,32 @@
#endif
[/set_variables]
{VARIABLE magetypetable_i 0}
[random_placement]
num_items={ON_DIFFICULTY 12 14 16}
variable=loc
min_distance=2
[filter_location]
terrain=Iwr
[not]
x,y=20,20
radius=6
[/not]
[not]
x=1-5
y=1-5
[/not]
[not]
[filter_adjacent_location]
terrain=!,Iwr
[/filter_adjacent_location]
[/not]
[/filter_location]
[command]
{GENERIC_UNIT 2 $magetypetable[$($loc.n % $magetypetable.length)].type $loc.x $loc.y}
[/command]
[/random_placement]
#ifdef EASY
{VARIABLE mages_to_place 12}
#endif
#ifdef NORMAL
{VARIABLE mages_to_place 14}
#endif
#ifdef HARD
{VARIABLE mages_to_place 16}
#endif
[while]
[variable]
name=mages_to_place
greater_than=0
[/variable]
[do]
{RANDOM 1..$possible_mage_locations.length}
{VARIABLE_OP random sub 1}
{GENERIC_UNIT 2 $magetypetable[$magetypetable_i].type $possible_mage_locations[$random].x $possible_mage_locations[$random].y}
[store_locations]
find_in=possible_mage_locations
[not]
x,y=$possible_mage_locations[$random].x,$possible_mage_locations[$random].y
radius=2
[/not]
variable=possible_mage_locations
[/store_locations]
{VARIABLE_OP magetypetable_i add 1}
[if]
[variable]
name=magetypetable_i
numerical_equals=$magetypetable.length
[/variable]
[then]
{VARIABLE magetypetable_i 0}
[/then]
[/if]
{VARIABLE_OP mages_to_place sub 1}
[/do]
[/while]
{CLEAR_VARIABLE magetypetable,magetypetable_i,possible_mage_locations}
{CLEAR_VARIABLE magetypetable}
[recall]
id=Darken Volk

View file

@ -189,8 +189,6 @@ At the end of your first turn, your keep will disappear, and you must battle wit
name=summon
first_time_only=no
{VARIABLE i 0}
[animate_unit]
[filter]
id=Mal-Ravanal
@ -198,12 +196,8 @@ At the end of your first turn, your keep will disappear, and you must battle wit
flag=summon
[/animate_unit]
[while]
[variable]
name=i
less_than=3
[/variable]
[repeat]
times=3
[do]
#ifdef EASY
{VARIABLE_OP new_summon_type rand "Bone Shooter,Bone Shooter,Revenant,Revenant,Necrophage,Necrophage,Wraith"}
@ -238,10 +232,9 @@ At the end of your first turn, your keep will disappear, and you must battle wit
animate=yes
[/unit]
{VARIABLE_OP i add 1}
[/do]
[/while]
{CLEAR_VARIABLE new_summon_type,new_summon_locations,i,loci}
[/repeat]
{CLEAR_VARIABLE new_summon_type,new_summon_locations,loci}
[fire_event]
name=summon_explanation

View file

@ -220,34 +220,19 @@
first_time_only=no
delayed_variable_substitution=yes
[store_locations]
terrain=Gs,Gd,Co,Ko,Re,Rb,Gll^Fp,Gll^Fmw,Gll^Fdw,Gd^Vo,Gd^Vc,Hhd^Vo ,Hhd^Vc
[random_placement]
num_items="size / ($turn_limit - $turn_number)"
variable=loc
allow_less=yes
[filter_location]
terrain=Gs,Gd,Co,Ko,Re,Rb,Gll^Fp,Gll^Fmw,Gll^Fdw,Gd^Vo,Gd^Vc,Hhd^Vo ,Hhd^Vc
[/filter_location]
variable=non_snowy_locs
[/store_locations]
{VARIABLE turns_left $turn_limit}
{VARIABLE_OP turns_left sub $turn_number}
{VARIABLE num_of_falling_snow $non_snowy_locs.length}
{VARIABLE_OP num_of_falling_snow divide $turns_left}
# {DEBUG_MSG "stored $non_snowy_locs.length non-snowy locs, putting snow on $num_of_falling_snow"}
{VARIABLE i 0}
[while]
[variable]
name=i
less_than=$num_of_falling_snow
[/variable]
[do]
{RANDOM "1..$non_snowy_locs.length"}
{VARIABLE_OP random sub 1}
[command]
[switch]
variable=non_snowy_locs[$random].terrain
variable=loc.terrain
[case]
value=Gs
@ -329,30 +314,19 @@
# just a fallback in case something goes wrong
[else]
{VARIABLE terrain $non_snowy_locs[$random].terrain}
{VARIABLE terrain $loc.terrain}
[/else]
[/switch]
[terrain]
x,y=$non_snowy_locs[$random].x,$non_snowy_locs[$random].y
x,y=$loc.x,$loc.y
terrain=$terrain
[/terrain]
[store_locations]
find_in=non_snowy_locs
[/command]
[/random_placement]
[not]
x,y=$non_snowy_locs[$random].x,$non_snowy_locs[$random].y
[/not]
variable=non_snowy_locs
[/store_locations]
{VARIABLE_OP i add 1}
[/do]
[/while]
{CLEAR_VARIABLE non_snowy_locs,i,num_of_falling_snow,random,terrain,turns_left}
{CLEAR_VARIABLE terrain}
[/event]
[/event]

View file

@ -1038,32 +1038,11 @@ _f, _f, Re, _f
[/have_unit]
[then]
{VARIABLE max_undead_spawns $turn_number}
{VARIABLE_OP max_undead_spawns sub 2}
[if]
[variable]
name=max_undead_spawns
greater_than=4
[/variable]
[then]
{VARIABLE max_undead_spawns 5}
[/then]
[else]
{VARIABLE max_undead_spawns $turn_number}
[/else]
[/if]
{VARIABLE got_a_quick_one_this_turn no}
{VARIABLE i 0}
[while]
[variable]
name=i
less_than=$max_undead_spawns
[/variable]
[repeat]
times="$(min($turn_number - 2, 5))"
[do]
{VARIABLE_OP undead_spawn_x rand "11..22"}
@ -1114,12 +1093,10 @@ _f, _f, Re, _f
x=$undead_spawn_x
y=45
[/unit]
{VARIABLE_OP i add 1}
[/do]
[/while]
[/repeat]
{CLEAR_VARIABLE i,max_undead_spawns,got_a_quick_one_this_turn,undead_spawn_type,undead_spawn_x}
{CLEAR_VARIABLE got_a_quick_one_this_turn,undead_spawn_type,undead_spawn_x}
[/then]
[/if]
[/event]

View file

@ -279,16 +279,9 @@
name=how_many_elves
rand=1..6
[/set_variable]
[set_variable]
name=number_of_elves
value=0
[/set_variable]
[while]
[variable]
name=number_of_elves
less_than=$how_many_elves
[/variable]
[repeat]
times=$how_many_elves
[do]
[set_variable]
name=unit_type
@ -305,12 +298,8 @@
variable=new_elf
find_vacant=yes
[/unstore_unit]
[set_variable]
name=number_of_elves
add=1
[/set_variable]
[/do]
[/while]
[/repeat]
[message]
speaker=$new_elf.id
@ -318,7 +307,7 @@
[/message]
{CLEAR_VARIABLE new_elf}
{CLEAR_VARIABLE number_of_elves,how_many_elves,unit_type}
{CLEAR_VARIABLE how_many_elves,unit_type}
[/event]
[event]

View file

@ -995,21 +995,15 @@
[event]
name=new turn
first_time_only=no
{VARIABLE i 0}
[while]
[variable]
name=i
less_than=$number_minions_to_spawn
[/variable]
[repeat]
times=$number_minions_to_spawn
[do]
[fire_event]
name=create_minion
[/fire_event]
{VARIABLE_OP i add 1}
[/do]
[/while]
{CLEAR_VARIABLE i}
[/repeat]
[/event]
# Event 3: Central Body heals fully each turn

View file

@ -11,12 +11,8 @@
#enddef
#define PLACE_UNITS_RANDOMLY NUMBER SIDE TYPE ROLE_STRING NAME_STRING TRAIT_WML
{VARIABLE i 0}
[while]
[variable]
name=i
less_than={NUMBER}
[/variable]
[repeat]
times={NUMBER}
[do]
{RANDOM "0..$($random_placement_locations.length - 1)"}
{VARIABLE random_placement_x $random_placement_locations[$random].x}
@ -32,9 +28,8 @@
animate=yes
{TRAIT_WML}
[/unit]
{VARIABLE_OP i add 1}
[/do]
[/while]
[/repeat]
#enddef
#define CLEAR_PLACEMENT_AREA

View file

@ -32,6 +32,7 @@ wesnoth.wml_actions.random_placement = function(cfg)
wesnoth.set_variable(variable .. ".x", point[1])
wesnoth.set_variable(variable .. ".y", point[2])
wesnoth.set_variable(variable .. ".n", i)
wesnoth.set_variable(variable .. ".terrain", wesnoth.get_terrain(point[1], point[2]))
if distance < 0 then
-- optimisation: nothing to do for distance < 0
elseif distance == 0 then