mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
Implemented a WayPoints functionality for GROUPS
WayPoints can be modified on a GROUP. A function hook is called whenever a group moves over a waypoint.
This commit is contained in:
155
Moose/Group.lua
155
Moose/Group.lua
@@ -20,6 +20,7 @@ GROUP = {
|
||||
GroupID = 0,
|
||||
Controller = nil,
|
||||
DCSGroup = nil,
|
||||
WayPointFunctions = {},
|
||||
}
|
||||
|
||||
--- A DCSGroup
|
||||
@@ -91,6 +92,85 @@ function GROUP:NewFromDCSUnit( DCSUnit )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Retrieve the group mission and allow to place function hooks within the mission waypoint plan.
|
||||
-- Use the method @{Group#GROUP:WayPointFunction} to define the hook functions for specific waypoints.
|
||||
-- Use the method @{Group@GROUP:WayPointExecute) to start the execution of the new mission plan.
|
||||
-- Note that when WayPointInitialize is called, the Mission of the group is RESTARTED!
|
||||
-- @param #GROUP self
|
||||
-- @param #number WayPoint
|
||||
-- @return #GROUP
|
||||
function GROUP:WayPointInitialize()
|
||||
|
||||
self.WayPoints = self:GetTaskRoute()
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
--- Registers a waypoint function that will be executed when the group moves over the WayPoint.
|
||||
-- @param #GROUP self
|
||||
-- @param #number WayPoint The waypoint number. Note that the start waypoint on the route is WayPoint 1!
|
||||
-- @param #number WayPointIndex When defining multiple WayPoint functions for one WayPoint, use WayPointIndex to set the sequence of actions.
|
||||
-- @param #function WayPointFunction The waypoint function to be called when the group moves over the waypoint. The waypoint function takes variable parameters.
|
||||
-- @return #GROUP
|
||||
function GROUP:WayPointFunction( WayPoint, WayPointIndex, WayPointFunction, ... )
|
||||
self:F( { 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 )
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
function GROUP:TaskFunction( WayPoint, WayPointIndex, FunctionString, FunctionArguments )
|
||||
|
||||
local DCSTask
|
||||
|
||||
local DCSScript = {}
|
||||
DCSScript[#DCSScript+1] = "local MissionGroup = GROUP.FindGroup( ... ) "
|
||||
DCSScript[#DCSScript+1] = FunctionString .. "( MissionGroup, " .. table.concat( FunctionArguments, "," ) .. ")"
|
||||
|
||||
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 group will be 1!
|
||||
-- @param #GROUP self
|
||||
-- @param #number WayPoint The WayPoint from where to execute the mission.
|
||||
-- @param #WaitTime The amount seconds to wait before initiating the mission.
|
||||
-- @return #GROUP
|
||||
function GROUP:WayPointExecute( WayPoint, WaitTime )
|
||||
|
||||
if not WayPoint then
|
||||
WayPoint = 1
|
||||
end
|
||||
|
||||
-- When starting the mission from a certain point, the TaskPoints need to be deleted before the given WayPoint.
|
||||
for TaskPointID = 1, WayPoint - 1 do
|
||||
table.remove( self.WayPoints, 1 )
|
||||
end
|
||||
|
||||
self:T( self.WayPoints )
|
||||
|
||||
self:SetTask( self:TaskRoute( self.WayPoints ), WaitTime )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
|
||||
|
||||
--- Gets the DCSGroup of the GROUP.
|
||||
-- @param #GROUP self
|
||||
-- @return DCSGroup#Group The DCSGroup.
|
||||
@@ -386,12 +466,20 @@ end
|
||||
--- Pushing Task on the queue from the group.
|
||||
-- @param #GROUP self
|
||||
-- @return Group#GROUP self
|
||||
function GROUP:PushTask( DCSTask )
|
||||
function GROUP:PushTask( DCSTask, WaitTime )
|
||||
self:F()
|
||||
|
||||
local Controller = self:_GetController()
|
||||
|
||||
Controller:pushTask( DCSTask )
|
||||
-- When a group SPAWNs, it takes about a second to get the group in the simulator. Setting tasks to unspawned groups provides unexpected results.
|
||||
-- Therefore we schedule the functions to set the mission and options for the Group.
|
||||
-- Controller:pushTask( DCSTask )
|
||||
|
||||
if not WaitTime then
|
||||
Controller:pushTask( DCSTask )
|
||||
else
|
||||
routines.scheduleFunction( Controller.pushTask, { Controller, DCSTask }, timer.getTime() + WaitTime )
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
@@ -399,13 +487,20 @@ end
|
||||
--- Clearing the Task Queue and Setting the Task on the queue from the group.
|
||||
-- @param #GROUP self
|
||||
-- @return Group#GROUP self
|
||||
function GROUP:SetTask( DCSTask )
|
||||
function GROUP:SetTask( DCSTask, WaitTime )
|
||||
self:F( { DCSTask } )
|
||||
|
||||
local Controller = self:_GetController()
|
||||
|
||||
Controller:setTask( DCSTask )
|
||||
-- When a group SPAWNs, it takes about a second to get the group in the simulator. Setting tasks to unspawned groups provides unexpected results.
|
||||
-- Therefore we schedule the functions to set the mission and options for the Group.
|
||||
-- Controller.setTask( Controller, DCSTask )
|
||||
|
||||
if not WaitTime then
|
||||
WaitTime = 1
|
||||
end
|
||||
routines.scheduleFunction( Controller.setTask, { Controller, DCSTask }, timer.getTime() + WaitTime )
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -480,7 +575,7 @@ end
|
||||
-- @param #GROUP self
|
||||
-- @param DCSCommand#Command DCSCommand
|
||||
-- @return DCSTask#Task
|
||||
function GROUP:TaskWrappedAction( DCSCommand )
|
||||
function GROUP:TaskWrappedAction( DCSCommand, Index )
|
||||
self:F( { DCSCommand } )
|
||||
|
||||
local DCSTaskWrappedAction
|
||||
@@ -488,9 +583,11 @@ function GROUP:TaskWrappedAction( DCSCommand )
|
||||
DCSTaskWrappedAction = {
|
||||
id = "WrappedAction",
|
||||
enabled = true,
|
||||
number = Index,
|
||||
auto = false,
|
||||
params = {
|
||||
action = DCSCommand
|
||||
}
|
||||
action = DCSCommand,
|
||||
},
|
||||
}
|
||||
|
||||
self:T( { DCSTaskWrappedAction } )
|
||||
@@ -593,10 +690,15 @@ end
|
||||
-- @param Zone#ZONE Zone The zone where to land.
|
||||
-- @param #number Duration The duration in seconds to stay on the ground.
|
||||
-- @return #GROUP self
|
||||
function GROUP:TaskLandAtZone( Zone, Duration )
|
||||
self:F( { self.GroupName, Zone, Duration } )
|
||||
function GROUP:TaskLandAtZone( Zone, Duration, RandomPoint )
|
||||
self:F( { self.GroupName, Zone, Duration, RandomPoint } )
|
||||
|
||||
local Point = Zone:GetPointVec2()
|
||||
local Point
|
||||
if RandomPoint then
|
||||
Point = Zone:GetRandomPointVec2()
|
||||
else
|
||||
Point = Zone:GetPointVec2()
|
||||
end
|
||||
|
||||
local DCSTask = self:TaskLandAtVec2( Point, Duration )
|
||||
|
||||
@@ -813,26 +915,7 @@ function GROUP:Route( GoPoints )
|
||||
return self
|
||||
end
|
||||
|
||||
--- Registers a Task to be executed at a waypoint.
|
||||
-- @param #GROUP self
|
||||
-- @param #number WayPoint The waypoint where to execute the task.
|
||||
-- @return #string The task.
|
||||
function GROUP:TaskRegisterWayPoint( WayPoint )
|
||||
|
||||
local DCSTask
|
||||
|
||||
DCSTask = self:TaskWrappedAction(
|
||||
self:CommandDoScript(
|
||||
"local MissionGroup = GROUP:New( ... ) " ..
|
||||
"env.info( MissionGroup:GetName() ) " ..
|
||||
"MissionGroup:RegisterWayPoint ( " .. WayPoint .. " )"
|
||||
)
|
||||
)
|
||||
|
||||
self:T( DCSTask )
|
||||
|
||||
return DCSTask
|
||||
end
|
||||
|
||||
--- Route the group to a given zone.
|
||||
-- The group final destination point can be randomized.
|
||||
@@ -860,7 +943,7 @@ function GROUP:TaskRouteToZone( Zone, Randomize, Speed, Formation )
|
||||
local ZonePoint
|
||||
|
||||
if Randomize then
|
||||
ZonePoint = Zone:GetRandomPoint()
|
||||
ZonePoint = Zone:GetRandomPointVec2()
|
||||
else
|
||||
ZonePoint = Zone:GetPointVec2()
|
||||
end
|
||||
@@ -901,8 +984,8 @@ function GROUP:CommandDoScript( DoScript )
|
||||
local DCSDoScript = {
|
||||
id = "Script",
|
||||
params = {
|
||||
command = DoScript
|
||||
}
|
||||
command = DoScript,
|
||||
},
|
||||
}
|
||||
|
||||
self:T( DCSDoScript )
|
||||
@@ -1260,7 +1343,7 @@ end
|
||||
function GROUP:Message( Message, Duration )
|
||||
self:F( { Message, Duration } )
|
||||
|
||||
return MESSAGE:New( Message, self:GetCallsign() .. "(" .. self:GetTypeName() .. ")", Duration, self:GetClassNameAndID() )
|
||||
return MESSAGE:New( Message, self:GetCallsign() .. " (" .. self:GetTypeName() .. ")", Duration, self:GetClassNameAndID() )
|
||||
end
|
||||
|
||||
--- Send a message to all coalitions.
|
||||
@@ -1308,12 +1391,6 @@ function GROUP:MessageToClient( Message, Duration, Client )
|
||||
self:Message( Message, Duration ):ToClient( Client )
|
||||
end
|
||||
|
||||
function GROUP:RegisterWayPoint( WayPoint )
|
||||
|
||||
self:Message( "Moving over wayPoint " .. WayPoint, 20 ):ToAll()
|
||||
self.WayPoint = WayPoint
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user