diff --git a/game/engines/default/engine/Generator.lua b/game/engines/default/engine/Generator.lua index 6a862afa33128e1ed6b3e5a49850af391870d009..aab994c24a1fa0363fe608489abccaa5d3f1b853 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 08e742abf5fbbdb5014711185dda4fe680fc2dc0..2ee29f0302caee44cdb462fb124092c8b599f844 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 070bb9aa7774b33352c5ac0627018b7bd3dfb49a..b2d3609d8d545510cb26a0970980e01f45d12eaf 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 a979a25ea4e4e118cb006620197ff4d26f8b41f1..76e1827f8504bbcb14f76b63d8b85c48d32e0890 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 bee748bfb7097c410d0f7826d06852863f11c807..def272ce876aae20b6da04815c04acc0408a13d4 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