fix: movement ai remove goto, do todo, remove unused call (#1505)

* remove goto

* Update MovementAIComponent.cpp
This commit is contained in:
David Markowitz 2024-03-24 20:24:38 -07:00 committed by GitHub
parent 3262bc3a86
commit 2b253a8248
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 30 deletions

View File

@ -162,7 +162,6 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
// Check if we should stop the tether effect // Check if we should stop the tether effect
if (m_TetherEffectActive) { if (m_TetherEffectActive) {
m_TetherTime -= deltaTime; m_TetherTime -= deltaTime;
const auto& info = m_MovementAI->GetInfo();
if (m_Target != LWOOBJID_EMPTY || (NiPoint3::DistanceSquared( if (m_Target != LWOOBJID_EMPTY || (NiPoint3::DistanceSquared(
m_StartPosition, m_StartPosition,
m_Parent->GetPosition()) < 20 * 20 && m_TetherTime <= 0) m_Parent->GetPosition()) < 20 * 20 && m_TetherTime <= 0)

View File

@ -96,33 +96,29 @@ void MovementAIComponent::Update(const float deltaTime) {
if (m_NextWaypoint == source) { if (m_NextWaypoint == source) {
m_TimeToTravel = 0.0f; m_TimeToTravel = 0.0f;
} else {
if (m_CurrentSpeed < m_MaxSpeed) {
m_CurrentSpeed += m_Acceleration;
}
goto nextAction; m_CurrentSpeed = std::min(m_CurrentSpeed, m_MaxSpeed);
const auto speed = m_CurrentSpeed * m_BaseSpeed; // scale speed based on base speed
const auto delta = m_NextWaypoint - source;
// Normalize the vector
const auto length = delta.Length();
if (length > 0.0f) {
velocity = (delta / length) * speed;
}
// Calclute the time it will take to reach the next waypoint with the current speed
m_TimeTravelled = 0.0f;
m_TimeToTravel = length / speed;
SetRotation(NiQuaternion::LookAt(source, m_NextWaypoint));
} }
if (m_CurrentSpeed < m_MaxSpeed) {
m_CurrentSpeed += m_Acceleration;
}
if (m_CurrentSpeed > m_MaxSpeed) {
m_CurrentSpeed = m_MaxSpeed;
}
const auto speed = m_CurrentSpeed * m_BaseSpeed; // scale speed based on base speed
const auto delta = m_NextWaypoint - source;
// Normalize the vector
const auto length = delta.Length();
if (length > 0) {
velocity = (delta / length) * speed;
}
// Calclute the time it will take to reach the next waypoint with the current speed
m_TimeTravelled = 0.0f;
m_TimeToTravel = 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 // Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
if (m_CurrentPath.empty()) { if (m_CurrentPath.empty()) {
@ -135,8 +131,6 @@ void MovementAIComponent::Update(const float deltaTime) {
m_CurrentPath.pop(); m_CurrentPath.pop();
} }
nextAction:
SetVelocity(velocity); SetVelocity(velocity);
Game::entityManager->SerializeEntity(m_Parent); Game::entityManager->SerializeEntity(m_Parent);
@ -319,8 +313,7 @@ void MovementAIComponent::SetDestination(const NiPoint3& destination) {
auto step = delta / 10.0f; auto step = delta / 10.0f;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
// TODO: Replace this with += when the NiPoint3::operator+= is fixed start += step;
start = start + step;
computedPath.push_back(start); computedPath.push_back(start);
} }