THoT: Rewrote the bandit spawns in lua

This commit is contained in:
Bär Halberkamp 2015-03-30 14:11:23 +02:00
parent 244a3803c0
commit e232c79505
3 changed files with 35 additions and 49 deletions

View file

@ -62,6 +62,10 @@
path=data/campaigns/The_Hammer_of_Thursagan/
[/binary_path]
[lua]
code="wesnoth.require 'campaigns/The_Hammer_of_Thursagan/lua/spawns.lua'"
[/lua]
{campaigns/The_Hammer_of_Thursagan/utils}
[+units]

View file

@ -0,0 +1,25 @@
-- Used for the bandit spawns in scenario 5
local helper = wesnoth.require "lua/helper.lua"
local wml_actions = wesnoth.wml_actions
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 bandit_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 = bandit_type , side = side})
wesnoth.put_unit(locs[loc_i][1], locs[loc_i][2], { type = bandit_type , side = side, random_traits = "yes", generate_name = "yes" , upkeep = "loyal" })
end
end

View file

@ -301,55 +301,12 @@
[/else]
[/if]
# Now place the indigs
{VARIABLE indig_countdown $indigs}
[while]
[variable]
name=indig_countdown
greater_than=0
[/variable]
[do]
[store_locations]
[filter_adjacent_location]
x,y=$x1,$y1
[/filter_adjacent_location]
[not]
[filter][/filter]
[/not]
variable=possible_indig_locations
[/store_locations]
{IF_VAR possible_indig_locations.length greater_than 0 (
[then]
{VARIABLE_OP random_location_index rand "1..$($possible_indig_locations.length - 1)"}
{RANDOM (Footpad,Thief,Thug)}
[move_unit_fake]
side=5
type=$random
x=$x1,$possible_indig_locations[$random_location_index].x
y=$y1,$possible_indig_locations[$random_location_index].y
[/move_unit_fake]
[unit]
type=$random
side=5
x=$possible_indig_locations[$random_location_index].x
y=$possible_indig_locations[$random_location_index].y
generate_name=yes
random_traits=yes
[/unit]
[/then]
)}
{VARIABLE_OP indig_countdown sub 1}
[/do]
[/while]
[spawn_units]
x,y=$x1,$y1
count=$indigs
types=Footpad,Thief,Thug
side=5
[/spawn_units]
# Perform appropriate notifications
[if]