forked from github/server
Bug 2576: fix indexing of portals.
This commit is contained in:
parent
ca5e7b82ae
commit
21e226b068
|
@ -16,12 +16,17 @@ local function tunnel_travelers(b)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_target(param)
|
local function get_target(param)
|
||||||
local ntargets = table.maxn(targets)
|
local ntargets = #targets
|
||||||
if ntargets==0 then
|
if ntargets == 0 then
|
||||||
|
eressea.log.error("Zero tunnel targets for [" .. param .. "]")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
local rn = math.fmod(rng_int(), ntargets)
|
local rn = math.fmod(rng_int(), ntargets)
|
||||||
return targets[rn]
|
local t = targets[rn + 1]
|
||||||
|
if not t then
|
||||||
|
eressea.log.error("NULL target for [" .. param .. "]" .. " at index " .. rn)
|
||||||
|
end
|
||||||
|
return t
|
||||||
end
|
end
|
||||||
|
|
||||||
local function tunnel_action(b, param)
|
local function tunnel_action(b, param)
|
||||||
|
@ -50,7 +55,7 @@ function tunnels.init()
|
||||||
local r, b
|
local r, b
|
||||||
for r in regions() do
|
for r in regions() do
|
||||||
if r:get_key('tnnL') then
|
if r:get_key('tnnL') then
|
||||||
targets[table.maxn(targets)+1] = r
|
table.insert(targets, r)
|
||||||
if (r:get_flag(0)) then
|
if (r:get_flag(0)) then
|
||||||
-- target region is chaotic? nope.
|
-- target region is chaotic? nope.
|
||||||
r:set_flag(0, false)
|
r:set_flag(0, false)
|
||||||
|
@ -62,10 +67,11 @@ function tunnels.init()
|
||||||
end
|
end
|
||||||
for b in r.buildings do
|
for b in r.buildings do
|
||||||
if b.type == 'portal' then
|
if b.type == 'portal' then
|
||||||
buildings[table.maxn(buildings)+1] = b
|
table.insert(buildings, b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
eressea.log.info("Found " .. #targets .. " tunnel targets")
|
||||||
end
|
end
|
||||||
|
|
||||||
function tunnels.update()
|
function tunnels.update()
|
||||||
|
|
Loading…
Reference in New Issue