Skip to content

Commit

Permalink
DID: Rewrote the goblin spawns in lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Asheviere committed Mar 30, 2015
1 parent be64610 commit d19926b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
4 changes: 4 additions & 0 deletions data/campaigns/Descent_Into_Darkness/_main.cfg
Expand Up @@ -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}

Expand Down
26 changes: 26 additions & 0 deletions 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

Expand Up @@ -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}

Expand Down

0 comments on commit d19926b

Please sign in to comment.