From cc7a1b3640d2bd9ae95be227c9b4067ef632ffc8 Mon Sep 17 00:00:00 2001 From: Aaron Kimbrell Date: Sat, 28 Nov 2026 05:15:04 -0600 Subject: [PATCH] feat(ai): shared Lua AI runs its waypoint actions Objects on the Lua AI (unless Set.SuspendLuaMovementAI) get the waypoint's actions in Arrived, in order with empty values nil, run them in the WayPointEvent state and send ContinueWaypoints themselves; the movement AI only waits for it. The actions the Lua hands on run through the movement AI's handlers. isLastPoint is the path's last waypoint on every path. Co-Authored-By: Claude Opus 5.5 --- dScripts/ai/LuaAI/LuaAIScript.cpp | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/dScripts/ai/LuaAI/LuaAIScript.cpp b/dScripts/ai/LuaAI/LuaAIScript.cpp index db0f6beca..00997d267 100644 --- a/dScripts/ai/LuaAI/LuaAIScript.cpp +++ b/dScripts/ai/LuaAI/LuaAIScript.cpp @@ -176,16 +176,19 @@ namespace { if (movement && !path.empty()) movement->SetPath(path, start); } - // MovementAIComponent goes on along the path by itself - void ContinueWaypoints() override {} + void ContinueWaypoints() override { + auto* const movement = m_Self->GetComponent(); + if (movement) movement->ContinueWaypoints(); + } float GetAnimationTime(const std::u16string& animation) const override { return RenderComponent::GetAnimationTime(m_Self, animation); } - // MovementAIComponent runs the waypoint commands itself, so the waypoints this binding reports have no actions - void RunWaypointAction(const std::string& name, const std::string&, std::optional) override { - LOG_DEBUG("Lua AI waypoint action %s on %llu is run by the movement AI", name.c_str(), m_Self->GetObjectID()); + // The actions the shared Lua hands to the object's own handlers, as the movement AI runs them + void RunWaypointAction(const std::string& name, const std::string& value, std::optional) override { + auto* const movement = m_Self->GetComponent(); + if (movement) movement->RunWaypointAction(name, value == LuaAI::NO_VALUE ? "" : value); } LWOOBJID GetObjectID() const override { return m_Self->GetObjectID(); } @@ -268,6 +271,9 @@ void LuaAIScript::StartLuaAI(Entity* self, const LuaAI::Settings& settings) { withConfig.hasGroupID = !self->GetVarAsString(u"groupID").empty(); auto& brain = g_Brains[self->GetObjectID()]; brain = std::make_unique(self, withConfig, managed); + // The Lua AI runs the waypoint actions and sends ContinueWaypoints itself, unless SuspendLuaMovementAI + auto* const movement = self->GetComponent(); + if (movement) movement->SetScriptRunsWaypointActions(!settings.suspendLuaMovementAI); brain->machine.Start(); } @@ -312,8 +318,14 @@ void LuaAIScript::OnWaypointReached(Entity* self, const uint32_t waypointIndex) msg.wayPoint = waypointIndex; if (path) { msg.pathName = path->pathName; - // Loop and bounce paths have no end - msg.isLastPoint = path->pathBehavior == PathBehavior::Once && waypointIndex + 1 >= path->pathWaypoints.size(); + msg.isLastPoint = waypointIndex + 1 == path->pathWaypoints.size(); + // The waypoint's config in order; an empty value is nil + if (waypointIndex < path->pathWaypoints.size() && !path->pathWaypoints[waypointIndex].actions.empty()) { + auto& actions = msg.actions.emplace(); + for (const auto& [name, value] : path->pathWaypoints[waypointIndex].actions) { + actions.push_back({ name, value.empty() ? LuaAI::NO_VALUE : value }); + } + } } // The end of the path is this arrival, not another one once the movement is done brain->host.moving = false;