From ff1ebf9775670d3b77e498c965fc61248080d614 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 9 Mar 2022 19:07:14 +0100 Subject: [PATCH] OPS - Legion: Improved max number of transport assets. - OPSGROUP: fixed bugs in speed parameter --- Moose Development/Moose/Core/Zone.lua | 2 +- .../Moose/Functional/Warehouse.lua | 5 +- Moose Development/Moose/Ops/Legion.lua | 61 ++++++++++++++++--- Moose Development/Moose/Ops/OpsGroup.lua | 6 +- 4 files changed, 60 insertions(+), 14 deletions(-) diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 4bf450816..c31840728 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -1219,7 +1219,7 @@ function ZONE_RADIUS:GetRandomVec2(inner, outer, surfacetypes) while gotit==false and N<=Nmax do gotit=_checkSurface(point) if gotit then - env.info(string.format("Got random coordinate with surface type %d after N=%d/%d iterations", land.getSurfaceType(point), N, Nmax)) + --env.info(string.format("Got random coordinate with surface type %d after N=%d/%d iterations", land.getSurfaceType(point), N, Nmax)) else point=_getpoint() N=N+1 diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index e7e2a0a5c..680723d62 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -4107,6 +4107,7 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, local cargobay={} local cargobaytot=0 local cargobaymax=0 + local weights={} for _i,_unit in pairs(group:GetUnits()) do local unit=_unit --Wrapper.Unit#UNIT local Desc=unit:GetDesc() @@ -4115,8 +4116,9 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, local unitweight=forceweight or Desc.massEmpty if unitweight then weight=weight+unitweight + weights[_i]=unitweight end - + local cargomax=0 local massfuel=Desc.fuelMassMax or 0 local massempty=Desc.massEmpty or 0 @@ -4165,6 +4167,7 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay, asset.speedmax=SpeedMax asset.size=smax asset.weight=weight + asset.weights=weights asset.DCSdesc=Descriptors asset.attribute=attribute asset.cargobay=cargobay diff --git a/Moose Development/Moose/Ops/Legion.lua b/Moose Development/Moose/Ops/Legion.lua index 7073651da..929bd7d73 100644 --- a/Moose Development/Moose/Ops/Legion.lua +++ b/Moose Development/Moose/Ops/Legion.lua @@ -534,6 +534,7 @@ function LEGION:CheckMissionQueue() local Transport=nil if mission.NcarriersMin then local Legions=mission.transportLegions or {self} + TransportAvail, Transport=self:AssignAssetsForTransport(Legions, assets, mission.NcarriersMin, mission.NcarriersMax, mission.transportDeployZone, mission.transportDisembarkZone) end @@ -1025,7 +1026,7 @@ function LEGION:onafterNewAsset(From, Event, To, asset, assignment) local nunits=#asset.template.units -- Debug text. - local text=string.format("Adding asset to squadron %s: assignment=%s, type=%s, attribute=%s, nunits=%d %s", cohort.name, assignment, asset.unittype, asset.attribute, nunits, tostring(cohort.ngrouping)) + local text=string.format("Adding asset to squadron %s: assignment=%s, type=%s, attribute=%s, nunits=%d ngroup=%s", cohort.name, assignment, asset.unittype, asset.attribute, nunits, tostring(cohort.ngrouping)) self:T(self.lid..text) -- Adjust number of elements in the group. @@ -1033,6 +1034,10 @@ function LEGION:onafterNewAsset(From, Event, To, asset, assignment) local template=asset.template local N=math.max(#template.units, cohort.ngrouping) + + -- We need to recalc the total weight and cargo bay. + asset.weight=0 + asset.cargobaytot=0 -- Handle units. for i=1,N do @@ -1043,15 +1048,28 @@ function LEGION:onafterNewAsset(From, Event, To, asset, assignment) -- If grouping is larger than units present, copy first unit. if i>nunits then table.insert(template.units, UTILS.DeepCopy(template.units[1])) + asset.cargobaytot=asset.cargobaytot+asset.cargobay[1] + asset.weight=asset.weight+asset.weights[1] + template.units[i].x=template.units[1].x+5*(i-nunits) + template.units[i].y=template.units[1].y+5*(i-nunits) + else + if i<=cohort.ngrouping then + asset.weight=asset.weight+asset.weights[i] + asset.cargobaytot=asset.cargobaytot+asset.cargobay[i] + end end -- Remove units if original template contains more than in grouping. - if cohort.ngroupingnunits then - unit=nil + if i>cohort.ngrouping then + template.units[i]=nil end end + -- Set number of units. asset.nunits=cohort.ngrouping + + -- Debug info. + self:T(self.lid..string.format("After regrouping: Nunits=%d, weight=%.1f cargobaytot=%.1f kg", #asset.template.units, asset.weight, asset.cargobaytot)) end -- Set takeoff type. @@ -1826,7 +1844,7 @@ function LEGION:RecruitAssetsForMission(Mission) end -- Recuit assets. - local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, Mission.type, Mission.alert5MissionType, NreqMin, NreqMax, TargetVec2, Payloads, Mission.engageRange, Mission.refuelSystem, nil) + local recruited, assets, legions=LEGION.RecruitCohortAssets(Cohorts, Mission.type, Mission.alert5MissionType, NreqMin, NreqMax, TargetVec2, Payloads, Mission.engageRange, Mission.refuelSystem) return recruited, assets, legions end @@ -1843,17 +1861,20 @@ function LEGION:RecruitAssetsForTransport(Transport) local cargoOpsGroups=Transport:GetCargoOpsGroups(false) local weightGroup=0 + local TotalWeight=nil -- At least one group should be spawned. if #cargoOpsGroups>0 then -- Calculate the max weight so we know which cohorts can provide carriers. + TotalWeight=0 for _,_opsgroup in pairs(cargoOpsGroups) do local opsgroup=_opsgroup --Ops.OpsGroup#OPSGROUP local weight=opsgroup:GetWeightTotal() if weight>weightGroup then weightGroup=weight end + TotalWeight=TotalWeight+weight end else -- No cargo groups! @@ -1871,7 +1892,7 @@ function LEGION:RecruitAssetsForTransport(Transport) -- Recruit assets and legions. - local recruited, assets, legions=LEGION.RecruitCohortAssets(self.cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NreqMin, NreqMax, TargetVec2, nil, nil, nil, weightGroup) + local recruited, assets, legions=LEGION.RecruitCohortAssets(self.cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NreqMin, NreqMax, TargetVec2, nil, nil, nil, weightGroup, TotalWeight) return recruited, assets, legions end @@ -1932,12 +1953,13 @@ end -- @param #number RangeMax Max range in meters. -- @param #number RefuelSystem Refuelsystem. -- @param #number CargoWeight Cargo weight for recruiting transport carriers. +-- @param #number TotalWeight Total cargo weight in kg. -- @param #table Categories Group categories. -- @param #table Attributes Group attributes. See `GROUP.Attribute.` -- @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, Categories, Attributes) +function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, NreqMin, NreqMax, TargetVec2, Payloads, RangeMax, RefuelSystem, CargoWeight, TotalWeight, Categories, Attributes) -- The recruited assets. local Assets={} @@ -2072,10 +2094,30 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt, --- -- Add assets to mission. + local cargobay=0 for i=1,Nassets do local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem + asset.isReserved=true + Legions[asset.legion.alias]=asset.legion + + if TotalWeight then + + -- Number of + local N=math.floor(asset.cargobaytot/asset.nunits / CargoWeight)*asset.nunits + --env.info(string.format("cargobaytot=%d, cargoweight=%d ==> N=%d", asset.cargobaytot, CargoWeight, N)) + + cargobay=cargobay + N*CargoWeight + + if cargobay>=TotalWeight then + --env.info(string.format("FF found enough assets to transport all cargo! N=%d [%d], cargobay=%.1f >= %.1f kg total weight", i, Nassets, cargobay, TotalWeight)) + Nassets=i + break + end + + end + end -- Return payloads of not needed assets. @@ -2170,7 +2212,7 @@ function LEGION:AssignAssetsForEscort(Cohorts, Assets, NescortMin, NescortMax) end -- Recruit escort asset for the mission asset. - local Erecruited, eassets, elegions=LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.ESCORT, nil, NescortMin, NescortMax, TargetVec2, nil, nil, nil, nil, Categories) + local Erecruited, eassets, elegions=LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.ESCORT, nil, NescortMin, NescortMax, TargetVec2, nil, nil, nil, nil, nil, Categories) if Erecruited then Escorts[asset.spawngroupname]={EscortLegions=elegions, EscortAssets=eassets, ecategory=asset.category, TargetTypes=TargetTypes} @@ -2281,13 +2323,14 @@ function LEGION:AssignAssetsForTransport(Legions, CargoAssets, NcarriersMin, Nca end -- Get all legions and heaviest cargo group weight - local CargoLegions={} ; local CargoWeight=nil + local CargoLegions={} ; local CargoWeight=nil ; local TotalWeight=0 for _,_asset in pairs(CargoAssets) do local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem CargoLegions[asset.legion.alias]=asset.legion if CargoWeight==nil or asset.weight>CargoWeight then CargoWeight=asset.weight end + TotalWeight=TotalWeight+asset.weight end -- Target is the deploy zone. @@ -2295,7 +2338,7 @@ function LEGION:AssignAssetsForTransport(Legions, CargoAssets, NcarriersMin, Nca -- Recruit assets and legions. local TransportAvail, CarrierAssets, CarrierLegions= - LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NcarriersMin, NcarriersMax, TargetVec2, nil, nil, nil, CargoWeight, Categories, Attributes) + LEGION.RecruitCohortAssets(Cohorts, AUFTRAG.Type.OPSTRANSPORT, nil, NcarriersMin, NcarriersMax, TargetVec2, nil, nil, nil, CargoWeight, TotalWeight, Categories, Attributes) if TransportAvail then diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 4b427a81f..e29ebb5c6 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3574,7 +3574,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) --Coordinate:MarkToAll("Random Patrol Zone Coordinate") -- Speed and altitude. - local Speed=UTILS.MpsToKnots(Task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise) + local Speed=Task.dcstask.params.speed and UTILS.MpsToKnots(Task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise) --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 @@ -4909,7 +4909,7 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) local Coordinate=zone:GetRandomCoordinate(nil, nil, surfacetypes) -- Speed and altitude. - local Speed=UTILS.MpsToKnots(task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise) + local Speed=task.dcstask.params.speed and UTILS.MpsToKnots(task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise) -- local Speed=UTILS.KmphToKnots(speed or self.speedCruise) local Altitude=UTILS.MetersToFeet(task.dcstask.params.altitude or self.altitudeCruise) @@ -4946,7 +4946,7 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) local Coordinate=zone:GetRandomCoordinate() -- Speed and altitude. - local Speed=UTILS.MpsToKnots(task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise) + local Speed=task.dcstask.params.speed and UTILS.MpsToKnots(task.dcstask.params.speed) or UTILS.KmphToKnots(self.speedCruise) --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