|
|
|
@ -12,19 +12,19 @@ using namespace std;
|
|
|
|
|
void Cell::addPlayer(Player *player)
|
|
|
|
|
{
|
|
|
|
|
auto it = find(player->cells.begin(), player->cells.end(), this);
|
|
|
|
|
if(it == player->cells.end())
|
|
|
|
|
if (it == player->cells.end())
|
|
|
|
|
player->cells.push_back(this);
|
|
|
|
|
players.push_back(player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Cell::removePlayer(Player *player)
|
|
|
|
|
{
|
|
|
|
|
for(Iterator it = begin(); it != end(); it++)
|
|
|
|
|
for (Iterator it = begin(); it != end(); it++)
|
|
|
|
|
{
|
|
|
|
|
if(*it == player)
|
|
|
|
|
if (*it == player)
|
|
|
|
|
{
|
|
|
|
|
auto it2 = find(player->cells.begin(), player->cells.end(), this);
|
|
|
|
|
if(it2 != player->cells.end())
|
|
|
|
|
if (it2 != player->cells.end())
|
|
|
|
|
player->cells.erase(it2);
|
|
|
|
|
players.erase(it);
|
|
|
|
|
return;
|
|
|
|
@ -73,7 +73,7 @@ Cell *CellController::getCellByXY(int x, int y)
|
|
|
|
|
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())
|
|
|
|
|
if (it == cells.end())
|
|
|
|
|
return nullptr;
|
|
|
|
|
return *it;
|
|
|
|
|
}
|
|
|
|
@ -83,7 +83,7 @@ Cell *CellController::getCellByID(std::string cellid)
|
|
|
|
|
auto it = find_if(cells.begin(), cells.end(), [cellid](const Cell *c) {
|
|
|
|
|
return c->cell.mName == cellid;
|
|
|
|
|
});
|
|
|
|
|
if(it == cells.end())
|
|
|
|
|
if (it == cells.end())
|
|
|
|
|
return nullptr;
|
|
|
|
|
return *it;
|
|
|
|
|
}
|
|
|
|
@ -98,7 +98,7 @@ Cell *CellController::addCell(ESM::Cell cellData)
|
|
|
|
|
c->cell.mCellId.mWorldspace == cellData.mCellId.mWorldspace;
|
|
|
|
|
});
|
|
|
|
|
Cell *cell;
|
|
|
|
|
if(it == cells.end())
|
|
|
|
|
if (it == cells.end())
|
|
|
|
|
{
|
|
|
|
|
cell = new Cell(cellData);
|
|
|
|
|
cells.push_back(cell);
|
|
|
|
@ -112,11 +112,11 @@ Cell *CellController::addCell(ESM::Cell cellData)
|
|
|
|
|
|
|
|
|
|
void CellController::removeCell(Cell *cell)
|
|
|
|
|
{
|
|
|
|
|
if(cell == nullptr)
|
|
|
|
|
if (cell == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
for (auto it = cells.begin(); it != cells.end();)
|
|
|
|
|
{
|
|
|
|
|
if(*it != nullptr && *it == cell)
|
|
|
|
|
if (*it != nullptr && *it == cell)
|
|
|
|
|
{
|
|
|
|
|
delete *it;
|
|
|
|
|
it = cells.erase(it);
|
|
|
|
@ -131,7 +131,7 @@ void CellController::removePlayer(Cell *cell, Player *player)
|
|
|
|
|
|
|
|
|
|
cell->removePlayer(player);
|
|
|
|
|
|
|
|
|
|
if(cell->players.empty())
|
|
|
|
|
if (cell->players.empty())
|
|
|
|
|
{
|
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Deleting empty cell from memory: %s", player->npc.mName, player->getId(), cell->cell.getDescription().c_str());
|
|
|
|
|
auto it = find(cells.begin(), cells.end(), cell);
|
|
|
|
@ -156,9 +156,9 @@ void CellController::deletePlayer(Player *player)
|
|
|
|
|
|
|
|
|
|
void CellController::update(Player *player)
|
|
|
|
|
{
|
|
|
|
|
for(auto cell : player->cellStateChanges.cellStates)
|
|
|
|
|
for (auto cell : player->cellStateChanges.cellStates)
|
|
|
|
|
{
|
|
|
|
|
if(cell.type == mwmp::CellState::LOAD)
|
|
|
|
|
if (cell.type == mwmp::CellState::LOAD)
|
|
|
|
|
{
|
|
|
|
|
Cell *c = addCell(cell.cell);
|
|
|
|
|
c->addPlayer(player);
|
|
|
|
@ -167,12 +167,12 @@ void CellController::update(Player *player)
|
|
|
|
|
{
|
|
|
|
|
LOG_MESSAGE_SIMPLE(Log::LOG_VERBOSE, "Player %s (%d) unloaded cell: %s", player->npc.mName, player->getId(), cell.cell.getDescription().c_str());
|
|
|
|
|
Cell *c;
|
|
|
|
|
if(!cell.cell.isExterior())
|
|
|
|
|
if (!cell.cell.isExterior())
|
|
|
|
|
c = getCellByID(cell.cell.mName);
|
|
|
|
|
else
|
|
|
|
|
c = getCellByXY(cell.cell.getGridX(), cell.cell.getGridY());
|
|
|
|
|
|
|
|
|
|
if(c != nullptr)
|
|
|
|
|
if (c != nullptr)
|
|
|
|
|
removePlayer(c, player);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|