refactor(component): proximity monitor and movement AI load their own rows

The ProximityMonitorComponent row's radii and the MovementAIComponent row
(with the level's wanderRadius over it) move out of Entity::Initialize into
each component's LoadDataFromTemplate / LoadConfigData. Same components and
bytes for every LOT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-01 15:47:10 -05:00
parent c710e1d3a9
commit 54adbcdce8
5 changed files with 52 additions and 41 deletions

View File

@@ -1,4 +1,6 @@
#include "MovementAIComponent.h"
#include "CDClientManager.h"
#include "CDMovementAIComponentTable.h"
#include <utility>
#include <cmath>
@@ -46,11 +48,6 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component
m_BaseCombatAI = m_Parent->GetComponent<BaseCombatAIComponent>();
//Try and fix the insane values:
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius *= 0.5f;
if (m_Info.wanderRadius > 8.0f) m_Info.wanderRadius = 8.0f;
if (m_Info.wanderSpeed > 0.5f) m_Info.wanderSpeed *= 0.5f;
m_BaseSpeed = GetBaseSpeed(m_Parent->GetLOT());
m_NextWaypoint = m_Parent->GetPosition();
@@ -73,7 +70,33 @@ MovementAIComponent::MovementAIComponent(Entity* parent, const int32_t component
}
// The level config: the attached path
// The MovementAIComponent row (an object made without one gets its info from the constructor)
void MovementAIComponent::LoadDataFromTemplate() {
if (m_ComponentID <= 0) return;
const auto componentID = m_ComponentID;
const auto moveAIComp = CDClientManager::GetTable<CDMovementAIComponentTable>()->Query([componentID](const CDMovementAIComponent& entry) { return (entry.id == componentID); });
if (moveAIComp.empty()) return;
m_Info.movementType = moveAIComp[0].MovementType;
m_Info.wanderRadius = moveAIComp[0].WanderRadius;
m_Info.wanderSpeed = moveAIComp[0].WanderSpeed;
m_Info.wanderChance = moveAIComp[0].WanderChance;
m_Info.wanderDelayMin = moveAIComp[0].WanderDelayMin;
m_Info.wanderDelayMax = moveAIComp[0].WanderDelayMax;
}
void MovementAIComponent::LoadConfigData() {
// The level's wanderRadius over the row's, unless usewanderdb
if (m_ComponentID > 0 && !m_Parent->GetVar<bool>(u"usewanderdb")) {
const auto wanderOverride = m_Parent->GetVarAs<float>(u"wanderRadius");
if (wanderOverride != 0.0f) m_Info.wanderRadius = wanderOverride;
}
//Try and fix the insane values:
if (m_Info.wanderRadius > 5.0f) m_Info.wanderRadius *= 0.5f;
if (m_Info.wanderRadius > 8.0f) m_Info.wanderRadius = 8.0f;
if (m_Info.wanderSpeed > 0.5f) m_Info.wanderSpeed *= 0.5f;
SetPath(m_Parent->GetVarAsString(u"attached_path"));
}

View File

@@ -66,6 +66,7 @@ public:
MovementAIComponent(Entity* parentEntity, const int32_t componentID, MovementAIInfo info);
void LoadDataFromTemplate() override;
void LoadConfigData() override;
void SetPath(const std::string pathName);

View File

@@ -1,4 +1,6 @@
#include "ProximityMonitorComponent.h"
#include "CDClientManager.h"
#include "CDProximityMonitorComponentTable.h"
#include "GameMessages.h"
#include "dZoneManager.h"
#include "ControllablePhysicsComponent.h"
@@ -17,6 +19,22 @@ ProximityMonitorComponent::ProximityMonitorComponent(Entity* parent, const int32
RegisterMsg(&ProximityMonitorComponent::OnGetObjectReportInfo);
}
// The ProximityMonitorComponent row's radii, "small,large" (one value, as LOT 9833's "4", is both): the rocket
// launch radii
void ProximityMonitorComponent::LoadDataFromTemplate() {
if (m_ComponentID <= 0) return;
const auto componentID = m_ComponentID;
const auto proxCompData = CDClientManager::GetTable<CDProximityMonitorComponentTable>()->Query([componentID](const CDProximityMonitorComponent& entry) { return (entry.id == componentID); });
if (proxCompData.empty()) return;
const auto radii = GeneralUtils::SplitString(proxCompData[0].Proximities, ',');
const auto small = radii.empty() ? std::nullopt : GeneralUtils::TryParse<int32_t>(radii[0]);
const auto large = radii.size() > 1 ? GeneralUtils::TryParse<int32_t>(radii[1]) : small;
if (!small || !large) return;
SetProximityRadius(*small, "rocketSmall");
SetProximityRadius(*large, "rocketLarge");
}
ProximityMonitorComponent::~ProximityMonitorComponent() {
for (const auto& en : m_ProximitiesData) {
if (!en.second) continue;

View File

@@ -25,6 +25,8 @@ public:
ProximityMonitorComponent(Entity* parentEntity, const int32_t componentID, int smallRadius = -1, int largeRadius = -1);
~ProximityMonitorComponent() override;
void LoadDataFromTemplate() override;
void Run(float deltaTime) override;
/**