From 9efe0fe24394406c5cfe2bcbb96243adec92067e Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 17 Aug 2024 23:50:52 +0200 Subject: [PATCH] CHIEF v0.6.1 - Strategic zone: If zero transports are available and min carriers is zero, cargo assets need to go by themselfs. --- Moose Development/Moose/Ops/Chief.lua | 26 +++++++++++++++++++++----- Moose Development/Moose/Ops/Legion.lua | 14 ++++++++++++-- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Ops/Chief.lua b/Moose Development/Moose/Ops/Chief.lua index 99c9d05d4..3e9f46561 100644 --- a/Moose Development/Moose/Ops/Chief.lua +++ b/Moose Development/Moose/Ops/Chief.lua @@ -34,6 +34,7 @@ -- @field Ops.Commander#COMMANDER commander Commander of assigned legions. -- @field #number Nsuccess Number of successful missions. -- @field #number Nfailure Number of failed mission. +-- @field #table assetNumbers Asset numbers. Each entry is a table of data type `#CHIEF.AssetNumber`. -- @extends Ops.Intel#INTEL --- *In preparing for battle I have always found that plans are useless, but planning is indispensable* -- Dwight D Eisenhower @@ -331,7 +332,7 @@ CHIEF.Strategy = { --- CHIEF class version. -- @field #string version -CHIEF.version="0.6.0" +CHIEF.version="0.6.1" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -1284,8 +1285,10 @@ end -- -- Empty: -- --- * `AUFTRAG.Type.ONGURAD` with Nmin=1 and Nmax=1 assets, Attribute=`GROUP.Attribute.GROUND_TANK`. +-- * `AUFTRAG.Type.ONGURAD` with Nmin=0 and Nmax=1 assets, Attribute=`GROUP.Attribute.GROUND_TANK`. +-- * `AUFTRAG.Type.ONGURAD` with Nmin=0 and Nmax=1 assets, Attribute=`GROUP.Attribute.GROUND_IFV`. -- * `AUFTRAG.Type.ONGUARD` with Nmin=1 and Nmax=3 assets, Attribute=`GROUP.Attribute.GROUND_INFANTRY`. +-- * `AUFTRAG.Type.OPSTRANSPORT` with Nmin=0 and Nmax=1 assets, Attribute=`GROUP.Attribute.AIR_TRANSPORTHELO` or `GROUP.Attribute.GROUND_APC`. This asset is used to transport the infantry groups. -- -- Resources can be created with the @{#CHIEF.CreateResource} and @{#CHIEF.AddToResource} functions. -- @@ -3033,10 +3036,13 @@ function CHIEF:RecruitAssetsForZone(StratZone, Resource) end -- Recruite infantry assets. + self:T(self.lid..string.format("Recruiting assets for zone %s", StratZone.opszone:GetName())) self:T(self.lid.."Missiontype="..MissionType) self:T({categories=Categories}) self:T({attributes=Attributes}) self:T({properties=Properties}) + + local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, MissionType, nil, NassetsMin, NassetsMax, TargetVec2, nil, RangeMax, nil, nil, nil, nil, Categories, Attributes, Properties) if recruited then @@ -3052,9 +3058,12 @@ function CHIEF:RecruitAssetsForZone(StratZone, Resource) local TargetCoord = TargetZone:GetCoordinate() -- First check if we need a transportation. - local transport=nil + local transport=nil --Ops.OpsTransport#OPSTRANSPORT + local Ntransports=0 if Resource.carrierNmin and Resource.carrierNmax and Resource.carrierNmax>0 then + self:T(self.lid..string.format("Recruiting carrier assets: Nmin=%s, Nmax=%s", tostring(Resource.carrierNmin), tostring(Resource.carrierNmax))) + -- Filter only those assets that shall be transported. local cargoassets=CHIEF._FilterAssets(assets, Resource.Categories, Resource.Attributes, Resource.Properties) @@ -3064,6 +3073,10 @@ function CHIEF:RecruitAssetsForZone(StratZone, Resource) recruited, transport=LEGION.AssignAssetsForTransport(self.commander, self.commander.legions, cargoassets, Resource.carrierNmin, Resource.carrierNmax, TargetZone, nil, Resource.carrierCategories, Resource.carrierAttributes, Resource.carrierProperties) + Ntransports=transport~=nil and #transport.assets or 0 + + self:T(self.lid..string.format("Recruited %d transport carrier assets success=%s", Ntransports, tostring(recruited))) + end end @@ -3076,7 +3089,7 @@ function CHIEF:RecruitAssetsForZone(StratZone, Resource) return false end - -- Debug messgage. + -- Debug message self:T2(self.lid..string.format("Recruited %d assets for mission %s", #assets, MissionType)) @@ -3224,10 +3237,13 @@ function CHIEF:RecruitAssetsForZone(StratZone, Resource) -- Attach mission to ops zone. StratZone.opszone:_AddMission(self.coalition, MissionType, mission) + mission:SetName(string.format("Stratzone %s-%d", StratZone.opszone:GetName(), mission.auftragsnummer)) + -- Attach mission to resource. Resource.mission=mission - if transport then + -- Check if transport assets could be allocated. If carrier Nmin=0 and 0 assets could be allocated, transport would still be created but not usefull obviously + if transport and Ntransports>0 then -- Attach OPS transport to mission. mission.opstransport=transport -- Set ops zone to transport. diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 99a2eeac1..1e57212e1 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -2619,6 +2619,8 @@ function LEGION._CohortCan(Cohort, MissionType, Categories, Attributes, Properti local RangeMax = RangeMax or 0 local InRange=(RangeMax and math.max(RangeMax, Rmax) or Rmax) >= TargetDistance + --env.info(string.format("Range TargetDist=%.1f Rmax=%.1f RangeMax=%.1f InRange=%s", TargetDistance, Rmax, RangeMax, tostring(InRange))) + return InRange end @@ -2684,7 +2686,7 @@ function LEGION._CohortCan(Cohort, MissionType, Categories, Attributes, Properti else Cohort:T(Cohort.lid..string.format("Cohort %s cannot because of category", Cohort.name)) return false - end + end if can then can=CheckAttribute(Cohort) @@ -2740,7 +2742,7 @@ function LEGION._CohortCan(Cohort, MissionType, Categories, Attributes, Properti else Cohort:T(Cohort.lid..string.format("Cohort %s cannot because of max weight", Cohort.name)) return false - end + end return nil end @@ -2784,6 +2786,8 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, -- Check if cohort can do the mission. local can=LEGION._CohortCan(cohort, MissionTypeRecruit, Categories, Attributes, Properties, WeaponTypes, TargetVec2, RangeMax, RefuelSystem, CargoWeight, MaxWeight) + + --env.info(string.format("RecruitCohortAssets %s Cohort=%s can=%s", MissionTypeRecruit, cohort:GetName(), tostring(can))) -- Check OnDuty, capable, in range and refueling type (if TANKER). if can then @@ -2800,6 +2804,12 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, end + -- Break if no assets could be found + if #Assets==0 then + env.info(string.format("LEGION.RecruitCohortAssets: No assets could be recruited for mission type %s [Nmin=%s, Nmax=%s]", MissionTypeRecruit, tostring(NreqMin), tostring(NreqMax))) + return false, {}, {} + end + -- Now we have a long list with assets. LEGION._OptimizeAssetSelection(Assets, MissionTypeOpt, TargetVec2, false, TotalWeight)