diff --git a/data/campaigns/Descent_Into_Darkness/_main.cfg b/data/campaigns/Descent_Into_Darkness/_main.cfg index 615f22437837..ede4e4e7c719 100644 --- a/data/campaigns/Descent_Into_Darkness/_main.cfg +++ b/data/campaigns/Descent_Into_Darkness/_main.cfg @@ -65,6 +65,10 @@ path=data/campaigns/Descent_Into_Darkness [/binary_path] +[lua] + code="wesnoth.require 'campaigns/Descent_Into_Darkness/lua/spawns.lua'" +[/lua] + {campaigns/Descent_Into_Darkness/utils} {campaigns/Descent_Into_Darkness/scenarios} diff --git a/data/campaigns/Descent_Into_Darkness/lua/spawns.lua b/data/campaigns/Descent_Into_Darkness/lua/spawns.lua new file mode 100644 index 000000000000..081b51736b58 --- /dev/null +++ b/data/campaigns/Descent_Into_Darkness/lua/spawns.lua @@ -0,0 +1,26 @@ +-- Used for the goblin spawns in scenario 2 + +local helper = wesnoth.require "lua/helper.lua" +local wml_actions = wesnoth.wml_actions +local _ = wesnoth.textdomain "wesnoth-did" +local T = helper.set_wml_tag_metatable {} + +function wml_actions.spawn_units(cfg) + local x = cfg.x or helper.wml_error("[spawn_units] missing required x= attribute.") + local y = cfg.y or helper.wml_error("[spawn_units] missing required y= attribute.") + local types = cfg.types or helper.wml_error("[spawn_units] missing required types= attribute.") + local count = cfg.count or helper.wml_error("[spawn_units] missing required count= attribute.") + local side = cfg.side or helper.wml_error("[spawn_units] missing required side= attribute.") + + for i=1,count do + local locs = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 1 } }) + if #locs == 0 then locs = wesnoth.get_locations({T["not"] { T.filter {} } , T["and"] { x = x, y = y, radius = 2 } }) end + + local unit_type = helper.rand(types) + local loc_i = helper.rand("1.."..#locs) + + wml_actions.move_unit_fake({x = string.format("%d,%d", x, locs[loc_i][1]) , y = string.format("%d,%d", y, locs[loc_i][2]) , type = unit_type , side = side}) + wesnoth.put_unit(locs[loc_i][1], locs[loc_i][2], { id = string.format("guard_%i_%i_%i", x, y, i), type = unit_type , side = side, random_traits = "yes", name= _"Villager", upkeep = "loyal" }) + end +end + diff --git a/data/campaigns/Descent_Into_Darkness/scenarios/02_Peaceful_Valley.cfg b/data/campaigns/Descent_Into_Darkness/scenarios/02_Peaceful_Valley.cfg index 98ffda267354..6b4e0866f4de 100644 --- a/data/campaigns/Descent_Into_Darkness/scenarios/02_Peaceful_Valley.cfg +++ b/data/campaigns/Descent_Into_Darkness/scenarios/02_Peaceful_Valley.cfg @@ -171,53 +171,13 @@ [/filter_condition] {VARIABLE_OP number_of_guards rand "0..2"} - {VARIABLE guard_i 1} - [while] - [variable] - name=guard_i - less_than_equal_to=$number_of_guards - [/variable] - - [do] - [store_locations] - [filter_adjacent_location] - x,y=$x1,$y1 - [/filter_adjacent_location] - - [not] - [filter] - [/filter] - [/not] - - variable=possible_guard_locations - [/store_locations] - - {IF_VAR possible_guard_locations.length greater_than 0 ( - [then] - {VARIABLE_OP random_location_index rand "0..$($possible_guard_locations.length - 1)"} - - [move_unit_fake] - side=2 - type=Goblin Spearman - x=$x1,$possible_guard_locations[$random_location_index].x - y=$y1,$possible_guard_locations[$random_location_index].y - [/move_unit_fake] - - [unit] - id=guard_$x1|_$y1|_$guard_i - name= _ "Villager" - type=Goblin Spearman - side=2 - x,y=$possible_guard_locations[$random_location_index].x,$possible_guard_locations[$random_location_index].y - random_traits=yes - [/unit] - [/then] - )} - - {VARIABLE_OP guard_i add 1} - [/do] - [/while] + [spawn_units] + x,y=$x1,$y1 + count=$number_of_guards + types=Goblin Spearman + side=2 + [/spawn_units] {VARIABLE village_$x1|_$y1|_cleared yes}