This commit is contained in:
Frank
2020-03-17 16:53:47 +01:00
parent 9cb551e6fa
commit 8823b96b5f
8 changed files with 188 additions and 26 deletions
+21 -3
View File
@@ -326,9 +326,27 @@ end -- coalition
do -- Types
--- @type Desc
-- @field #TypeName typeName type name
-- @field #string displayName localized display name
-- @field #table attributes object type attributes
-- @field #number speedMax0 Max speed in meters/second at zero altitude.
-- @field #number massEmpty Empty mass in kg.
-- @field #number tankerType Type of refueling system: 0=boom, 1=probe.
-- @field #number range Range in km(?).
-- @field #table box Bounding box.
-- @field #number Hmax Max height in meters.
-- @field #number Kmax ?
-- @field #number speedMax10K Max speed in meters/second at 10k altitude.
-- @field #number NyMin ?
-- @field #number NyMax ?
-- @field #number fuelMassMax Max fuel mass in kg.
-- @field #number speedMax10K Max speed in meters/second.
-- @field #number massMax Max mass of unit.
-- @field #number RCS ?
-- @field #number life Life points.
-- @field #number VyMax Max vertical velocity in m/s.
-- @field #number Kab ?
-- @field #table attributes Table of attributes.
-- @field #TypeName typeName Type Name.
-- @field #string displayName Localized display name.
-- @field #number category Unit category.
--- A distance type
-- @type Distance
+64 -15
View File
@@ -25,8 +25,9 @@
-- @field Core.Set#SET_ZONE zonesetTANKER Set of TANKER zones.
-- @field Core.Set#SET_ZONE zonesetAWACS Set of AWACS zones.
-- @field #number nflightsCAP Number of CAP flights constantly in the air.
-- @field #number nflightsTANKER Number of TANKER flights constantly in the air.
-- @field #number nflightsAWACS Number of AWACS flights constantly in the air.
-- @field #number nflightsTANKERboom Number of TANKER flights with BOOM constantly in the air.
-- @field #number nflightsTANKERprobe Number of TANKER flights with PROBE constantly in the air.
-- @field #table pointsCAP Table of CAP points.
-- @field #table pointsTANKER Table of Tanker points.
-- @field #table pointsAWACS Table of AWACS points.
@@ -140,7 +141,8 @@ function AIRWING:New(warehousename, airwingname)
-- Defaults:
self.nflightsCAP=0
self.nflightsAWACS=0
self.nflightsTANKER=0
self.nflightsTANKERboom=0
self.nflightsTANKERprobe=0
------------------------
--- Pseudo Functions ---
@@ -430,10 +432,12 @@ end
--- Set number of TANKER flights constantly in the air.
-- @param #AIRWING self
-- @param #number n Number of flights. Default 1.
-- @param #number Nboom Number of flights. Default 1.
-- @param #number Nprobe Number of flights. Default 1.
-- @return #AIRWING self
function AIRWING:SetNumberTANKER(n)
self.nflightsTANKER=n or 1
function AIRWING:SetNumberTANKER(Nboom, Nprobe)
self.nflightsTANKERboom=Nboom or 1
self.nflightsTANKERprobe=Nprobe or 1
return self
end
@@ -652,6 +656,8 @@ function AIRWING:CheckCAP()
missionCAP.patroldata=patrol
patrol.noccupied=patrol.noccupied+1
self:AddMission(missionCAP)
end
@@ -664,20 +670,55 @@ end
-- @return #AIRWING self
function AIRWING:CheckTANKER()
local N=self:CountMissionsInQueue({AUFTRAG.Type.TANKER})
--local N=self:CountMissionsInQueue({AUFTRAG.Type.TANKER})
--local N=self:CountAssetsOnMission({AUFTRAG.Type.TANKER})
for i=1,self.nflightsTANKER-N do
local Nboom=0
local Nprob=0
-- Count tanker mission.
for _,_mission in pairs(self.missionqueue) do
local mission=_mission --Ops.Auftrag#AUFTRAG
if mission:IsNotOver() and self:CheckMissionType(mission.type, AUFTRAG.Type.TANKER) then
if mission.refuelSystem==0 then
Nboom=Nboom+1
elseif mission.refuelSystem==1 then
Nprob=Nprob+1
end
end
end
for i=1,self.nflightsTANKERboom-Nboom do
local patrol=self:_GetPatrolData(self.pointsTANKER)
local mission=AUFTRAG:NewTANKER(patrol.coord, patrol.speed, patrol.heading, patrol.leg, patrol.altitude)
local mission=AUFTRAG:NewTANKER(patrol.coord, patrol.speed, patrol.heading, patrol.leg, patrol.altitude, 0)
mission.patroldata=patrol
patrol.noccupied=patrol.noccupied+1
self:AddMission(mission)
end
for i=1,self.nflightsTANKERprobe-Nprob do
local patrol=self:_GetPatrolData(self.pointsTANKER)
local mission=AUFTRAG:NewTANKER(patrol.coord, patrol.speed, patrol.heading, patrol.leg, patrol.altitude, 1)
mission.patroldata=patrol
patrol.noccupied=patrol.noccupied+1
self:AddMission(mission)
end
return self
end
@@ -696,6 +737,8 @@ function AIRWING:CheckAWACS()
mission.patroldata=patrol
patrol.noccupied=patrol.noccupied+1
self:AddMission(mission)
end
@@ -717,17 +760,23 @@ function AIRWING:GetTankerForFlight(flightgroup)
for _,_tanker in pairs(tankers) do
local tanker=_tanker --#AIRWING.SquadronAsset
local tankercoord=tanker.flightgroup.group:GetCoordinate()
local assetcoord=flightgroup.group:GetCoordinate()
-- Check that donor and acceptor use the same refuelling system.
if flightgroup.refueltype and flightgroup.refueltype==tanker.flightgroup.tankertype then
local dist=assetcoord:Get2DDistance(tankercoord)
table.insert(tankeropt, {tanker=tanker, dist=dist})
local tankercoord=tanker.flightgroup.group:GetCoordinate()
local assetcoord=flightgroup.group:GetCoordinate()
local dist=assetcoord:Get2DDistance(tankercoord)
table.insert(tankeropt, {tanker=tanker, dist=dist})
end
end
-- Sort tankers wrt to distance.
table.sort(tankeropt, function(a,b) return a.dist<b.dist end)
return tankeropt[1]
-- Return tanker asset.
return tankeropt[1].tanker
end
@@ -1307,7 +1356,7 @@ end
-- @param #AIRWING self
-- @param #table MissionTypes Types on mission to be checked. Default all.
-- @return #table Assets on pending requests.
function AIRWING:GetAssetsOnMission(MissionTypes)
function AIRWING:GetAssetsOnMission(MissionTypes, IncludeQueued)
local assets={}
local Np=0
+15 -5
View File
@@ -50,6 +50,7 @@
-- @field #number engageWeaponExpend How many weapons are used.
-- @field #boolean engageAsGroup Group attack.
-- @field #number engageMaxDistance Max engage distance.
-- @field #number refuelSystem For refuel type for TANKER missions.
--
-- @field Wrapper.Group#GROUP escortGroup The group to be escorted.
-- @field DCS#Vec3 escortVec3 The 3D offset vector from the escorted group to the escort group.
@@ -65,6 +66,7 @@
-- @field #string missionTask Mission task. Seed ENUMS.MissionTask.
-- @field #number missionAltitude Mission altitude in meters.
-- @field #number missionFraction Mission coordiante fraction. Default is 0.5.
-- @field #table enrouteTasks Mission enroute tasks.
--
-- @field #number missionRepeated Number of times mission was repeated.
-- @field #number missionRepeatMax Number of times mission is repeated if failed.
@@ -108,6 +110,7 @@ AUFTRAG = {
flightdata = {},
assets = {},
missionFraction = 0.5,
enrouteTasks = {},
}
--- Global mission counter.
@@ -385,8 +388,9 @@ end
-- @param #number Heading Heading of race-track pattern in degrees. Default 270 (East to West).
-- @param #number Leg Length of race-track in NM. Default 10 NM.
-- @param #number Altitude Orbit altitude in feet.
-- @param #number RefuelSystem Refueling system.
-- @return #AUFTRAG self
function AUFTRAG:NewTANKER(OrbitCoordinate, OrbitSpeed, Heading, Leg, Altitude)
function AUFTRAG:NewTANKER(OrbitCoordinate, OrbitSpeed, Heading, Leg, Altitude, RefuelSystem)
-- Create ORBIT first.
local mission=self:NewORBIT(OrbitCoordinate, OrbitSpeed, Heading, Leg, Altitude)
@@ -396,6 +400,8 @@ function AUFTRAG:NewTANKER(OrbitCoordinate, OrbitSpeed, Heading, Leg, Altitude)
mission.missionTask=ENUMS.MissionTask.REFUELING
mission.refuelSystem=RefuelSystem
mission.DCStask=mission:GetDCSMissionTask()
return mission
@@ -1583,7 +1589,8 @@ function AUFTRAG:GetDCSMissionTask()
local DCStask=CONTROLLABLE.EnRouteTaskAWACS(nil)
table.insert(DCStasks, DCStask)
table.insert(self.enrouteTasks, DCStask)
--table.insert(DCStasks, DCStask)
elseif self.type==AUFTRAG.Type.BAI then
@@ -1631,7 +1638,8 @@ function AUFTRAG:GetDCSMissionTask()
local DCStask=CONTROLLABLE.EnRouteTaskEngageTargetsInZone(nil, self.engageZone:GetVec2(), self.engageZone:GetRadius(), self.engageTargetTypes, Priority)
table.insert(DCStasks, DCStask)
table.insert(self.enrouteTasks, DCStask)
--table.insert(DCStasks, DCStask)
elseif self.type==AUFTRAG.Type.CAS then
@@ -1641,7 +1649,8 @@ function AUFTRAG:GetDCSMissionTask()
local DCStask=CONTROLLABLE.EnRouteTaskEngageTargetsInZone(nil, self.engageZone:GetVec2(), self.engageZone:GetRadius(), self.engageTargetTypes, Priority)
table.insert(DCStasks, DCStask)
table.insert(self.enrouteTasks, DCStask)
--table.insert(DCStasks, DCStask)
elseif self.type==AUFTRAG.Type.ESCORT then
@@ -1723,8 +1732,9 @@ function AUFTRAG:GetDCSMissionTask()
-- TANKER Mission --
--------------------
--local DCStask=CONTROLLABLE.EnRouteTaskTanker(nil)
local DCStask=CONTROLLABLE.EnRouteTaskTanker(nil)
table.insert(self.enrouteTasks, DCStask)
--table.insert(DCStasks, DCStask)
elseif self.type==AUFTRAG.Type.TRANSPORT then
@@ -1898,7 +1898,7 @@ function FLIGHTCONTROL:_LandAI(flight, parking)
-- Remove flight from waiting queue.
self:_RemoveFlightFromQueue(self.Qholding, flight, "holding")
-- Altitude above ground for a glide slope of 3.
-- Altitude above ground for a glide slope of 3 degrees..
local alpha=math.rad(3)
local x1=UTILS.NMToMeters(10)
local x2=UTILS.NMToMeters(5)
@@ -43,6 +43,8 @@
-- @field #number speedmax Max speed in km/h.
-- @field #number rangemax Max range in km.
-- @field #number ceiling Max altitude the aircraft can fly at in meters.
-- @field #number tankertype The refueling system type (0=boom, 1=probe), if the group is a tanker.
-- @field #number refueltype The refueling system type (0=boom, 1=probe), if the group can refuel from a tanker.
-- @field #boolean ai If true, flight is purely AI. If false, flight contains at least one human player.
-- @field #boolean fuellow Fuel low switch.
-- @field #number fuellowthresh Low fuel threshold in percent.
@@ -2940,9 +2942,13 @@ function FLIGHTGROUP:onafterFuelLow(From, Event, To)
local airbase=self.destbase or self.homebase
if self.airwing then
-- Get closest tanker from airwing that can refuel this flight.
local tanker=self.airwing:GetTankerForFlight(self)
if tanker then
-- Send flight to tanker with refueling task.
self:Refuel(tanker.flightgroup.group:GetCoordinate())
else
@@ -3488,6 +3494,12 @@ function FLIGHTGROUP:RouteToMission(mission, delay)
env.info("FF mission altitude [m]="..waypointcoord.y)
end
-- Add enroute tasks.
for _,task in mission.enrouteTasks do
self:AddTaskEnroute(task)
end
-- Some speed.
local speed=UTILS.KmphToKnots(math.min(self.speedmax*0.8, 1000))
-- Add waypoint.
@@ -3648,6 +3660,9 @@ function FLIGHTGROUP:_InitGroup()
self.ceiling=self.descriptors.Hmax
_,self.tankertype=unit:IsTanker()
_,self.refueltype=unit:IsRefuelable()
self.ai=not self:_IsHuman(self.group)
for _,_element in pairs(self.elements) do
@@ -3666,6 +3681,8 @@ function FLIGHTGROUP:_InitGroup()
text=text..string.format("Speed max = %.1f Knots\n", UTILS.KmphToKnots(self.speedmax))
text=text..string.format("Range max = %.1f km\n", self.rangemax/1000)
text=text..string.format("Ceiling = %.1f feet\n", UTILS.MetersToFeet(self.ceiling))
text=text..string.format("Tanker type = %s\n", tostring(self.tankertype))
text=text..string.format("Refuel type = %s\n", tostring(self.refueltype))
text=text..string.format("AI = %s\n", tostring(self.ai))
text=text..string.format("Helicopter = %s\n", tostring(self.group:IsHelicopter()))
text=text..string.format("Elements = %d\n", #self.elements)
+16 -1
View File
@@ -27,6 +27,7 @@
-- @field #number Ngroups Number of asset flight groups this squadron has.
-- @field #number engageRange Engagement range in meters.
-- @field #string attribute Generalized attribute of the squadron template group.
-- @field #number refuelSystem For tanker squads, the refuel system used.
-- @extends Core.Fsm#FSM
--- Be surprised!
@@ -53,6 +54,7 @@ SQUADRON = {
airwing = nil,
Ngroups = nil,
engageRange = nil,
refuelSystem = nil,
}
--- Flight group element.
@@ -111,6 +113,8 @@ function SQUADRON:New(TemplateGroupName, Ngroups, SquadronName)
self:SetEngagementRange()
self.attribute=self.templategroup:GetAttribute()
_,self.refuelSystem=self.templategroup:GetUnit(1):IsTanker()
-- Start State.
@@ -327,6 +331,17 @@ function SQUADRON:CanMission(Mission)
-- WARNING: This assumes that all assets of the squad can do the same mission types!
local cando=self:CheckMissionType(Mission.type, self.missiontypes)
-- Check that tanker mission
if cando and Mission.type==AUFTRAG.Type.TANKER then
if Mission.refuelSystem and Mission.refuelSystem==self.refuelSystem then
-- Correct refueling system.
else
cando=false
end
end
if cando then
local TargetDistance=Mission:GetTargetDistance(self.airwing:GetCoordinate())
@@ -337,7 +352,7 @@ function SQUADRON:CanMission(Mission)
-- Set range is valid.
if TargetDistance<=self.engageRange then
-- Check if has already any missions in the queue.
-- Check if asset is currently on a mission (STARTED or QUEUED).
if self.airwing:IsAssetOnMission(asset) then
---
@@ -90,7 +90,6 @@ end
--- Returns the type name of the DCS Identifiable.
-- @param #IDENTIFIABLE self
-- @return #string The type name of the DCS Identifiable.
-- @return #nil The DCS Identifiable is not existing or alive.
function IDENTIFIABLE:GetTypeName()
self:F2( self.IdentifiableName )
+54
View File
@@ -436,6 +436,60 @@ function UNIT:GetRange()
return nil
end
--- Check if the unit is refuelable. Also retrieves the refuelling system (boom or probe) if applicable.
-- @param #UNIT self
-- @return #boolean If true, unit is refuelable (checks for the attribute "Refuelable").
-- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsRefuelable()
self:F2( self.UnitName )
local refuelable=self:HasAttribute("Refuelable")
local system=nil
local Desc=self:GetDesc().attributes
if Desc and Desc.tankerType then
system=Desc.tankerType
end
return refuelable, system
end
--- Check if the unit is a tanker. Also retrieves the refuelling system (boom or probe) if applicable.
-- @param #UNIT self
-- @return #boolean If true, unit is refuelable (checks for the attribute "Refuelable").
-- @return #number Refueling system (if any): 0=boom, 1=probe.
function UNIT:IsTanker()
self:F2( self.UnitName )
local tanker=self:HasAttribute("Tankers")
local system=nil
local Desc=self:GetDesc().attributes
if Desc and Desc.tankerType then
system=Desc.tankerType
end
local typename=self:GetTypeName()
if typename=="IL-78M" then
system=1 --probe
elseif typename=="KC130" then
system=-1 --?
elseif typename=="KC135BDA" then
system=-1 --?
elseif typename=="KC135BDA" then
system=-1 --?
elseif typename=="KC135MPRS" then
system=0 --boom
elseif typename=="S-3B Tanker" then
system=1 --probe
end
return tanker, system
end
--- Returns the unit's group if it exist and nil otherwise.
-- @param Wrapper.Unit#UNIT self
-- @return Wrapper.Group#GROUP The Group of the Unit.