OPS Cleanup

This commit is contained in:
Frank 2021-08-12 11:07:28 +02:00
parent 93f4b345c5
commit b21c3ed4e9
6 changed files with 92 additions and 88 deletions

View File

@ -557,17 +557,8 @@ end
-- @param #string SquadronName Name of the squadron, e.g. "VFA-37". -- @param #string SquadronName Name of the squadron, e.g. "VFA-37".
-- @return Ops.Squadron#SQUADRON The squadron object. -- @return Ops.Squadron#SQUADRON The squadron object.
function AIRWING:GetSquadron(SquadronName) function AIRWING:GetSquadron(SquadronName)
local squad=self:_GetCohort(SquadronName)
for _,_squadron in pairs(self.cohorts) do return squad
local squadron=_squadron --Ops.Squadron#SQUADRON
if squadron.name==SquadronName then
return squadron
end
end
return nil
end end
--- Get squadron of an asset. --- Get squadron of an asset.

View File

@ -454,12 +454,12 @@ AUFTRAG.version="0.7.1"
-- TODO list -- TODO list
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- DONE: Option to assign a specific payload for the mission (requires an AIRWING).
-- TODO: Mission success options damaged, destroyed. -- TODO: Mission success options damaged, destroyed.
-- TODO: Recon mission. What input? Set of coordinates?
-- NOPE: Clone mission. How? Deepcopy? ==> Create a new auftrag.
-- TODO: F10 marker to create new missions. -- TODO: F10 marker to create new missions.
-- TODO: Add recovery tanker mission for boat ops. -- TODO: Add recovery tanker mission for boat ops.
-- DONE: Option to assign a specific payload for the mission (requires an AIRWING).
-- NOPE: Clone mission. How? Deepcopy? ==> Create a new auftrag.
-- DONE: Recon mission. What input? Set of coordinates?
-- DONE: Option to assign mission to specific squadrons (requires an AIRWING). -- DONE: Option to assign mission to specific squadrons (requires an AIRWING).
-- DONE: Add mission start conditions. -- DONE: Add mission start conditions.
-- DONE: Add rescue helo mission for boat ops. -- DONE: Add rescue helo mission for boat ops.
@ -1877,6 +1877,21 @@ function AUFTRAG:AddConditionPush(ConditionFunction, ...)
return self return self
end end
--- Assign a legion cohort to the mission. Only these cohorts will be considered for the job.
-- @param #AUFTRAG self
-- @param Ops.Cohort#COHORT Cohort The cohort.
-- @return #AUFTRAG self
function AUFTRAG:_AssignCohort(Cohort)
self.squadrons=self.squadrons or {}
self:T3(self.lid..string.format("Assigning cohort %s", tostring(Cohort.name)))
table.insert(self.squadrons, Cohort)
return self
end
--- Assign airwing squadron(s) to the mission. Only these squads will be considered for the job. --- Assign airwing squadron(s) to the mission. Only these squads will be considered for the job.
-- @param #AUFTRAG self -- @param #AUFTRAG self
@ -1887,10 +1902,9 @@ function AUFTRAG:AssignSquadrons(Squadrons)
for _,_squad in pairs(Squadrons) do for _,_squad in pairs(Squadrons) do
local squadron=_squad --Ops.Squadron#SQUADRON local squadron=_squad --Ops.Squadron#SQUADRON
self:I(self.lid..string.format("Assigning squadron %s", tostring(squadron.name))) self:I(self.lid..string.format("Assigning squadron %s", tostring(squadron.name)))
self:_AssignCohort(squadron)
end end
self.squadrons=Squadrons
return self return self
end end

View File

@ -142,9 +142,7 @@ end
-- @param #string PlatoonName Name of the platoon. -- @param #string PlatoonName Name of the platoon.
-- @return Ops.Platoon#PLATOON The Platoon object. -- @return Ops.Platoon#PLATOON The Platoon object.
function BRIGADE:GetPlatoon(PlatoonName) function BRIGADE:GetPlatoon(PlatoonName)
local platoon=self:_GetCohort(PlatoonName) local platoon=self:_GetCohort(PlatoonName)
return platoon return platoon
end end
@ -152,7 +150,7 @@ end
-- @param #BRIGADE self -- @param #BRIGADE self
-- @param Ops.Warehouse#WAREHOUSE.Assetitem Asset The platoon asset. -- @param Ops.Warehouse#WAREHOUSE.Assetitem Asset The platoon asset.
-- @return Ops.Platoon#PLATOON The platoon object. -- @return Ops.Platoon#PLATOON The platoon object.
function BRIGADE:GetSquadronOfAsset(Asset) function BRIGADE:GetPlatoonOfAsset(Asset)
local platoon=self:GetPlatoon(Asset.squadname) local platoon=self:GetPlatoon(Asset.squadname)
return platoon return platoon
end end
@ -160,8 +158,8 @@ end
--- Remove asset from squadron. --- Remove asset from squadron.
-- @param #BRIGADE self -- @param #BRIGADE self
-- @param #BRIGADE.SquadronAsset Asset The squad asset. -- @param #BRIGADE.SquadronAsset Asset The squad asset.
function BRIGADE:RemoveAssetFromSquadron(Asset) function BRIGADE:RemoveAssetFromPlatoon(Asset)
local squad=self:GetSquadronOfAsset(Asset) local squad=self:GetPlatoonOfAsset(Asset)
if squad then if squad then
squad:DelAsset(Asset) squad:DelAsset(Asset)
end end

View File

@ -2,10 +2,10 @@
-- --
-- **Main Features:** -- **Main Features:**
-- --
-- * Set parameters like livery, skill valid for all platoon members. -- * Set parameters like livery, skill valid for all cohort members.
-- * Define modex and callsigns. -- * Define modex and callsigns.
-- * Define mission types, this platoon can perform (see Ops.Auftrag#AUFTRAG). -- * Define mission types, this cohort can perform (see Ops.Auftrag#AUFTRAG).
-- * Pause/unpause platoon operations. -- * Pause/unpause cohort operations.
-- --
-- === -- ===
-- --
@ -19,21 +19,21 @@
-- @field #string ClassName Name of the class. -- @field #string ClassName Name of the class.
-- @field #number verbose Verbosity level. -- @field #number verbose Verbosity level.
-- @field #string lid Class id string for output to DCS log file. -- @field #string lid Class id string for output to DCS log file.
-- @field #string name Name of the platoon. -- @field #string name Name of the cohort.
-- @field #string templatename Name of the template group. -- @field #string templatename Name of the template group.
-- @field #string aircrafttype Type of the airframe the platoon is using. -- @field #string aircrafttype Type of the units the cohort is using.
-- @field Wrapper.Group#GROUP templategroup Template group. -- @field Wrapper.Group#GROUP templategroup Template group.
-- @field #table assets Cohort assets. -- @field #table assets Cohort assets.
-- @field #table missiontypes Capabilities (mission types and performances) of the platoon. -- @field #table missiontypes Capabilities (mission types and performances) of the cohort.
-- @field #number maintenancetime Time in seconds needed for maintenance of a returned flight. -- @field #number maintenancetime Time in seconds needed for maintenance of a returned flight.
-- @field #number repairtime Time in seconds for each -- @field #number repairtime Time in seconds for each
-- @field #string livery Livery of the platoon. -- @field #string livery Livery of the cohort.
-- @field #number skill Skill of platoon members. -- @field #number skill Skill of cohort members.
-- @field Ops.Legion#LEGION legion The LEGION object the cohort belongs to. -- @field Ops.Legion#LEGION legion The LEGION object the cohort belongs to.
-- @field #number Ngroups Number of asset flight groups this platoon has. -- @field #number Ngroups Number of asset OPS groups this cohort has.
-- @field #number engageRange Mission range in meters. -- @field #number engageRange Mission range in meters.
-- @field #string attribute Generalized attribute of the platoon template group. -- @field #string attribute Generalized attribute of the cohort template group.
-- @field #table tacanChannel List of TACAN channels available to the platoon. -- @field #table tacanChannel List of TACAN channels available to the cohort.
-- @field #number radioFreq Radio frequency in MHz the cohort uses. -- @field #number radioFreq Radio frequency in MHz the cohort uses.
-- @field #number radioModu Radio modulation the cohort uses. -- @field #number radioModu Radio modulation the cohort uses.
-- @field #table tacanChannel List of TACAN channels available to the cohort. -- @field #table tacanChannel List of TACAN channels available to the cohort.
@ -72,7 +72,7 @@ COHORT = {
--- COHORT class version. --- COHORT class version.
-- @field #string version -- @field #string version
COHORT.version="0.0.1" COHORT.version="0.0.2"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list -- TODO list
@ -88,8 +88,8 @@ COHORT.version="0.0.1"
--- Create a new COHORT object and start the FSM. --- Create a new COHORT object and start the FSM.
-- @param #COHORT self -- @param #COHORT self
-- @param #string TemplateGroupName Name of the template group. -- @param #string TemplateGroupName Name of the template group.
-- @param #number Ngroups Number of asset groups of this platoon. Default 3. -- @param #number Ngroups Number of asset groups of this Cohort. Default 3.
-- @param #string CohortName Name of the platoon, e.g. "VFA-37". -- @param #string CohortName Name of the cohort.
-- @return #COHORT self -- @return #COHORT self
function COHORT:New(TemplateGroupName, Ngroups, CohortName) function COHORT:New(TemplateGroupName, Ngroups, CohortName)
@ -133,10 +133,10 @@ function COHORT:New(TemplateGroupName, Ngroups, CohortName)
self:AddTransition("Stopped", "Start", "OnDuty") -- Start FSM. self:AddTransition("Stopped", "Start", "OnDuty") -- Start FSM.
self:AddTransition("*", "Status", "*") -- Status update. self:AddTransition("*", "Status", "*") -- Status update.
self:AddTransition("OnDuty", "Pause", "Paused") -- Pause platoon. self:AddTransition("OnDuty", "Pause", "Paused") -- Pause cohort.
self:AddTransition("Paused", "Unpause", "OnDuty") -- Unpause platoon. self:AddTransition("Paused", "Unpause", "OnDuty") -- Unpause cohort.
self:AddTransition("*", "Stop", "Stopped") -- Stop platoon. self:AddTransition("*", "Stop", "Stopped") -- Stop cohort.
------------------------ ------------------------
@ -176,7 +176,7 @@ end
-- User functions -- User functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Set livery painted on all platoon aircraft. --- Set livery painted on all cohort units.
-- Note that the livery name in general is different from the name shown in the mission editor. -- Note that the livery name in general is different from the name shown in the mission editor.
-- --
-- Valid names are the names of the **livery directories**. Check out the folder in your DCS installation for: -- Valid names are the names of the **livery directories**. Check out the folder in your DCS installation for:
@ -196,10 +196,10 @@ function COHORT:SetLivery(LiveryName)
return self return self
end end
--- Set skill level of all platoon team members. --- Set skill level of all cohort team members.
-- @param #COHORT self -- @param #COHORT self
-- @param #string Skill Skill of all flights. -- @param #string Skill Skill of all flights.
-- @usage myplatoon:SetSkill(AI.Skill.EXCELLENT) -- @usage mycohort:SetSkill(AI.Skill.EXCELLENT)
-- @return #COHORT self -- @return #COHORT self
function COHORT:SetSkill(Skill) function COHORT:SetSkill(Skill)
self.skill=Skill self.skill=Skill
@ -230,7 +230,6 @@ end
-- @param #COHORT self -- @param #COHORT self
-- @param #number Frequency Radio frequency in MHz. Default 251 MHz. -- @param #number Frequency Radio frequency in MHz. Default 251 MHz.
-- @param #number Modulation Radio modulation. Default 0=AM. -- @param #number Modulation Radio modulation. Default 0=AM.
-- @usage myplatoon:SetSkill(AI.Skill.EXCELLENT)
-- @return #COHORT self -- @return #COHORT self
function COHORT:SetRadio(Frequency, Modulation) function COHORT:SetRadio(Frequency, Modulation)
self.radioFreq=Frequency or 251 self.radioFreq=Frequency or 251
@ -249,7 +248,7 @@ function COHORT:SetGrouping(nunits)
return self return self
end end
--- Set mission types this platoon is able to perform. --- Set mission types this cohort is able to perform.
-- @param #COHORT self -- @param #COHORT self
-- @param #table MissionTypes Table of mission types. Can also be passed as a #string if only one type. -- @param #table MissionTypes Table of mission types. Can also be passed as a #string if only one type.
-- @param #number Performance Performance describing how good this mission can be performed. Higher is better. Default 50. Max 100. -- @param #number Performance Performance describing how good this mission can be performed. Higher is better. Default 50. Max 100.
@ -286,7 +285,7 @@ function COHORT:AddMissionCapability(MissionTypes, Performance)
return self return self
end end
--- Get mission types this platoon is able to perform. --- Get mission types this cohort is able to perform.
-- @param #COHORT self -- @param #COHORT self
-- @return #table Table of mission types. Could be empty {}. -- @return #table Table of mission types. Could be empty {}.
function COHORT:GetMissionTypes() function COHORT:GetMissionTypes()
@ -301,7 +300,7 @@ function COHORT:GetMissionTypes()
return missiontypes return missiontypes
end end
--- Get mission capabilities of this platoon. --- Get mission capabilities of this cohort.
-- @param #COHORT self -- @param #COHORT self
-- @return #table Table of mission capabilities. -- @return #table Table of mission capabilities.
function COHORT:GetMissionCapabilities() function COHORT:GetMissionCapabilities()
@ -324,7 +323,7 @@ function COHORT:GetMissionPeformance(MissionType)
return -1 return -1
end end
--- Set max mission range. Only missions in a circle of this radius around the platoon airbase are executed. --- Set max mission range. Only missions in a circle of this radius around the cohort base are executed.
-- @param #COHORT self -- @param #COHORT self
-- @param #number Range Range in NM. Default 100 NM. -- @param #number Range Range in NM. Default 100 NM.
-- @return #COHORT self -- @return #COHORT self
@ -409,9 +408,9 @@ function COHORT:DelGroup(GroupName)
return self return self
end end
--- Get name of the platoon --- Get name of the cohort.
-- @param #COHORT self -- @param #COHORT self
-- @return #string Name of the platoon. -- @return #string Name of the cohort.
function COHORT:GetName() function COHORT:GetName()
return self.name return self.name
end end
@ -485,7 +484,7 @@ function COHORT:GetModex(Asset)
end end
--- Add TACAN channels to the platoon. Note that channels can only range from 1 to 126. --- Add TACAN channels to the cohort. Note that channels can only range from 1 to 126.
-- @param #COHORT self -- @param #COHORT self
-- @param #number ChannelMin Channel. -- @param #number ChannelMin Channel.
-- @param #number ChannelMax Channel. -- @param #number ChannelMax Channel.
@ -542,21 +541,21 @@ function COHORT:ReturnTacan(channel)
self.tacanChannel[channel]=true self.tacanChannel[channel]=true
end end
--- Check if platoon is "OnDuty". --- Check if cohort is "OnDuty".
-- @param #COHORT self -- @param #COHORT self
-- @return #boolean If true, squdron is in state "OnDuty". -- @return #boolean If true, squdron is in state "OnDuty".
function COHORT:IsOnDuty() function COHORT:IsOnDuty()
return self:Is("OnDuty") return self:Is("OnDuty")
end end
--- Check if platoon is "Stopped". --- Check if cohort is "Stopped".
-- @param #COHORT self -- @param #COHORT self
-- @return #boolean If true, squdron is in state "Stopped". -- @return #boolean If true, squdron is in state "Stopped".
function COHORT:IsStopped() function COHORT:IsStopped()
return self:Is("Stopped") return self:Is("Stopped")
end end
--- Check if platoon is "Paused". --- Check if cohort is "Paused".
-- @param #COHORT self -- @param #COHORT self
-- @return #boolean If true, squdron is in state "Paused". -- @return #boolean If true, squdron is in state "Paused".
function COHORT:IsPaused() function COHORT:IsPaused()
@ -700,7 +699,7 @@ end
-- Misc Functions -- Misc Functions
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--- Check if there is a platoon that can execute a given mission. --- Check if there is a cohort that can execute a given mission.
-- We check the mission type, the refuelling system, engagement range -- We check the mission type, the refuelling system, engagement range
-- @param #COHORT self -- @param #COHORT self
-- @param Ops.Auftrag#AUFTRAG Mission The mission. -- @param Ops.Auftrag#AUFTRAG Mission The mission.
@ -968,7 +967,7 @@ function COHORT:CheckMissionCapability(MissionTypes, Capabilities)
return false return false
end end
--- Check if the platoon 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`.
-- @return #boolean If true, the cohort has the requested attribute. -- @return #boolean If true, the cohort has the requested attribute.

View File

@ -183,7 +183,7 @@ end
--- Get cohort of an asset. --- Get cohort of an asset.
-- @param #LEGION self -- @param #LEGION self
-- @param Functional.Warehouse#WAREHOUSE.Assetitem Asset The squadron asset. -- @param Functional.Warehouse#WAREHOUSE.Assetitem Asset The asset.
-- @return Ops.Cohort#COHORT The Cohort object. -- @return Ops.Cohort#COHORT The Cohort object.
function LEGION:_GetCohortOfAsset(Asset) function LEGION:_GetCohortOfAsset(Asset)
local cohort=self:_GetCohort(Asset.squadname) local cohort=self:_GetCohort(Asset.squadname)
@ -392,8 +392,8 @@ function LEGION:CalculateAssetMissionScore(asset, Mission, includePayload)
end end
-- Add mission performance to score. -- Add mission performance to score.
local squad=self:_GetCohortOfAsset(asset) local cohort=self:_GetCohortOfAsset(asset)
local missionperformance=squad:GetMissionPeformance(Mission.type) local missionperformance=cohort:GetMissionPeformance(Mission.type)
score=score+missionperformance score=score+missionperformance
-- Add payload performance to score. -- Add payload performance to score.
@ -685,14 +685,14 @@ function LEGION:onafterNewAsset(From, Event, To, asset, assignment)
-- Set spawn group name. This has to include "AID-" for warehouse. -- Set spawn group name. This has to include "AID-" for warehouse.
asset.spawngroupname=string.format("%s_AID-%d", cohort.name, asset.uid) asset.spawngroupname=string.format("%s_AID-%d", cohort.name, asset.uid)
-- Add asset to squadron. -- Add asset to cohort.
cohort:AddAsset(asset) cohort:AddAsset(asset)
-- TODO -- TODO
--asset.terminalType=AIRBASE.TerminalType.OpenBig --asset.terminalType=AIRBASE.TerminalType.OpenBig
else else
--env.info("FF squad asset returned") --env.info("FF cohort asset returned")
self:AssetReturned(cohort, asset) self:AssetReturned(cohort, asset)
end end
@ -730,8 +730,10 @@ function LEGION:onafterAssetReturned(From, Event, To, Cohort, Asset)
Asset.Treturned=timer.getAbsTime() Asset.Treturned=timer.getAbsTime()
if self:IsAirwing() then if self:IsAirwing() then
-- Trigger airwing/squadron event.
self:SquadronAssetReturned(Cohort, Asset) self:SquadronAssetReturned(Cohort, Asset)
elseif self:IsBrigade() then elseif self:IsBrigade() then
-- Trigger brigade/platoon event.
self:PlatoonAssetReturned(Cohort, Asset) self:PlatoonAssetReturned(Cohort, Asset)
end end
end end
@ -751,10 +753,10 @@ function LEGION:onafterAssetSpawned(From, Event, To, group, asset, request)
-- Call parent warehouse function first. -- Call parent warehouse function first.
self:GetParent(self, LEGION).onafterAssetSpawned(self, From, Event, To, group, asset, request) self:GetParent(self, LEGION).onafterAssetSpawned(self, From, Event, To, group, asset, request)
-- Get the SQUADRON of the asset. -- Get the COHORT of the asset.
local cohort=self:_GetCohortOfAsset(asset) local cohort=self:_GetCohortOfAsset(asset)
-- Check if we have a squadron or if this was some other request. -- Check if we have a cohort or if this was some other request.
if cohort then if cohort then
-- Create a flight group. -- Create a flight group.
@ -774,7 +776,7 @@ function LEGION:onafterAssetSpawned(From, Event, To, group, asset, request)
asset.Treturned=nil asset.Treturned=nil
--- ---
-- Squadron -- Cohort
--- ---
-- Get TACAN channel. -- Get TACAN channel.
@ -857,7 +859,7 @@ function LEGION:onafterAssetDead(From, Event, To, asset, request)
-- Remove asset from squadron same -- Remove asset from squadron same
end end
--- On after "Destroyed" event. Remove assets from cohorts. Stop squadrons. --- On after "Destroyed" event. Remove assets from cohorts. Stop cohorts.
-- @param #LEGION self -- @param #LEGION self
-- @param #string From From state. -- @param #string From From state.
-- @param #string Event Event. -- @param #string Event Event.
@ -959,10 +961,10 @@ function LEGION:_CreateFlightGroup(asset)
self:E(self.lid.."ERROR: not airwing or brigade!") self:E(self.lid.."ERROR: not airwing or brigade!")
end end
-- Set airwing. -- Set legion.
flightgroup:_SetLegion(self) flightgroup:_SetLegion(self)
-- Set squadron. -- Set cohort.
flightgroup.cohort=self:_GetCohortOfAsset(asset) flightgroup.cohort=self:_GetCohortOfAsset(asset)
-- Set home base. -- Set home base.
@ -1153,9 +1155,9 @@ function LEGION:CountAssets(InStock, MissionTypes, Attributes)
local N=0 local N=0
for _,_squad in pairs(self.cohorts) do for _,_cohort in pairs(self.cohorts) do
local squad=_squad --Ops.Squadron#SQUADRON local cohort=_cohort --Ops.Cohort#COHORT
N=N+squad:CountAssets(InStock, MissionTypes, Attributes) N=N+cohort:CountAssets(InStock, MissionTypes, Attributes)
end end
return N return N
@ -1164,11 +1166,11 @@ end
--- Count assets on mission. --- Count assets on mission.
-- @param #LEGION self -- @param #LEGION self
-- @param #table MissionTypes Types on mission to be checked. Default all. -- @param #table MissionTypes Types on mission to be checked. Default all.
-- @param Ops.Squadron#SQUADRON Squadron Only count assets of this squadron. Default count assets of all squadrons. -- @param Ops.Cohort#COHORT Cohort Only count assets of this cohort. Default count assets of all cohorts.
-- @return #number Number of pending and queued assets. -- @return #number Number of pending and queued assets.
-- @return #number Number of pending assets. -- @return #number Number of pending assets.
-- @return #number Number of queued assets. -- @return #number Number of queued assets.
function LEGION:CountAssetsOnMission(MissionTypes, Squadron) function LEGION:CountAssetsOnMission(MissionTypes, Cohort)
local Nq=0 local Nq=0
local Np=0 local Np=0
@ -1182,7 +1184,7 @@ function LEGION:CountAssetsOnMission(MissionTypes, Squadron)
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
if Squadron==nil or Squadron.name==asset.squadname then if Cohort==nil or Cohort.name==asset.squadname then
local request, isqueued=self:GetRequestByID(mission.requestID) local request, isqueued=self:GetRequestByID(mission.requestID)
@ -1232,28 +1234,28 @@ end
--- Get the aircraft types of this airwing. --- Get the aircraft types of this airwing.
-- @param #LEGION self -- @param #LEGION self
-- @param #boolean onlyactive Count only the active ones. -- @param #boolean onlyactive Count only the active ones.
-- @param #table squadrons Table of squadrons. Default all. -- @param #table cohorts Table of cohorts. Default all.
-- @return #table Table of unit types. -- @return #table Table of unit types.
function LEGION:GetAircraftTypes(onlyactive, squadrons) function LEGION:GetAircraftTypes(onlyactive, cohorts)
-- Get all unit types that can do the job. -- Get all unit types that can do the job.
local unittypes={} local unittypes={}
-- Loop over all squadrons. -- Loop over all cohorts.
for _,_squadron in pairs(squadrons or self.cohorts) do for _,_cohort in pairs(cohorts or self.cohorts) do
local squadron=_squadron --Ops.Squadron#SQUADRON local cohort=_cohort --Ops.Cohort#COHORT
if (not onlyactive) or squadron:IsOnDuty() then if (not onlyactive) or cohort:IsOnDuty() then
local gotit=false local gotit=false
for _,unittype in pairs(unittypes) do for _,unittype in pairs(unittypes) do
if squadron.aircrafttype==unittype then if cohort.aircrafttype==unittype then
gotit=true gotit=true
break break
end end
end end
if not gotit then if not gotit then
table.insert(unittypes, squadron.aircrafttype) table.insert(unittypes, cohort.aircrafttype)
end end
end end
@ -1274,10 +1276,10 @@ function LEGION:CanMission(Mission)
local Assets={} local Assets={}
-- 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 squadrons=Mission.squadrons or self.cohorts local cohorts=Mission.squadrons or self.cohorts
-- Get aircraft unit types for the job. -- Get aircraft unit types for the job.
local unittypes=self:GetAircraftTypes(true, squadrons) local unittypes=self:GetAircraftTypes(true, cohorts)
-- Count all payloads in stock. -- Count all payloads in stock.
if self:IsAirwing() then if self:IsAirwing() then
@ -1289,18 +1291,18 @@ function LEGION:CanMission(Mission)
end end
end end
for squadname,_squadron in pairs(squadrons) do for cohortname,_cohort in pairs(cohorts) do
local squadron=_squadron --Ops.Cohort#COHORT local cohort=_cohort --Ops.Cohort#COHORT
-- Check if this squadron can. -- Check if this squadron can.
local can=squadron:CanMission(Mission) local can=cohort:CanMission(Mission)
if can then if can then
-- Number of payloads available. -- Number of payloads available.
local Npayloads=self:IsAirwing() and self:CountPayloadsInStock(Mission.type, squadron.aircrafttype, Mission.payloads) or 999 local Npayloads=self:IsAirwing() and self:CountPayloadsInStock(Mission.type, cohort.aircrafttype, Mission.payloads) or 999
local assets=squadron:RecruitAssets(Mission, Npayloads) local assets=cohort:RecruitAssets(Mission, Npayloads)
-- Total number. -- Total number.
for _,asset in pairs(assets) do for _,asset in pairs(assets) do
@ -1308,7 +1310,7 @@ function LEGION:CanMission(Mission)
end end
-- Debug output. -- Debug output.
local text=string.format("Mission=%s, squadron=%s, payloads=%d, can=%s, assets=%d. Found %d/%d", Mission.type, squadron.name, Npayloads, tostring(can), #assets, #Assets, Mission.nassets) 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) self:T(self.lid..text)
end end

View File

@ -80,7 +80,7 @@ SQUADRON.version="0.8.0"
-- TODO list -- TODO list
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO: Parking spots for squadrons? -- DONE: Parking spots for squadrons?
-- DONE: Engage radius. -- DONE: Engage radius.
-- DONE: Modex. -- DONE: Modex.
-- DONE: Call signs. -- DONE: Call signs.