From e8e0090b9bf424fb9d94476d0ab4b7421cec115a Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sun, 30 Apr 2017 18:44:59 +0300 Subject: [PATCH] [General] Use new SimpleCreatureStats struct in BaseActor --- apps/openmw-mp/Script/Functions/Actors.cpp | 27 +++++++++---------- apps/openmw/mwmp/Cell.cpp | 2 -- apps/openmw/mwmp/DedicatedActor.cpp | 5 +--- apps/openmw/mwmp/LocalActor.cpp | 8 +++--- components/openmw-mp/Base/BaseActor.hpp | 5 ++-- components/openmw-mp/Base/BaseStructs.hpp | 7 +++++ .../Packets/Actor/PacketActorStatsDynamic.cpp | 10 +++---- 7 files changed, 28 insertions(+), 36 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index 5760ffda8..06f4c0a10 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -33,8 +33,6 @@ void ActorFunctions::InitializeActorList(unsigned short pid) noexcept writeActorList.cell.blank(); writeActorList.baseActors.clear(); writeActorList.guid = player->guid; - - tempActor.creatureStats = new ESM::CreatureStats(); } unsigned int ActorFunctions::GetActorListSize() noexcept @@ -100,32 +98,32 @@ double ActorFunctions::GetActorRotZ(unsigned int i) noexcept double ActorFunctions::GetActorHealthBase(unsigned int i) noexcept { - return readActorList->baseActors.at(i).creatureStats->mDynamic[0].mBase; + return readActorList->baseActors.at(i).creatureStats.mDynamic[0].mBase; } double ActorFunctions::GetActorHealthCurrent(unsigned int i) noexcept { - return readActorList->baseActors.at(i).creatureStats->mDynamic[0].mCurrent; + return readActorList->baseActors.at(i).creatureStats.mDynamic[0].mCurrent; } double ActorFunctions::GetActorMagickaBase(unsigned int i) noexcept { - return readActorList->baseActors.at(i).creatureStats->mDynamic[1].mBase; + return readActorList->baseActors.at(i).creatureStats.mDynamic[1].mBase; } double ActorFunctions::GetActorMagickaCurrent(unsigned int i) noexcept { - return readActorList->baseActors.at(i).creatureStats->mDynamic[1].mCurrent; + return readActorList->baseActors.at(i).creatureStats.mDynamic[1].mCurrent; } double ActorFunctions::GetActorFatigueBase(unsigned int i) noexcept { - return readActorList->baseActors.at(i).creatureStats->mDynamic[2].mBase; + return readActorList->baseActors.at(i).creatureStats.mDynamic[2].mBase; } double ActorFunctions::GetActorFatigueCurrent(unsigned int i) noexcept { - return readActorList->baseActors.at(i).creatureStats->mDynamic[2].mCurrent; + return readActorList->baseActors.at(i).creatureStats.mDynamic[2].mCurrent; } void ActorFunctions::SetActorListCell(const char* cellDescription) noexcept @@ -174,32 +172,32 @@ void ActorFunctions::SetActorRotation(double x, double y, double z) noexcept void ActorFunctions::SetActorHealthBase(double value) noexcept { - tempActor.creatureStats->mDynamic[0].mBase = value; + tempActor.creatureStats.mDynamic[0].mBase = value; } void ActorFunctions::SetActorHealthCurrent(double value) noexcept { - tempActor.creatureStats->mDynamic[0].mCurrent = value; + tempActor.creatureStats.mDynamic[0].mCurrent = value; } void ActorFunctions::SetActorMagickaBase(double value) noexcept { - tempActor.creatureStats->mDynamic[1].mBase = value; + tempActor.creatureStats.mDynamic[1].mBase = value; } void ActorFunctions::SetActorMagickaCurrent(double value) noexcept { - tempActor.creatureStats->mDynamic[1].mCurrent = value; + tempActor.creatureStats.mDynamic[1].mCurrent = value; } void ActorFunctions::SetActorFatigueBase(double value) noexcept { - tempActor.creatureStats->mDynamic[2].mBase = value; + tempActor.creatureStats.mDynamic[2].mBase = value; } void ActorFunctions::SetActorFatigueCurrent(double value) noexcept { - tempActor.creatureStats->mDynamic[2].mCurrent = value; + tempActor.creatureStats.mDynamic[2].mCurrent = value; } void ActorFunctions::AddActor() noexcept @@ -207,7 +205,6 @@ void ActorFunctions::AddActor() noexcept writeActorList.baseActors.push_back(tempActor); tempActor = emptyActor; - tempActor.creatureStats = new ESM::CreatureStats(); } void ActorFunctions::SendActorList() noexcept diff --git a/apps/openmw/mwmp/Cell.cpp b/apps/openmw/mwmp/Cell.cpp index 0a35f8b03..dd9211d31 100644 --- a/apps/openmw/mwmp/Cell.cpp +++ b/apps/openmw/mwmp/Cell.cpp @@ -326,7 +326,6 @@ void Cell::uninitializeLocalActors() for (std::map::iterator it = localActors.begin(); it != localActors.end(); ++it) { Main::get().getCellController()->removeLocalActorRecord(it->first); - delete it->second->creatureStats; delete it->second; } @@ -338,7 +337,6 @@ void Cell::uninitializeDedicatedActors() for (std::map::iterator it = dedicatedActors.begin(); it != dedicatedActors.end(); ++it) { Main::get().getCellController()->removeDedicatedActorRecord(it->first); - delete it->second->creatureStats; delete it->second; } diff --git a/apps/openmw/mwmp/DedicatedActor.cpp b/apps/openmw/mwmp/DedicatedActor.cpp index 700e0f19d..09c4996bc 100644 --- a/apps/openmw/mwmp/DedicatedActor.cpp +++ b/apps/openmw/mwmp/DedicatedActor.cpp @@ -29,9 +29,6 @@ DedicatedActor::DedicatedActor() animation.groupname = ""; sound = ""; - creatureStats = new ESM::CreatureStats(); - creatureStats->blank(); - hasStatsDynamicData = false; hasChangedCell = true; @@ -145,7 +142,7 @@ void DedicatedActor::setStatsDynamic() for (int i = 0; i < 3; ++i) { - value.readState(creatureStats->mDynamic[i]); + value.readState(creatureStats.mDynamic[i]); ptrCreatureStats->setDynamic(i, value); } } diff --git a/apps/openmw/mwmp/LocalActor.cpp b/apps/openmw/mwmp/LocalActor.cpp index 76fd84ab4..39cdf706e 100644 --- a/apps/openmw/mwmp/LocalActor.cpp +++ b/apps/openmw/mwmp/LocalActor.cpp @@ -32,8 +32,6 @@ LocalActor::LocalActor() attack.type = Attack::MELEE; attack.shouldSend = false; - - creatureStats = new ESM::CreatureStats(); } LocalActor::~LocalActor() @@ -165,9 +163,9 @@ void LocalActor::updateStatsDynamic(bool forceUpdate) oldMagicka = magicka; oldFatigue = fatigue; - health.writeState(creatureStats->mDynamic[0]); - magicka.writeState(creatureStats->mDynamic[1]); - fatigue.writeState(creatureStats->mDynamic[2]); + health.writeState(creatureStats.mDynamic[0]); + magicka.writeState(creatureStats.mDynamic[1]); + fatigue.writeState(creatureStats.mDynamic[2]); statTimer = 0; diff --git a/components/openmw-mp/Base/BaseActor.hpp b/components/openmw-mp/Base/BaseActor.hpp index 6946e65b9..b6b01523a 100644 --- a/components/openmw-mp/Base/BaseActor.hpp +++ b/components/openmw-mp/Base/BaseActor.hpp @@ -2,7 +2,6 @@ #define OPENMW_BASEACTOR_HPP #include -#include #include @@ -28,8 +27,6 @@ namespace mwmp ESM::Cell cell; - ESM::CreatureStats *creatureStats; - unsigned int movementFlags; char drawState; bool isFlying; @@ -37,6 +34,8 @@ namespace mwmp std::string response; std::string sound; + SimpleCreatureStats creatureStats; + Animation animation; Attack attack; }; diff --git a/components/openmw-mp/Base/BaseStructs.hpp b/components/openmw-mp/Base/BaseStructs.hpp index 8a8bfef5b..880aaae29 100644 --- a/components/openmw-mp/Base/BaseStructs.hpp +++ b/components/openmw-mp/Base/BaseStructs.hpp @@ -1,6 +1,8 @@ #ifndef OPENMW_BASESTRUCTS_HPP #define OPENMW_BASESTRUCTS_HPP +#include + #include namespace mwmp @@ -48,6 +50,11 @@ namespace mwmp int count; bool persist; }; + + struct SimpleCreatureStats + { + ESM::StatState mDynamic[3]; + }; } #endif //OPENMW_BASESTRUCTS_HPP diff --git a/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp b/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp index a4e6e0636..4f2628487 100644 --- a/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp +++ b/components/openmw-mp/Packets/Actor/PacketActorStatsDynamic.cpp @@ -34,18 +34,14 @@ void PacketActorStatsDynamic::Packet(RakNet::BitStream *bs, bool send) { actor = actorList->baseActors.at(i); } - else - { - actor.creatureStats = new ESM::CreatureStats(); - } RW(actor.refId, send); RW(actor.refNumIndex, send); RW(actor.mpNum, send); - RW(actor.creatureStats->mDynamic[0], send); // health - RW(actor.creatureStats->mDynamic[1], send); // magic - RW(actor.creatureStats->mDynamic[2], send); // fatigue + RW(actor.creatureStats.mDynamic[0], send); // health + RW(actor.creatureStats.mDynamic[1], send); // magic + RW(actor.creatureStats.mDynamic[2], send); // fatigue if (!send) {