From bdf13f29f7d030a8656dcfe61b27c7e824303ef6 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 6 Sep 2021 23:40:58 +0200 Subject: [PATCH] OPS - COMMANDER and LEGION clean up of obsolete stuff for recruiting assets. --- Moose Development/Moose/Ops/Commander.lua | 111 ++-------------------- Moose Development/Moose/Ops/Legion.lua | 103 +------------------- Moose Development/Moose/Ops/OpsGroup.lua | 4 +- 3 files changed, 12 insertions(+), 206 deletions(-) diff --git a/Moose Development/Moose/Ops/Commander.lua b/Moose Development/Moose/Ops/Commander.lua index 8025fdcf0..e0ce6daab 100644 --- a/Moose Development/Moose/Ops/Commander.lua +++ b/Moose Development/Moose/Ops/Commander.lua @@ -489,10 +489,9 @@ function COMMANDER:CheckMissionQueue() --- -- PLANNNED Mission - --- - - --- + -- -- 1. Select best assets from legions + -- 2. Assign mission to legions that have the best assets. --- -- Recruite assets from legions. @@ -515,98 +514,6 @@ function COMMANDER:CheckMissionQueue() return end - if false then - - -- Get legions for mission. - local Legions=self:GetLegionsForMission(mission) - - -- Get ALL assets from pre-selected legions. - local assets=self:GetAssets(InStock, legions, MissionTypes, Attributes) - - - -- Now we select the best assets from all legions. - legions={} - if #assets>=mission.nassets then - - for _,_asset in pairs(assets) do - local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem - asset.payload=asset.legion:FetchPayloadFromStock(asset.unittype, mission.type, mission.payloads) - asset.score=asset.legion:CalculateAssetMissionScore(asset, mission, true) - end - - --- Sort assets wrt to their mission score. Higher is better. - local function optimize(assetA, assetB) - return (assetA.score>assetB.score) - end - table.sort(assets, optimize) - - -- Remove distance parameter. - local text=string.format("Optimized assets for %s mission:", mission.type) - for i,Asset in pairs(assets) do - local asset=Asset --Functional.Warehouse#WAREHOUSE.Assetitem - - -- Score text. - text=text..string.format("\n%s %s: score=%d", asset.squadname, asset.spawngroupname, asset.score) - - -- Nillify score. - asset.score=nil - - -- Add assets to mission. - if i<=mission.nassets then - - -- Add asset to mission. - mission:AddAsset(Asset) - - -- Put into table. - legions[asset.legion.alias]=asset.legion - - -- Number of assets requested from this legion. - -- TODO: Check if this is really necessary as we do not go through the selection process. - mission.Nassets=mission.Nassets or {} - if mission.Nassets[asset.legion.alias] then - mission.Nassets[asset.legion.alias]=mission.Nassets[asset.legion.alias]+1 - else - mission.Nassets[asset.legion.alias]=1 - end - - else - - -- Return payload of asset (if any). - if asset.payload then - asset.legion:ReturnPayloadFromAsset(asset) - end - - end - end - self:T2(self.lid..text) - - else - self:T2(self.lid..string.format("Not enough assets available for mission")) - end - - --- - -- Assign Mission to Legions - --- - - if legions then - - for _,_legion in pairs(legions) do - local legion=_legion --Ops.Legion#LEGION - - -- Debug message. - self:I(self.lid..string.format("Assigning mission %s [%s] to legion %s", mission:GetName(), mission:GetType(), legion.alias)) - - -- Add mission to legion. - self:MissionAssign(legion, mission) - - end - - -- Only ONE mission is assigned. - return - end - - end -- if false then - else --- @@ -733,14 +640,14 @@ end -- @return #boolean If `true` enough assets could be recruited. -- @return #table Legions that have recruited assets. function COMMANDER:RecruitAssets(Mission) - - env.info("FF recruit assets") -- The recruited assets. local Assets={} + -- Legions we consider for selecting assets. local legions=Mission.mylegions or self.legions + -- Legions which have the best assets for the Mission. local Legions={} for _,_legion in pairs(legions) do @@ -766,15 +673,11 @@ function COMMANDER:RecruitAssets(Mission) if cohort:CanMission(Mission) and npayloads>0 then - env.info("FF npayloads="..Npayloads[cohort.aircrafttype]) - -- Recruit assets from squadron. local assets, npayloads=cohort:RecruitAssets(Mission, npayloads) Npayloads[cohort.aircrafttype]=npayloads - env.info("FF npayloads="..Npayloads[cohort.aircrafttype]) - for _,asset in pairs(assets) do table.insert(Assets, asset) end @@ -827,7 +730,7 @@ function COMMANDER:RecruitAssets(Mission) -- Add assets to mission. for i=1,Nassets do local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - self:I(self.lid..string.format("Adding asset %s to mission %s [%s]", asset.spawngroupname, Mission.name, Mission.type)) + self:T(self.lid..string.format("Adding asset %s to mission %s [%s]", asset.spawngroupname, Mission.name, Mission.type)) Mission:AddAsset(asset) Legions[asset.legion.alias]=asset.legion end @@ -837,7 +740,7 @@ function COMMANDER:RecruitAssets(Mission) for i=Nassets+1,#Assets do local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem if asset.legion:IsAirwing() and not asset.spawned then - self:I(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) + self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) asset.legion:ReturnPayloadFromAsset(asset) end end @@ -855,7 +758,7 @@ function COMMANDER:RecruitAssets(Mission) for i=1,#Assets do local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem if asset.legion:IsAirwing() and not asset.spawned then - self:I(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) + self:T2(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) asset.legion:ReturnPayloadFromAsset(asset) end end diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 6cbb5d8f3..7ffce3b98 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -432,98 +432,7 @@ function LEGION:_GetNextMission() if recruited then return mission end - - -- OBSOLETE - if false then - -- Check if legion can do the mission and gather required assets. - local can, assets=self:CanMission(mission) - - -- Check that mission is still scheduled, time has passed and enough assets are available. - if can then - - -- Number of required assets. - local Nassets=mission:GetRequiredAssets(self) - - -- Optimize the asset selection. Most useful assets will come first. We do not include the payload as some assets have and some might not. - self:_OptimizeAssetSelection(assets, mission, false) - - -- Assign assets to mission. - local remove={} - local gotpayload={} - if self:IsAirwing() then - for i=1,#assets do - local asset=assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - - -- Get payload for the asset. - if not asset.payload then - local payload=self:FetchPayloadFromStock(asset.unittype, mission.type, mission.payloads) - if payload then - asset.payload=payload - table.insert(gotpayload, asset.uid) - else - table.insert(remove, asset.uid) - end - end - end - self:T(self.lid..string.format("Provided %d assets with payloads. Could not get payload for %d assets", #gotpayload, #remove)) - - -- Now remove assets for which we don't have a payload. - for i=#assets,1,-1 do - local asset=assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - for _,uid in pairs(remove) do - if uid==asset.uid then - table.remove(assets, i) - end - end - end - - -- Another check. - if #assets0 then - self:E(self.lid..string.format("ERROR: mission %s of type %s has already assets attached!", mission.name, mission.type)) - end - --mission.assets={} - - -- Assign assets to mission. - for i=1,Nassets do - local asset=assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - - -- Should not happen as we just checked! - if self:IsAirwing() and not asset.payload then - self:E(self.lid.."ERROR: No payload for asset! This should not happen!") - end - - -- Add asset to mission. - mission:AddAsset(asset) - end - - -- Now return the remaining payloads. - if self:IsAirwing() then - for i=Nassets+1,#assets do - local asset=assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - for _,uid in pairs(gotpayload) do - if uid==asset.uid then - self:ReturnPayloadFromAsset(asset) - break - end - end - end - end - - return mission - end - - end -- OBSOLETE end -- mission due? end -- mission loop @@ -1765,8 +1674,6 @@ end -- @return #boolean If `true` enough assets could be recruited. function LEGION:RecruitAssets(Mission) - env.info("FF recruit assets") - -- Number of payloads in stock per aircraft type. local Npayloads={} @@ -1790,15 +1697,11 @@ function LEGION:RecruitAssets(Mission) if cohort:CanMission(Mission) and npayloads>0 then - env.info("FF npayloads="..Npayloads[cohort.aircrafttype]) - -- Recruit assets from squadron. local assets, npayloads=cohort:RecruitAssets(Mission, npayloads) Npayloads[cohort.aircrafttype]=npayloads - env.info("FF npayloads="..Npayloads[cohort.aircrafttype]) - for _,asset in pairs(assets) do table.insert(Assets, asset) end @@ -1850,7 +1753,7 @@ function LEGION:RecruitAssets(Mission) -- Add assets to mission. for i=1,Nassets do local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem - self:I(self.lid..string.format("Adding asset %s to mission %s [%s]", asset.spawngroupname, Mission.name, Mission.type)) + self:T(self.lid..string.format("Adding asset %s to mission %s [%s]", asset.spawngroupname, Mission.name, Mission.type)) Mission:AddAsset(asset) end @@ -1860,7 +1763,7 @@ function LEGION:RecruitAssets(Mission) for i=Nassets+1,#Assets do local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem if not asset.spawned then - self:I(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) + self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) self:ReturnPayloadFromAsset(asset) end end @@ -1880,7 +1783,7 @@ function LEGION:RecruitAssets(Mission) for i=1,#Assets do local asset=Assets[i] if not asset.spawned then - self:I(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) + self:T(self.lid..string.format("Returning payload from asset %s", asset.spawngroupname)) self:ReturnPayloadFromAsset(asset) end end diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index f6999e6d3..e8e51836f 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3355,7 +3355,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) local Speed=UTILS.KmphToKnots(Task.dcstask.params.speed or self.speedCruise) local Altitude=Task.dcstask.params.altitude and UTILS.MetersToFeet(Task.dcstask.params.altitude) or nil - Coordinate:MarkToAll("Recon Waypoint Execute") + --Coordinate:MarkToAll("Recon Waypoint Execute") local currUID=self:GetWaypointCurrent().uid @@ -4448,7 +4448,7 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) local Altitude=task.dcstask.params.altitude and UTILS.MetersToFeet(task.dcstask.params.altitude) or nil -- Debug. - Coordinate:MarkToAll("Recon Waypoint n="..tostring(n)) + --Coordinate:MarkToAll("Recon Waypoint n="..tostring(n)) local currUID=self:GetWaypointCurrent().uid