mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-08-13 17:31:41 +00:00
FlightControl/Group
This commit is contained in:
@@ -582,7 +582,7 @@ function FLIGHTCONTROL:_CheckParking()
|
|||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
self:E(self.lid..string.format("ERROR: Element %s is not alive any more!", element.unitname))
|
self:E(self.lid..string.format("ERROR: Element %s is not alive any more!", element.name))
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -783,10 +783,11 @@ function FLIGHTCONTROL:_CreateFlightGroup(group)
|
|||||||
-- If it does not exist yet, create one.
|
-- If it does not exist yet, create one.
|
||||||
if not flight then
|
if not flight then
|
||||||
flight=FLIGHTGROUP:New(group:GetName())
|
flight=FLIGHTGROUP:New(group:GetName())
|
||||||
flight:__Start(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
flight:SetFlightControl(self)
|
if flight.destination and flight.destination:GetName()==self.airbasename then
|
||||||
|
flight:SetFlightControl(self)
|
||||||
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
|
||||||
@@ -1008,7 +1009,7 @@ function FLIGHTCONTROL:_CheckInbound()
|
|||||||
if flight and flight.destination and flight.destination:GetName()==self.airbasename then
|
if flight and flight.destination and flight.destination:GetName()==self.airbasename then
|
||||||
|
|
||||||
-- Send AI to orbit outside 10 NM zone and wait until the next Marshal stack is available.
|
-- Send AI to orbit outside 10 NM zone and wait until the next Marshal stack is available.
|
||||||
if not (self:_InQueue(self.Qwaiting, flight.group) or self:_InQueue(self.Qlanding, flight.group)) then
|
if not (self:_InQueue(self.Qwaiting, flight.group) or self:_InQueue(self.Qlanding, flight.group) or flight:IsHolding()) then
|
||||||
self:_WaitAI(flight, 1, true)
|
self:_WaitAI(flight, 1, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1028,15 +1029,12 @@ function FLIGHTCONTROL:_WaitAI(flight, stack, respawn)
|
|||||||
-- Set flag to something other than -100 and <0
|
-- Set flag to something other than -100 and <0
|
||||||
flight.flag=stack
|
flight.flag=stack
|
||||||
|
|
||||||
-- Add AI flight to waiting queue.
|
|
||||||
table.insert(self.Qwaiting, flight)
|
|
||||||
|
|
||||||
-- Holding point.
|
-- Holding point.
|
||||||
local holding=self:_GetHoldingpoint(flight)
|
local holding=self:_GetHoldingpoint(flight)
|
||||||
local altitude=holding.pos0.y
|
local altitude=holding.pos0.y
|
||||||
local angels=UTILS.MetersToFeet(altitude)/1000
|
local angels=UTILS.MetersToFeet(altitude)/1000
|
||||||
|
|
||||||
flight:Hold(holding, altitude)
|
flight:Hold(self.airbase, holding.pos0)
|
||||||
|
|
||||||
if true then
|
if true then
|
||||||
return
|
return
|
||||||
@@ -1117,6 +1115,17 @@ function FLIGHTCONTROL:_LandAI(flight)
|
|||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:T(self.lid..string.format("Landing AI flight %s.", flight.groupname))
|
self:T(self.lid..string.format("Landing AI flight %s.", flight.groupname))
|
||||||
|
|
||||||
|
-- Add flight to landing queue.
|
||||||
|
table.insert(self.Qlanding, flight)
|
||||||
|
|
||||||
|
flight.flaghold:Set(1)
|
||||||
|
|
||||||
|
if true then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Airbase position.
|
-- Airbase position.
|
||||||
local airbase=self.airbase:GetCoordinate()
|
local airbase=self.airbase:GetCoordinate()
|
||||||
|
|
||||||
|
|||||||
@@ -568,6 +568,13 @@ function FLIGHTGROUP:IsArrived()
|
|||||||
return self:Is("Arrived")
|
return self:Is("Arrived")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Check if flight is holding.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @return #boolean If true, flight is holding.
|
||||||
|
function FLIGHTGROUP:IsHolding()
|
||||||
|
return self:Is("Holding")
|
||||||
|
end
|
||||||
|
|
||||||
--- Check if flight is dead.
|
--- Check if flight is dead.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
-- @return #boolean
|
-- @return #boolean
|
||||||
@@ -807,8 +814,11 @@ function FLIGHTGROUP:OnEventEngineStartup(EventData)
|
|||||||
local element=self:GetElementByName(unitname)
|
local element=self:GetElementByName(unitname)
|
||||||
|
|
||||||
if element then
|
if element then
|
||||||
self:I(self.sid..string.format("Element %s started engines ==> taxiing", element.name))
|
if self:IsAirborne() or self:IsHolding() then
|
||||||
self:ElementTaxiing(element)
|
else
|
||||||
|
self:I(self.sid..string.format("Element %s started engines ==> taxiing", element.name))
|
||||||
|
self:ElementTaxiing(element)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1248,7 +1258,7 @@ function FLIGHTGROUP:onafterOrbit(From, Event, To, Coord, Altitude, Speed)
|
|||||||
self.group:SetTask(TaskOrbit)
|
self.group:SetTask(TaskOrbit)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after "Hold" event.
|
--- On before "Hold" event.
|
||||||
-- @param #FLIGHTGROUP self
|
-- @param #FLIGHTGROUP self
|
||||||
-- @param #string From From state.
|
-- @param #string From From state.
|
||||||
-- @param #string Event Event.
|
-- @param #string Event Event.
|
||||||
@@ -1256,7 +1266,31 @@ end
|
|||||||
-- @param Wrapper.Airbase#AIRBASE airbase The airbase to hold at.
|
-- @param Wrapper.Airbase#AIRBASE airbase The airbase to hold at.
|
||||||
-- @param #number SpeedTo Speed used for travelling from current position to holding point in knots.
|
-- @param #number SpeedTo Speed used for travelling from current position to holding point in knots.
|
||||||
-- @param #number SpeedHold Holding speed in knots.
|
-- @param #number SpeedHold Holding speed in knots.
|
||||||
function FLIGHTGROUP:onafterHold(From, Event, To, airbase, SpeedTo, SpeedHold)
|
function FLIGHTGROUP:onbeforeHold(From, Event, To, airbase, SpeedTo, SpeedHold)
|
||||||
|
|
||||||
|
if airbase==nil then
|
||||||
|
self:E("FF airbase is nil!")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
if airbase and airbase:GetCoalition()~=self.group:GetCoalition() then
|
||||||
|
self:E("FF wrong coalition!")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
--- On after "Hold" event. Order flight to hold at an airbase and wait for signal to land.
|
||||||
|
-- @param #FLIGHTGROUP self
|
||||||
|
-- @param #string From From state.
|
||||||
|
-- @param #string Event Event.
|
||||||
|
-- @param #string To To state.
|
||||||
|
-- @param Wrapper.Airbase#AIRBASE airbase The airbase to hold at.
|
||||||
|
-- @param Core.Point#COORDINATE Holdingpoint Coordinate where to hold.
|
||||||
|
-- @param #number SpeedTo Speed used for travelling from current position to holding point in knots. Default 350 kts.
|
||||||
|
-- @param #number SpeedHold Holding speed in knots. Default 250 kts.
|
||||||
|
function FLIGHTGROUP:onafterHold(From, Event, To, airbase, HoldingPoint, SpeedTo, SpeedHold)
|
||||||
|
|
||||||
-- Debug message.
|
-- Debug message.
|
||||||
local text=string.format("Flight group set to hold at airbase %s", airbase:GetName())
|
local text=string.format("Flight group set to hold at airbase %s", airbase:GetName())
|
||||||
@@ -1266,42 +1300,27 @@ function FLIGHTGROUP:onafterHold(From, Event, To, airbase, SpeedTo, SpeedHold)
|
|||||||
|
|
||||||
self.group:ClearTasks()
|
self.group:ClearTasks()
|
||||||
|
|
||||||
local Coord=airbase:GetZone():GetRandomCoordinate():SetAltitude(UTILS.FeetToMeters(6000))
|
SpeedTo=SpeedTo or 350
|
||||||
if self.flightcontrol then
|
SpeedHold=SpeedHold or 250
|
||||||
Coord=self.flightcontrol:_GetHoldingpoint(self)
|
|
||||||
end
|
-- Holding point.
|
||||||
|
HoldingPoint=HoldingPoint or airbase:GetZone():GetRandomCoordinate():SetAltitude(UTILS.FeetToMeters(6000))
|
||||||
|
|
||||||
self.flaghold:Set(333)
|
self.flaghold:Set(333)
|
||||||
|
|
||||||
|
-- Task fuction when reached holding point.
|
||||||
local TaskArrived=self.group:TaskFunction("FLIGHTGROUP._ReachedHolding", self)
|
local TaskArrived=self.group:TaskFunction("FLIGHTGROUP._ReachedHolding", self)
|
||||||
|
|
||||||
|
-- Orbit until flaghold=1 (=true)
|
||||||
local wp=airbase:GetCoordinate():WaypointAir(nil , COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint,SpeedTo, true , nil, {}, "Holding Point")
|
local TaskOrbit=self.group:TaskOrbit(HoldingPoint, nil, UTILS.KnotsToMps(SpeedHold))
|
||||||
|
|
||||||
local Task2Hold=self.group:TaskRoute(wp)
|
|
||||||
|
|
||||||
local TaskOrbit=self.group:TaskOrbit(Coord)
|
|
||||||
|
|
||||||
local TaskStop=self.group:TaskCondition(nil, self.flaghold.UserFlagName, 1)
|
local TaskStop=self.group:TaskCondition(nil, self.flaghold.UserFlagName, 1)
|
||||||
--local TaskStop=self.group:TaskCondition(nil, nil, nil, nil, 30*60)
|
|
||||||
|
|
||||||
local wp=airbase:GetCoordinate():WaypointAirLanding(SpeedHold, airbase, {}, "Landing")
|
|
||||||
|
|
||||||
local TaskLand=self.group:TaskRoute(wp)
|
|
||||||
|
|
||||||
local TaskControlled=self.group:TaskControlled(TaskOrbit, TaskStop)
|
local TaskControlled=self.group:TaskControlled(TaskOrbit, TaskStop)
|
||||||
|
|
||||||
local TaskCombo=self.group:TaskCombo({Task2Hold, TaskArrived, TaskControlled, TaskLand})
|
-- Waypoints.
|
||||||
local TaskCombo=self.group:TaskCombo({Task2Hold, TaskArrived, TaskLand})
|
|
||||||
|
|
||||||
--self.group:SetTask(TaskCombo)
|
|
||||||
|
|
||||||
local coordAB=airbase:GetCoordinate()
|
|
||||||
|
|
||||||
local wp={}
|
local wp={}
|
||||||
wp[1]=self.group:GetCoordinate():WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint,SpeedTo, true , nil, {}, "Current Pos")
|
wp[1]=self.group:GetCoordinate():WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint, UTILS.KnotsToKmph(SpeedTo), true , nil, {}, "Current Pos")
|
||||||
wp[2]=coordAB:WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint,SpeedTo, true , nil, {TaskArrived, TaskControlled}, "Holding Point")
|
wp[2]=HoldingPoint:WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint, UTILS.KnotsToKmph(SpeedTo), true , nil, {TaskArrived, TaskControlled}, "Holding Point")
|
||||||
wp[3]=coordAB:WaypointAirLanding(SpeedHold, airbase, {}, "Landing")
|
wp[3]=airbase:GetCoordinate():WaypointAirLanding(SpeedHold, airbase, {}, "Landing")
|
||||||
|
|
||||||
local respawn=true
|
local respawn=true
|
||||||
|
|
||||||
@@ -1320,9 +1339,8 @@ function FLIGHTGROUP:onafterHold(From, Event, To, airbase, SpeedTo, SpeedHold)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--self.group:Route(wp, 1)
|
self.group:Route(wp, 1)
|
||||||
|
|
||||||
--self:RouteRTB(RTBAirbase,Speed,Altitude,TaskOverhead)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after TaskPause event.
|
--- On after TaskPause event.
|
||||||
@@ -1333,6 +1351,10 @@ function FLIGHTGROUP._ReachedHolding(group, flightgroup)
|
|||||||
group:GetCoordinate():MarkToAll("Holding Point Reached")
|
group:GetCoordinate():MarkToAll("Holding Point Reached")
|
||||||
--TODO: add flight to FC waiting queue.
|
--TODO: add flight to FC waiting queue.
|
||||||
flightgroup.flaghold:Set(666)
|
flightgroup.flaghold:Set(666)
|
||||||
|
|
||||||
|
if flightgroup.flightcontrol then
|
||||||
|
table.insert(flightgroup.flightcontrol.Qwaiting, flightgroup)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- On after TaskExecute event.
|
--- On after TaskExecute event.
|
||||||
|
|||||||
@@ -1079,7 +1079,7 @@ end
|
|||||||
-- @param #CONTROLLABLE self
|
-- @param #CONTROLLABLE self
|
||||||
-- @param Core.Point#COORDINATE Coord Coordinate at which the CONTROLLABLE orbits.
|
-- @param Core.Point#COORDINATE Coord Coordinate at which the CONTROLLABLE orbits.
|
||||||
-- @param #number Altitude Altitude in meters of the orbit pattern. Default y component of Coord.
|
-- @param #number Altitude Altitude in meters of the orbit pattern. Default y component of Coord.
|
||||||
-- @param #number Speed Speed [m/s] flying the orbit pattern. Default 250 knots.
|
-- @param #number Speed Speed [m/s] flying the orbit pattern. Default 128 m/s = 250 knots.
|
||||||
-- @param Core.Point#COORDINATE CoordRaceTrack (Optional) If this coordinate is specified, the CONTROLLABLE will fly a race-track pattern using this and the initial coordinate.
|
-- @param Core.Point#COORDINATE CoordRaceTrack (Optional) If this coordinate is specified, the CONTROLLABLE will fly a race-track pattern using this and the initial coordinate.
|
||||||
-- @return #CONTROLLABLE self
|
-- @return #CONTROLLABLE self
|
||||||
function CONTROLLABLE:TaskOrbit(Coord, Altitude, Speed, CoordRaceTrack)
|
function CONTROLLABLE:TaskOrbit(Coord, Altitude, Speed, CoordRaceTrack)
|
||||||
|
|||||||
Reference in New Issue
Block a user