format codebase

This commit is contained in:
aronwk-aaron
2022-07-28 08:39:57 -05:00
parent 4f7aa11067
commit 19e77a38d8
881 changed files with 34700 additions and 38689 deletions

View File

@@ -17,7 +17,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) :
m_Done = true;
m_BaseCombatAI = nullptr;
m_BaseCombatAI = reinterpret_cast<BaseCombatAIComponent*>(m_Parent->GetComponent(COMPONENT_TYPE_BASE_COMBAT_AI));
//Try and fix the insane values:
@@ -42,12 +42,11 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) :
MovementAIComponent::~MovementAIComponent() = default;
void MovementAIComponent::Update(const float deltaTime) {
if (m_Interrupted)
{
if (m_Interrupted) {
const auto source = GetCurrentWaypoint();
const auto speed = deltaTime * 2.5f;
NiPoint3 velocity;
velocity.x = (m_PullPoint.x - source.x) * speed;
@@ -56,21 +55,19 @@ void MovementAIComponent::Update(const float deltaTime) {
SetPosition(source + velocity);
if (Vector3::DistanceSquared(GetCurrentPosition(), m_PullPoint) < 2 * 2)
{
if (Vector3::DistanceSquared(GetCurrentPosition(), m_PullPoint) < 2 * 2) {
m_Interrupted = false;
}
return;
}
if (AtFinalWaypoint()) // Are we done?
{
return;
}
if (m_HaltDistance > 0)
{
if (m_HaltDistance > 0) {
if (Vector3::DistanceSquared(ApproximateLocation(), GetDestination()) < m_HaltDistance * m_HaltDistance) // Prevent us from hugging the target
{
Stop();
@@ -79,12 +76,10 @@ void MovementAIComponent::Update(const float deltaTime) {
}
}
if (m_Timer > 0)
{
if (m_Timer > 0) {
m_Timer -= deltaTime;
if (m_Timer > 0)
{
if (m_Timer > 0) {
return;
}
@@ -92,7 +87,7 @@ void MovementAIComponent::Update(const float deltaTime) {
}
const auto source = GetCurrentWaypoint();
SetPosition(source);
NiPoint3 velocity = NiPoint3::ZERO;
@@ -101,20 +96,17 @@ void MovementAIComponent::Update(const float deltaTime) {
{
m_NextWaypoint = GetCurrentWaypoint();
if (m_NextWaypoint == source)
{
if (m_NextWaypoint == source) {
m_Timer = 0;
goto nextAction;
}
if (m_CurrentSpeed < m_Speed)
{
if (m_CurrentSpeed < m_Speed) {
m_CurrentSpeed += m_Acceleration;
}
if (m_CurrentSpeed > m_Speed)
{
if (m_CurrentSpeed > m_Speed) {
m_CurrentSpeed = m_Speed;
}
@@ -125,8 +117,7 @@ void MovementAIComponent::Update(const float deltaTime) {
// Normalize the vector
const auto length = sqrtf(delta.x * delta.x + delta.y * delta.y + delta.z * delta.z);
if (length > 0)
{
if (length > 0) {
velocity.x = (delta.x / length) * speed;
velocity.y = (delta.y / length) * speed;
velocity.z = (delta.z / length) * speed;
@@ -134,80 +125,66 @@ void MovementAIComponent::Update(const float deltaTime) {
// Calclute the time it will take to reach the next waypoint with the current speed
m_TotalTime = m_Timer = length / speed;
SetRotation(NiQuaternion::LookAt(source, m_NextWaypoint));
}
else
{
} else {
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
if (!m_Queue.empty())
{
if (!m_Queue.empty()) {
SetDestination(m_Queue.top());
m_Queue.pop();
}
else
{
} else {
// We have reached our final waypoint
Stop();
return;
}
}
nextAction:
nextAction:
SetVelocity(velocity);
EntityManager::Instance()->SerializeEntity(m_Parent);
}
const MovementAIInfo& MovementAIComponent::GetInfo() const
{
const MovementAIInfo& MovementAIComponent::GetInfo() const {
return m_Info;
}
bool MovementAIComponent::AdvanceWaypointIndex()
{
if (m_PathIndex >= m_CurrentPath.size())
{
bool MovementAIComponent::AdvanceWaypointIndex() {
if (m_PathIndex >= m_CurrentPath.size()) {
return false;
}
m_PathIndex++;
return true;
}
NiPoint3 MovementAIComponent::GetCurrentWaypoint() const
{
if (m_PathIndex >= m_CurrentPath.size())
{
NiPoint3 MovementAIComponent::GetCurrentWaypoint() const {
if (m_PathIndex >= m_CurrentPath.size()) {
return GetCurrentPosition();
}
return m_CurrentPath[m_PathIndex];
}
NiPoint3 MovementAIComponent::GetNextWaypoint() const
{
NiPoint3 MovementAIComponent::GetNextWaypoint() const {
return m_NextWaypoint;
}
NiPoint3 MovementAIComponent::GetCurrentPosition() const
{
NiPoint3 MovementAIComponent::GetCurrentPosition() const {
return m_Parent->GetPosition();
}
NiPoint3 MovementAIComponent::ApproximateLocation() const
{
NiPoint3 MovementAIComponent::ApproximateLocation() const {
auto source = GetCurrentPosition();
if (m_Done)
{
if (m_Done) {
return source;
}
auto destination = m_NextWaypoint;
auto factor = m_TotalTime > 0 ? (m_TotalTime - m_Timer) / m_TotalTime : 0;
@@ -217,27 +194,23 @@ NiPoint3 MovementAIComponent::ApproximateLocation() const
auto z = source.z + factor * (destination.z - source.z);
NiPoint3 approximation = NiPoint3(x, y, z);
if (dpWorld::Instance().IsLoaded())
{
if (dpWorld::Instance().IsLoaded()) {
approximation.y = dpWorld::Instance().GetHeightAtPoint(approximation);
}
return approximation;
}
bool MovementAIComponent::Warp(const NiPoint3& point)
{
bool MovementAIComponent::Warp(const NiPoint3& point) {
Stop();
NiPoint3 destination = point;
if (dpWorld::Instance().IsLoaded())
{
if (dpWorld::Instance().IsLoaded()) {
destination.y = dpWorld::Instance().GetHeightAtPoint(point);
if (std::abs(destination.y - point.y) > 3)
{
if (std::abs(destination.y - point.y) > 3) {
return false;
}
}
@@ -249,29 +222,25 @@ bool MovementAIComponent::Warp(const NiPoint3& point)
return true;
}
float MovementAIComponent::GetTimer() const
{
float MovementAIComponent::GetTimer() const {
return m_Timer;
}
bool MovementAIComponent::AtFinalWaypoint() const
{
bool MovementAIComponent::AtFinalWaypoint() const {
return m_Done;
}
void MovementAIComponent::Stop()
{
if (m_Done)
{
void MovementAIComponent::Stop() {
if (m_Done) {
return;
}
SetPosition(ApproximateLocation());
SetVelocity(NiPoint3::ZERO);
m_TotalTime = m_Timer = 0;
m_Done = true;
m_CurrentPath = {};
@@ -279,24 +248,21 @@ void MovementAIComponent::Stop()
m_PathIndex = 0;
m_CurrentSpeed = 0;
EntityManager::Instance()->SerializeEntity(m_Parent);
}
void MovementAIComponent::PullToPoint(const NiPoint3& point)
{
void MovementAIComponent::PullToPoint(const NiPoint3& point) {
Stop();
m_Interrupted = true;
m_PullPoint = point;
}
void MovementAIComponent::SetPath(std::vector<NiPoint3> path)
{
void MovementAIComponent::SetPath(std::vector<NiPoint3> path) {
std::reverse(path.begin(), path.end());
for (const auto& point : path)
{
for (const auto& point : path) {
m_Queue.push(point);
}
@@ -305,26 +271,23 @@ void MovementAIComponent::SetPath(std::vector<NiPoint3> path)
m_Queue.pop();
}
float MovementAIComponent::GetBaseSpeed(LOT lot)
{
float MovementAIComponent::GetBaseSpeed(LOT lot) {
// Check if the lot is in the cache
const auto& it = m_PhysicsSpeedCache.find(lot);
if (it != m_PhysicsSpeedCache.end())
{
if (it != m_PhysicsSpeedCache.end()) {
return it->second;
}
CDComponentsRegistryTable* componentRegistryTable = CDClientManager::Instance()->GetTable<CDComponentsRegistryTable>("ComponentsRegistry");
CDPhysicsComponentTable* physicsComponentTable = CDClientManager::Instance()->GetTable<CDPhysicsComponentTable>("PhysicsComponent");
int32_t componentID;
CDPhysicsComponent* physicsComponent = nullptr;
componentID = componentRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_CONTROLLABLE_PHYSICS, -1);
componentID = componentRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_CONTROLLABLE_PHYSICS, -1);
if (componentID != -1)
{
if (componentID != -1) {
physicsComponent = physicsComponentTable->GetByID(componentID);
goto foundComponent;
@@ -332,23 +295,19 @@ float MovementAIComponent::GetBaseSpeed(LOT lot)
componentID = componentRegistryTable->GetByIDAndType(lot, COMPONENT_TYPE_SIMPLE_PHYSICS, -1);
if (componentID != -1)
{
if (componentID != -1) {
physicsComponent = physicsComponentTable->GetByID(componentID);
goto foundComponent;
}
foundComponent:
foundComponent:
float speed;
if (physicsComponent == nullptr)
{
if (physicsComponent == nullptr) {
speed = 8;
}
else
{
} else {
speed = physicsComponent->speed;
}
@@ -357,12 +316,10 @@ float MovementAIComponent::GetBaseSpeed(LOT lot)
return speed;
}
void MovementAIComponent::SetPosition(const NiPoint3& value)
{
void MovementAIComponent::SetPosition(const NiPoint3& value) {
auto* controllablePhysicsComponent = m_Parent->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr)
{
if (controllablePhysicsComponent != nullptr) {
controllablePhysicsComponent->SetPosition(value);
return;
@@ -370,23 +327,19 @@ void MovementAIComponent::SetPosition(const NiPoint3& value)
auto* simplePhysicsComponent = m_Parent->GetComponent<SimplePhysicsComponent>();
if (simplePhysicsComponent != nullptr)
{
if (simplePhysicsComponent != nullptr) {
simplePhysicsComponent->SetPosition(value);
}
}
void MovementAIComponent::SetRotation(const NiQuaternion& value)
{
if (m_LockRotation)
{
void MovementAIComponent::SetRotation(const NiQuaternion& value) {
if (m_LockRotation) {
return;
}
auto* controllablePhysicsComponent = m_Parent->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr)
{
if (controllablePhysicsComponent != nullptr) {
controllablePhysicsComponent->SetRotation(value);
return;
@@ -394,18 +347,15 @@ void MovementAIComponent::SetRotation(const NiQuaternion& value)
auto* simplePhysicsComponent = m_Parent->GetComponent<SimplePhysicsComponent>();
if (simplePhysicsComponent != nullptr)
{
if (simplePhysicsComponent != nullptr) {
simplePhysicsComponent->SetRotation(value);
}
}
void MovementAIComponent::SetVelocity(const NiPoint3& value)
{
void MovementAIComponent::SetVelocity(const NiPoint3& value) {
auto* controllablePhysicsComponent = m_Parent->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr)
{
if (controllablePhysicsComponent != nullptr) {
controllablePhysicsComponent->SetVelocity(value);
return;
@@ -413,19 +363,16 @@ void MovementAIComponent::SetVelocity(const NiPoint3& value)
auto* simplePhysicsComponent = m_Parent->GetComponent<SimplePhysicsComponent>();
if (simplePhysicsComponent != nullptr)
{
if (simplePhysicsComponent != nullptr) {
simplePhysicsComponent->SetVelocity(value);
}
}
void MovementAIComponent::SetDestination(const NiPoint3& value)
{
if (m_Interrupted)
{
void MovementAIComponent::SetDestination(const NiPoint3& value) {
if (m_Interrupted) {
return;
}
/*if (Vector3::DistanceSquared(value, GetDestination()) < 2 * 2)
{
return;
@@ -433,19 +380,15 @@ void MovementAIComponent::SetDestination(const NiPoint3& value)
const auto location = ApproximateLocation();
if (!AtFinalWaypoint())
{
if (!AtFinalWaypoint()) {
SetPosition(location);
}
std::vector<NiPoint3> computedPath;
if (dpWorld::Instance().IsLoaded())
{
if (dpWorld::Instance().IsLoaded()) {
computedPath = dpWorld::Instance().GetPath(GetCurrentPosition(), value, m_Info.wanderSpeed);
}
else
{
} else {
// Than take 10 points between the current position and the destination and make that the path
auto point = location;
@@ -454,8 +397,7 @@ void MovementAIComponent::SetDestination(const NiPoint3& value)
auto step = delta / 10;
for (int i = 0; i < 10; i++)
{
for (int i = 0; i < 10; i++) {
point = point + step;
computedPath.push_back(point);
@@ -472,10 +414,8 @@ void MovementAIComponent::SetDestination(const NiPoint3& value)
m_CurrentPath.push_back(location);
// Simply path
for (auto point : computedPath)
{
if (dpWorld::Instance().IsLoaded())
{
for (auto point : computedPath) {
if (dpWorld::Instance().IsLoaded()) {
point.y = dpWorld::Instance().GetHeightAtPoint(point);
}
@@ -483,71 +423,59 @@ void MovementAIComponent::SetDestination(const NiPoint3& value)
}
m_CurrentPath.push_back(computedPath[computedPath.size() - 1]);
m_PathIndex = 0;
m_TotalTime = m_Timer = 0;
m_Done = false;
}
NiPoint3 MovementAIComponent::GetDestination() const
{
if (m_CurrentPath.empty())
{
NiPoint3 MovementAIComponent::GetDestination() const {
if (m_CurrentPath.empty()) {
return GetCurrentPosition();
}
return m_CurrentPath[m_CurrentPath.size() - 1];
}
void MovementAIComponent::SetSpeed(const float value)
{
void MovementAIComponent::SetSpeed(const float value) {
m_Speed = value;
m_Acceleration = value / 5;
}
float MovementAIComponent::GetSpeed() const
{
float MovementAIComponent::GetSpeed() const {
return m_Speed;
}
void MovementAIComponent::SetAcceleration(const float value)
{
void MovementAIComponent::SetAcceleration(const float value) {
m_Acceleration = value;
}
float MovementAIComponent::GetAcceleration() const
{
float MovementAIComponent::GetAcceleration() const {
return m_Acceleration;
}
void MovementAIComponent::SetHaltDistance(const float value)
{
void MovementAIComponent::SetHaltDistance(const float value) {
m_HaltDistance = value;
}
float MovementAIComponent::GetHaltDistance() const
{
float MovementAIComponent::GetHaltDistance() const {
return m_HaltDistance;
}
void MovementAIComponent::SetCurrentSpeed(float value)
{
void MovementAIComponent::SetCurrentSpeed(float value) {
m_CurrentSpeed = value;
}
float MovementAIComponent::GetCurrentSpeed() const
{
float MovementAIComponent::GetCurrentSpeed() const {
return m_CurrentSpeed;
}
void MovementAIComponent::SetLockRotation(bool value)
{
void MovementAIComponent::SetLockRotation(bool value) {
m_LockRotation = value;
}
bool MovementAIComponent::GetLockRotation() const
{
bool MovementAIComponent::GetLockRotation() const {
return m_LockRotation;
}