[Server] Add permanent debug to Cell and CellController

0.6.1
David Cernat 8 years ago
parent 366c24ab04
commit 7f51ca5298

@ -13,7 +13,18 @@ void Cell::addPlayer(Player *player)
{
auto it = find(player->cells.begin(), player->cells.end(), this);
if (it == player->cells.end())
{
LOG_APPEND(Log::LOG_INFO, "- Adding %s to Player %s",
getDescription().c_str(),
player->npc.mName.c_str());
player->cells.push_back(this);
}
LOG_APPEND(Log::LOG_INFO, "- Adding %s to Cell %s",
player->npc.mName.c_str(),
getDescription().c_str());
players.push_back(player);
}
@ -25,7 +36,18 @@ void Cell::removePlayer(Player *player)
{
auto it2 = find(player->cells.begin(), player->cells.end(), this);
if (it2 != player->cells.end())
{
LOG_APPEND(Log::LOG_INFO, "- Removing %s from Player %s",
getDescription().c_str(),
player->npc.mName.c_str());
player->cells.erase(it2);
}
LOG_APPEND(Log::LOG_INFO, "- Removing %s from Cell %s",
player->npc.mName.c_str(),
getDescription().c_str());
players.erase(it);
return;
}
@ -69,7 +91,7 @@ CellController::CellController()
CellController::~CellController()
{
for(auto cell : cells)
for (auto cell : cells)
{
delete cell;
}
@ -107,21 +129,33 @@ Cell *CellController::getCell(ESM::Cell *esmCell)
Cell *CellController::getCellByXY(int x, int y)
{
auto it = find_if(cells.begin(), cells.end(), [x, y](const Cell *c) {
auto it = find_if(cells.begin(), cells.end(), [x, y](const Cell *c)
{
return c->cell.mData.mX == x && c->cell.mData.mY == y;
});
if (it == cells.end())
{
LOG_APPEND(Log::LOG_INFO, "- Attempt to get Cell at %i, %i failed!", x, y);
return nullptr;
}
return *it;
}
Cell *CellController::getCellByName(std::string cellName)
{
auto it = find_if(cells.begin(), cells.end(), [cellName](const Cell *c) {
auto it = find_if(cells.begin(), cells.end(), [cellName](const Cell *c)
{
return c->cell.mName == cellName;
});
if (it == cells.end())
{
LOG_APPEND(Log::LOG_INFO, "- Attempt to get Cell at %s failed!", cellName.c_str());
return nullptr;
}
return *it;
}
@ -133,14 +167,23 @@ Cell *CellController::addCell(ESM::Cell cellData)
return c->cell.isExterior() ? (c->cell.mData.mX == cellData.mData.mX && c->cell.mData.mY == cellData.mData.mY) :
(c->cell.mName == cellData.mName);
});
Cell *cell;
if (it == cells.end())
{
LOG_APPEND(Log::LOG_INFO, "- Adding %s to CellController",
cellData.getDescription().c_str());
cell = new Cell(cellData);
cells.push_back(cell);
}
else
{
LOG_APPEND(Log::LOG_INFO, "- Found %s in CellController",
cellData.getDescription().c_str());
cell = *it;
}
return cell;
@ -150,10 +193,14 @@ void CellController::removeCell(Cell *cell)
{
if (cell == nullptr)
return;
for (auto it = cells.begin(); it != cells.end();)
{
if (*it != nullptr && *it == cell)
{
LOG_APPEND(Log::LOG_INFO, "- Removing %s from CellController",
cell->getDescription().c_str());
delete *it;
it = cells.erase(it);
}
@ -178,12 +225,22 @@ void CellController::removePlayer(Cell *cell, Player *player)
void CellController::deletePlayer(Player *player)
{
LOG_APPEND(Log::LOG_INFO, "- Iterating through Cells from Player %s",
player->npc.mName.c_str());
for_each(player->getCells()->begin(), player->getCells()->end(), [&player](Cell *cell)
{
LOG_APPEND(Log::LOG_INFO, "-- Found Cell %s",
cell->getDescription().c_str());
for_each(player->getCells()->begin(), player->getCells()->end(), [&player](Cell *cell) {
for (auto it = cell->begin(); it != cell->end(); ++it)
{
if (*it == player)
{
LOG_APPEND(Log::LOG_INFO, "-- Deleting %s from Cell %s",
player->npc.mName.c_str(),
cell->getDescription().c_str());
cell->players.erase(it);
break;
}

Loading…
Cancel
Save