From 500fc5faa4c108d58af845d1b491dda2cbf83a6a Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Mon, 10 Jan 2011 01:32:14 +0000 Subject: [PATCH] Fix objects not recharging (I think) git-svn-id: http://svn.net-core.org/repos/t-engine4@2338 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/engines/default/engine/GameEnergyBased.lua | 5 +++++ game/engines/default/engine/Object.lua | 7 +++++++ game/engines/default/engine/interface/ActorInventory.lua | 6 ++++++ game/engines/default/engine/interface/ObjectActivable.lua | 3 +++ game/modules/tome/data/general/grids/forest.lua | 2 +- 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/game/engines/default/engine/GameEnergyBased.lua b/game/engines/default/engine/GameEnergyBased.lua index 3ef21bbe4d..49cc0472b3 100644 --- a/game/engines/default/engine/GameEnergyBased.lua +++ b/game/engines/default/engine/GameEnergyBased.lua @@ -121,3 +121,8 @@ function _M:removeEntity(e) if not self.entities[e.uid] then error("Entity "..e.uid.." not present in the game") end self.entities[e.uid] = nil end + +--- Does the game have this entity ? +function _M:hasEntity(e) + return self.entities[e.uid] +end diff --git a/game/engines/default/engine/Object.lua b/game/engines/default/engine/Object.lua index e1d5e8fd57..5ee75a3123 100644 --- a/game/engines/default/engine/Object.lua +++ b/game/engines/default/engine/Object.lua @@ -52,6 +52,13 @@ function _M:resolve(t, last, on_entity) end end +--- Loaded, we add ourself back to the game +function _M:loaded() + engine.Entity.loaded(self) + + if not game:hasEntity(self) then game:addEntity(self) end +end + --- Can this object act at all -- Most object will want to answer false, only recharging and stuff needs them function _M:canAct() diff --git a/game/engines/default/engine/interface/ActorInventory.lua b/game/engines/default/engine/interface/ActorInventory.lua index 383d44c9c7..d31547a5e4 100644 --- a/game/engines/default/engine/interface/ActorInventory.lua +++ b/game/engines/default/engine/interface/ActorInventory.lua @@ -103,6 +103,9 @@ function _M:addObject(inven_id, o) self:onAddObject(o) + -- Make sure the object is registered with the game, if need be + if not game:hasEntity(o) then game:addEntity(o) end + return true, #inven end @@ -171,6 +174,9 @@ function _M:removeObject(inven, item, no_unstack) self:onRemoveObject(o) + -- Make sure the object is registered with the game, if need be + if not game:hasEntity(o) then game:addEntity(o) end + return o, finish end diff --git a/game/engines/default/engine/interface/ObjectActivable.lua b/game/engines/default/engine/interface/ObjectActivable.lua index 3f2544bd2a..b2b00c4796 100644 --- a/game/engines/default/engine/interface/ObjectActivable.lua +++ b/game/engines/default/engine/interface/ObjectActivable.lua @@ -61,6 +61,9 @@ function _M:getUseDesc() end function _M:useObject(who, ...) + -- Make sure the object is registered with the game, if need be + if not game:hasEntity(self) then game:addEntity(self) end + if self.use_power then if self.power >= self.use_power.power then local rets = { self.use_power.use(self, who, ...) } diff --git a/game/modules/tome/data/general/grids/forest.lua b/game/modules/tome/data/general/grids/forest.lua index e1d6d3097c..c184916542 100644 --- a/game/modules/tome/data/general/grids/forest.lua +++ b/game/modules/tome/data/general/grids/forest.lua @@ -108,7 +108,7 @@ newEntity{ newEntity{ define_as = "ROCK_VAULT", type = "wall", subtype = "grass", - name = "huge lose rock", image = "terrain/grass.png", add_displays = {class.new{image="terrain/rock_grass.png"}}, + name = "huge loose rock", image = "terrain/grass.png", add_displays = {class.new{image="terrain/rock_grass.png"}}, display = '+', color=colors.GREY, back_color={r=44,g=95,b=43}, notice = true, always_remember = true, -- GitLab