Add mandlers for all the trigger related waypoint commands

And add a call to the cppscript for reaching a waypoint
This commit is contained in:
Aronwk 2025-06-13 01:05:12 -05:00
parent 2f315d9288
commit 2eeacbf746
3 changed files with 78 additions and 10 deletions

View File

@ -66,6 +66,67 @@ void MovementAIComponent::SetPath(const std::string pathName) {
SetMaxSpeed(1); SetMaxSpeed(1);
SetCurrentSpeed(m_BaseSpeed); SetCurrentSpeed(m_BaseSpeed);
SetPath(m_Path->pathWaypoints); SetPath(m_Path->pathWaypoints);
auto start_index = m_Parent->GetVarAs<uint32_t>(u"attached_path_start");
if (start_index >= m_Path->waypointCount) start_index = 0;
SetDestination(m_Path->pathWaypoints[m_PathIndex].position);
m_PathIndex = start_index;
}
void MovementAIComponent::SetPath(const std::string pathName, uint32_t startIndex, bool reverse) {
m_Path = Game::zoneManager->GetZone()->GetPath(pathName);
if (!pathName.empty()) LOG("WARNING: %s path %s", m_Path ? "Found" : "Failed to find", pathName.c_str());
if (!m_Path) return;
SetMaxSpeed(1);
SetCurrentSpeed(m_BaseSpeed);
if (reverse) {
m_IsBounced = !m_IsBounced;
auto pathWaypoints = m_Path->pathWaypoints;
std::reverse(pathWaypoints.begin(), pathWaypoints.end());
SetPath(pathWaypoints);
} else {
SetPath(m_Path->pathWaypoints);
}
SetDestination(m_Path->pathWaypoints[startIndex].position);
m_PathIndex = startIndex;
}
void MovementAIComponent::TurnAroundOnPath() {
if (m_Path) {
auto currentIndex = m_PathIndex;
m_IsBounced = !m_IsBounced;
std::vector<PathWaypoint> waypoints = m_Path->pathWaypoints;
if (m_IsBounced) std::reverse(waypoints.begin(), waypoints.end());
SetPath(waypoints);
SetDestination(waypoints[currentIndex].position);
m_PathIndex = currentIndex;
}
}
void MovementAIComponent::GoForwardOnPath() {
if (m_Path) {
auto currentIndex = m_PathIndex;
m_IsBounced = false;
SetPath(m_Path->pathWaypoints);
SetDestination(m_Path->pathWaypoints[currentIndex].position);
m_PathIndex = currentIndex;
}
}
void MovementAIComponent::GoBackwardOnPath() {
if (m_Path) {
auto currentIndex = m_PathIndex;
m_IsBounced = true;
std::vector<PathWaypoint> waypoints = m_Path->pathWaypoints;
std::reverse(waypoints.begin(), waypoints.end());
SetPath(waypoints);
SetDestination(waypoints[currentIndex].position);
m_PathIndex = currentIndex;
}
} }
void MovementAIComponent::Pause() { void MovementAIComponent::Pause() {
@ -188,7 +249,7 @@ bool MovementAIComponent::AdvanceWaypointIndex() {
if (m_PathIndex >= m_InterpolatedWaypoints.size()) { if (m_PathIndex >= m_InterpolatedWaypoints.size()) {
return false; return false;
} }
m_Parent->GetScript()->OnWaypointReached(m_Parent, m_PathIndex);
m_PathIndex++; m_PathIndex++;
return true; return true;

View File

@ -65,6 +65,10 @@ public:
MovementAIComponent(Entity* parentEntity, MovementAIInfo info); MovementAIComponent(Entity* parentEntity, MovementAIInfo info);
void SetPath(const std::string pathName); void SetPath(const std::string pathName);
void SetPath(const std::string pathName, uint32_t startIndex, bool reverse);
void TurnAroundOnPath();
void GoForwardOnPath();
void GoBackwardOnPath();
void Update(float deltaTime) override; void Update(float deltaTime) override;

View File

@ -457,40 +457,43 @@ void TriggerComponent::HandleActivatePhysics(Entity* targetEntity, std::string a
void TriggerComponent::HandleSetPath(Entity* targetEntity, std::vector<std::string> argArray) { void TriggerComponent::HandleSetPath(Entity* targetEntity, std::vector<std::string> argArray) {
auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>(); auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>();
if (!movementAIComponent) return; if (!movementAIComponent) return;
// movementAIComponent->SetupPath(argArray.at(0)); uint32_t start_index = 0;
bool reverse = false;
if (argArray.size() >= 2) { if (argArray.size() >= 2) {
auto index = GeneralUtils::TryParse<int32_t>(argArray.at(1)); auto index = GeneralUtils::TryParse<int32_t>(argArray.at(1));
if (!index) return; if (index) {
// movementAIComponent->SetPathStartingWaypointIndex(index.value()); start_index = index.value();
}
} }
if (argArray.size() >= 3 && argArray.at(2) == "1") { if (argArray.size() >= 3 && argArray.at(2) == "1") {
// movementAIComponent->ReversePath(); reverse = true;
} }
movementAIComponent->SetPath(argArray.at(0), start_index, reverse);
} }
void TriggerComponent::HandleTurnAroundOnPath(Entity* targetEntity) { void TriggerComponent::HandleTurnAroundOnPath(Entity* targetEntity) {
auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>(); auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>();
// if (movementAIComponent) movementAIComponent->ReversePath(); if (movementAIComponent) movementAIComponent->TurnAroundOnPath();
} }
void TriggerComponent::HandleGoForwardOnPath(Entity* targetEntity) { void TriggerComponent::HandleGoForwardOnPath(Entity* targetEntity) {
auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>(); auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>();
if (!movementAIComponent) return; if (!movementAIComponent) return;
// if (movementAIComponent->GetIsInReverse()) movementAIComponent->ReversePath(); movementAIComponent->GoForwardOnPath();
} }
void TriggerComponent::HandleGoBackwardOnPath(Entity* targetEntity) { void TriggerComponent::HandleGoBackwardOnPath(Entity* targetEntity) {
auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>(); auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>();
if (!movementAIComponent) return; if (!movementAIComponent) return;
// if (!movementAIComponent->GetIsInReverse()) movementAIComponent->ReversePath(); movementAIComponent->GoBackwardOnPath();
} }
void TriggerComponent::HandleStopPathing(Entity* targetEntity) { void TriggerComponent::HandleStopPathing(Entity* targetEntity) {
auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>(); auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>();
// if (movementAIComponent) movementAIComponent->Pause(); if (movementAIComponent) movementAIComponent->Pause();
} }
void TriggerComponent::HandleStartPathing(Entity* targetEntity) { void TriggerComponent::HandleStartPathing(Entity* targetEntity) {
auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>(); auto* movementAIComponent = targetEntity->GetComponent<MovementAIComponent>();
// if (movementAIComponent) movementAIComponent->Resume(); if (movementAIComponent) movementAIComponent->Resume();
} }