mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Many Fixes
This commit is contained in:
@@ -95,6 +95,22 @@
|
||||
-- * @{#CONTROLLABLE.TaskCondition}: Return a condition section for a controlled task.
|
||||
-- * @{#CONTROLLABLE.TaskControlled}: Return a Controlled Task taking a Task and a TaskCondition.
|
||||
--
|
||||
-- ### Call a function as a Task
|
||||
--
|
||||
-- A function can be called which is part of a Task. The method @{#CONTROLLABLE.TaskFunction}() prepares
|
||||
-- a Task that can call a GLOBAL function from within the Controller execution.
|
||||
-- This method can also be used to **embed a function call when a certain waypoint has been reached**.
|
||||
-- See below the **Tasks at Waypoints** section.
|
||||
--
|
||||
-- Demonstration Mission: [GRP-502 - Route at waypoint to random point](https://github.com/FlightControl-Master/MOOSE_MISSIONS/tree/release-2-2-pre/GRP - Group Commands/GRP-502 - Route at waypoint to random point)
|
||||
--
|
||||
-- ### Tasks at Waypoints
|
||||
--
|
||||
-- Special Task methods are available to set tasks at certain waypoints.
|
||||
-- The method @{#CONTROLLABLE.SetTaskAtWaypoint}() helps preparing a Route, embedding a Task at the Waypoint of the Route.
|
||||
--
|
||||
-- This creates a Task element, with an action to call a function as part of a Wrapped Task.
|
||||
--
|
||||
-- ### Obtain the mission from controllable templates
|
||||
--
|
||||
-- Controllable templates contain complete mission descriptions. Sometimes you want to copy a complete mission from a controllable and assign it to another:
|
||||
@@ -257,6 +273,16 @@ function CONTROLLABLE:GetLife0()
|
||||
return nil
|
||||
end
|
||||
|
||||
--- Returns relative amount of fuel (from 0.0 to 1.0) the unit has in its internal tanks.
|
||||
-- This method returns nil to ensure polymorphic behaviour! This method needs to be overridden by GROUP or UNIT.
|
||||
-- @param #CONTROLLABLE self
|
||||
-- @return #nil The CONTROLLABLE is not existing or alive.
|
||||
function CONTROLLABLE:GetFuel()
|
||||
self:F( self.ControllableName )
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -449,11 +475,11 @@ function CONTROLLABLE:TaskWrappedAction( DCSCommand, Index )
|
||||
self:F2( { DCSCommand } )
|
||||
|
||||
local DCSTaskWrappedAction
|
||||
|
||||
|
||||
DCSTaskWrappedAction = {
|
||||
id = "WrappedAction",
|
||||
enabled = true,
|
||||
number = Index,
|
||||
number = Index or 1,
|
||||
auto = false,
|
||||
params = {
|
||||
action = DCSCommand,
|
||||
@@ -464,6 +490,23 @@ function CONTROLLABLE:TaskWrappedAction( DCSCommand, Index )
|
||||
return DCSTaskWrappedAction
|
||||
end
|
||||
|
||||
--- Set a Task at a Waypoint using a Route list.
|
||||
-- @param #CONTROLLABLE self
|
||||
-- @param Wrapper.Controllable#CONTROLLABLE.RouteList RouteList A list of Waypoints.
|
||||
-- @param #number WaypointNumber The number of the Waypoint. The first Waypoint starts at 1!
|
||||
-- @param Dcs.DCSTasking.Task#Task Task The Task structure to be executed!
|
||||
-- @return Dcs.DCSTasking.Task#Task
|
||||
function CONTROLLABLE:SetTaskAtWaypoint( RouteList, WaypointNumber, Task )
|
||||
|
||||
RouteList[ WaypointNumber ].task = self:TaskCombo( { Task } )
|
||||
|
||||
self:T3( { RouteList[ WaypointNumber ].task } )
|
||||
return RouteList[ WaypointNumber ].task
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Executes a command action
|
||||
-- @param #CONTROLLABLE self
|
||||
-- @param Dcs.DCSCommand#Command DCSCommand
|
||||
@@ -1480,6 +1523,84 @@ function CONTROLLABLE:TaskEmbarkToTransport( Point, Radius )
|
||||
return DCSTask
|
||||
end
|
||||
|
||||
--- This creates a Task element, with an action to call a function as part of a Wrapped Task.
|
||||
-- This Task can then be embedded at a Waypoint by calling the method @{#CONTROLLABLE.SetTaskAtWaypoint}.
|
||||
-- @param #CONTROLLABLE self
|
||||
-- @param #string FunctionString The function name embedded as a string that will be called.
|
||||
-- @param ... The variable arguments passed to the function when called! These arguments can be of any type!
|
||||
-- @return #CONTROLLABLE
|
||||
-- @usage
|
||||
--
|
||||
-- local ZoneList = {
|
||||
-- ZONE:New( "ZONE1" ),
|
||||
-- ZONE:New( "ZONE2" ),
|
||||
-- ZONE:New( "ZONE3" ),
|
||||
-- ZONE:New( "ZONE4" ),
|
||||
-- ZONE:New( "ZONE5" )
|
||||
-- }
|
||||
--
|
||||
-- GroundGroup = GROUP:FindByName( "Vehicle" )
|
||||
--
|
||||
-- --- @param Wrapper.Group#GROUP GroundGroup
|
||||
-- function RouteToZone( Vehicle, ZoneRoute )
|
||||
--
|
||||
-- local Route = {}
|
||||
--
|
||||
-- Vehicle:E( { ZoneRoute = ZoneRoute } )
|
||||
--
|
||||
-- Vehicle:MessageToAll( "Moving to zone " .. ZoneRoute:GetName(), 10 )
|
||||
--
|
||||
-- -- Get the current coordinate of the Vehicle
|
||||
-- local FromCoord = Vehicle:GetCoordinate()
|
||||
--
|
||||
-- -- Select a random Zone and get the Coordinate of the new Zone.
|
||||
-- local RandomZone = ZoneList[ math.random( 1, #ZoneList ) ] -- Core.Zone#ZONE
|
||||
-- local ToCoord = RandomZone:GetCoordinate()
|
||||
--
|
||||
-- -- Create a "ground route point", which is a "point" structure that can be given as a parameter to a Task
|
||||
-- Route[#Route+1] = FromCoord:RoutePointGround( 72 )
|
||||
-- Route[#Route+1] = ToCoord:RoutePointGround( 60, "Vee" )
|
||||
--
|
||||
-- local TaskRouteToZone = Vehicle:TaskFunction( "RouteToZone", RandomZone )
|
||||
--
|
||||
-- Vehicle:SetTaskAtWaypoint( Route, #Route, TaskRouteToZone ) -- Set for the given Route at Waypoint 2 the TaskRouteToZone.
|
||||
--
|
||||
-- Vehicle:Route( Route, math.random( 10, 20 ) ) -- Move after a random seconds to the Route. See the Route method for details.
|
||||
--
|
||||
-- end
|
||||
--
|
||||
-- RouteToZone( GroundGroup, ZoneList[1] )
|
||||
--
|
||||
function CONTROLLABLE:TaskFunction( FunctionString, ... )
|
||||
self:F2( { FunctionString, arg } )
|
||||
|
||||
local DCSTask
|
||||
|
||||
local DCSScript = {}
|
||||
DCSScript[#DCSScript+1] = "local MissionControllable = GROUP:Find( ... ) "
|
||||
|
||||
if arg and arg.n > 0 then
|
||||
local ArgumentKey = tostring( arg )
|
||||
self:SetState( self, ArgumentKey, arg )
|
||||
DCSScript[#DCSScript+1] = "local Arguments = MissionControllable:GetState( MissionControllable, '" .. ArgumentKey .. "' ) "
|
||||
DCSScript[#DCSScript+1] = "MissionControllable:ClearState( MissionControllable, '" .. ArgumentKey .. "' ) "
|
||||
DCSScript[#DCSScript+1] = FunctionString .. "( MissionControllable, unpack( Arguments ) )"
|
||||
else
|
||||
DCSScript[#DCSScript+1] = FunctionString .. "( MissionControllable )"
|
||||
end
|
||||
|
||||
DCSTask = self:TaskWrappedAction(
|
||||
self:CommandDoScript(
|
||||
table.concat( DCSScript )
|
||||
)
|
||||
)
|
||||
|
||||
self:T( DCSTask )
|
||||
|
||||
return DCSTask
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- (AIR + GROUND) Return a mission task from a mission template.
|
||||
@@ -1620,19 +1741,16 @@ end
|
||||
|
||||
--- Make the controllable to follow a given route.
|
||||
-- @param #CONTROLLABLE self
|
||||
-- @param #table GoPoints A table of Route Points.
|
||||
-- @return #CONTROLLABLE self
|
||||
function CONTROLLABLE:Route( GoPoints )
|
||||
self:F2( GoPoints )
|
||||
-- @param #table Route A table of Route Points.
|
||||
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
|
||||
-- @return #CONTROLLABLE The CONTROLLABLE.
|
||||
function CONTROLLABLE:Route( Route, DelaySeconds )
|
||||
self:F2( Route )
|
||||
|
||||
local DCSControllable = self:GetDCSObject()
|
||||
|
||||
if DCSControllable then
|
||||
local Points = routines.utils.deepCopy( GoPoints )
|
||||
local MissionTask = { id = 'Mission', params = { route = { points = Points, }, }, }
|
||||
local Controller = self:_GetController()
|
||||
--Controller.setTask( Controller, MissionTask )
|
||||
self.TaskScheduler:Schedule( Controller, Controller.setTask, { MissionTask }, 1 )
|
||||
local RouteTask = self:TaskRoute( Route ) -- Create a RouteTask, that will route the CONTROLLABLE to the Route.
|
||||
self:SetTask( RouteTask, DelaySeconds or 1 ) -- Execute the RouteTask after the specified seconds (default is 1).
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -2321,37 +2439,11 @@ function CONTROLLABLE:WayPointFunction( WayPoint, WayPointIndex, WayPointFunctio
|
||||
self:F2( { WayPoint, WayPointIndex, WayPointFunction } )
|
||||
|
||||
table.insert( self.WayPoints[WayPoint].task.params.tasks, WayPointIndex )
|
||||
self.WayPoints[WayPoint].task.params.tasks[WayPointIndex] = self:TaskFunction( WayPoint, WayPointIndex, WayPointFunction, arg )
|
||||
self.WayPoints[WayPoint].task.params.tasks[WayPointIndex] = self:TaskFunction( WayPointFunction, arg )
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
function CONTROLLABLE:TaskFunction( WayPoint, WayPointIndex, FunctionString, FunctionArguments )
|
||||
self:F2( { WayPoint, WayPointIndex, FunctionString, FunctionArguments } )
|
||||
|
||||
local DCSTask
|
||||
|
||||
local DCSScript = {}
|
||||
DCSScript[#DCSScript+1] = "local MissionControllable = GROUP:Find( ... ) "
|
||||
|
||||
if FunctionArguments and #FunctionArguments > 0 then
|
||||
DCSScript[#DCSScript+1] = FunctionString .. "( MissionControllable, " .. table.concat( FunctionArguments, "," ) .. ")"
|
||||
else
|
||||
DCSScript[#DCSScript+1] = FunctionString .. "( MissionControllable )"
|
||||
end
|
||||
|
||||
DCSTask = self:TaskWrappedAction(
|
||||
self:CommandDoScript(
|
||||
table.concat( DCSScript )
|
||||
), WayPointIndex
|
||||
)
|
||||
|
||||
self:T( DCSTask )
|
||||
|
||||
return DCSTask
|
||||
|
||||
end
|
||||
|
||||
--- Executes the WayPoint plan.
|
||||
-- The function gets a WayPoint parameter, that you can use to restart the mission at a specific WayPoint.
|
||||
-- Note that when the WayPoint parameter is used, the new start mission waypoint of the controllable will be 1!
|
||||
|
||||
Reference in New Issue
Block a user