1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 10:49:57 +00:00
openmw-tes3mp/apps/openmw/mwmp/Cell.cpp

94 lines
2.5 KiB
C++
Raw Normal View History

2017-04-06 01:00:50 +00:00
#include "../mwworld/worldimp.hpp"
#include <components/esm/cellid.hpp>
#include <components/openmw-mp/Log.hpp>
#include <components/openmw-mp/Utils.hpp>
2017-04-06 01:00:50 +00:00
#include "Cell.hpp"
#include "Main.hpp"
#include "LocalPlayer.hpp"
using namespace mwmp;
mwmp::Cell::Cell(MWWorld::CellStore* cellStore)
{
store = cellStore;
std::map<std::string, LocalActor *> localActors;
std::map<std::string, DedicatedActor *> dedicatedActors;
}
mwmp::Cell::~Cell()
{
}
void Cell::update()
{
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end();)
{
LocalActor *actor = it->second;
// TODO:: Make sure this condition actually works
if (actor->getPtr().getCell() && actor->getPtr().getCell() != store)
2017-04-06 01:00:50 +00:00
{
LOG_APPEND(Log::LOG_INFO, "- Removing LocalActor %s which is no longer in this cell", it->first.c_str());
localActors.erase(it++);
}
else
{
LOG_APPEND(Log::LOG_VERBOSE, "- Updating LocalActor %s", it->first.c_str());
actor->update();
2017-04-06 01:00:50 +00:00
++it;
}
}
}
void Cell::initializeLocalActors()
{
ESM::Cell esmCell = *store->getCell();
MWWorld::CellRefList<ESM::NPC> *npcList = store->getNpcs();
for (typename MWWorld::CellRefList<ESM::NPC>::List::iterator listIter(npcList->mList.begin());
listIter != npcList->mList.end(); ++listIter)
{
MWWorld::Ptr ptr(&*listIter, 0);
std::string mapIndex = generateMapIndex(ptr);
localActors[mapIndex] = new LocalActor();
localActors[mapIndex]->cell = esmCell;
2017-04-06 01:59:55 +00:00
ptr.getBase()->isLocalActor = true;
2017-04-06 01:00:50 +00:00
localActors[mapIndex]->setPtr(ptr);
LOG_APPEND(Log::LOG_INFO, "- Initialized LocalActor %s", mapIndex.c_str());
}
}
2017-04-06 01:59:55 +00:00
void Cell::uninitializeLocalActors()
{
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end(); ++it)
{
LocalActor *actor = it->second;
actor->getPtr().getBase()->isLocalActor = false;
}
localActors.clear();
}
2017-04-06 01:00:50 +00:00
std::string Cell::generateMapIndex(MWWorld::Ptr ptr)
{
std::string mapIndex = "";
mapIndex += ptr.getCellRef().getRefId();
mapIndex += "-" + Utils::toString(ptr.getCellRef().getRefNum().mIndex);
mapIndex += "-" + Utils::toString(ptr.getCellRef().getMpNum());
2017-04-06 01:00:50 +00:00
return mapIndex;
}
MWWorld::CellStore *mwmp::Cell::getCellStore()
{
return store;
}
std::string mwmp::Cell::getDescription()
{
return store->getCell()->getDescription();
}