From fe44e966e06f8b1d49a40f9c556bcb292df90582 Mon Sep 17 00:00:00 2001 From: smiki Date: Thu, 26 Mar 2026 02:43:06 +0100 Subject: [PATCH] [ADDED] CHIEF:AddLegionRecruitMinRange --- Moose Development/Moose/Ops/Chief.lua | 14 ++++++++++++-- Moose Development/Moose/Ops/Commander.lua | 5 +++-- Moose Development/Moose/Ops/Legion.lua | 14 +++++++++----- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Moose Development/Moose/Ops/Chief.lua b/Moose Development/Moose/Ops/Chief.lua index d88d39955..3a7961778 100644 --- a/Moose Development/Moose/Ops/Chief.lua +++ b/Moose Development/Moose/Ops/Chief.lua @@ -257,6 +257,7 @@ CHIEF = { tacview = false, Nsuccess = 0, Nfailure = 0, + LegionRecruitMinRange = {} } --- Defence condition. @@ -2465,9 +2466,9 @@ function CHIEF:CheckTargetQueue() -- Debug info. self:T2(self.lid..string.format("Recruiting assets for mission type %s [performance=%d] of target %s", mp.MissionType, mp.Performance, target:GetName())) - + local minRange = self.LegionRecruitMinRange[target.category] -- Recruit assets. - local recruited, assets, legions=self.commander:RecruitAssetsForTarget(target, mp.MissionType, NassetsMin, NassetsMax) + local recruited, assets, legions=self.commander:RecruitAssetsForTarget(target, mp.MissionType, NassetsMin, NassetsMax, minRange) if recruited then @@ -3369,6 +3370,15 @@ function CHIEF:CanMission(Mission) return self.commander and self.commander:CanMission(Mission) end +--- Exclude legion recruitment that are below a minimum range to target based on the target category. +--- Ex. Prevent intercepts from spawning too close to the target. +-- @param #CHIEF self +-- @param #string TargetCategory The target category. +-- @param #number MinRange Minimum range in meters. +function CHIEF:AddLegionRecruitMinRange(TargetCategory, MinRange) + self.LegionRecruitMinRange[TargetCategory] = MinRange +end + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/Moose Development/Moose/Ops/Commander.lua b/Moose Development/Moose/Ops/Commander.lua index f4637b281..3db6f3bab 100644 --- a/Moose Development/Moose/Ops/Commander.lua +++ b/Moose Development/Moose/Ops/Commander.lua @@ -1914,10 +1914,11 @@ end -- @param #string MissionType Mission Type. -- @param #number NassetsMin Min number of required assets. -- @param #number NassetsMax Max number of required assets. +-- @param #number (optional) RangeMin Minimum range to target. (Default is 0, which means no minimum range) -- @return #boolean If `true` enough assets could be recruited. -- @return #table Assets that have been recruited from all legions. -- @return #table Legions that have recruited assets. -function COMMANDER:RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMax) +function COMMANDER:RecruitAssetsForTarget(Target, MissionType, NassetsMin, NassetsMax, RangeMin) -- Cohorts. local Cohorts=self:_GetCohorts() @@ -1926,7 +1927,7 @@ function COMMANDER:RecruitAssetsForTarget(Target, MissionType, NassetsMin, Nasse local TargetVec2=Target:GetVec2() -- Recruite assets. - local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, MissionType, nil, NassetsMin, NassetsMax, TargetVec2) + local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, MissionType, nil, NassetsMin, NassetsMax, TargetVec2, nil, nil, nil , nil, nil, nil, nil, nil, nil, nil, RangeMin) return recruited, assets, legions diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 9995da864..1576a40d5 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -2577,8 +2577,11 @@ end -- @param #number RefuelSystem Refueling system (boom or probe). -- @param #number CargoWeight Cargo weight [kg]. This checks the cargo bay of the cohort assets and ensures that it is large enough to carry the given cargo weight. -- @param #number MaxWeight Max weight [kg]. This checks whether the cohort asset group is not too heavy. +-- @param RangeMin Min range in meters. (Default is 0, i.e. no minimum range.) -- @return #boolean Returns `true` if given cohort can meet all requirements. -function LEGION._CohortCan(Cohort, MissionType, Categories, Attributes, Properties, WeaponTypes, TargetVec2, RangeMax, RefuelSystem, CargoWeight, MaxWeight) +function LEGION._CohortCan(Cohort, MissionType, Categories, Attributes, Properties, WeaponTypes, TargetVec2, RangeMax, RefuelSystem, CargoWeight, MaxWeight, RangeMin) + + RangeMin = RangeMin or 0 --- Function to check category. local function CheckCategory(_cohort) @@ -2656,8 +2659,8 @@ function LEGION._CohortCan(Cohort, MissionType, Categories, Attributes, Properti -- Is in range? local Rmax=cohort:GetMissionRange(WeaponTypes) local RangeMax = RangeMax or 0 - local InRange=(RangeMax and math.max(RangeMax, Rmax) or Rmax) >= TargetDistance - + local InRange=(RangeMax and math.max(RangeMax, Rmax) or Rmax) >= TargetDistance and TargetDistance > RangeMin + --env.info(string.format("Range TargetDist=%.1f Rmax=%.1f RangeMax=%.1f InRange=%s", TargetDistance, Rmax, RangeMax, tostring(InRange))) return InRange @@ -2803,10 +2806,11 @@ end -- @param #table Attributes Group attributes. See `GROUP.Attribute.` -- @param #table Properties DCS attributes. -- @param #table WeaponTypes Bit of weapon types. +-- @param #number RangeMin Min range in meters. (Default is 0, i.e. no minimum range.) -- @return #boolean If `true` enough assets could be recruited. -- @return #table Recruited assets. **NOTE** that we set the `asset.isReserved=true` flag so it cant be recruited by anyone else. -- @return #table Legions of recruited assets. -function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, NreqMin, NreqMax, TargetVec2, Payloads, RangeMax, RefuelSystem, CargoWeight, TotalWeight, MaxWeight, Categories, Attributes, Properties, WeaponTypes) +function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, NreqMin, NreqMax, TargetVec2, Payloads, RangeMax, RefuelSystem, CargoWeight, TotalWeight, MaxWeight, Categories, Attributes, Properties, WeaponTypes, RangeMin) -- The recruited assets. local Assets={} @@ -2824,7 +2828,7 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, local cohort=_cohort --Ops.Cohort#COHORT -- Check if cohort can do the mission. - local can=LEGION._CohortCan(cohort, MissionTypeRecruit, Categories, Attributes, Properties, WeaponTypes, TargetVec2, RangeMax, RefuelSystem, CargoWeight, MaxWeight) + local can=LEGION._CohortCan(cohort, MissionTypeRecruit, Categories, Attributes, Properties, WeaponTypes, TargetVec2, RangeMax, RefuelSystem, CargoWeight, MaxWeight, RangeMin) --env.info(string.format("RecruitCohortAssets %s Cohort=%s can=%s", MissionTypeRecruit, cohort:GetName(), tostring(can)))