diff --git a/game/modules/tome/class/Party.lua b/game/modules/tome/class/Party.lua index cc56d320757b038343bd324731720f1386ad37ad..0717c1f063ec5227ead2d02b71065d03776d36f8 100644 --- a/game/modules/tome/class/Party.lua +++ b/game/modules/tome/class/Party.lua @@ -99,6 +99,24 @@ function _M:findMember(filter) end end +function _M:setDeathTurn(actor, turn) + local def = self.members[actor] + if not def then return end + def.last_death_turn = turn +end + +function _M:findLastDeath() + local max_turn = -9999 + local last = nil + + for i, actor in ipairs(self.m_list) do + local def = self.members[actor] + + if def.last_death_turn and def.last_death_turn > max_turn then max_turn = def.last_death_turn; last = actor end + end + return last or self:findMember{main=true} +end + function _M:canControl(actor, vocal) if not actor then return false end if actor == game.player then return false end diff --git a/game/modules/tome/class/interface/PartyDeath.lua b/game/modules/tome/class/interface/PartyDeath.lua index a257498e13a6a86fde731d93a997f8d6b856901a..bfabef4cca2d9892a096744bdbd5230273a6c1da 100644 --- a/game/modules/tome/class/interface/PartyDeath.lua +++ b/game/modules/tome/class/interface/PartyDeath.lua @@ -26,6 +26,9 @@ function _M:onPartyDeath(src) -- Remove from the party if needed if self.remove_from_party_on_death then game.party:removeMember(self, true) + -- Overwise note the death turn + else + game.party:setDeathTurn(self, game.turn) end -- Die diff --git a/game/modules/tome/dialogs/DeathDialog.lua b/game/modules/tome/dialogs/DeathDialog.lua index 4db1585e2d6b153d6a4b475faa6375e7bb2076b0..cb372b4c34bcdf472e5e0984d3c94634ae7a9414 100644 --- a/game/modules/tome/dialogs/DeathDialog.lua +++ b/game/modules/tome/dialogs/DeathDialog.lua @@ -91,11 +91,15 @@ function _M:resurrectBasic(actor) actor.dead = false actor.died = (actor.died or 0) + 1 - local x, y = util.findFreeGrid(actor.x, actor.y, 20, true, {[Map.ACTOR]=true}) - if not x then x, y = actor.x, actor.y end - actor.x, actor.y = nil, nil + -- Find the position of the last dead + local last = game.party:findLastDeath() + + local x, y = util.findFreeGrid(last.x, last.y, 20, true, {[Map.ACTOR]=true}) + if not x then x, y = last.x, last.y end + actor.x, actor.y = nil, nil actor:move(x, y, true) + game.level:addEntity(actor) game:unregisterDialog(self) game.level.map:redisplay()