From 0ba8a407bcb38e1c6228a8bcd4ad2c091c1d92ee Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 30 Apr 2017 04:03:03 +0300 Subject: [PATCH] [Server] Reuse Cell deletion code in CellController --- apps/openmw-mp/CellController.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/openmw-mp/CellController.cpp b/apps/openmw-mp/CellController.cpp index 6b9aead47..63064af9e 100644 --- a/apps/openmw-mp/CellController.cpp +++ b/apps/openmw-mp/CellController.cpp @@ -112,12 +112,11 @@ void CellController::removeCell(Cell *cell) if (cell == nullptr) return; - Script::Call(cell->getDescription().c_str()); - for (auto it = cells.begin(); it != cells.end();) { if (*it != nullptr && *it == cell) { + Script::Call(cell->getDescription().c_str()); LOG_APPEND(Log::LOG_INFO, "- Removing %s from CellController", cell->getDescription().c_str()); delete *it; @@ -134,10 +133,8 @@ void CellController::removePlayer(Cell *cell, Player *player) if (cell->players.empty()) { - LOG_APPEND(Log::LOG_INFO, "- Deleting empty cell from memory: %s", cell->getDescription().c_str()); - auto it = find(cells.begin(), cells.end(), cell); - delete *it; - cells.erase(it); + LOG_APPEND(Log::LOG_INFO, "- Cell %s has no players left", cell->getDescription().c_str()); + removeCell(cell); } }