mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2026-07-26 10:29:37 +00:00
FlightControl/Group
This commit is contained in:
@@ -582,7 +582,7 @@ function FLIGHTCONTROL:_CheckParking()
|
||||
end
|
||||
|
||||
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
|
||||
@@ -783,10 +783,11 @@ function FLIGHTCONTROL:_CreateFlightGroup(group)
|
||||
-- If it does not exist yet, create one.
|
||||
if not flight then
|
||||
flight=FLIGHTGROUP:New(group:GetName())
|
||||
flight:__Start(1)
|
||||
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
|
||||
|
||||
-- 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)
|
||||
end
|
||||
|
||||
@@ -1028,15 +1029,12 @@ function FLIGHTCONTROL:_WaitAI(flight, stack, respawn)
|
||||
-- Set flag to something other than -100 and <0
|
||||
flight.flag=stack
|
||||
|
||||
-- Add AI flight to waiting queue.
|
||||
table.insert(self.Qwaiting, flight)
|
||||
|
||||
-- Holding point.
|
||||
local holding=self:_GetHoldingpoint(flight)
|
||||
local altitude=holding.pos0.y
|
||||
local angels=UTILS.MetersToFeet(altitude)/1000
|
||||
|
||||
flight:Hold(holding, altitude)
|
||||
flight:Hold(self.airbase, holding.pos0)
|
||||
|
||||
if true then
|
||||
return
|
||||
@@ -1116,6 +1114,17 @@ function FLIGHTCONTROL:_LandAI(flight)
|
||||
|
||||
-- Debug info.
|
||||
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.
|
||||
local airbase=self.airbase:GetCoordinate()
|
||||
|
||||
@@ -568,6 +568,13 @@ function FLIGHTGROUP:IsArrived()
|
||||
return self:Is("Arrived")
|
||||
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.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @return #boolean
|
||||
@@ -807,8 +814,11 @@ function FLIGHTGROUP:OnEventEngineStartup(EventData)
|
||||
local element=self:GetElementByName(unitname)
|
||||
|
||||
if element then
|
||||
self:I(self.sid..string.format("Element %s started engines ==> taxiing", element.name))
|
||||
self:ElementTaxiing(element)
|
||||
if self:IsAirborne() or self:IsHolding() then
|
||||
else
|
||||
self:I(self.sid..string.format("Element %s started engines ==> taxiing", element.name))
|
||||
self:ElementTaxiing(element)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1248,7 +1258,7 @@ function FLIGHTGROUP:onafterOrbit(From, Event, To, Coord, Altitude, Speed)
|
||||
self.group:SetTask(TaskOrbit)
|
||||
end
|
||||
|
||||
--- On after "Hold" event.
|
||||
--- On before "Hold" event.
|
||||
-- @param #FLIGHTGROUP self
|
||||
-- @param #string From From state.
|
||||
-- @param #string Event Event.
|
||||
@@ -1256,7 +1266,31 @@ end
|
||||
-- @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 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.
|
||||
local text=string.format("Flight group set to hold at airbase %s", airbase:GetName())
|
||||
@@ -1265,43 +1299,28 @@ function FLIGHTGROUP:onafterHold(From, Event, To, airbase, SpeedTo, SpeedHold)
|
||||
|
||||
|
||||
self.group:ClearTasks()
|
||||
|
||||
SpeedTo=SpeedTo or 350
|
||||
SpeedHold=SpeedHold or 250
|
||||
|
||||
local Coord=airbase:GetZone():GetRandomCoordinate():SetAltitude(UTILS.FeetToMeters(6000))
|
||||
if self.flightcontrol then
|
||||
Coord=self.flightcontrol:_GetHoldingpoint(self)
|
||||
end
|
||||
-- Holding point.
|
||||
HoldingPoint=HoldingPoint or airbase:GetZone():GetRandomCoordinate():SetAltitude(UTILS.FeetToMeters(6000))
|
||||
|
||||
self.flaghold:Set(333)
|
||||
|
||||
-- Task fuction when reached holding point.
|
||||
local TaskArrived=self.group:TaskFunction("FLIGHTGROUP._ReachedHolding", self)
|
||||
|
||||
|
||||
local wp=airbase:GetCoordinate():WaypointAir(nil , COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint,SpeedTo, true , nil, {}, "Holding Point")
|
||||
|
||||
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, nil, nil, nil, 30*60)
|
||||
|
||||
local wp=airbase:GetCoordinate():WaypointAirLanding(SpeedHold, airbase, {}, "Landing")
|
||||
|
||||
local TaskLand=self.group:TaskRoute(wp)
|
||||
|
||||
-- Orbit until flaghold=1 (=true)
|
||||
local TaskOrbit=self.group:TaskOrbit(HoldingPoint, nil, UTILS.KnotsToMps(SpeedHold))
|
||||
local TaskStop=self.group:TaskCondition(nil, self.flaghold.UserFlagName, 1)
|
||||
local TaskControlled=self.group:TaskControlled(TaskOrbit, TaskStop)
|
||||
|
||||
local TaskCombo=self.group:TaskCombo({Task2Hold, TaskArrived, TaskControlled, TaskLand})
|
||||
local TaskCombo=self.group:TaskCombo({Task2Hold, TaskArrived, TaskLand})
|
||||
|
||||
--self.group:SetTask(TaskCombo)
|
||||
|
||||
local coordAB=airbase:GetCoordinate()
|
||||
|
||||
-- Waypoints.
|
||||
local wp={}
|
||||
wp[1]=self.group:GetCoordinate():WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint,SpeedTo, true , nil, {}, "Current Pos")
|
||||
wp[2]=coordAB:WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint,SpeedTo, true , nil, {TaskArrived, TaskControlled}, "Holding Point")
|
||||
wp[3]=coordAB:WaypointAirLanding(SpeedHold, airbase, {}, "Landing")
|
||||
wp[1]=self.group:GetCoordinate():WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint, UTILS.KnotsToKmph(SpeedTo), true , nil, {}, "Current Pos")
|
||||
wp[2]=HoldingPoint:WaypointAir(nil, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.FlyoverPoint, UTILS.KnotsToKmph(SpeedTo), true , nil, {TaskArrived, TaskControlled}, "Holding Point")
|
||||
wp[3]=airbase:GetCoordinate():WaypointAirLanding(SpeedHold, airbase, {}, "Landing")
|
||||
|
||||
local respawn=true
|
||||
|
||||
@@ -1320,9 +1339,8 @@ function FLIGHTGROUP:onafterHold(From, Event, To, airbase, SpeedTo, SpeedHold)
|
||||
|
||||
end
|
||||
|
||||
--self.group:Route(wp, 1)
|
||||
|
||||
--self:RouteRTB(RTBAirbase,Speed,Altitude,TaskOverhead)
|
||||
self.group:Route(wp, 1)
|
||||
|
||||
end
|
||||
|
||||
--- On after TaskPause event.
|
||||
@@ -1333,6 +1351,10 @@ function FLIGHTGROUP._ReachedHolding(group, flightgroup)
|
||||
group:GetCoordinate():MarkToAll("Holding Point Reached")
|
||||
--TODO: add flight to FC waiting queue.
|
||||
flightgroup.flaghold:Set(666)
|
||||
|
||||
if flightgroup.flightcontrol then
|
||||
table.insert(flightgroup.flightcontrol.Qwaiting, flightgroup)
|
||||
end
|
||||
end
|
||||
|
||||
--- On after TaskExecute event.
|
||||
|
||||
@@ -1079,7 +1079,7 @@ end
|
||||
-- @param #CONTROLLABLE self
|
||||
-- @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 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.
|
||||
-- @return #CONTROLLABLE self
|
||||
function CONTROLLABLE:TaskOrbit(Coord, Altitude, Speed, CoordRaceTrack)
|
||||
|
||||
Reference in New Issue
Block a user