mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
OPS
- Recruit assets with new function (LEGION, COMMANDER, CHIEF)
This commit is contained in:
parent
bbbca04066
commit
4dfdb99731
@ -1061,7 +1061,7 @@ function CHIEF:CheckTargetQueue()
|
||||
self:I(self.lid..string.format("Recruiting assets for mission type %s [performance=%d] of target %s", mp.MissionType, mp.Performance, target:GetName()))
|
||||
|
||||
-- Recruit assets.
|
||||
local recruited, legions, assets=self:RecruitAssetsForTarget(target, mp.MissionType, NassetsMin, NassetsMax)
|
||||
local recruited, assets, legions=self:RecruitAssetsForTarget(target, mp.MissionType, NassetsMin, NassetsMax)
|
||||
|
||||
if recruited then
|
||||
|
||||
@ -1370,8 +1370,8 @@ end
|
||||
-- @param Ops.Target#TARGET Target The target.
|
||||
-- @param #string MissionType Mission Type.
|
||||
-- @return #boolean If `true` enough assets could be recruited.
|
||||
-- @return #table Legions that have recruited assets.
|
||||
-- @return #table Assets that have been recruited from all legions.
|
||||
-- @return #table Legions that have recruited assets.
|
||||
function CHIEF:RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMax)
|
||||
|
||||
-- Cohorts.
|
||||
|
||||
@ -683,9 +683,16 @@ function COMMANDER:CheckMissionQueue()
|
||||
---
|
||||
|
||||
-- Recruite assets from legions.
|
||||
local recruited, legions=self:RecruitAssets(mission)
|
||||
local recruited, assets, legions=self:RecruitAssetsForMission(mission)
|
||||
|
||||
if recruited then
|
||||
|
||||
-- Add asset to transport.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
asset.isReserved=true
|
||||
mission:AddAsset(asset)
|
||||
end
|
||||
|
||||
for _,_legion in pairs(legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
@ -935,9 +942,16 @@ function COMMANDER:CheckTransportQueue()
|
||||
---
|
||||
|
||||
-- Recruite assets from legions.
|
||||
local recruited, legions=self:RecruitAssetsForTransport(transport)
|
||||
local recruited, assets, legions=self:RecruitAssetsForTransport(transport)
|
||||
|
||||
if recruited then
|
||||
|
||||
-- Add asset to transport.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
asset.isReserved=true
|
||||
transport:AddAsset(asset)
|
||||
end
|
||||
|
||||
for _,_legion in pairs(legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
@ -966,12 +980,65 @@ function COMMANDER:CheckTransportQueue()
|
||||
|
||||
end
|
||||
|
||||
--- Recruit assets for a given OPS transport.
|
||||
-- @param #COMMANDER self
|
||||
-- @param Ops.OpsTransport#OPSTRANSPORT Transport The OPS transport.
|
||||
-- @return #boolean If `true`, enough assets could be recruited.
|
||||
-- @return #table Recruited assets.
|
||||
-- @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
|
||||
|
||||
-- Cohorts.
|
||||
local Cohorts={}
|
||||
for _,_legion in pairs(self.legions) do
|
||||
local legion=_legion --Ops.Legion#LEGION
|
||||
-- Loops over cohorts.
|
||||
for _,_cohort in pairs(legion.cohorts) do
|
||||
local cohort=_cohort --Ops.Cohort#COHORT
|
||||
table.insert(Cohorts, cohort)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Target is the deploy zone.
|
||||
local TargetVec2=Transport:GetDeployZone():GetVec2()
|
||||
|
||||
-- Number of required carriers.
|
||||
local NreqMin,NreqMax=Transport:GetRequiredCarriers()
|
||||
|
||||
-- Recruit assets and legions.
|
||||
local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NreqMin, NreqMax, TargetVec2, nil, nil, nil, weightGroup)
|
||||
|
||||
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)
|
||||
function COMMANDER:_RecruitAssetsForTransport(Transport)
|
||||
|
||||
-- Get all undelivered cargo ops groups.
|
||||
local cargoOpsGroups=Transport:GetCargoOpsGroups(false)
|
||||
|
||||
@ -504,20 +504,44 @@ function LEGION:_GetNextTransport()
|
||||
return nil
|
||||
end
|
||||
|
||||
--TODO: Sort transports wrt to prio and importance. See mission sorting!
|
||||
-- Sort results table wrt prio and start time.
|
||||
local function _sort(a, b)
|
||||
local taskA=a --Ops.Auftrag#AUFTRAG
|
||||
local taskB=b --Ops.Auftrag#AUFTRAG
|
||||
return (taskA.prio<taskB.prio) or (taskA.prio==taskB.prio and taskA.Tstart<taskB.Tstart)
|
||||
end
|
||||
table.sort(self.transportqueue, _sort)
|
||||
|
||||
-- Get the lowest importance value (lower means more important).
|
||||
-- If a mission with importance 1 exists, mission with importance 2 will not be assigned. Missions with no importance (nil) can still be selected.
|
||||
local vip=math.huge
|
||||
for _,_transport in pairs(self.transportqueue) do
|
||||
local transport=_transport --Ops.OpsTransport#OPSTRANSPORT
|
||||
if transport.importance and transport.importance<vip then
|
||||
vip=transport.importance
|
||||
end
|
||||
end
|
||||
|
||||
-- Look for first task that is not accomplished.
|
||||
for _,_transport in pairs(self.transportqueue) do
|
||||
local transport=_transport --Ops.OpsTransport#OPSTRANSPORT
|
||||
|
||||
-- Check if transport is still queued and ready.
|
||||
if transport:IsQueued(self) and transport:IsReadyToGo() then
|
||||
if transport:IsQueued(self) and transport:IsReadyToGo() and (transport.importance==nil or transport.importance<=vip) then
|
||||
|
||||
-- Recruit assets for transport.
|
||||
local recruited=self:RecruitAssetsForTransport(transport)
|
||||
local recruited, assets, _=self:RecruitAssetsForTransport(transport)
|
||||
|
||||
-- Did we find enough assets?
|
||||
if recruited then
|
||||
|
||||
-- Add asset to transport.
|
||||
for _,_asset in pairs(assets) do
|
||||
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
|
||||
asset.isReserved=true
|
||||
transport:AddAsset(asset)
|
||||
end
|
||||
|
||||
return transport
|
||||
end
|
||||
|
||||
@ -1575,11 +1599,55 @@ function LEGION:RecruitAssetsForMission(Mission)
|
||||
local TargetVec2=Mission:GetTargetVec2()
|
||||
local Payloads=Mission.payloads
|
||||
|
||||
local recruited, assets, legions=LEGION.RecruitCohortAssets(self.cohorts, Mission.type, Mission.alert5MissionType, NreqMin, NreqMax, TargetVec2, Payloads, Mission.engageRange, Mission.refuelSystem, nil)
|
||||
local Cohorts=Mission.squadrons or self.cohorts
|
||||
|
||||
local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, Mission.type, Mission.alert5MissionType, NreqMin, NreqMax, TargetVec2, Payloads, Mission.engageRange, Mission.refuelSystem, nil)
|
||||
|
||||
return recruited, assets, legions
|
||||
end
|
||||
|
||||
--- Recruit assets for a given OPS transport.
|
||||
-- @param #LEGION self
|
||||
-- @param Ops.OpsTransport#OPSTRANSPORT Transport The OPS transport.
|
||||
-- @return #boolean If `true`, enough assets could be recruited.
|
||||
function LEGION: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
|
||||
|
||||
|
||||
-- Target is the deploy zone.
|
||||
local TargetVec2=Transport:GetDeployZone():GetVec2()
|
||||
|
||||
-- Number of required carriers.
|
||||
local NreqMin,NreqMax=Transport:GetRequiredCarriers()
|
||||
|
||||
|
||||
-- Recruit assets and legions.
|
||||
local recruited, assets, legions=LEGION.RecruitCohortAssets(self.cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NreqMin, NreqMax, TargetVec2, nil, nil, nil, weightGroup)
|
||||
|
||||
return recruited, assets, legions
|
||||
end
|
||||
|
||||
|
||||
--- Recruit assets for a given mission.
|
||||
-- @param #LEGION self
|
||||
-- @param Ops.Auftrag#AUFTRAG Mission The mission.
|
||||
@ -1744,7 +1812,7 @@ end
|
||||
-- @param #LEGION self
|
||||
-- @param Ops.OpsTransport#OPSTRANSPORT Transport The OPS transport.
|
||||
-- @return #boolean If `true`, enough assets could be recruited.
|
||||
function LEGION:RecruitAssetsForTransport(Transport)
|
||||
function LEGION:_RecruitAssetsForTransport(Transport)
|
||||
|
||||
-- Get all undelivered cargo ops groups.
|
||||
local cargoOpsGroups=Transport:GetCargoOpsGroups(false)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user