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