controllable

This commit is contained in:
Frank 2020-01-19 22:14:45 +01:00
parent e6e5787fc6
commit 1e1154d190
4 changed files with 94 additions and 33 deletions

View File

@ -3656,7 +3656,7 @@ do -- AI_A2A_DISPATCHER
for DefenderSquadronName, DefenderSquadron in pairs( self.DefenderSquadrons ) do for DefenderSquadronName, DefenderSquadron in pairs( self.DefenderSquadrons ) do
self:I( { DefenderSquadron = DefenderSquadron.Name } ) self:T( { DefenderSquadron = DefenderSquadron.Name } )
local Airbase = DefenderSquadron.Airbase local Airbase = DefenderSquadron.Airbase
local AirbaseCoordinate = Airbase:GetCoordinate() local AirbaseCoordinate = Airbase:GetCoordinate()

View File

@ -689,6 +689,10 @@ function ZONE_RADIUS:Scan( ObjectCategories, UnitCategories )
local ObjectCategory = ZoneObject:getCategory() local ObjectCategory = ZoneObject:getCategory()
--local name=ZoneObject:getName()
--env.info(string.format("Zone object %s", tostring(name)))
--self:E(ZoneObject)
if ( ObjectCategory == Object.Category.UNIT and ZoneObject:isExist() and ZoneObject:isActive() ) or (ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then if ( ObjectCategory == Object.Category.UNIT and ZoneObject:isExist() and ZoneObject:isActive() ) or (ObjectCategory == Object.Category.STATIC and ZoneObject:isExist()) then
local CoalitionDCSUnit = ZoneObject:getCoalition() local CoalitionDCSUnit = ZoneObject:getCoalition()

View File

@ -5957,27 +5957,29 @@ function WAREHOUSE:_OnEventArrived(EventData)
if self.uid==wid then if self.uid==wid then
local request=self:_GetRequestOfGroup(group, self.pending) local request=self:_GetRequestOfGroup(group, self.pending)
local istransport=self:_GroupIsTransport(group,request)
if request then
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations. local istransport=self:_GroupIsTransport(group,request)
local rightairbase=group:GetCoordinate():GetClosestAirbase():GetName()==request.warehouse:GetAirbase():GetName()
-- Check if engine shutdown happend at right airbase because the event is also triggered in other situations.
-- Check that group is cargo and not transport. local rightairbase=group:GetCoordinate():GetClosestAirbase():GetName()==request.warehouse:GetAirbase():GetName()
if istransport==false and rightairbase then
-- Check that group is cargo and not transport.
-- Debug info. if istransport==false and rightairbase then
local text=string.format("Air asset group %s from warehouse %s arrived at its destination.", group:GetName(), self.alias)
self:_InfoMessage(text) -- Debug info.
local text=string.format("Air asset group %s from warehouse %s arrived at its destination.", group:GetName(), self.alias)
-- Trigger arrived event for this group. Note that each unit of a group will trigger this event. So the onafterArrived function needs to take care of that. self:_InfoMessage(text)
-- Actually, we only take the first unit of the group that arrives. If it does, we assume the whole group arrived, which might not be the case, since
-- some units might still be taxiing or whatever. Therefore, we add 10 seconds for each additional unit of the group until the first arrived event is triggered. -- Trigger arrived event for this group. Note that each unit of a group will trigger this event. So the onafterArrived function needs to take care of that.
local nunits=#group:GetUnits() -- Actually, we only take the first unit of the group that arrives. If it does, we assume the whole group arrived, which might not be the case, since
local dt=10*(nunits-1)+1 -- one unit = 1 sec, two units = 11 sec, three units = 21 sec before we call the group arrived. -- some units might still be taxiing or whatever. Therefore, we add 10 seconds for each additional unit of the group until the first arrived event is triggered.
self:__Arrived(dt, group) local nunits=#group:GetUnits()
local dt=10*(nunits-1)+1 -- one unit = 1 sec, two units = 11 sec, three units = 21 sec before we call the group arrived.
self:__Arrived(dt, group)
end
end end
end end
else else

View File

@ -1,4 +1,4 @@
--- **Wrapper** -- CONTROLLABLE is an intermediate class wrapping Group and Unit classes "controllers". --- **Wrapper** -- CONTROLLABLE is an intermediate class wrapping Group and Unit classes "controllers".
-- --
-- === -- ===
-- --
@ -2375,16 +2375,30 @@ do -- Route methods
-- @param #number Speed (optional) Speed in km/h. The default speed is 20 km/h. -- @param #number Speed (optional) Speed in km/h. The default speed is 20 km/h.
-- @param #string Formation (optional) The route point Formation, which is a text string that specifies exactly the Text in the Type of the route point, like "Vee", "Echelon Right". -- @param #string Formation (optional) The route point Formation, which is a text string that specifies exactly the Text in the Type of the route point, like "Vee", "Echelon Right".
-- @param #number DelaySeconds Wait for the specified seconds before executing the Route. -- @param #number DelaySeconds Wait for the specified seconds before executing the Route.
-- @param #function WaypointFunction (Optional) Function called when passing a waypoint. First parameters of the function are the @{CONTROLLABLE} object, the number of the waypoint and the total number of waypoints.
-- @param #table WaypointFunctionArguments (Optional) List of parameters passed to the *WaypointFunction*.
-- @return #CONTROLLABLE The CONTROLLABLE. -- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteGroundTo( ToCoordinate, Speed, Formation, DelaySeconds ) function CONTROLLABLE:RouteGroundTo( ToCoordinate, Speed, Formation, DelaySeconds, WaypointFunction, WaypointFunctionArguments )
local FromCoordinate = self:GetCoordinate() local FromCoordinate = self:GetCoordinate()
--local FromWP = FromCoordinate:WaypointGround()
local FromWP = FromCoordinate:WaypointGround(Speed, Formation) local FromWP = FromCoordinate:WaypointGround(Speed, Formation)
local ToWP = ToCoordinate:WaypointGround( Speed, Formation ) local ToWP = ToCoordinate:WaypointGround( Speed, Formation )
self:Route( { FromWP, ToWP }, DelaySeconds ) local route={FromWP, ToWP}
-- Add passing waypoint function.
if WaypointFunction then
local N=#route
for n,waypoint in pairs(route) do
waypoint.task = {}
waypoint.task.id = "ComboTask"
waypoint.task.params = {}
waypoint.task.params.tasks = {self:TaskFunction("CONTROLLABLE.___PassingWaypoint", n, N, WaypointFunction, unpack(WaypointFunctionArguments or {}))}
end
end
self:Route( route, DelaySeconds )
return self return self
end end
@ -2395,8 +2409,10 @@ do -- Route methods
-- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h. -- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h.
-- @param #number DelaySeconds (Optional) Wait for the specified seconds before executing the Route. Default is one second. -- @param #number DelaySeconds (Optional) Wait for the specified seconds before executing the Route. Default is one second.
-- @param #string OffRoadFormation (Optional) The formation at initial and final waypoint. Default is "Off Road". -- @param #string OffRoadFormation (Optional) The formation at initial and final waypoint. Default is "Off Road".
-- @param #function WaypointFunction (Optional) Function called when passing a waypoint. First parameters of the function are the @{CONTROLLABLE} object, the number of the waypoint and the total number of waypoints.
-- @param #table WaypointFunctionArguments (Optional) List of parameters passed to the *WaypointFunction*.
-- @return #CONTROLLABLE The CONTROLLABLE. -- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteGroundOnRoad( ToCoordinate, Speed, DelaySeconds, OffRoadFormation ) function CONTROLLABLE:RouteGroundOnRoad( ToCoordinate, Speed, DelaySeconds, OffRoadFormation, WaypointFunction, WaypointFunctionArguments )
-- Defaults. -- Defaults.
Speed=Speed or 20 Speed=Speed or 20
@ -2404,7 +2420,7 @@ do -- Route methods
OffRoadFormation=OffRoadFormation or "Off Road" OffRoadFormation=OffRoadFormation or "Off Road"
-- Get the route task. -- Get the route task.
local route=self:TaskGroundOnRoad(ToCoordinate, Speed, OffRoadFormation) local route=self:TaskGroundOnRoad(ToCoordinate, Speed, OffRoadFormation, nil, nil, WaypointFunction, WaypointFunctionArguments)
-- Route controllable to destination. -- Route controllable to destination.
self:Route( route, DelaySeconds ) self:Route( route, DelaySeconds )
@ -2417,15 +2433,17 @@ do -- Route methods
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to. -- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h. -- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h.
-- @param #number DelaySeconds (Optional) Wait for the specified seconds before executing the Route. Default is one second. -- @param #number DelaySeconds (Optional) Wait for the specified seconds before executing the Route. Default is one second.
-- @param #function WaypointFunction (Optional) Function called when passing a waypoint. First parameters of the function are the @{CONTROLLABLE} object, the number of the waypoint and the total number of waypoints.
-- @param #table WaypointFunctionArguments (Optional) List of parameters passed to the *WaypointFunction*.
-- @return #CONTROLLABLE The CONTROLLABLE. -- @return #CONTROLLABLE The CONTROLLABLE.
function CONTROLLABLE:RouteGroundOnRailRoads( ToCoordinate, Speed, DelaySeconds) function CONTROLLABLE:RouteGroundOnRailRoads( ToCoordinate, Speed, DelaySeconds, WaypointFunction, WaypointFunctionArguments )
-- Defaults. -- Defaults.
Speed=Speed or 20 Speed=Speed or 20
DelaySeconds=DelaySeconds or 1 DelaySeconds=DelaySeconds or 1
-- Get the route task. -- Get the route task.
local route=self:TaskGroundOnRailRoads(ToCoordinate, Speed) local route=self:TaskGroundOnRailRoads(ToCoordinate, Speed, WaypointFunction, WaypointFunctionArguments )
-- Route controllable to destination. -- Route controllable to destination.
self:Route( route, DelaySeconds ) self:Route( route, DelaySeconds )
@ -2442,10 +2460,12 @@ do -- Route methods
-- @param #string OffRoadFormation (Optional) The formation at initial and final waypoint. Default is "Off Road". -- @param #string OffRoadFormation (Optional) The formation at initial and final waypoint. Default is "Off Road".
-- @param #boolean Shortcut (Optional) If true, controllable will take the direct route if the path on road is 10x longer or path on road is less than 5% of total path. -- @param #boolean Shortcut (Optional) If true, controllable will take the direct route if the path on road is 10x longer or path on road is less than 5% of total path.
-- @param Core.Point#COORDINATE FromCoordinate (Optional) Explicit initial coordinate. Default is the position of the controllable. -- @param Core.Point#COORDINATE FromCoordinate (Optional) Explicit initial coordinate. Default is the position of the controllable.
-- @param #function WaypointFunction (Optional) Function called when passing a waypoint. First parameters of the function are the @{CONTROLLABLE} object, the number of the waypoint and the total number of waypoints.
-- @param #table WaypointFunctionArguments (Optional) List of parameters passed to the *WaypointFunction*.
-- @return DCS#Task Task. -- @return DCS#Task Task.
-- @return #boolean If true, path on road is possible. If false, task will route the group directly to its destination. -- @return #boolean If true, path on road is possible. If false, task will route the group directly to its destination.
function CONTROLLABLE:TaskGroundOnRoad( ToCoordinate, Speed, OffRoadFormation, Shortcut, FromCoordinate ) function CONTROLLABLE:TaskGroundOnRoad( ToCoordinate, Speed, OffRoadFormation, Shortcut, FromCoordinate, WaypointFunction, WaypointFunctionArguments )
self:F2({ToCoordinate=ToCoordinate, Speed=Speed, OffRoadFormation=OffRoadFormation}) self:I({ToCoordinate=ToCoordinate, Speed=Speed, OffRoadFormation=OffRoadFormation, WaypointFunction=WaypointFunction, Args=WaypointFunctionArguments})
-- Defaults. -- Defaults.
Speed=Speed or 20 Speed=Speed or 20
@ -2495,6 +2515,7 @@ do -- Route methods
if LongRoad and Shortcut then if LongRoad and Shortcut then
-- Road is long ==> we take the short cut. -- Road is long ==> we take the short cut.
table.insert(route, FromCoordinate:WaypointGround(Speed, OffRoadFormation)) table.insert(route, FromCoordinate:WaypointGround(Speed, OffRoadFormation))
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation)) table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
@ -2523,7 +2544,18 @@ do -- Route methods
table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation)) table.insert(route, ToCoordinate:WaypointGround(Speed, OffRoadFormation))
end end
-- Add passing waypoint function.
if WaypointFunction then
local N=#route
for n,waypoint in pairs(route) do
waypoint.task = {}
waypoint.task.id = "ComboTask"
waypoint.task.params = {}
waypoint.task.params.tasks = {self:TaskFunction("CONTROLLABLE.___PassingWaypoint", n, N, WaypointFunction, unpack(WaypointFunctionArguments or {}))}
end
end
return route, canroad return route, canroad
end end
@ -2531,8 +2563,10 @@ do -- Route methods
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to. -- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.
-- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h. -- @param #number Speed (Optional) Speed in km/h. The default speed is 20 km/h.
-- @param #function WaypointFunction (Optional) Function called when passing a waypoint. First parameters of the function are the @{CONTROLLABLE} object, the number of the waypoint and the total number of waypoints.
-- @param #table WaypointFunctionArguments (Optional) List of parameters passed to the *WaypointFunction*.
-- @return Task -- @return Task
function CONTROLLABLE:TaskGroundOnRailRoads(ToCoordinate, Speed) function CONTROLLABLE:TaskGroundOnRailRoads(ToCoordinate, Speed, WaypointFunction, WaypointFunctionArguments )
self:F2({ToCoordinate=ToCoordinate, Speed=Speed}) self:F2({ToCoordinate=ToCoordinate, Speed=Speed})
-- Defaults. -- Defaults.
@ -2557,10 +2591,31 @@ do -- Route methods
table.insert(route, PathOnRail[2]:WaypointGround(Speed, "On Railroad")) table.insert(route, PathOnRail[2]:WaypointGround(Speed, "On Railroad"))
end end
-- Add passing waypoint function.
if WaypointFunction then
local N=#route
for n,waypoint in pairs(route) do
waypoint.task = {}
waypoint.task.id = "ComboTask"
waypoint.task.params = {}
waypoint.task.params.tasks = {self:TaskFunction("CONTROLLABLE.___PassingWaypoint", n, N, WaypointFunction, unpack(WaypointFunctionArguments or {}))}
end
end
return route return route
end end
--- Task function when controllable passes a waypoint.
-- @param #CONTROLLABLE controllable The controllable object.
-- @param #number n Current waypoint number passed.
-- @param #number N Total number of waypoints.
-- @param #function waypointfunction Function called when a waypoint is passed.
function CONTROLLABLE.___PassingWaypoint(controllable, n, N, waypointfunction, ...)
waypointfunction(controllable, n, N, ...)
end
--- Make the AIR Controllable fly towards a specific point. --- Make the AIR Controllable fly towards a specific point.
-- @param #CONTROLLABLE self -- @param #CONTROLLABLE self
-- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to. -- @param Core.Point#COORDINATE ToCoordinate A Coordinate to drive to.