[General] Use new SimpleCreatureStats struct in BaseActor

This commit is contained in:
David Cernat 2017-04-30 18:44:59 +03:00
parent 0e8d115794
commit e8e0090b9b
7 changed files with 28 additions and 36 deletions

View file

@ -33,8 +33,6 @@ void ActorFunctions::InitializeActorList(unsigned short pid) noexcept
writeActorList.cell.blank(); writeActorList.cell.blank();
writeActorList.baseActors.clear(); writeActorList.baseActors.clear();
writeActorList.guid = player->guid; writeActorList.guid = player->guid;
tempActor.creatureStats = new ESM::CreatureStats();
} }
unsigned int ActorFunctions::GetActorListSize() noexcept unsigned int ActorFunctions::GetActorListSize() noexcept
@ -100,32 +98,32 @@ double ActorFunctions::GetActorRotZ(unsigned int i) noexcept
double ActorFunctions::GetActorHealthBase(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 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 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 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 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 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 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 void ActorFunctions::SetActorHealthBase(double value) noexcept
{ {
tempActor.creatureStats->mDynamic[0].mBase = value; tempActor.creatureStats.mDynamic[0].mBase = value;
} }
void ActorFunctions::SetActorHealthCurrent(double value) noexcept void ActorFunctions::SetActorHealthCurrent(double value) noexcept
{ {
tempActor.creatureStats->mDynamic[0].mCurrent = value; tempActor.creatureStats.mDynamic[0].mCurrent = value;
} }
void ActorFunctions::SetActorMagickaBase(double value) noexcept void ActorFunctions::SetActorMagickaBase(double value) noexcept
{ {
tempActor.creatureStats->mDynamic[1].mBase = value; tempActor.creatureStats.mDynamic[1].mBase = value;
} }
void ActorFunctions::SetActorMagickaCurrent(double value) noexcept void ActorFunctions::SetActorMagickaCurrent(double value) noexcept
{ {
tempActor.creatureStats->mDynamic[1].mCurrent = value; tempActor.creatureStats.mDynamic[1].mCurrent = value;
} }
void ActorFunctions::SetActorFatigueBase(double value) noexcept void ActorFunctions::SetActorFatigueBase(double value) noexcept
{ {
tempActor.creatureStats->mDynamic[2].mBase = value; tempActor.creatureStats.mDynamic[2].mBase = value;
} }
void ActorFunctions::SetActorFatigueCurrent(double value) noexcept void ActorFunctions::SetActorFatigueCurrent(double value) noexcept
{ {
tempActor.creatureStats->mDynamic[2].mCurrent = value; tempActor.creatureStats.mDynamic[2].mCurrent = value;
} }
void ActorFunctions::AddActor() noexcept void ActorFunctions::AddActor() noexcept
@ -207,7 +205,6 @@ void ActorFunctions::AddActor() noexcept
writeActorList.baseActors.push_back(tempActor); writeActorList.baseActors.push_back(tempActor);
tempActor = emptyActor; tempActor = emptyActor;
tempActor.creatureStats = new ESM::CreatureStats();
} }
void ActorFunctions::SendActorList() noexcept void ActorFunctions::SendActorList() noexcept

View file

@ -326,7 +326,6 @@ void Cell::uninitializeLocalActors()
for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end(); ++it) for (std::map<std::string, LocalActor *>::iterator it = localActors.begin(); it != localActors.end(); ++it)
{ {
Main::get().getCellController()->removeLocalActorRecord(it->first); Main::get().getCellController()->removeLocalActorRecord(it->first);
delete it->second->creatureStats;
delete it->second; delete it->second;
} }
@ -338,7 +337,6 @@ void Cell::uninitializeDedicatedActors()
for (std::map<std::string, DedicatedActor *>::iterator it = dedicatedActors.begin(); it != dedicatedActors.end(); ++it) for (std::map<std::string, DedicatedActor *>::iterator it = dedicatedActors.begin(); it != dedicatedActors.end(); ++it)
{ {
Main::get().getCellController()->removeDedicatedActorRecord(it->first); Main::get().getCellController()->removeDedicatedActorRecord(it->first);
delete it->second->creatureStats;
delete it->second; delete it->second;
} }

View file

@ -29,9 +29,6 @@ DedicatedActor::DedicatedActor()
animation.groupname = ""; animation.groupname = "";
sound = ""; sound = "";
creatureStats = new ESM::CreatureStats();
creatureStats->blank();
hasStatsDynamicData = false; hasStatsDynamicData = false;
hasChangedCell = true; hasChangedCell = true;
@ -145,7 +142,7 @@ void DedicatedActor::setStatsDynamic()
for (int i = 0; i < 3; ++i) for (int i = 0; i < 3; ++i)
{ {
value.readState(creatureStats->mDynamic[i]); value.readState(creatureStats.mDynamic[i]);
ptrCreatureStats->setDynamic(i, value); ptrCreatureStats->setDynamic(i, value);
} }
} }

View file

@ -32,8 +32,6 @@ LocalActor::LocalActor()
attack.type = Attack::MELEE; attack.type = Attack::MELEE;
attack.shouldSend = false; attack.shouldSend = false;
creatureStats = new ESM::CreatureStats();
} }
LocalActor::~LocalActor() LocalActor::~LocalActor()
@ -165,9 +163,9 @@ void LocalActor::updateStatsDynamic(bool forceUpdate)
oldMagicka = magicka; oldMagicka = magicka;
oldFatigue = fatigue; oldFatigue = fatigue;
health.writeState(creatureStats->mDynamic[0]); health.writeState(creatureStats.mDynamic[0]);
magicka.writeState(creatureStats->mDynamic[1]); magicka.writeState(creatureStats.mDynamic[1]);
fatigue.writeState(creatureStats->mDynamic[2]); fatigue.writeState(creatureStats.mDynamic[2]);
statTimer = 0; statTimer = 0;

View file

@ -2,7 +2,6 @@
#define OPENMW_BASEACTOR_HPP #define OPENMW_BASEACTOR_HPP
#include <components/esm/loadcell.hpp> #include <components/esm/loadcell.hpp>
#include <components/esm/creaturestats.hpp>
#include <components/openmw-mp/Base/BaseStructs.hpp> #include <components/openmw-mp/Base/BaseStructs.hpp>
@ -28,8 +27,6 @@ namespace mwmp
ESM::Cell cell; ESM::Cell cell;
ESM::CreatureStats *creatureStats;
unsigned int movementFlags; unsigned int movementFlags;
char drawState; char drawState;
bool isFlying; bool isFlying;
@ -37,6 +34,8 @@ namespace mwmp
std::string response; std::string response;
std::string sound; std::string sound;
SimpleCreatureStats creatureStats;
Animation animation; Animation animation;
Attack attack; Attack attack;
}; };

View file

@ -1,6 +1,8 @@
#ifndef OPENMW_BASESTRUCTS_HPP #ifndef OPENMW_BASESTRUCTS_HPP
#define OPENMW_BASESTRUCTS_HPP #define OPENMW_BASESTRUCTS_HPP
#include <components/esm/statstate.hpp>
#include <RakNetTypes.h> #include <RakNetTypes.h>
namespace mwmp namespace mwmp
@ -48,6 +50,11 @@ namespace mwmp
int count; int count;
bool persist; bool persist;
}; };
struct SimpleCreatureStats
{
ESM::StatState<float> mDynamic[3];
};
} }
#endif //OPENMW_BASESTRUCTS_HPP #endif //OPENMW_BASESTRUCTS_HPP

View file

@ -34,18 +34,14 @@ void PacketActorStatsDynamic::Packet(RakNet::BitStream *bs, bool send)
{ {
actor = actorList->baseActors.at(i); actor = actorList->baseActors.at(i);
} }
else
{
actor.creatureStats = new ESM::CreatureStats();
}
RW(actor.refId, send); RW(actor.refId, send);
RW(actor.refNumIndex, send); RW(actor.refNumIndex, send);
RW(actor.mpNum, send); RW(actor.mpNum, send);
RW(actor.creatureStats->mDynamic[0], send); // health RW(actor.creatureStats.mDynamic[0], send); // health
RW(actor.creatureStats->mDynamic[1], send); // magic RW(actor.creatureStats.mDynamic[1], send); // magic
RW(actor.creatureStats->mDynamic[2], send); // fatigue RW(actor.creatureStats.mDynamic[2], send); // fatigue
if (!send) if (!send)
{ {