mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-23 22:13:35 +00:00
use indexes for pathing
This commit is contained in:
parent
20b2a62932
commit
bce87aaa06
@ -47,6 +47,7 @@ MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) :
|
||||
m_TimeTravelled = 0;
|
||||
m_CurrentSpeed = 0;
|
||||
m_MaxSpeed = 0;
|
||||
m_CurrentPathWaypointIndex = 0;
|
||||
m_LockRotation = false;
|
||||
}
|
||||
|
||||
@ -123,14 +124,11 @@ void MovementAIComponent::Update(const float deltaTime) {
|
||||
SetRotation(NiQuaternion::LookAt(source, m_NextWaypoint));
|
||||
} else {
|
||||
// Check if there are more waypoints in the queue, if so set our next destination to the next waypoint
|
||||
if (m_CurrentPath.empty()) {
|
||||
if (AdvancePathWaypointIndex()) {
|
||||
Stop();
|
||||
|
||||
return;
|
||||
}
|
||||
SetDestination(m_CurrentPath.top());
|
||||
|
||||
m_CurrentPath.pop();
|
||||
SetDestination(GetCurrentPathWaypoint());
|
||||
}
|
||||
|
||||
nextAction:
|
||||
@ -140,6 +138,11 @@ nextAction:
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
bool MovementAIComponent::AdvancePathWaypointIndex() {
|
||||
if (m_CurrentPathWaypointIndex < m_CurrentPath.size()) m_CurrentPathWaypointIndex++;
|
||||
return m_CurrentPathWaypointIndex < m_CurrentPath.size();
|
||||
}
|
||||
|
||||
const MovementAIInfo& MovementAIComponent::GetInfo() const {
|
||||
return m_Info;
|
||||
}
|
||||
@ -209,11 +212,12 @@ void MovementAIComponent::Stop() {
|
||||
m_AtFinalWaypoint = true;
|
||||
|
||||
m_InterpolatedWaypoints.clear();
|
||||
while (!m_CurrentPath.empty()) m_CurrentPath.pop();
|
||||
m_CurrentPath.clear();
|
||||
|
||||
m_PathIndex = 0;
|
||||
|
||||
m_CurrentSpeed = 0;
|
||||
m_CurrentPathWaypointIndex = 0;
|
||||
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
@ -227,11 +231,11 @@ void MovementAIComponent::PullToPoint(const NiPoint3& point) {
|
||||
|
||||
void MovementAIComponent::SetPath(std::vector<NiPoint3> path) {
|
||||
if (path.empty()) return;
|
||||
std::for_each(path.rbegin(), path.rend() - 1, [this](const NiPoint3& point) {
|
||||
this->m_CurrentPath.push(point);
|
||||
});
|
||||
m_CurrentPath = path;
|
||||
|
||||
SetDestination(path.front());
|
||||
m_CurrentPathWaypointIndex = 0;
|
||||
|
||||
SetDestination(m_CurrentPath.front());
|
||||
}
|
||||
|
||||
float MovementAIComponent::GetBaseSpeed(LOT lot) {
|
||||
|
@ -191,6 +191,10 @@ public:
|
||||
*/
|
||||
void SetPath(std::vector<NiPoint3> path);
|
||||
|
||||
bool AdvancePathWaypointIndex();
|
||||
|
||||
const NiPoint3& GetCurrentPathWaypoint() const { return m_CurrentPathWaypointIndex < m_CurrentPath.size() ? m_CurrentPath.at(m_CurrentPathWaypointIndex) : m_Parent->GetPosition(); }
|
||||
|
||||
/**
|
||||
* Returns the base speed from the DB for a given LOT
|
||||
* @param lot the lot to check for
|
||||
@ -301,7 +305,12 @@ private:
|
||||
/**
|
||||
* The path from the current position to the destination.
|
||||
*/
|
||||
std::stack<NiPoint3> m_CurrentPath;
|
||||
std::vector<NiPoint3> m_CurrentPath;
|
||||
|
||||
/**
|
||||
* The index of the current waypoint in the path
|
||||
*/
|
||||
uint32_t m_CurrentPathWaypointIndex;
|
||||
};
|
||||
|
||||
#endif // MOVEMENTAICOMPONENT_H
|
||||
|
@ -301,9 +301,9 @@ void SGCannon::OnActivityTimerDone(Entity* self, const std::string& name) {
|
||||
pathWaypoints.push_back(waypoint.position);
|
||||
}
|
||||
|
||||
if (GeneralUtils::GenerateRandomNumber<float_t>(0, 1) < 0.5f) {
|
||||
std::reverse(pathWaypoints.begin(), pathWaypoints.end());
|
||||
}
|
||||
// if (GeneralUtils::GenerateRandomNumber<float_t>(0, 1) < 0.5f) {
|
||||
// std::reverse(pathWaypoints.begin(), pathWaypoints.end());
|
||||
// }
|
||||
|
||||
movementAI->SetPath(pathWaypoints);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user