Working built in reverse for movementAI

This commit is contained in:
David Markowitz 2023-08-06 23:40:30 -07:00
parent 3e12dd782b
commit 6a5ff30a32
4 changed files with 19 additions and 8 deletions

View File

@ -143,10 +143,10 @@ nextAction:
bool MovementAIComponent::AdvancePathWaypointIndex() { bool MovementAIComponent::AdvancePathWaypointIndex() {
m_CurrentPathWaypointIndex = m_NextPathWaypointIndex; m_CurrentPathWaypointIndex = m_NextPathWaypointIndex;
if (m_IsInReverse) { if (m_IsInReverse) {
if (m_CurrentPathWaypointIndex > 0) m_NextPathWaypointIndex--; if (m_CurrentPathWaypointIndex >= 0) m_NextPathWaypointIndex--;
return m_NextPathWaypointIndex >= 0; return m_CurrentPathWaypointIndex >= 0;
} else { } else {
if (m_CurrentPathWaypointIndex < m_CurrentPath.size()) m_NextPathWaypointIndex++; if (m_CurrentPathWaypointIndex <= m_CurrentPath.size()) m_NextPathWaypointIndex++;
return m_CurrentPathWaypointIndex < m_CurrentPath.size(); return m_CurrentPathWaypointIndex < m_CurrentPath.size();
} }
} }
@ -237,6 +237,13 @@ void MovementAIComponent::PullToPoint(const NiPoint3& point) {
m_PullPoint = point; m_PullPoint = point;
} }
const NiPoint3& MovementAIComponent::GetCurrentPathWaypoint() const {
if (m_CurrentPathWaypointIndex >= m_CurrentPath.size() || m_CurrentPathWaypointIndex < 0) {
return m_Parent->GetPosition();
}
return m_CurrentPath.at(m_CurrentPathWaypointIndex);
}
void MovementAIComponent::SetPath(std::vector<NiPoint3> path, bool startInReverse) { void MovementAIComponent::SetPath(std::vector<NiPoint3> path, bool startInReverse) {
if (path.empty()) return; if (path.empty()) return;
m_CurrentPath = path; m_CurrentPath = path;
@ -247,7 +254,7 @@ void MovementAIComponent::SetPath(std::vector<NiPoint3> path, bool startInRevers
m_CurrentPathWaypointIndex = m_IsInReverse ? m_CurrentPath.size() - 1 : 0; m_CurrentPathWaypointIndex = m_IsInReverse ? m_CurrentPath.size() - 1 : 0;
m_NextPathWaypointIndex = m_IsInReverse ? m_CurrentPath.size() - 1 : 0; m_NextPathWaypointIndex = m_IsInReverse ? m_CurrentPath.size() - 1 : 0;
AdvancePathWaypointIndex(); AdvancePathWaypointIndex();
SetDestination(m_CurrentPath.front()); SetDestination(GetCurrentPathWaypoint());
} }
float MovementAIComponent::GetBaseSpeed(LOT lot) { float MovementAIComponent::GetBaseSpeed(LOT lot) {

View File

@ -194,7 +194,7 @@ public:
// Advance the path waypoint index and return if there is a next waypoint // Advance the path waypoint index and return if there is a next waypoint
bool AdvancePathWaypointIndex(); bool AdvancePathWaypointIndex();
const NiPoint3& GetCurrentPathWaypoint() const { return m_CurrentPathWaypointIndex < m_CurrentPath.size() ? m_CurrentPath.at(m_CurrentPathWaypointIndex) : m_Parent->GetPosition(); } const NiPoint3& GetCurrentPathWaypoint() const;
/** /**
* Returns the base speed from the DB for a given LOT * Returns the base speed from the DB for a given LOT
@ -311,13 +311,16 @@ private:
/** /**
* The index of the current waypoint in the path * The index of the current waypoint in the path
*/ */
uint32_t m_CurrentPathWaypointIndex; int32_t m_CurrentPathWaypointIndex;
/** /**
* The index of the current waypoint in the path * The index of the current waypoint in the path
*/ */
uint32_t m_NextPathWaypointIndex; int32_t m_NextPathWaypointIndex;
/**
* Whether or not the path is being read in reverse
*/
bool m_IsInReverse; bool m_IsInReverse;
}; };

View File

@ -348,6 +348,7 @@ int main(int argc, char** argv) {
Game::im->GetInstance(0, false, 0); Game::im->GetInstance(0, false, 0);
Game::im->GetInstance(1000, false, 0); Game::im->GetInstance(1000, false, 0);
Game::im->GetInstance(1300, false, 0);
StartAuthServer(); StartAuthServer();
} }

View File

@ -301,7 +301,7 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) {
pathWaypoints.push_back(waypoint.position); pathWaypoints.push_back(waypoint.position);
} }
movementAI->SetPath(pathWaypoints, true); movementAI->SetPath(pathWaypoints, GeneralUtils::GenerateRandomNumber<float>(0, 1) > 0.5f);
enemy->AddDieCallback([this, self, enemy, name]() { enemy->AddDieCallback([this, self, enemy, name]() {
RegisterHit(self, enemy, name); RegisterHit(self, enemy, name);