From 1bdec00a619ae049bb941468a720e1701ac1c4b6 Mon Sep 17 00:00:00 2001 From: David Markowitz Date: Sat, 17 Jun 2023 02:39:33 -0700 Subject: [PATCH] More organization of header --- dGame/dEntity/Entity.cpp | 16 ++-- dGame/dEntity/Entity.h | 86 ++++++++++--------- .../02_server/Enemy/Waves/WaveBossApe.cpp | 2 +- .../Enemy/Waves/WaveBossHammerling.cpp | 2 +- .../Enemy/Waves/WaveBossHorsemen.cpp | 2 +- .../Enemy/Waves/WaveBossSpiderling.cpp | 2 +- .../Map/NT/NtCombatChallengeServer.cpp | 2 +- .../Property/AG_Small/EnemySpiderSpawner.cpp | 2 +- dScripts/ai/ACT/ActMine.cpp | 2 +- dScripts/ai/WILD/WildNinjaBricks.cpp | 2 +- dScripts/ai/WILD/WildNinjaStudent.cpp | 2 +- 11 files changed, 61 insertions(+), 59 deletions(-) diff --git a/dGame/dEntity/Entity.cpp b/dGame/dEntity/Entity.cpp index 8dbbbc58..f638009e 100644 --- a/dGame/dEntity/Entity.cpp +++ b/dGame/dEntity/Entity.cpp @@ -746,13 +746,10 @@ void Entity::ResetFlags() { // Unused } -// std::for_each void Entity::UpdateXMLDoc(tinyxml2::XMLDocument* doc) { DluAssert(doc != nullptr); - for (const auto& pair : m_Components) { - if (pair.second == nullptr) continue; - - pair.second->UpdateXml(doc); + for (const auto&[componentId, component] : m_Components) { + if (component) component->UpdateXml(doc); } } @@ -1121,9 +1118,10 @@ void Entity::RegisterCoinDrop(const uint64_t& coinsDropped) { } void Entity::AddChild(Entity* child) { + if (!child) return; m_IsParentChildDirty = true; - if (std::find(m_ChildEntities.begin(), m_ChildEntities.end(), child) != m_ChildEntities.end()) return; - m_ChildEntities.push_back(child); + if (std::find(m_ChildEntities.begin(), m_ChildEntities.end(), child) == m_ChildEntities.end()) m_ChildEntities.push_back(child); + else Game::logger->Log("Entity", "WARNING: Entity (objid:lot) %llu:%i already has (%llu:%i) as a child", GetObjectID(), GetLOT(), child->GetObjectID(), child->GetLOT()); } void Entity::RemoveChild(Entity* child) { @@ -1138,7 +1136,7 @@ void Entity::RemoveChild(Entity* child) { void Entity::RemoveParent() { if (m_ParentEntity) m_IsParentChildDirty = true; - else Game::logger->Log("Entity", "WARNING: Attempted to remove parent from(objid:lot) (%llu:%i) when no parent existed", GetObjectID(), GetLOT()); + else Game::logger->Log("Entity", "WARNING: Attempted to remove parent from (objid:lot) (%llu:%i) when no parent existed", GetObjectID(), GetLOT()); this->m_ParentEntity = nullptr; } @@ -1363,7 +1361,7 @@ void Entity::Resurrect() { if (IsPlayer()) GameMessages::SendResurrect(this); } -void Entity::AddToGroups(const std::string& group) { +void Entity::AddGroup(const std::string& group) { if (std::find(m_Groups.begin(), m_Groups.end(), group) == m_Groups.end()) { m_Groups.push_back(group); } diff --git a/dGame/dEntity/Entity.h b/dGame/dEntity/Entity.h index 1faed1c8..d6629932 100644 --- a/dGame/dEntity/Entity.h +++ b/dGame/dEntity/Entity.h @@ -98,6 +98,9 @@ public: Entity* GetOwner() const; void SetOwnerOverride(const LWOOBJID& value) { m_OwnerOverride = value; }; + Entity* GetScheduledKiller() { return m_ScheduleKiller; } + std::vector& GetTargetsInPhantom(); + const std::unordered_map& GetComponents() { return m_Components; } // Position related info const NiPoint3& GetDefaultPosition() const { return m_DefaultPosition; }; @@ -110,6 +113,9 @@ public: const NiQuaternion& GetRotation() const; void SetRotation(const NiQuaternion& rotation); + virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; } + virtual NiQuaternion GetRespawnRotation() const { return NiQuaternion::IDENTITY; } + // Spawner related info Spawner* GetSpawner() const { return m_Spawner; } @@ -117,6 +123,7 @@ public: const std::vector& GetGroups() { return m_Groups; }; void SetGroups(const std::vector& value) { m_Groups = value; } + void AddGroup(const std::string& group); // LDF related into const std::vector& GetSettings() const { return m_Settings; } @@ -149,14 +156,12 @@ public: Character* GetCharacter() const { return m_Character; } void SetCharacter(Character* value) { m_Character = value; } - // End info - bool IsDead() const; - // If you are calling this, then calling GetComponent, just call GetComponent and check for nullptr. bool HasComponent(const eReplicaComponentType componentId) const; + // Event management /** * Call these when you want to observe events. Observed events should follow the following naming convention * in scripts Notify. For example, if you want to observe the "OnDeath" event, you would call @@ -170,6 +175,7 @@ public: */ void Unsubscribe(CppScripts::Script* scriptToRemove, const std::string& notificationName); + // Proximity radius management void AddProximityRadius(const float proxRadius, const std::string& name); void AddProximityRadius(const BoxDimensions& dimensions, const std::string& name); @@ -178,9 +184,18 @@ public: inline void SetProximityRadius(const float proxRadius, const std::string& name) { this->AddProximityRadius(proxRadius, name); } inline void SetProximityRadius(const BoxDimensions& dimensions, const std::string& name) { this->AddProximityRadius(dimensions, name); } + void AddRebuildCompleteCallback(const std::function& callback) const; + void AddCollisionPhantomCallback(const std::function& callback) { m_PhantomCollisionCallbacks.push_back(callback); }; + void AddDieCallback(const std::function& callback) { m_DieCallbacks.push_back(callback); }; + void TriggerEvent(const eTriggerEventType event, Entity* optionalTarget = nullptr); + void NotifyObject(Entity* sender, const std::u16string& name, const int32_t param1 = 0, const int32_t param2 = 0); + + // Parent Child management void AddChild(Entity* child); void RemoveChild(Entity* child); void RemoveParent(); + + // Timer management void AddTimer(const std::string& name, const float time); void AddCallbackTimer(const float time, const std::function& callback); bool HasTimer(const std::string& name); @@ -188,16 +203,13 @@ public: void CancelAllTimers(); void CancelTimer(const std::string& name); - void AddToGroups(const std::string& group); - bool IsPlayer() const; - + // Serialization void WriteBaseReplicaData(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType); void WriteComponents(RakNet::BitStream* outBitStream, const eReplicaPacketType packetType); - void ResetFlags(); - void UpdateXMLDoc(tinyxml2::XMLDocument* doc); - void Update(float deltaTime); - // Events + // Scripting + // Get the script attached to this entity. Will never return nullptr. + CppScripts::Script* GetScript() const; void OnCollisionProximity(const LWOOBJID otherEntity, const std::string& proxName, const std::string& status); void OnCollisionPhantom(const LWOOBJID otherEntity); void OnCollisionLeavePhantom(const LWOOBJID otherEntity); @@ -208,7 +220,6 @@ public: void OnCinematicUpdate(Entity* self, Entity* sender, const eCinematicEvent event, const std::u16string& pathName, const float pathTime, const float totalTime, const int32_t waypoint); - void NotifyObject(Entity* sender, const std::u16string& name, const int32_t param1 = 0, const int32_t param2 = 0); void OnEmoteReceived(const int32_t emote, Entity* target); void OnUse(Entity* originator); @@ -228,14 +239,19 @@ public: void OnMessageBoxResponse(Entity* sender, const int32_t button, const std::u16string& identifier, const std::u16string& userData); void OnChoiceBoxResponse(Entity* sender, const int32_t button, const std::u16string& buttonIdentifier, const std::u16string& identifier); void RequestActivityExit(Entity* sender, const LWOOBJID& player, const bool canceled); + // End scripting + // Cleanup functions void Smash(const LWOOBJID source = LWOOBJID_EMPTY, const eKillType killType = eKillType::VIOLENT, const std::u16string& deathType = u""); + // Odds are you do not need to call this. Call Smash instead. void Kill(Entity* murderer = nullptr); - void AddRebuildCompleteCallback(const std::function& callback) const; - void AddCollisionPhantomCallback(const std::function& callback) { m_PhantomCollisionCallbacks.push_back(callback); }; - void AddDieCallback(const std::function& callback) { m_DieCallbacks.push_back(callback); }; + + void ScheduleKillAfterUpdate(Entity* murderer = nullptr); + void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; } + void Resurrect(); + // Loot management (should be moved to Player. Not every Entity needs this.) void AddLootItem(const Loot::Info& info); void PickupItem(const LWOOBJID& objectID); @@ -243,37 +259,29 @@ public: void PickupCoins(const uint64_t& count); void RegisterCoinDrop(const uint64_t& count); - void ScheduleKillAfterUpdate(Entity* murderer = nullptr); - void TriggerEvent(const eTriggerEventType event, Entity* optionalTarget = nullptr); - void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; } - - virtual NiPoint3 GetRespawnPosition() const { return NiPoint3::ZERO; } - virtual NiQuaternion GetRespawnRotation() const { return NiQuaternion::IDENTITY; } - CppScripts::Script* GetScript() const; - + // State checkers void Sleep(); void Wake(); bool IsSleeping() const; + bool IsDead() const; + bool IsPlayer() const; - /* + // Update + void UpdateXMLDoc(tinyxml2::XMLDocument* doc); + void Update(float deltaTime); + /** * Utility */ - //Retroactively corrects the model vault size due to incorrect initialization in a previous patch. + //Retroactively corrects the model vault size due to incorrect initialization in a previous patch. void RetroactiveVaultSize(); + void ResetFlags(); + + // LDF Setting accessors bool GetBoolean(const std::u16string& name) const { return GetVar(name); }; int32_t GetI32(const std::u16string& name) const { return GetVar(name); }; int64_t GetI64(const std::u16string& name) const { return GetVar(name); }; - - void SetBoolean(const std::u16string& name, bool value) { SetVar(name, value); } - void SetI32(const std::u16string& name, int32_t value) { SetVar(name, value); }; - void SetI64(const std::u16string& name, int64_t value) { SetVar(name, value); }; - bool HasVar(const std::u16string& name) const; - - /** - * Get the LDF data. - */ LDFBaseData* GetVarData(const std::u16string& name) const; /** @@ -281,14 +289,10 @@ public: */ std::string GetVarAsString(const std::u16string& name) const; - /* - * Collision - */ - std::vector& GetTargetsInPhantom(); - - Entity* GetScheduledKiller() { return m_ScheduleKiller; } - - const std::unordered_map& GetComponents() { return m_Components; } + // LDF Setting assignment shorthands + void SetBoolean(const std::u16string& name, bool value) { SetVar(name, value); } + void SetI32(const std::u16string& name, int32_t value) { SetVar(name, value); }; + void SetI64(const std::u16string& name, int64_t value) { SetVar(name, value); }; // Template declarations template diff --git a/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp b/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp index b4e5a078..70181d3c 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossApe.cpp @@ -17,7 +17,7 @@ void WaveBossApe::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroups("boss"); + self->AddGroup("boss"); BaseEnemyApe::OnStartup(self); } diff --git a/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp b/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp index 640b026e..850c75fb 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossHammerling.cpp @@ -11,7 +11,7 @@ void WaveBossHammerling::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroups("boss"); + self->AddGroup("boss"); } void WaveBossHammerling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, diff --git a/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp b/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp index ee5a946b..61f2c39e 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossHorsemen.cpp @@ -11,7 +11,7 @@ void WaveBossHorsemen::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroups("boss"); + self->AddGroup("boss"); } void diff --git a/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp b/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp index 2c03ac1e..91750a38 100644 --- a/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp +++ b/dScripts/02_server/Enemy/Waves/WaveBossSpiderling.cpp @@ -11,7 +11,7 @@ void WaveBossSpiderling::OnStartup(Entity* self) { combatAIComponent->SetStunImmune(true); } - self->AddToGroups("boss"); + self->AddGroup("boss"); } void WaveBossSpiderling::OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, diff --git a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp index ff98d741..33a7e1d7 100644 --- a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp +++ b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp @@ -123,7 +123,7 @@ void NtCombatChallengeServer::OnChildLoaded(Entity* self, Entity* child) { EntityManager::Instance()->SerializeEntity(child); - child->AddToGroups("targets_" + std::to_string(self->GetObjectID())); + child->AddGroup("targets_" + std::to_string(self->GetObjectID())); } void NtCombatChallengeServer::ResetGame(Entity* self) { diff --git a/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp b/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp index 1adc6066..072cabe7 100644 --- a/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp +++ b/dScripts/02_server/Map/Property/AG_Small/EnemySpiderSpawner.cpp @@ -51,7 +51,7 @@ void EnemySpiderSpawner::OnTimerDone(Entity* self, std::string timerName) { Entity* newEntity = EntityManager::Instance()->CreateEntity(info, nullptr); if (newEntity) { EntityManager::Instance()->ConstructEntity(newEntity); - newEntity->AddToGroups("BabySpider"); + newEntity->AddGroup("BabySpider"); /* auto* movementAi = newEntity->GetComponent(); diff --git a/dScripts/ai/ACT/ActMine.cpp b/dScripts/ai/ACT/ActMine.cpp index fd584f48..d34093a9 100644 --- a/dScripts/ai/ACT/ActMine.cpp +++ b/dScripts/ai/ACT/ActMine.cpp @@ -18,7 +18,7 @@ void ActMine::OnRebuildNotifyState(Entity* self, eRebuildState state) { self->SetVar(u"RebuildComplete", true); self->SetVar(u"NumWarnings", 0); - self->AddToGroups("reset"); + self->AddGroup("reset"); } } diff --git a/dScripts/ai/WILD/WildNinjaBricks.cpp b/dScripts/ai/WILD/WildNinjaBricks.cpp index 702b2f38..b8e2fd9c 100644 --- a/dScripts/ai/WILD/WildNinjaBricks.cpp +++ b/dScripts/ai/WILD/WildNinjaBricks.cpp @@ -2,7 +2,7 @@ #include "Entity.h" void WildNinjaBricks::OnStartup(Entity* self) { - self->AddToGroups("Ninjastuff"); + self->AddGroup("Ninjastuff"); } void WildNinjaBricks::OnNotifyObject(Entity* self, Entity* sender, const std::u16string& name, int32_t param1, int32_t param2) { diff --git a/dScripts/ai/WILD/WildNinjaStudent.cpp b/dScripts/ai/WILD/WildNinjaStudent.cpp index 36115ea6..b0683162 100644 --- a/dScripts/ai/WILD/WildNinjaStudent.cpp +++ b/dScripts/ai/WILD/WildNinjaStudent.cpp @@ -3,7 +3,7 @@ #include "Entity.h" void WildNinjaStudent::OnStartup(Entity* self) { - self->AddToGroups("Ninjastuff"); + self->AddGroup("Ninjastuff"); GameMessages::SendPlayAnimation(self, u"bow"); }