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;