diff --git a/data/campaigns/Dead_Water/scenarios/01_Invasion.cfg b/data/campaigns/Dead_Water/scenarios/01_Invasion.cfg index e7f9c6f2c48..234f77ecd2d 100644 --- a/data/campaigns/Dead_Water/scenarios/01_Invasion.cfg +++ b/data/campaigns/Dead_Water/scenarios/01_Invasion.cfg @@ -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 diff --git a/data/campaigns/Descent_Into_Darkness/scenarios/08_A_Small_Favor2.cfg b/data/campaigns/Descent_Into_Darkness/scenarios/08_A_Small_Favor2.cfg index 64db35c1b57..b0329e51604 100644 --- a/data/campaigns/Descent_Into_Darkness/scenarios/08_A_Small_Favor2.cfg +++ b/data/campaigns/Descent_Into_Darkness/scenarios/08_A_Small_Favor2.cfg @@ -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 diff --git a/data/campaigns/Eastern_Invasion/scenarios/17a_The_Duel.cfg b/data/campaigns/Eastern_Invasion/scenarios/17a_The_Duel.cfg index a5dd29b5e2c..7686fd9428b 100644 --- a/data/campaigns/Eastern_Invasion/scenarios/17a_The_Duel.cfg +++ b/data/campaigns/Eastern_Invasion/scenarios/17a_The_Duel.cfg @@ -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 diff --git a/data/campaigns/Heir_To_The_Throne/scenarios/12_Northern_Winter.cfg b/data/campaigns/Heir_To_The_Throne/scenarios/12_Northern_Winter.cfg index d348db98a45..a748191b356 100644 --- a/data/campaigns/Heir_To_The_Throne/scenarios/12_Northern_Winter.cfg +++ b/data/campaigns/Heir_To_The_Throne/scenarios/12_Northern_Winter.cfg @@ -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] diff --git a/data/campaigns/The_South_Guard/scenarios/06b_The_Long_March.cfg b/data/campaigns/The_South_Guard/scenarios/06b_The_Long_March.cfg index 4d3fd0d4d64..dc3622a589a 100644 --- a/data/campaigns/The_South_Guard/scenarios/06b_The_Long_March.cfg +++ b/data/campaigns/The_South_Guard/scenarios/06b_The_Long_March.cfg @@ -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] diff --git a/data/campaigns/The_South_Guard/scenarios/09a_Vengeance.cfg b/data/campaigns/The_South_Guard/scenarios/09a_Vengeance.cfg index 3b5af7015c9..d05b721dc20 100644 --- a/data/campaigns/The_South_Guard/scenarios/09a_Vengeance.cfg +++ b/data/campaigns/The_South_Guard/scenarios/09a_Vengeance.cfg @@ -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] diff --git a/data/campaigns/Under_the_Burning_Suns/scenarios_old/12_The_Final_Confrontation.cfg b/data/campaigns/Under_the_Burning_Suns/scenarios_old/12_The_Final_Confrontation.cfg index 74e3f839ae3..9af67d8043c 100644 --- a/data/campaigns/Under_the_Burning_Suns/scenarios_old/12_The_Final_Confrontation.cfg +++ b/data/campaigns/Under_the_Burning_Suns/scenarios_old/12_The_Final_Confrontation.cfg @@ -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 diff --git a/data/campaigns/Under_the_Burning_Suns/utils/macros.cfg b/data/campaigns/Under_the_Burning_Suns/utils/macros.cfg index a93a8b4cec6..e3e89df1d22 100644 --- a/data/campaigns/Under_the_Burning_Suns/utils/macros.cfg +++ b/data/campaigns/Under_the_Burning_Suns/utils/macros.cfg @@ -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 diff --git a/data/lua/wml/random_placement.lua b/data/lua/wml/random_placement.lua index ef401ec24a3..cd7e0fbfa7f 100644 --- a/data/lua/wml/random_placement.lua +++ b/data/lua/wml/random_placement.lua @@ -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