mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
OPS
- Clean up on "CheckMissionType" and "CheckMissionCapability" functions ==> moved to AUFTRAG as global functions.
This commit is contained in:
@@ -330,7 +330,7 @@ function AIRWING:NewPayload(Unit, Npayloads, MissionTypes, Performance)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Add ORBIT for all.
|
-- Add ORBIT for all.
|
||||||
if not self:CheckMissionType(AUFTRAG.Type.ORBIT, MissionTypes) then
|
if not AUFTRAG.CheckMissionType(AUFTRAG.Type.ORBIT, MissionTypes) then
|
||||||
local capability={} --Ops.Auftrag#AUFTRAG.Capability
|
local capability={} --Ops.Auftrag#AUFTRAG.Capability
|
||||||
capability.MissionType=AUFTRAG.Type.ORBIT
|
capability.MissionType=AUFTRAG.Type.ORBIT
|
||||||
capability.Performance=50
|
capability.Performance=50
|
||||||
@@ -452,7 +452,7 @@ function AIRWING:FetchPayloadFromStock(UnitType, MissionType, Payloads)
|
|||||||
local payload=_payload --#AIRWING.Payload
|
local payload=_payload --#AIRWING.Payload
|
||||||
|
|
||||||
local specialpayload=_checkPayloads(payload)
|
local specialpayload=_checkPayloads(payload)
|
||||||
local compatible=self:CheckMissionCapability(MissionType, payload.capabilities)
|
local compatible=AUFTRAG.CheckMissionCapability(MissionType, payload.capabilities)
|
||||||
|
|
||||||
local goforit = specialpayload or (specialpayload==nil and compatible)
|
local goforit = specialpayload or (specialpayload==nil and compatible)
|
||||||
|
|
||||||
@@ -466,7 +466,7 @@ function AIRWING:FetchPayloadFromStock(UnitType, MissionType, Payloads)
|
|||||||
self:I(self.lid..string.format("Sorted payloads for mission type %s and aircraft type=%s:", MissionType, UnitType))
|
self:I(self.lid..string.format("Sorted payloads for mission type %s and aircraft type=%s:", MissionType, UnitType))
|
||||||
for _,_payload in ipairs(self.payloads) do
|
for _,_payload in ipairs(self.payloads) do
|
||||||
local payload=_payload --#AIRWING.Payload
|
local payload=_payload --#AIRWING.Payload
|
||||||
if payload.aircrafttype==UnitType and self:CheckMissionCapability(MissionType, payload.capabilities) then
|
if payload.aircrafttype==UnitType and AUFTRAG.CheckMissionCapability(MissionType, payload.capabilities) then
|
||||||
local performace=self:GetPayloadPeformance(payload, MissionType)
|
local performace=self:GetPayloadPeformance(payload, MissionType)
|
||||||
self:I(self.lid..string.format("- %s payload for %s: avail=%d performace=%d", MissionType, payload.aircrafttype, payload.navail, performace))
|
self:I(self.lid..string.format("- %s payload for %s: avail=%d performace=%d", MissionType, payload.aircrafttype, payload.navail, performace))
|
||||||
end
|
end
|
||||||
@@ -1165,7 +1165,7 @@ function AIRWING:CountPayloadsInStock(MissionTypes, UnitTypes, Payloads)
|
|||||||
for _,MissionType in pairs(MissionTypes) do
|
for _,MissionType in pairs(MissionTypes) do
|
||||||
|
|
||||||
local specialpayload=_checkPayloads(payload)
|
local specialpayload=_checkPayloads(payload)
|
||||||
local compatible=self:CheckMissionCapability(MissionType, payload.capabilities)
|
local compatible=AUFTRAG.CheckMissionCapability(MissionType, payload.capabilities)
|
||||||
|
|
||||||
local goforit = specialpayload or (specialpayload==nil and compatible)
|
local goforit = specialpayload or (specialpayload==nil and compatible)
|
||||||
|
|
||||||
|
|||||||
@@ -4317,6 +4317,86 @@ function AUFTRAG:GetMissionTaskforMissionType(MissionType)
|
|||||||
return mtask
|
return mtask
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
-- Global Functions
|
||||||
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--- Checks if a mission type is contained in a table of possible types.
|
||||||
|
-- @param #string MissionType The requested mission type.
|
||||||
|
-- @param #table PossibleTypes A table with possible mission types.
|
||||||
|
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
||||||
|
function AUFTRAG.CheckMissionType(MissionType, PossibleTypes)
|
||||||
|
|
||||||
|
if type(PossibleTypes)=="string" then
|
||||||
|
PossibleTypes={PossibleTypes}
|
||||||
|
end
|
||||||
|
|
||||||
|
for _,canmission in pairs(PossibleTypes) do
|
||||||
|
if canmission==MissionType then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Check if a mission type is contained in a list of possible capabilities.
|
||||||
|
-- @param #table MissionTypes The requested mission type. Can also be passed as a single mission type `#string`.
|
||||||
|
-- @param #table Capabilities A table with possible capabilities `Ops.Auftrag#AUFTRAG.Capability`.
|
||||||
|
-- @param #boolean All If `true`, given mission type must be includedin ALL capabilities. If `false` or `nil`, it must only match one.
|
||||||
|
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
||||||
|
function AUFTRAG.CheckMissionCapability(MissionTypes, Capabilities, All)
|
||||||
|
|
||||||
|
-- Ensure table.
|
||||||
|
if type(MissionTypes)~="table" then
|
||||||
|
MissionTypes={MissionTypes}
|
||||||
|
end
|
||||||
|
|
||||||
|
for _,cap in pairs(Capabilities) do
|
||||||
|
local capability=cap --Ops.Auftrag#AUFTRAG.Capability
|
||||||
|
for _,MissionType in pairs(MissionTypes) do
|
||||||
|
if All==true then
|
||||||
|
if capability.MissionType~=MissionType then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if capability.MissionType==MissionType then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if All==true then
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if a mission type is contained in a list of possible capabilities.
|
||||||
|
-- @param #table MissionTypes The requested mission type. Can also be passed as a single mission type `#string`.
|
||||||
|
-- @param #table Capabilities A table with possible capabilities `Ops.Auftrag#AUFTRAG.Capability`.
|
||||||
|
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
||||||
|
function AUFTRAG.CheckMissionCapabilityAny(MissionTypes, Capabilities)
|
||||||
|
|
||||||
|
local res=AUFTRAG.CheckMissionCapability(MissionTypes, Capabilities, false)
|
||||||
|
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--- Check if a mission type is contained in a list of possible capabilities.
|
||||||
|
-- @param #table MissionTypes The requested mission type. Can also be passed as a single mission type `#string`.
|
||||||
|
-- @param #table Capabilities A table with possible capabilities `Ops.Auftrag#AUFTRAG.Capability`.
|
||||||
|
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
||||||
|
function AUFTRAG.CheckMissionCapabilityAll(MissionTypes, Capabilities)
|
||||||
|
|
||||||
|
local res=AUFTRAG.CheckMissionCapability(MissionTypes, Capabilities, true)
|
||||||
|
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1388,31 +1388,15 @@ function CHIEF:RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMa
|
|||||||
|
|
||||||
-- Distance to target.
|
-- Distance to target.
|
||||||
local TargetDistance=Target:GetCoordinate():Get2DDistance(legion:GetCoordinate())
|
local TargetDistance=Target:GetCoordinate():Get2DDistance(legion:GetCoordinate())
|
||||||
|
|
||||||
-- Number of payloads in stock per aircraft type.
|
|
||||||
local Npayloads={}
|
|
||||||
|
|
||||||
-- First get payloads for aircraft types of squadrons.
|
|
||||||
for _,_cohort in pairs(legion.cohorts) do
|
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
|
||||||
if Npayloads[cohort.aircrafttype]==nil then
|
|
||||||
Npayloads[cohort.aircrafttype]=legion:IsAirwing() and legion:CountPayloadsInStock(MissionType, cohort.aircrafttype) or 999
|
|
||||||
self:T2(self.lid..string.format("Got N=%d payloads for mission type %s [%s]", Npayloads[cohort.aircrafttype], MissionType, cohort.aircrafttype))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Loops over cohorts.
|
-- Loops over cohorts.
|
||||||
for _,_cohort in pairs(legion.cohorts) do
|
for _,_cohort in pairs(legion.cohorts) do
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
local cohort=_cohort --Ops.Cohort#COHORT
|
||||||
|
|
||||||
local npayloads=Npayloads[cohort.aircrafttype]
|
if cohort:IsOnDuty() and AUFTRAG.CheckMissionCapability({MissionType}, cohort.missiontypes) and cohort.engageRange>=TargetDistance then
|
||||||
|
|
||||||
if cohort:IsOnDuty() and cohort:CheckMissionCapability({MissionType}) and cohort.engageRange>=TargetDistance and npayloads>0 then
|
|
||||||
|
|
||||||
-- Recruit assets from squadron.
|
-- Recruit assets from squadron.
|
||||||
local assets, npayloads=cohort:RecruitAssets(MissionType, npayloads)
|
local assets, npayloads=cohort:RecruitAssets(MissionType, 999)
|
||||||
|
|
||||||
Npayloads[cohort.aircrafttype]=npayloads
|
|
||||||
|
|
||||||
for _,asset in pairs(assets) do
|
for _,asset in pairs(assets) do
|
||||||
table.insert(Assets, asset)
|
table.insert(Assets, asset)
|
||||||
|
|||||||
@@ -45,11 +45,9 @@
|
|||||||
--
|
--
|
||||||
-- ===
|
-- ===
|
||||||
--
|
--
|
||||||
-- 
|
|
||||||
--
|
|
||||||
-- # The COHORT Concept
|
-- # The COHORT Concept
|
||||||
--
|
--
|
||||||
-- A COHORT is essential part of an BRIGADE and consists of **one** type of aircraft.
|
-- A COHORT is essential part of a LEGION and consists of **one** unit type.
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
@@ -83,7 +81,7 @@ COHORT.version="0.0.2"
|
|||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- TODO: A lot!
|
-- TODO: A lot!
|
||||||
-- TODO: Make general so that PLATOON and SQUADRON can inherit this class.
|
-- DONE: Make general so that PLATOON and SQUADRON can inherit this class.
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- Constructor
|
-- Constructor
|
||||||
@@ -285,7 +283,7 @@ function COHORT:AddMissionCapability(MissionTypes, Performance)
|
|||||||
for _,missiontype in pairs(MissionTypes) do
|
for _,missiontype in pairs(MissionTypes) do
|
||||||
|
|
||||||
-- Check not to add the same twice.
|
-- Check not to add the same twice.
|
||||||
if self:CheckMissionCapability(missiontype, self.missiontypes) then
|
if AUFTRAG.CheckMissionCapability(missiontype, self.missiontypes) then
|
||||||
self:E(self.lid.."WARNING: Mission capability already present! No need to add it twice.")
|
self:E(self.lid.."WARNING: Mission capability already present! No need to add it twice.")
|
||||||
-- TODO: update performance.
|
-- TODO: update performance.
|
||||||
else
|
else
|
||||||
@@ -736,7 +734,7 @@ function COHORT:CanMission(Mission)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Check mission type. WARNING: This assumes that all assets of the cohort can do the same mission types!
|
-- Check mission type. WARNING: This assumes that all assets of the cohort can do the same mission types!
|
||||||
if not self:CheckMissionType(Mission.type, self:GetMissionTypes()) then
|
if not AUFTRAG.CheckMissionType(Mission.type, self:GetMissionTypes()) then
|
||||||
self:T(self.lid..string.format("INFO: Cohort cannot do mission type %s (%s, %s)", Mission.type, Mission.name, Mission:GetTargetName()))
|
self:T(self.lid..string.format("INFO: Cohort cannot do mission type %s (%s, %s)", Mission.type, Mission.name, Mission:GetTargetName()))
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
@@ -780,7 +778,7 @@ function COHORT:CountAssets(InStock, MissionTypes, Attributes)
|
|||||||
for _,_asset in pairs(self.assets) do
|
for _,_asset in pairs(self.assets) do
|
||||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||||
|
|
||||||
if MissionTypes==nil or self:CheckMissionCapability(MissionTypes, self.missiontypes) then
|
if MissionTypes==nil or AUFTRAG.CheckMissionCapability(MissionTypes, self.missiontypes) then
|
||||||
if Attributes==nil or self:CheckAttribute(Attributes) then
|
if Attributes==nil or self:CheckAttribute(Attributes) then
|
||||||
if asset.spawned then
|
if asset.spawned then
|
||||||
if InStock==false or InStock==nil then
|
if InStock==false or InStock==nil then
|
||||||
@@ -806,6 +804,9 @@ end
|
|||||||
-- @return #number Number of payloads still available after recruiting the assets.
|
-- @return #number Number of payloads still available after recruiting the assets.
|
||||||
function COHORT:RecruitAssets(MissionType, Npayloads)
|
function COHORT:RecruitAssets(MissionType, Npayloads)
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:T3(self.lid..string.format("Recruiting asset for Mission type=%s", MissionType))
|
||||||
|
|
||||||
-- Recruited assets.
|
-- Recruited assets.
|
||||||
local assets={}
|
local assets={}
|
||||||
|
|
||||||
@@ -832,7 +833,7 @@ function COHORT:RecruitAssets(MissionType, Npayloads)
|
|||||||
self:I(self.lid..string.format("Adding asset on GCICAP mission for an INTERCEPT mission"))
|
self:I(self.lid..string.format("Adding asset on GCICAP mission for an INTERCEPT mission"))
|
||||||
table.insert(assets, asset)
|
table.insert(assets, asset)
|
||||||
|
|
||||||
elseif self.legion:IsAssetOnMission(asset, AUFTRAG.Type.ALERT5) and self:CheckMissionCapability(MissionType, asset.payload.capabilities) then
|
elseif self.legion:IsAssetOnMission(asset, AUFTRAG.Type.ALERT5) and AUFTRAG.CheckMissionCapability(MissionType, asset.payload.capabilities) then
|
||||||
|
|
||||||
-- Check if the payload of this asset is compatible with the mission.
|
-- Check if the payload of this asset is compatible with the mission.
|
||||||
self:I(self.lid..string.format("Adding asset on ALERT 5 mission for %s mission", MissionType))
|
self:I(self.lid..string.format("Adding asset on ALERT 5 mission for %s mission", MissionType))
|
||||||
@@ -856,7 +857,7 @@ function COHORT:RecruitAssets(MissionType, Npayloads)
|
|||||||
local flightgroup=asset.flightgroup
|
local flightgroup=asset.flightgroup
|
||||||
|
|
||||||
|
|
||||||
if flightgroup and flightgroup:IsAlive() then
|
if flightgroup and flightgroup:IsAlive() and not (flightgroup:IsDead() or flightgroup:IsStopped()) then
|
||||||
|
|
||||||
-- Assume we are ready and check if any condition tells us we are not.
|
-- Assume we are ready and check if any condition tells us we are not.
|
||||||
local combatready=true
|
local combatready=true
|
||||||
@@ -885,7 +886,7 @@ function COHORT:RecruitAssets(MissionType, Npayloads)
|
|||||||
if flightgroup:IsHolding() or flightgroup:IsLanding() or flightgroup:IsLanded() or flightgroup:IsArrived() then
|
if flightgroup:IsHolding() or flightgroup:IsLanding() or flightgroup:IsLanded() or flightgroup:IsArrived() then
|
||||||
combatready=false
|
combatready=false
|
||||||
end
|
end
|
||||||
if asset.payload and not self:CheckMissionCapability(MissionType, asset.payload.capabilities) then
|
if asset.payload and not AUFTRAG.CheckMissionCapability(MissionType, asset.payload.capabilities) then
|
||||||
combatready=false
|
combatready=false
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -901,12 +902,6 @@ function COHORT:RecruitAssets(MissionType, Npayloads)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Applies to all opsgroups.
|
|
||||||
if flightgroup:IsDead() or flightgroup:IsStopped() then
|
|
||||||
combatready=false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--TODO: Check transport for combat readyness!
|
--TODO: Check transport for combat readyness!
|
||||||
|
|
||||||
-- This asset is "combatready".
|
-- This asset is "combatready".
|
||||||
@@ -940,6 +935,8 @@ function COHORT:RecruitAssets(MissionType, Npayloads)
|
|||||||
end -- not requested check
|
end -- not requested check
|
||||||
end -- loop over assets
|
end -- loop over assets
|
||||||
|
|
||||||
|
self:T2(self.lid..string.format("Recruited %d assets for Mission type=%s", #assets, MissionType))
|
||||||
|
|
||||||
return assets, Npayloads
|
return assets, Npayloads
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -988,52 +985,6 @@ function COHORT:IsRepaired(Asset)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Checks if a mission type is contained in a table of possible types.
|
|
||||||
-- @param #COHORT self
|
|
||||||
-- @param #string MissionType The requested mission type.
|
|
||||||
-- @param #table PossibleTypes A table with possible mission types.
|
|
||||||
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
|
||||||
function COHORT:CheckMissionType(MissionType, PossibleTypes)
|
|
||||||
|
|
||||||
if type(PossibleTypes)=="string" then
|
|
||||||
PossibleTypes={PossibleTypes}
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,canmission in pairs(PossibleTypes) do
|
|
||||||
if canmission==MissionType then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Check if a mission type is contained in a list of possible capabilities.
|
|
||||||
-- @param #COHORT self
|
|
||||||
-- @param #table MissionTypes The requested mission type. Can also be passed as a single mission type `#string`.
|
|
||||||
-- @param #table Capabilities (Optional) A table with possible capabilities `Ops.Auftrag#AUFTRAG.Capability`. Default is capabilities of the cohort.
|
|
||||||
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
|
||||||
function COHORT:CheckMissionCapability(MissionTypes, Capabilities)
|
|
||||||
|
|
||||||
if type(MissionTypes)~="table" then
|
|
||||||
MissionTypes={MissionTypes}
|
|
||||||
end
|
|
||||||
|
|
||||||
Capabilities=Capabilities or self.missiontypes
|
|
||||||
|
|
||||||
for _,cap in pairs(Capabilities) do
|
|
||||||
local capability=cap --Ops.Auftrag#AUFTRAG.Capability
|
|
||||||
for _,MissionType in pairs(MissionTypes) do
|
|
||||||
if capability.MissionType==MissionType then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Check if the cohort attribute matches the given attribute(s).
|
--- Check if the cohort attribute matches the given attribute(s).
|
||||||
-- @param #COHORT self
|
-- @param #COHORT self
|
||||||
-- @param #table Attributes The requested attributes. See `WAREHOUSE.Attribute` enum. Can also be passed as a single attribute `#string`.
|
-- @param #table Attributes The requested attributes. See `WAREHOUSE.Attribute` enum. Can also be passed as a single attribute `#string`.
|
||||||
|
|||||||
@@ -735,35 +735,15 @@ function COMMANDER:RecruitAssets(Mission)
|
|||||||
|
|
||||||
for _,_legion in pairs(legions) do
|
for _,_legion in pairs(legions) do
|
||||||
local legion=_legion --Ops.Legion#LEGION
|
local legion=_legion --Ops.Legion#LEGION
|
||||||
|
|
||||||
-- Number of payloads in stock per aircraft type.
|
|
||||||
local Npayloads={}
|
|
||||||
|
|
||||||
-- First get payloads for aircraft types of squadrons.
|
|
||||||
for _,_cohort in pairs(legion.cohorts) do
|
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
|
||||||
if Npayloads[cohort.aircrafttype]==nil then
|
|
||||||
local MissionType=Mission.type
|
|
||||||
if MissionType==AUFTRAG.Type.ALERT5 then
|
|
||||||
MissionType=Mission.alert5MissionType
|
|
||||||
end
|
|
||||||
Npayloads[cohort.aircrafttype]=legion:IsAirwing() and legion:CountPayloadsInStock(MissionType, cohort.aircrafttype, Mission.payloads) or 999
|
|
||||||
self:T2(self.lid..string.format("Got N=%d payloads for mission type %s [%s]", Npayloads[cohort.aircrafttype], MissionType, cohort.aircrafttype))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Loops over cohorts.
|
-- Loops over cohorts.
|
||||||
for _,_cohort in pairs(legion.cohorts) do
|
for _,_cohort in pairs(legion.cohorts) do
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
local cohort=_cohort --Ops.Cohort#COHORT
|
||||||
|
|
||||||
local npayloads=Npayloads[cohort.aircrafttype]
|
if cohort:CanMission(Mission) then
|
||||||
|
|
||||||
if cohort:CanMission(Mission) and npayloads>0 then
|
|
||||||
|
|
||||||
-- Recruit assets from squadron.
|
-- Recruit assets from squadron.
|
||||||
local assets, npayloads=cohort:RecruitAssets(Mission.type, npayloads)
|
local assets, npayloads=cohort:RecruitAssets(Mission.type, 999)
|
||||||
|
|
||||||
Npayloads[cohort.aircrafttype]=npayloads
|
|
||||||
|
|
||||||
for _,asset in pairs(assets) do
|
for _,asset in pairs(assets) do
|
||||||
table.insert(Assets, asset)
|
table.insert(Assets, asset)
|
||||||
|
|||||||
@@ -288,7 +288,6 @@ function LEGION:AddMission(Mission)
|
|||||||
--Mission.opstransport:SetPickupZone(self.spawnzone)
|
--Mission.opstransport:SetPickupZone(self.spawnzone)
|
||||||
--Mission.opstransport:SetEmbarkZone(self.spawnzone)
|
--Mission.opstransport:SetEmbarkZone(self.spawnzone)
|
||||||
|
|
||||||
|
|
||||||
-- Loop over all defined transport legions.
|
-- Loop over all defined transport legions.
|
||||||
for _,_legion in pairs(Mission.transportLegions) do
|
for _,_legion in pairs(Mission.transportLegions) do
|
||||||
local legion=_legion --Ops.Legion#LEGION
|
local legion=_legion --Ops.Legion#LEGION
|
||||||
@@ -1240,7 +1239,7 @@ function LEGION:IsAssetOnMission(asset, MissionTypes)
|
|||||||
local status=mission:GetGroupStatus(asset.flightgroup)
|
local status=mission:GetGroupStatus(asset.flightgroup)
|
||||||
|
|
||||||
-- Only if mission is started or executing.
|
-- Only if mission is started or executing.
|
||||||
if (status==AUFTRAG.GroupStatus.STARTED or status==AUFTRAG.GroupStatus.EXECUTING) and self:CheckMissionType(mission.type, MissionTypes) then
|
if (status==AUFTRAG.GroupStatus.STARTED or status==AUFTRAG.GroupStatus.EXECUTING) and AUFTRAG.CheckMissionType(mission.type, MissionTypes) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1340,7 +1339,7 @@ function LEGION:CountPayloadsInStock(MissionTypes, UnitTypes, Payloads)
|
|||||||
for _,MissionType in pairs(MissionTypes) do
|
for _,MissionType in pairs(MissionTypes) do
|
||||||
|
|
||||||
local specialpayload=_checkPayloads(payload)
|
local specialpayload=_checkPayloads(payload)
|
||||||
local compatible=self:CheckMissionCapability(MissionType, payload.capabilities)
|
local compatible=AUFTRAG.CheckMissionCapability(MissionType, payload.capabilities)
|
||||||
|
|
||||||
local goforit = specialpayload or (specialpayload==nil and compatible)
|
local goforit = specialpayload or (specialpayload==nil and compatible)
|
||||||
|
|
||||||
@@ -1374,7 +1373,7 @@ function LEGION:CountMissionsInQueue(MissionTypes)
|
|||||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||||
|
|
||||||
-- Check if this mission type is requested.
|
-- Check if this mission type is requested.
|
||||||
if mission:IsNotOver() and self:CheckMissionType(mission.type, MissionTypes) then
|
if mission:IsNotOver() and AUFTRAG.CheckMissionType(mission.type, MissionTypes) then
|
||||||
N=N+1
|
N=N+1
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1462,7 +1461,7 @@ function LEGION:CountAssetsOnMission(MissionTypes, Cohort)
|
|||||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||||
|
|
||||||
-- Check if this mission type is requested.
|
-- Check if this mission type is requested.
|
||||||
if self:CheckMissionType(mission.type, MissionTypes or AUFTRAG.Type) then
|
if AUFTRAG.CheckMissionType(mission.type, MissionTypes or AUFTRAG.Type) then
|
||||||
|
|
||||||
for _,_asset in pairs(mission.assets or {}) do
|
for _,_asset in pairs(mission.assets or {}) do
|
||||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||||
@@ -1504,7 +1503,7 @@ function LEGION:GetAssetsOnMission(MissionTypes)
|
|||||||
local mission=_mission --Ops.Auftrag#AUFTRAG
|
local mission=_mission --Ops.Auftrag#AUFTRAG
|
||||||
|
|
||||||
-- Check if this mission type is requested.
|
-- Check if this mission type is requested.
|
||||||
if self:CheckMissionType(mission.type, MissionTypes) then
|
if AUFTRAG.CheckMissionType(mission.type, MissionTypes) then
|
||||||
|
|
||||||
for _,_asset in pairs(mission.assets or {}) do
|
for _,_asset in pairs(mission.assets or {}) do
|
||||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||||
@@ -1556,76 +1555,12 @@ function LEGION:GetAircraftTypes(onlyactive, cohorts)
|
|||||||
return unittypes
|
return unittypes
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Check if assets for a given mission type are available.
|
--- Recruit assets for a given mission.
|
||||||
--
|
|
||||||
-- OBSOLETE and renamed to _CanMission (to see if it is still used somewhere)
|
|
||||||
--
|
|
||||||
-- @param #LEGION self
|
-- @param #LEGION self
|
||||||
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
||||||
-- @return #boolean If true, enough assets are available.
|
-- @return #boolean If `true` enough assets could be recruited.
|
||||||
-- @return #table Assets that can do the required mission.
|
function LEGION:RecruitAssets(Mission)
|
||||||
function LEGION:_CanMission(Mission)
|
|
||||||
|
|
||||||
-- Assume we CAN and NO assets are available.
|
|
||||||
local Can=true
|
|
||||||
local Assets={}
|
|
||||||
|
|
||||||
-- Squadrons for the job. If user assigned to mission or simply all.
|
|
||||||
local cohorts=Mission.squadrons or self.cohorts
|
|
||||||
|
|
||||||
-- Number of required assets.
|
|
||||||
local Nassets=Mission:GetRequiredAssets(self)
|
|
||||||
|
|
||||||
-- Get aircraft unit types for the job.
|
|
||||||
local unittypes=self:GetAircraftTypes(true, cohorts)
|
|
||||||
|
|
||||||
-- Count all payloads in stock.
|
|
||||||
if self:IsAirwing() then
|
|
||||||
|
|
||||||
-- Number of payloads in stock.
|
|
||||||
local Npayloads=self:CountPayloadsInStock(Mission.type, unittypes, Mission.payloads)
|
|
||||||
|
|
||||||
if Npayloads<Nassets then
|
|
||||||
self:T(self.lid..string.format("INFO: Not enough PAYLOADS available! Got %d but need at least %d", Npayloads, Nassets))
|
|
||||||
return false, Assets
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Loop over cohorts and recruit assets.
|
|
||||||
for cohortname,_cohort in pairs(cohorts) do
|
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
|
||||||
|
|
||||||
-- Check if this cohort can.
|
|
||||||
local can=cohort:CanMission(Mission)
|
|
||||||
|
|
||||||
if can then
|
|
||||||
|
|
||||||
-- Number of payloads available.
|
|
||||||
local Npayloads=self:IsAirwing() and self:CountPayloadsInStock(Mission.type, cohort.aircrafttype, Mission.payloads) or 999
|
|
||||||
|
|
||||||
-- Recruit assets.
|
|
||||||
local assets=cohort:RecruitAssets(Mission.type, Npayloads)
|
|
||||||
|
|
||||||
-- Total number.
|
|
||||||
for _,asset in pairs(assets) do
|
|
||||||
table.insert(Assets, asset)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Debug output.
|
|
||||||
local text=string.format("Mission=%s, cohort=%s, payloads=%d, can=%s, assets=%d. Found %d/%d", Mission.type, cohort.name, Npayloads, tostring(can), #assets, #Assets, Mission.nassets)
|
|
||||||
self:T(self.lid..text)
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check if required assets are present.
|
|
||||||
if Nassets>#Assets then
|
|
||||||
self:T(self.lid..string.format("INFO: Not enough assets available! Got %d but need at least %d", #Assets, Mission.nassets))
|
|
||||||
Can=false
|
|
||||||
end
|
|
||||||
|
|
||||||
return Can, Assets
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Recruit assets for a given mission.
|
--- Recruit assets for a given mission.
|
||||||
@@ -1634,41 +1569,36 @@ end
|
|||||||
-- @return #boolean If `true` enough assets could be recruited.
|
-- @return #boolean If `true` enough assets could be recruited.
|
||||||
function LEGION:RecruitAssets(Mission)
|
function LEGION:RecruitAssets(Mission)
|
||||||
|
|
||||||
-- Number of payloads in stock per aircraft type.
|
-- The recruited assets.
|
||||||
local Npayloads={}
|
local Assets={}
|
||||||
|
|
||||||
|
-- Get number of required assets.
|
||||||
|
local Nassets=Mission:GetRequiredAssets(self)
|
||||||
|
|
||||||
-- Squadrons for the job. If user assigned to mission or simply all.
|
-- Squadrons for the job. If user assigned to mission or simply all.
|
||||||
local cohorts=Mission.squadrons or self.cohorts
|
local cohorts=Mission.squadrons or self.cohorts
|
||||||
|
|
||||||
-- First get payloads for aircraft types of squadrons.
|
-- Target position.
|
||||||
for _,_cohort in pairs(cohorts) do
|
local TargetVec2=Mission.type~=AUFTRAG.Type.ALERT5 and Mission:GetTargetVec2() or nil
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
|
||||||
if Npayloads[cohort.aircrafttype]==nil then
|
-- Set mission type.
|
||||||
local MissionType=Mission.type
|
local MissionType=Mission.type
|
||||||
if MissionType==AUFTRAG.Type.ALERT5 then
|
if MissionType==AUFTRAG.Type.ALERT5 and Mission.alert5MissionType then
|
||||||
MissionType=Mission.alert5MissionType
|
-- If this is an Alert5 mission, we try to find the assets that are
|
||||||
end
|
MissionType=Mission.alert5MissionType
|
||||||
Npayloads[cohort.aircrafttype]=self:IsAirwing() and self:CountPayloadsInStock(MissionType, cohort.aircrafttype, Mission.payloads) or 999
|
|
||||||
self:T2(self.lid..string.format("Got N=%d payloads for mission type=%s and unit type=%s", Npayloads[cohort.aircrafttype], MissionType, cohort.aircrafttype))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- The recruited assets.
|
|
||||||
local Assets={}
|
|
||||||
|
|
||||||
-- Loops over cohorts.
|
-- Loops over cohorts.
|
||||||
for _,_cohort in pairs(cohorts) do
|
for _,_cohort in pairs(cohorts) do
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
local cohort=_cohort --Ops.Cohort#COHORT
|
||||||
|
|
||||||
local npayloads=Npayloads[cohort.aircrafttype]
|
-- Check OnDuty, mission type, range and refueling type (if TANKER).
|
||||||
|
if cohort:CanMission(Mission) then
|
||||||
|
|
||||||
if cohort:CanMission(Mission) and npayloads>0 then
|
-- Recruit assets from cohort.
|
||||||
|
local assets, npayloads=cohort:RecruitAssets(Mission.type, 999)
|
||||||
-- Recruit assets from squadron.
|
|
||||||
local assets, npayloads=cohort:RecruitAssets(Mission.type, npayloads)
|
|
||||||
|
|
||||||
Npayloads[cohort.aircrafttype]=npayloads
|
|
||||||
|
|
||||||
|
-- Add assets to the list.
|
||||||
for _,asset in pairs(assets) do
|
for _,asset in pairs(assets) do
|
||||||
table.insert(Assets, asset)
|
table.insert(Assets, asset)
|
||||||
end
|
end
|
||||||
@@ -1677,9 +1607,6 @@ function LEGION:RecruitAssets(Mission)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Target position.
|
|
||||||
local TargetVec2=Mission.type~=AUFTRAG.Type.ALERT5 and Mission:GetTargetVec2() or nil
|
|
||||||
|
|
||||||
-- Now we have a long list with assets.
|
-- Now we have a long list with assets.
|
||||||
self:_OptimizeAssetSelection(Assets, Mission.type, TargetVec2, false)
|
self:_OptimizeAssetSelection(Assets, Mission.type, TargetVec2, false)
|
||||||
|
|
||||||
@@ -1692,14 +1619,6 @@ function LEGION:RecruitAssets(Mission)
|
|||||||
-- Only assets that have no payload. Should be only spawned assets!
|
-- Only assets that have no payload. Should be only spawned assets!
|
||||||
if not asset.payload then
|
if not asset.payload then
|
||||||
|
|
||||||
-- Set mission type.
|
|
||||||
local MissionType=Mission.type
|
|
||||||
|
|
||||||
-- Get a loadout for the actual mission this group is waiting for.
|
|
||||||
if Mission.type==AUFTRAG.Type.ALERT5 and Mission.alert5MissionType then
|
|
||||||
MissionType=Mission.alert5MissionType
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Fetch payload for asset. This can be nil!
|
-- Fetch payload for asset. This can be nil!
|
||||||
asset.payload=self:FetchPayloadFromStock(asset.unittype, MissionType, Mission.payloads)
|
asset.payload=self:FetchPayloadFromStock(asset.unittype, MissionType, Mission.payloads)
|
||||||
|
|
||||||
@@ -1720,9 +1639,6 @@ function LEGION:RecruitAssets(Mission)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get number of required assets.
|
|
||||||
local Nassets=Mission:GetRequiredAssets(self)
|
|
||||||
|
|
||||||
if #Assets>=Nassets then
|
if #Assets>=Nassets then
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -1774,6 +1690,35 @@ function LEGION:RecruitAssets(Mission)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Recruit assets for a given mission.
|
||||||
|
-- @param #LEGION self
|
||||||
|
-- @param #string MissionType Mission type.
|
||||||
|
-- @param #table Cohorts Cohorts included.
|
||||||
|
-- @param #table Payloads (Optional) Special payloads.
|
||||||
|
-- @return #table Table of payloads for each unit type.
|
||||||
|
function LEGION:_CountPayloads(MissionType, Cohorts, Payloads)
|
||||||
|
|
||||||
|
-- Number of payloads in stock per aircraft type.
|
||||||
|
local Npayloads={}
|
||||||
|
|
||||||
|
-- First get payloads for aircraft types of squadrons.
|
||||||
|
for _,_cohort in pairs(Cohorts) do
|
||||||
|
local cohort=_cohort --Ops.Cohort#COHORT
|
||||||
|
|
||||||
|
-- We only need that element once.
|
||||||
|
if Npayloads[cohort.aircrafttype]==nil then
|
||||||
|
|
||||||
|
-- Count number of payloads in stock for the cohort aircraft type.
|
||||||
|
Npayloads[cohort.aircrafttype]=cohort.legion:IsAirwing() and self:CountPayloadsInStock(MissionType, cohort.aircrafttype, Payloads) or 999
|
||||||
|
|
||||||
|
-- Debug info.
|
||||||
|
self:T2(self.lid..string.format("Got N=%d payloads for mission type=%s and unit type=%s", Npayloads[cohort.aircrafttype], MissionType, cohort.aircrafttype))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Npayloads
|
||||||
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
-- Transport Functions
|
-- Transport Functions
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
@@ -1806,18 +1751,15 @@ function LEGION:RecruitAssetsForTransport(Transport)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Number of payloads in stock per aircraft type.
|
-- Target is the deploy zone.
|
||||||
local Npayloads={}
|
local TargetVec2=Transport:GetDeployZone():GetVec2()
|
||||||
|
|
||||||
-- First get payloads for aircraft types of squadrons.
|
|
||||||
for _,_cohort in pairs(self.cohorts) do
|
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
|
||||||
if Npayloads[cohort.aircrafttype]==nil then
|
|
||||||
Npayloads[cohort.aircrafttype]=self:IsAirwing() and self:CountPayloadsInStock(AUFTRAG.Type.OPSTRANSPORT, cohort.aircrafttype) or 999
|
|
||||||
self:T2(self.lid..string.format("Got N=%d payloads for mission type=%s and unit type=%s", Npayloads[cohort.aircrafttype], AUFTRAG.Type.OPSTRANSPORT, cohort.aircrafttype))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
-- Number of payloads in stock per aircraft type.
|
||||||
|
local Npayloads=self:_CountPayloads(AUFTRAG.Type.OPSTRANSPORT, self.cohorts)
|
||||||
|
|
||||||
|
-- Number of required carriers.
|
||||||
|
local NreqMin,NreqMax=Transport:GetRequiredCarriers()
|
||||||
|
|
||||||
-- The recruited assets.
|
-- The recruited assets.
|
||||||
local Assets={}
|
local Assets={}
|
||||||
|
|
||||||
@@ -1825,9 +1767,9 @@ function LEGION:RecruitAssetsForTransport(Transport)
|
|||||||
for _,_cohort in pairs(self.cohorts) do
|
for _,_cohort in pairs(self.cohorts) do
|
||||||
local cohort=_cohort --Ops.Cohort#COHORT
|
local cohort=_cohort --Ops.Cohort#COHORT
|
||||||
|
|
||||||
local npayloads=Npayloads[cohort.aircrafttype]
|
local npayloads=999 --Npayloads[cohort.aircrafttype]
|
||||||
|
|
||||||
if cohort:IsOnDuty() and npayloads>0 and cohort:CheckMissionCapability({AUFTRAG.Type.OPSTRANSPORT}) and cohort.cargobayLimit>=weightGroup then
|
if cohort:IsOnDuty() and npayloads>0 and AUFTRAG.CheckMissionCapability({AUFTRAG.Type.OPSTRANSPORT}, cohort.missiontypes) and cohort.cargobayLimit>=weightGroup then
|
||||||
|
|
||||||
-- Recruit assets from squadron.
|
-- Recruit assets from squadron.
|
||||||
local assets, npayloads=cohort:RecruitAssets(AUFTRAG.Type.OPSTRANSPORT, npayloads)
|
local assets, npayloads=cohort:RecruitAssets(AUFTRAG.Type.OPSTRANSPORT, npayloads)
|
||||||
@@ -1842,9 +1784,6 @@ function LEGION:RecruitAssetsForTransport(Transport)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Target is the deploy zone.
|
|
||||||
local TargetVec2=Transport:GetDeployZone():GetVec2()
|
|
||||||
|
|
||||||
-- Sort asset list. Best ones come first.
|
-- Sort asset list. Best ones come first.
|
||||||
self:_OptimizeAssetSelection(Assets, AUFTRAG.Type.OPSTRANSPORT, TargetVec2, false)
|
self:_OptimizeAssetSelection(Assets, AUFTRAG.Type.OPSTRANSPORT, TargetVec2, false)
|
||||||
|
|
||||||
@@ -1874,9 +1813,6 @@ function LEGION:RecruitAssetsForTransport(Transport)
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Number of required carriers.
|
|
||||||
local NreqMin,NreqMax=Transport:GetRequiredCarriers()
|
|
||||||
|
|
||||||
-- Number of assets. At most NreqMax.
|
-- Number of assets. At most NreqMax.
|
||||||
local Nassets=math.min(#Assets, NreqMax)
|
local Nassets=math.min(#Assets, NreqMax)
|
||||||
|
|
||||||
@@ -2042,43 +1978,6 @@ end
|
|||||||
-- Misc Functions
|
-- Misc Functions
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
--- Check if a mission type is contained in a list of possible types.
|
|
||||||
-- @param #LEGION self
|
|
||||||
-- @param #string MissionType The requested mission type.
|
|
||||||
-- @param #table PossibleTypes A table with possible mission types.
|
|
||||||
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
|
||||||
function LEGION:CheckMissionType(MissionType, PossibleTypes)
|
|
||||||
|
|
||||||
if type(PossibleTypes)=="string" then
|
|
||||||
PossibleTypes={PossibleTypes}
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,canmission in pairs(PossibleTypes) do
|
|
||||||
if canmission==MissionType then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Check if a mission type is contained in a list of possible capabilities.
|
|
||||||
-- @param #LEGION self
|
|
||||||
-- @param #string MissionType The requested mission type.
|
|
||||||
-- @param #table Capabilities A table with possible capabilities.
|
|
||||||
-- @return #boolean If true, the requested mission type is part of the possible mission types.
|
|
||||||
function LEGION:CheckMissionCapability(MissionType, Capabilities)
|
|
||||||
|
|
||||||
for _,cap in pairs(Capabilities) do
|
|
||||||
local capability=cap --Ops.Auftrag#AUFTRAG.Capability
|
|
||||||
if capability.MissionType==MissionType then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Get payload performance for a given type of misson type.
|
--- Get payload performance for a given type of misson type.
|
||||||
-- @param #LEGION self
|
-- @param #LEGION self
|
||||||
-- @param Ops.Airwing#AIRWING.Payload Payload The payload table.
|
-- @param Ops.Airwing#AIRWING.Payload Payload The payload table.
|
||||||
|
|||||||
Reference in New Issue
Block a user