OPS Recruting

- Removed obsolete recruiting functions from code
This commit is contained in:
Frank
2021-09-18 18:23:22 +02:00
parent 4dfdb99731
commit 09015449cd
3 changed files with 45 additions and 735 deletions

View File

@@ -687,13 +687,14 @@ function COMMANDER:CheckMissionQueue()
if recruited then
-- Add asset to transport.
-- Add asset to mission.
for _,_asset in pairs(assets) do
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
asset.isReserved=true
mission:AddAsset(asset)
end
-- Assign mission to legion(s).
for _,_legion in pairs(legions) do
local legion=_legion --Ops.Legion#LEGION
@@ -759,141 +760,6 @@ function COMMANDER:RecruitAssetsForMission(Mission)
return recruited, assets, legions
end
--- Recruit assets for a given mission.
-- @param #COMMANDER self
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
-- @return #boolean If `true` enough assets could be recruited.
-- @return #table Legions that have recruited assets.
function COMMANDER:RecruitAssets(Mission)
-- The recruited assets.
local Assets={}
-- Legions we consider for selecting assets.
local legions=Mission.mylegions or self.legions
--TODO: Setting of Mission.squadrons (cohorts) will not work here!
-- Legions which have the best assets for the Mission.
local Legions={}
for _,_legion in pairs(legions) do
local legion=_legion --Ops.Legion#LEGION
-- Loops over cohorts.
for _,_cohort in pairs(legion.cohorts) do
local cohort=_cohort --Ops.Cohort#COHORT
if cohort:CanMission(Mission) then
-- Recruit assets from squadron.
local assets, npayloads=cohort:RecruitAssets(Mission.type, 999)
for _,asset in pairs(assets) do
table.insert(Assets, asset)
end
end
end
end
-- Target position.
local TargetVec2=Mission.type~=AUFTRAG.Type.ALERT5 and Mission:GetTargetVec2() or nil
-- Now we have a long list with assets.
LEGION._OptimizeAssetSelection(self, Assets, Mission.type, TargetVec2, false)
for _,_asset in pairs(Assets) do
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() then
-- Only assets that have no payload. Should be only spawned assets!
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!
asset.payload=asset.legion:FetchPayloadFromStock(asset.unittype, MissionType, Mission.payloads)
end
end
end
-- Remove assets that dont have a payload.
for i=#Assets,1,-1 do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() and not asset.payload then
self:T3(self.lid..string.format("Remove asset %s with no payload", tostring(asset.spawngroupname)))
table.remove(Assets, i)
end
end
-- Now find the best asset for the given payloads.
LEGION._OptimizeAssetSelection(self, Assets, Mission.type, TargetVec2, true)
-- Get number of required assets.
local Nassets=Mission:GetRequiredAssets(self)
if #Assets>=Nassets then
---
-- Found enough assets
---
-- Add assets to mission.
for i=1,Nassets do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
asset.isReserved=true
Mission:AddAsset(asset)
Legions[asset.legion.alias]=asset.legion
end
-- Return payloads of not needed assets.
for i=Nassets+1,#Assets do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() and not asset.spawned then
self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname))
asset.legion:ReturnPayloadFromAsset(asset)
end
end
-- Found enough assets.
return true, Legions
else
---
-- NOT enough assets
---
-- Return payloads of assets.
for i=1,#Assets do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() and not asset.spawned then
self:T2(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname))
asset.legion:ReturnPayloadFromAsset(asset)
end
end
-- Not enough assets found.
return false, {}
end
return nil, {}
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Transport Functions
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -953,6 +819,7 @@ function COMMANDER:CheckTransportQueue()
transport:AddAsset(asset)
end
-- Assign transport to legion(s).
for _,_legion in pairs(legions) do
local legion=_legion --Ops.Legion#LEGION
@@ -1033,173 +900,6 @@ function COMMANDER:RecruitAssetsForTransport(Transport)
return recruited, assets, legions
end
--- Recruit assets for a given transport.
-- @param #COMMANDER self
-- @param Ops.OpsTransport#OPSTRANSPORT Transport The transport.
-- @return #boolean If `true`, enough assets could be recruited.
-- @return #table Legions that have recruited assets.
function COMMANDER:_RecruitAssetsForTransport(Transport)
-- Get all undelivered cargo ops groups.
local cargoOpsGroups=Transport:GetCargoOpsGroups(false)
local weightGroup=0
-- At least one group should be spawned.
if #cargoOpsGroups>0 then
-- Calculate the max weight so we know which cohorts can provide carriers.
for _,_opsgroup in pairs(cargoOpsGroups) do
local opsgroup=_opsgroup --Ops.OpsGroup#OPSGROUP
local weight=opsgroup:GetWeightTotal()
if weight>weightGroup then
weightGroup=weight
end
end
else
-- No cargo groups!
return false, {}
end
-- The recruited assets.
local Assets={}
-- Legions we consider for selecting assets.
local legions=self.legions
--TODO: Setting of Mission.squadrons (cohorts) will not work here!
-- Legions which have the best assets for the Mission.
local Legions={}
for _,_legion in pairs(legions) do
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
Npayloads[cohort.aircrafttype]=legion:IsAirwing() and legion:CountPayloadsInStock(AUFTRAG.Type.OPSTRANSPORT, cohort.aircrafttype) or 999
self:T2(self.lid..string.format("Got N=%d payloads for mission type %s [%s]", Npayloads[cohort.aircrafttype], AUFTRAG.Type.OPSTRANSPORT, cohort.aircrafttype))
end
end
-- Loops over cohorts.
for _,_cohort in pairs(legion.cohorts) do
local cohort=_cohort --Ops.Cohort#COHORT
local npayloads=Npayloads[cohort.aircrafttype]
if cohort:IsOnDuty() and npayloads>0 and cohort:CheckMissionCapability({AUFTRAG.Type.OPSTRANSPORT}) and cohort.cargobayLimit>=weightGroup then
-- Recruit assets from squadron.
local assets, npayloads=cohort:RecruitAssets(AUFTRAG.Type.OPSTRANSPORT, npayloads)
Npayloads[cohort.aircrafttype]=npayloads
for _,asset in pairs(assets) do
table.insert(Assets, asset)
end
end
end
end
-- Target position.
local TargetVec2=Transport:GetDeployZone():GetVec2()
-- Now we have a long list with assets.
LEGION._OptimizeAssetSelection(self, Assets, AUFTRAG.Type.OPSTRANSPORT, TargetVec2, false)
for _,_asset in pairs(Assets) do
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() then
-- Only assets that have no payload. Should be only spawned assets!
if not asset.payload then
-- Fetch payload for asset. This can be nil!
asset.payload=asset.legion:FetchPayloadFromStock(asset.unittype, AUFTRAG.Type.OPSTRANSPORT)
end
end
end
-- Remove assets that dont have a payload.
for i=#Assets,1,-1 do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() and not asset.payload then
table.remove(Assets, i)
end
end
-- Number of required carriers.
local NreqMin,NreqMax=Transport:GetRequiredCarriers()
-- Number of assets. At most NreqMax.
local Nassets=math.min(#Assets, NreqMax)
if Nassets>=NreqMin then
---
-- Found enough assets
---
-- Add assets to transport.
for i=1,Nassets do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
asset.isReserved=true
Transport:AddAsset(asset)
Legions[asset.legion.alias]=asset.legion
end
-- Return payloads of not needed assets.
for i=Nassets+1,#Assets do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() and not asset.spawned then
self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname))
asset.legion:ReturnPayloadFromAsset(asset)
end
end
-- Found enough assets.
return true, Legions
else
---
-- NOT enough assets
---
-- Return payloads of assets.
if self:IsAirwing() then
for i=1,#Assets do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
if asset.legion:IsAirwing() and not asset.spawned then
self:T2(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname))
asset.legion:ReturnPayloadFromAsset(asset)
end
end
end
-- Not enough assets found.
return false, {}
end
return nil, {}
end
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Resources
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------