From a73cbac226bfee24475dcc9b0698f4e57d1b4f57 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 1 May 2017 00:42:34 +0300 Subject: [PATCH] [Server] Store a BaseActorList in every Cell to keep track of Actor data --- apps/openmw-mp/Cell.cpp | 61 ++++++++++++++++++++++++++++++++++++++++- apps/openmw-mp/Cell.hpp | 8 ++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/apps/openmw-mp/Cell.cpp b/apps/openmw-mp/Cell.cpp index 7e5698841..61135c62c 100644 --- a/apps/openmw-mp/Cell.cpp +++ b/apps/openmw-mp/Cell.cpp @@ -4,6 +4,8 @@ #include "Cell.hpp" +#include + #include #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; diff --git a/apps/openmw-mp/Cell.hpp b/apps/openmw-mp/Cell.hpp index 648142907..d2d34d96b 100644 --- a/apps/openmw-mp/Cell.hpp +++ b/apps/openmw-mp/Cell.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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; };