From bb15eb8b66807bb34bb5b6cea090a13efcc6966a Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Mon, 27 Sep 2010 12:30:42 +0000
Subject: [PATCH] Pits should not generate "monsters in walls"

git-svn-id: http://svn.net-core.org/repos/t-engine4@1313 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engines/default/engine/Generator.lua            |  8 ++++++++
 game/engines/default/engine/generator/map/Static.lua | 11 +++--------
 game/modules/tome/data/rooms/forest_clearing.lua     |  2 +-
 game/modules/tome/data/rooms/money_vault.lua         |  8 ++------
 game/modules/tome/data/rooms/pit.lua                 |  2 +-
 5 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/game/engines/default/engine/Generator.lua b/game/engines/default/engine/Generator.lua
index 6a862afa33..aab994c24a 100644
--- a/game/engines/default/engine/Generator.lua
+++ b/game/engines/default/engine/Generator.lua
@@ -60,3 +60,11 @@ function _M:resolve(c, list, force)
 	res:resolve(nil, true)
 	return res
 end
+
+function _M:roomMapAddEntity(i, j, type, e)
+	self.map.room_map[i] = self.map.room_map[i] or {}
+	self.map.room_map[i][j] = self.map.room_map[i][j] or {}
+	self.map.room_map[i][j].add_entities = self.map.room_map[i][j].add_entities or {}
+	local rm = self.map.room_map[i][j].add_entities
+	rm[#rm+1] = {type, e}
+end
diff --git a/game/engines/default/engine/generator/map/Static.lua b/game/engines/default/engine/generator/map/Static.lua
index 08e742abf5..2ee29f0302 100644
--- a/game/engines/default/engine/generator/map/Static.lua
+++ b/game/engines/default/engine/generator/map/Static.lua
@@ -183,11 +183,6 @@ function _M:generate(lev, old_lev)
 		local status = self.tiles[c] and self.tiles[c].status
 		local define_spot = self.tiles[c] and self.tiles[c].define_spot
 
-		self.map.room_map[i-1] = self.map.room_map[i-1] or {}
-		self.map.room_map[i-1][j-1] = self.map.room_map[i-1][j-1] or {}
-		self.map.room_map[i-1][j-1].add_entities = self.map.room_map[i-1][j-1].add_entities or {}
-		local rm = self.map.room_map[i-1][j-1].add_entities
-
 		if object then
 			local o
 			if type(object) == "string" then o = self.zone:makeEntityByName(self.level, "object", object)
@@ -195,7 +190,7 @@ function _M:generate(lev, old_lev)
 			else o = self.zone:finishEntity(self.level, "object", object)
 			end
 
-			if o then rm[#rm+1] = {"object", o} end
+			if o then self:roomMapAddEntity(i-1, j-1, "object", o) end
 		end
 
 		if trap then
@@ -204,7 +199,7 @@ function _M:generate(lev, old_lev)
 			elseif type(trap) == "table" and trap.random_filter then t = self.zone:makeEntity(self.level, "trap", trap.random_filter, nil, true)
 			else t = self.zone:finishEntity(self.level, "trap", trap)
 			end
-			if t then rm[#rm+1] = {"trap", t} end
+			if t then self:roomMapAddEntity(i-1, j-1, "trap", t) end
 		end
 
 		if actor then
@@ -213,7 +208,7 @@ function _M:generate(lev, old_lev)
 			elseif type(actor) == "table" and actor.random_filter then m = self.zone:makeEntity(self.level, "actor", actor.random_filter, nil, true)
 			else m = self.zone:finishEntity(self.level, "actor", actor)
 			end
-			if m then rm[#rm+1] = {"actor", m} end
+			if m then self:roomMapAddEntity(i-1, j-1, "actor", m) end
 		end
 
 		if status then
diff --git a/game/modules/tome/data/rooms/forest_clearing.lua b/game/modules/tome/data/rooms/forest_clearing.lua
index 070bb9aa77..b2d3609d8d 100644
--- a/game/modules/tome/data/rooms/forest_clearing.lua
+++ b/game/modules/tome/data/rooms/forest_clearing.lua
@@ -42,7 +42,7 @@ return function(gen, id)
 					if ispit then
 						local e = gen.zone:makeEntity(gen.level, "actor", ispit, nil, true)
 						if e then
-							gen.zone:addEntity(gen.level, e, "actor", i-1+x, j-1+y)
+							if e then gen:roomMapAddEntity(i-1+x, j-1+y, "actor", e) end
 							gen.map.attrs(i-1+x, j-1+y, "no_decay", true)
 						end
 					end
diff --git a/game/modules/tome/data/rooms/money_vault.lua b/game/modules/tome/data/rooms/money_vault.lua
index a979a25ea4..76e1827f85 100644
--- a/game/modules/tome/data/rooms/money_vault.lua
+++ b/game/modules/tome/data/rooms/money_vault.lua
@@ -32,15 +32,11 @@ return function(gen, id)
 
 					-- Add money
 					local e = gen.zone:makeEntity(gen.level, "object", {type="money"}, nil, true)
-					if e then
-						gen.zone:addEntity(gen.level, e, "object", i-1+x, j-1+y)
-					end
+					if e then gen:roomMapAddEntity(i-1+x, j-1+y, "object", e) end
 					-- Add guardians
 					if rng.percent(50) then
 						e = gen.zone:makeEntity(gen.level, "actor")
-						if e then
-							gen.zone:addEntity(gen.level, e, "actor", i-1+x, j-1+y)
-						end
+						if e then gen:roomMapAddEntity(i-1+x, j-1+y, "actor", e) end
 					end
 				end
 				if is_lit then gen.map.lites(i-1+x, j-1+y, true) end
diff --git a/game/modules/tome/data/rooms/pit.lua b/game/modules/tome/data/rooms/pit.lua
index bee748bfb7..def272ce87 100644
--- a/game/modules/tome/data/rooms/pit.lua
+++ b/game/modules/tome/data/rooms/pit.lua
@@ -48,7 +48,7 @@ return function(gen, id)
 					doors[#doors+1] = {i-1+x, j-1+y}
 				else
 					local e = gen.zone:makeEntity(gen.level, "actor", filter, nil, true)
-					if e then gen.zone:addEntity(gen.level, e, "actor", i-1+x, j-1+y) end
+					if e then gen:roomMapAddEntity(i-1+x, j-1+y, "actor", e) end
 				end
 				if is_lit then gen.map.lites(i-1+x, j-1+y, true) end
 			end
-- 
GitLab