feat(object): add CGUnit_C::RefreshDataPointers

This commit is contained in:
fallenoak 2026-02-13 14:32:55 -06:00
parent e56bde0dde
commit 6860d86369
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 90 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include "object/client/ObjMgr.hpp"
#include "db/Db.hpp"
#include "ui/Game.hpp"
#include <storm/Error.hpp>
WOWGUID CGUnit_C::s_activeMover;
@ -95,6 +96,10 @@ const char* CGUnit_C::GetDisplayRaceNameFromRecord(const ChrRacesRec* raceRec, U
CGUnit_C::CGUnit_C(uint32_t time, CClientObjCreate& objCreate) : CGObject_C(time, objCreate) {
// TODO
this->RefreshDataPointers();
// TODO
}
CGUnit_C::~CGUnit_C() {
@ -115,16 +120,22 @@ int32_t CGUnit_C::CanBeTargetted() {
return this->CanHighlight();
}
int32_t CGUnit_C::GetDisplayID() const {
// Prefer local display ID if set and unit's display ID hasn't been overridden from unit's
// native display ID.
if (this->GetLocalDisplayID() && this->GetDisplayID() == this->GetNativeDisplayID()) {
return this->GetLocalDisplayID();
}
return this->CGUnit::GetDisplayID();
}
int32_t CGUnit_C::GetLocalDisplayID() const {
return this->m_localDisplayID;
}
CreatureModelDataRec* CGUnit_C::GetModelData() const {
// Prefer local display ID if set and unit's display ID hasn't been overridden from unit's
// native display ID; otherwise prefer overridden display ID.
auto displayID = this->GetLocalDisplayID() && this->GetDisplayID() == this->GetNativeDisplayID()
? this->GetLocalDisplayID()
: this->GetDisplayID();
auto displayID = this->GetDisplayID();
auto creatureDisplayInfoRec = g_creatureDisplayInfoDB.GetRecord(displayID);
@ -170,6 +181,63 @@ void CGUnit_C::PostMovementUpdate(const CClientMoveUpdate& move, int32_t activeM
// TODO
}
void CGUnit_C::RefreshDataPointers() {
auto displayID = this->GetDisplayID();
// Display info
this->m_displayInfo = g_creatureDisplayInfoDB.GetRecord(displayID);
if (!this->m_displayInfo) {
// TODO auto name = this->GetUnitName(0, 1);
// TODO SysMsgPrintf(2, 2, "NOUNITDISPLAYID|%d|%s", displayID, name);
this->m_displayInfo = g_creatureDisplayInfoDB.GetRecordByIndex(0);
if (!this->m_displayInfo) {
STORM_APP_FATAL("Error, NO creature display records found");
}
}
// Display info extra
this->m_displayInfoExtra = g_creatureDisplayInfoExtraDB.GetRecord(this->m_displayInfo->m_extendedDisplayInfoID);
// Model data
this->m_modelData = g_creatureModelDataDB.GetRecord(this->m_displayInfo->m_modelID);
// Sound data
this->m_soundData = g_creatureSoundDataDB.GetRecord(this->m_displayInfo->m_soundID);
if (!this->m_soundData) {
this->m_soundData = g_creatureSoundDataDB.GetRecord(this->m_modelData->m_soundID);
}
// Blood levels
this->m_bloodRec = g_unitBloodLevelsDB.GetRecord(this->m_displayInfo->m_bloodID);
if (!this->m_bloodRec) {
this->m_bloodRec = g_unitBloodLevelsDB.GetRecord(this->m_modelData->m_bloodID);
if (!this->m_bloodRec) {
this->m_bloodRec = g_unitBloodLevelsDB.GetRecordByIndex(0);
}
}
// Creature stats
if (this->GetType() == HIER_TYPE_UNIT) {
// TODO load creature stats
}
// Flags
// TODO set flags
}
void CGUnit_C::SetStorage(uint32_t* storage, uint32_t* saved) {
this->CGObject_C::SetStorage(storage, saved);

View File

@ -9,7 +9,11 @@
class ChrClassesRec;
class ChrRacesRec;
class CreatureDisplayInfoRec;
class CreatureDisplayInfoExtraRec;
class CreatureModelDataRec;
class CreatureSoundDataRec;
class UnitBloodLevelsRec;
class CGUnit_C : public CGObject_C, public CGUnit {
public:
@ -31,15 +35,27 @@ class CGUnit_C : public CGObject_C, public CGUnit {
// Public member functions
CGUnit_C(uint32_t time, CClientObjCreate& objCreate);
int32_t GetLocalDisplayID() const;
int32_t GetDisplayID() const;
CreatureModelDataRec* GetModelData() const;
void PostInit(uint32_t time, const CClientObjCreate& init, bool a4);
void PostMovementUpdate(const CClientMoveUpdate& move, int32_t activeMover);
void SetStorage(uint32_t* storage, uint32_t* saved);
protected:
// Protected member functions
int32_t GetLocalDisplayID() const;
void RefreshDataPointers();
private:
// Private member variables
// TODO
CreatureDisplayInfoRec* m_displayInfo;
CreatureDisplayInfoExtraRec* m_displayInfoExtra;
CreatureModelDataRec* m_modelData;
CreatureSoundDataRec* m_soundData;
// TODO
UnitBloodLevelsRec* m_bloodRec;
// TODO
int32_t m_localDisplayID = 0;
// TODO
};