From 58310ffba41390b47fdd6b1282653daf3d4dd2d4 Mon Sep 17 00:00:00 2001 From: Bam4d Date: Wed, 4 Aug 2021 10:59:17 +0100 Subject: [PATCH] bug fix to allow objects owned by players to be removed after death --- src/Griddly/Core/Grid.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Griddly/Core/Grid.cpp b/src/Griddly/Core/Grid.cpp index e81787c7d..6239f52fa 100644 --- a/src/Griddly/Core/Grid.cpp +++ b/src/Griddly/Core/Grid.cpp @@ -159,12 +159,10 @@ std::unordered_map Grid::executeAndRecord(uint32_t playerId, } std::unordered_map Grid::executeAction(uint32_t playerId, std::shared_ptr action) { - - float executionProbability = 1.0; auto executionProbabilityIt = actionProbabilities_.find(action->getActionName()); - if(executionProbabilityIt != actionProbabilities_.end()) { + if (executionProbabilityIt != actionProbabilities_.end()) { executionProbability = executionProbabilityIt->second; } @@ -572,9 +570,12 @@ bool Grid::removeObject(std::shared_ptr object) { invalidateLocation(location); // if we are removing a player's avatar - if (playerAvatars_.size() > 0 && playerId != 0 && playerAvatars_.at(playerId) == object) { - spdlog::debug("Removing player {0} avatar {1}", playerId, objectName); - playerAvatars_.erase(playerId); + if (playerAvatars_.size() > 0 && playerId != 0) { + auto playerAvatarIt = playerAvatars_.find(playerId); + if (playerAvatarIt != playerAvatars_.end() && playerAvatarIt->second == object) { + spdlog::debug("Removing player {0} avatar {1}", playerId, objectName); + playerAvatars_.erase(playerId); + } } if (collisionDetectors_.size() > 0) {