diff --git a/Moose Development/Moose/Ops/Chief.lua b/Moose Development/Moose/Ops/Chief.lua index 1d2a40039..d1019de85 100644 --- a/Moose Development/Moose/Ops/Chief.lua +++ b/Moose Development/Moose/Ops/Chief.lua @@ -1070,7 +1070,9 @@ function CHIEF:CheckTargetQueue() -- Add asset to mission. if mission then - for _,asset in pairs(assets) do + for _,_asset in pairs(assets) do + local asset=_asset + asset.isReserved=true mission:AddAsset(asset) end Legions=legions @@ -1395,132 +1397,6 @@ function CHIEF:RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMa end ---- Recruit assets for a given mission. OLD! --- @param #CHIEF self --- @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. -function CHIEF:_RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMax) - - -- The recruited assets. - local Assets={} - - -- Legions which have the best assets for the Mission. - local Legions={} - - -- Target vector. - local TargetVec2=Target:GetVec2() - - for _,_legion in pairs(self.commander.legions) do - local legion=_legion --Ops.Legion#LEGION - - -- Distance to target. - local TargetDistance=Target:GetCoordinate():Get2DDistance(legion:GetCoordinate()) - - -- Loops over cohorts. - for _,_cohort in pairs(legion.cohorts) do - local cohort=_cohort --Ops.Cohort#COHORT - - if cohort:IsOnDuty() and AUFTRAG.CheckMissionCapability({MissionType}, cohort.missiontypes) and cohort.engageRange>=TargetDistance then - - -- Recruit assets from squadron. - local assets, npayloads=cohort:RecruitAssets(MissionType, 999) - - for _,asset in pairs(assets) do - table.insert(Assets, asset) - end - - end - - end - - end - - -- Now we have a long list with assets. - LEGION._OptimizeAssetSelection(self, Assets, MissionType, 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, MissionType) - - 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, MissionType, TargetVec2, true) - - -- Number of assets. At most NreqMax. - local Nassets=math.min(#Assets, NassetsMax) - - if #Assets>=Nassets then - - --- - -- Found enough assets - --- - - -- Get Legions of assets and put into table. - for i=1,Nassets do - local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - Legions[asset.legion.alias]=asset.legion - end - - - -- Return payloads and remove not needed assets. - for i=#Assets,Nassets+1,-1 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 - table.remove(Assets, i) - end - - -- Found enough assets. - return true, Legions, Assets - 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 - ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- \ No newline at end of file diff --git a/Moose Development/Moose/Ops/Commander.lua b/Moose Development/Moose/Ops/Commander.lua index e88f34f53..055888f08 100644 --- a/Moose Development/Moose/Ops/Commander.lua +++ b/Moose Development/Moose/Ops/Commander.lua @@ -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 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 4a8e4726c..843c34b3d 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -1585,6 +1585,39 @@ function LEGION:GetAircraftTypes(onlyactive, cohorts) return unittypes end +--- Count payloads of all cohorts for all unit types. +-- @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 + +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +-- Recruiting Functions +------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + --- Recruit assets for a given mission. -- @param #LEGION self -- @param Ops.Auftrag#AUFTRAG Mission The mission. @@ -1593,14 +1626,20 @@ end -- @return #table Legions of recruited assets. function LEGION:RecruitAssetsForMission(Mission) + -- Get required assets. local NreqMin=Mission:GetRequiredAssets() local NreqMax=NreqMin + -- Target position vector. local TargetVec2=Mission:GetTargetVec2() + + -- Payloads. local Payloads=Mission.payloads + -- Cohorts. local Cohorts=Mission.squadrons or self.cohorts + -- Recuit assets. local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, Mission.type, Mission.alert5MissionType, NreqMin, NreqMax, TargetVec2, Payloads, Mission.engageRange, Mission.refuelSystem, nil) return recruited, assets, legions @@ -1647,311 +1686,6 @@ function LEGION:RecruitAssetsForTransport(Transport) return recruited, assets, legions end - ---- Recruit assets for a given mission. --- @param #LEGION self --- @param Ops.Auftrag#AUFTRAG Mission The mission. --- @return #boolean If `true` enough assets could be recruited. -function LEGION:RecruitAssets(Mission) - - -- The recruited assets. - local Assets={} - - -- Get number of required assets. - local Nassets=Mission:GetRequiredAssets(self) - - -- Squadrons for the job. If user assigned to mission or simply all. - local cohorts=Mission.squadrons or self.cohorts - - -- Target position. - local TargetVec2=Mission.type~=AUFTRAG.Type.ALERT5 and Mission:GetTargetVec2() or nil - - -- Set mission type. - local MissionType=Mission.type - if MissionType==AUFTRAG.Type.ALERT5 and Mission.alert5MissionType then - -- If this is an Alert5 mission, we try to find the assets that are - MissionType=Mission.alert5MissionType - end - - -- Loops over cohorts. - for _,_cohort in pairs(cohorts) do - local cohort=_cohort --Ops.Cohort#COHORT - - -- Check OnDuty, mission type, range and refueling type (if TANKER). - if cohort:CanMission(Mission) then - - -- Recruit assets from cohort. - local assets, npayloads=cohort:RecruitAssets(Mission.type, 999) - - -- Add assets to the list. - for _,asset in pairs(assets) do - table.insert(Assets, asset) - end - - end - - end - - -- Now we have a long list with assets. - self:_OptimizeAssetSelection(Assets, Mission.type, TargetVec2, false) - - -- If airwing, get the best payload available. - if self:IsAirwing() then - - for _,_asset in pairs(Assets) do - local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem - - -- 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=self:FetchPayloadFromStock(asset.unittype, MissionType, Mission.payloads) - - end - - end - - -- Remove assets that dont have a payload. - for i=#Assets,1,-1 do - local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - if not asset.payload then - table.remove(Assets, i) - end - end - - -- Now find the best asset for the given payloads. - self:_OptimizeAssetSelection(Assets, Mission.type, TargetVec2, true) - - end - - if #Assets>=Nassets then - - --- - -- Found enough assets - --- - - -- Add assets to mission. - for i=1,Nassets do - local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - self:T(self.lid..string.format("Adding asset %s to mission %s [%s]", asset.spawngroupname, Mission.name, Mission.type)) - Mission:AddAsset(asset) - end - - if self:IsAirwing() then - - -- Return payloads of not needed assets. - for i=Nassets+1,#Assets do - local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - if not asset.spawned then - self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) - self:ReturnPayloadFromAsset(asset) - end - end - - end - - -- Found enough assets. - return true - else - - --- - -- NOT enough assets - --- - - -- Return payloads of assets. - if self:IsAirwing() then - for i=1,#Assets do - local asset=Assets[i] - if not asset.spawned then - self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) - self:ReturnPayloadFromAsset(asset) - end - end - end - - -- Not enough assets found. - return false - 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 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - ---- 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 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. - local Assets={} - - -- Loops over cohorts. - for _,_cohort in pairs(self.cohorts) do - local cohort=_cohort --Ops.Cohort#COHORT - - local npayloads=999 --Npayloads[cohort.aircrafttype] - - if cohort:IsOnDuty() and npayloads>0 and AUFTRAG.CheckMissionCapability({AUFTRAG.Type.OPSTRANSPORT}, cohort.missiontypes) 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 - - -- Sort asset list. Best ones come first. - self:_OptimizeAssetSelection(Assets, AUFTRAG.Type.OPSTRANSPORT, TargetVec2, false) - - -- If airwing, get the best payload available. - if self:IsAirwing() then - - for _,_asset in pairs(Assets) do - local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem - - -- 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=self:FetchPayloadFromStock(asset.unittype, AUFTRAG.Type.OPSTRANSPORT) - - end - - end - - -- Remove assets that dont have a payload. - for i=#Assets,1,-1 do - local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - if not asset.payload then - table.remove(Assets, i) - end - end - - end - - -- Number of assets. At most NreqMax. - local Nassets=math.min(#Assets, NreqMax) - - if Nassets>=NreqMin then - - --- - -- Found enough assets - --- - - -- Add assets to mission. - for i=1,Nassets do - local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - asset.isReserved=true - Transport:AddAsset(asset) - end - - if self:IsAirwing() then - - -- Return payloads of not needed assets. - for i=Nassets+1,#Assets do - local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - if not asset.spawned then - self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) - self:ReturnPayloadFromAsset(asset) - end - end - - end - - -- Found enough assets. - return true - else - - --- - -- NOT enough assets - --- - - -- Return payloads of assets. - if self:IsAirwing() then - for i=1,#Assets do - local asset=Assets[i] - if not asset.spawned then - self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) - self:ReturnPayloadFromAsset(asset) - end - end - end - - -- Not enough assets found. - return false - end - -end - ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Recruiting and Optimization Functions -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------