Skip to content
Snippets Groups Projects
Commit 34678de7 authored by dg's avatar dg
Browse files

Sanity checks to level generators, thanks shoob

git-svn-id: http://svn.net-core.org/repos/t-engine4@899 51575b47-30f0-44d4-a5cc-537603b46e54
parent 05049fda
No related branches found
No related tags found
No related merge requests found
......@@ -465,6 +465,7 @@ function _M:getLevel(game, lev, old_lev, no_close)
end
function _M:getGenerator(what, level, spots)
print("[GENERATOR] requiring", what, level.data.generator and level.data.generator[what] and level.data.generator[what].class)
return require(level.data.generator[what].class).new(
self,
level.map,
......@@ -508,19 +509,19 @@ function _M:newLevel(level_data, lev, old_lev, game)
level.spots = spots
-- Generate objects
if level_data.generator.object then
if level_data.generator.object and level_data.generator.object.class then
local generator = self:getGenerator("object", level, spots)
generator:generate()
end
-- Generate traps
if level_data.generator.trap then
if level_data.generator.trap and level_data.generator.trap.class then
local generator = self:getGenerator("trap", level, spots)
generator:generate()
end
-- Generate actors
if level_data.generator.actor then
if level_data.generator.actor and level_data.generator.actor.class then
local generator = self:getGenerator("actor", level, spots)
generator:generate()
end
......
......@@ -79,6 +79,8 @@ function _M:roomAlloc(room, id, lev, old_lev)
room = room(self, id, lev, old_lev)
end
print("alloc", room.name)
-- Sanity check
if self.map.w - 2 - room.w < 2 or self.map.h - 2 - room.h < 2 then return false end
local tries = 100
while tries > 0 do
......@@ -164,11 +166,12 @@ end
--- Tunnel from x1,y1 to x2,y2
function _M:tunnel(x1, y1, x2, y2, id)
if x1 == x2 and y1 == y2 then return end
-- Disable the many prints of tunnelling
local print = function()end
local xdir, ydir = self:tunnelDir(x1, y1, x2, y2)
print("tunneling from",x1, y1, "to", x2, y2, "initial dir", xdir, ydir)
-- print("tunneling from",x1, y1, "to", x2, y2, "initial dir", xdir, ydir)
local startx, starty = x1, y1
local tun = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment