forked from mirror/openmw-tes3mp
[Server] Store a BaseActorList in every Cell to keep track of Actor data
This commit is contained in:
parent
e8e0090b9b
commit
a73cbac226
2 changed files with 68 additions and 1 deletions
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "Cell.hpp"
|
||||
|
||||
#include <components/openmw-mp/NetworkMessages.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include "Player.hpp"
|
||||
|
||||
|
@ -11,7 +13,7 @@ using namespace std;
|
|||
|
||||
Cell::Cell(ESM::Cell cell) : cell(cell)
|
||||
{
|
||||
|
||||
cellActorList.count = 0;
|
||||
}
|
||||
|
||||
Cell::Iterator Cell::begin() const
|
||||
|
@ -61,6 +63,63 @@ void Cell::removePlayer(Player *player)
|
|||
}
|
||||
}
|
||||
|
||||
void Cell::readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList)
|
||||
{
|
||||
for (unsigned int i = 0; i < newActorList->count; i++)
|
||||
{
|
||||
mwmp::BaseActor newActor = newActorList->baseActors.at(i);
|
||||
mwmp::BaseActor *cellActor;
|
||||
|
||||
if (containsActor(newActor.refNumIndex, newActor.mpNum))
|
||||
{
|
||||
cellActor = getActor(newActor.refNumIndex, newActor.mpNum);
|
||||
|
||||
switch (packetID)
|
||||
{
|
||||
case ID_ACTOR_STATS_DYNAMIC:
|
||||
|
||||
cellActor->creatureStats.mDynamic[0] = newActor.creatureStats.mDynamic[0];
|
||||
cellActor->creatureStats.mDynamic[1] = newActor.creatureStats.mDynamic[1];
|
||||
cellActor->creatureStats.mDynamic[2] = newActor.creatureStats.mDynamic[2];
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
cellActorList.baseActors.push_back(newActor);
|
||||
}
|
||||
|
||||
cellActorList.count = cellActorList.baseActors.size();
|
||||
}
|
||||
|
||||
bool Cell::containsActor(int refNumIndex, int mpNum)
|
||||
{
|
||||
for (unsigned int i = 0; i < cellActorList.baseActors.size(); i++)
|
||||
{
|
||||
mwmp::BaseActor actor = cellActorList.baseActors.at(i);
|
||||
|
||||
if (actor.refNumIndex == refNumIndex && actor.mpNum == mpNum)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
mwmp::BaseActor *Cell::getActor(int refNumIndex, int mpNum)
|
||||
{
|
||||
for (unsigned int i = 0; i < cellActorList.baseActors.size(); i++)
|
||||
{
|
||||
mwmp::BaseActor *actor = &cellActorList.baseActors.at(i);
|
||||
|
||||
if (actor->refNumIndex == refNumIndex && actor->mpNum == mpNum)
|
||||
return actor;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
mwmp::BaseActorList *Cell::getActorList()
|
||||
{
|
||||
return &cellActorList;
|
||||
}
|
||||
|
||||
Cell::TPlayers Cell::getPlayers() const
|
||||
{
|
||||
return players;
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <deque>
|
||||
#include <string>
|
||||
#include <components/esm/records.hpp>
|
||||
#include <components/openmw-mp/Base/BaseActor.hpp>
|
||||
#include <components/openmw-mp/Base/BaseEvent.hpp>
|
||||
#include <components/openmw-mp/Packets/Actor/ActorPacket.hpp>
|
||||
#include <components/openmw-mp/Packets/World/WorldPacket.hpp>
|
||||
|
@ -29,6 +30,11 @@ public:
|
|||
void addPlayer(Player *player);
|
||||
void removePlayer(Player *player);
|
||||
|
||||
void readActorList(unsigned char packetID, const mwmp::BaseActorList *newActorList);
|
||||
bool containsActor(int refNumIndex, int mpNum);
|
||||
mwmp::BaseActor *getActor(int refNumIndex, int mpNum);
|
||||
mwmp::BaseActorList *getActorList();
|
||||
|
||||
TPlayers getPlayers() const;
|
||||
void sendToLoaded(mwmp::ActorPacket *actorPacket, mwmp::BaseActorList *baseActorList) const;
|
||||
void sendToLoaded(mwmp::WorldPacket *worldPacket, mwmp::BaseEvent *baseEvent) const;
|
||||
|
@ -39,6 +45,8 @@ public:
|
|||
private:
|
||||
TPlayers players;
|
||||
ESM::Cell cell;
|
||||
|
||||
mwmp::BaseActorList cellActorList;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue