- Legion: Improved max number of transport assets.
- OPSGROUP: fixed bugs in speed parameter
This commit is contained in:
Frank
2022-03-09 19:07:14 +01:00
parent e6f388518a
commit ff1ebf9775
4 changed files with 60 additions and 14 deletions

View File

@@ -1219,7 +1219,7 @@ function ZONE_RADIUS:GetRandomVec2(inner, outer, surfacetypes)
while gotit==false and N<=Nmax do while gotit==false and N<=Nmax do
gotit=_checkSurface(point) gotit=_checkSurface(point)
if gotit then 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 else
point=_getpoint() point=_getpoint()
N=N+1 N=N+1

View File

@@ -4107,6 +4107,7 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay,
local cargobay={} local cargobay={}
local cargobaytot=0 local cargobaytot=0
local cargobaymax=0 local cargobaymax=0
local weights={}
for _i,_unit in pairs(group:GetUnits()) do for _i,_unit in pairs(group:GetUnits()) do
local unit=_unit --Wrapper.Unit#UNIT local unit=_unit --Wrapper.Unit#UNIT
local Desc=unit:GetDesc() local Desc=unit:GetDesc()
@@ -4115,8 +4116,9 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay,
local unitweight=forceweight or Desc.massEmpty local unitweight=forceweight or Desc.massEmpty
if unitweight then if unitweight then
weight=weight+unitweight weight=weight+unitweight
weights[_i]=unitweight
end end
local cargomax=0 local cargomax=0
local massfuel=Desc.fuelMassMax or 0 local massfuel=Desc.fuelMassMax or 0
local massempty=Desc.massEmpty or 0 local massempty=Desc.massEmpty or 0
@@ -4165,6 +4167,7 @@ function WAREHOUSE:_RegisterAsset(group, ngroups, forceattribute, forcecargobay,
asset.speedmax=SpeedMax asset.speedmax=SpeedMax
asset.size=smax asset.size=smax
asset.weight=weight asset.weight=weight
asset.weights=weights
asset.DCSdesc=Descriptors asset.DCSdesc=Descriptors
asset.attribute=attribute asset.attribute=attribute
asset.cargobay=cargobay asset.cargobay=cargobay

View File

@@ -534,6 +534,7 @@ function LEGION:CheckMissionQueue()
local Transport=nil local Transport=nil
if mission.NcarriersMin then if mission.NcarriersMin then
local Legions=mission.transportLegions or {self} local Legions=mission.transportLegions or {self}
TransportAvail, Transport=self:AssignAssetsForTransport(Legions, assets, mission.NcarriersMin, mission.NcarriersMax, mission.transportDeployZone, mission.transportDisembarkZone) TransportAvail, Transport=self:AssignAssetsForTransport(Legions, assets, mission.NcarriersMin, mission.NcarriersMax, mission.transportDeployZone, mission.transportDisembarkZone)
end end
@@ -1025,7 +1026,7 @@ function LEGION:onafterNewAsset(From, Event, To, asset, assignment)
local nunits=#asset.template.units local nunits=#asset.template.units
-- Debug text. -- 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) self:T(self.lid..text)
-- Adjust number of elements in the group. -- Adjust number of elements in the group.
@@ -1033,6 +1034,10 @@ function LEGION:onafterNewAsset(From, Event, To, asset, assignment)
local template=asset.template local template=asset.template
local N=math.max(#template.units, cohort.ngrouping) 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. -- Handle units.
for i=1,N do 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 grouping is larger than units present, copy first unit.
if i>nunits then if i>nunits then
table.insert(template.units, UTILS.DeepCopy(template.units[1])) 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 end
-- Remove units if original template contains more than in grouping. -- Remove units if original template contains more than in grouping.
if cohort.ngrouping<nunits and i>nunits then if i>cohort.ngrouping then
unit=nil template.units[i]=nil
end end
end end
-- Set number of units.
asset.nunits=cohort.ngrouping 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 end
-- Set takeoff type. -- Set takeoff type.
@@ -1826,7 +1844,7 @@ function LEGION:RecruitAssetsForMission(Mission)
end end
-- Recuit assets. -- 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 return recruited, assets, legions
end end
@@ -1843,17 +1861,20 @@ function LEGION:RecruitAssetsForTransport(Transport)
local cargoOpsGroups=Transport:GetCargoOpsGroups(false) local cargoOpsGroups=Transport:GetCargoOpsGroups(false)
local weightGroup=0 local weightGroup=0
local TotalWeight=nil
-- At least one group should be spawned. -- At least one group should be spawned.
if #cargoOpsGroups>0 then if #cargoOpsGroups>0 then
-- Calculate the max weight so we know which cohorts can provide carriers. -- Calculate the max weight so we know which cohorts can provide carriers.
TotalWeight=0
for _,_opsgroup in pairs(cargoOpsGroups) do for _,_opsgroup in pairs(cargoOpsGroups) do
local opsgroup=_opsgroup --Ops.OpsGroup#OPSGROUP local opsgroup=_opsgroup --Ops.OpsGroup#OPSGROUP
local weight=opsgroup:GetWeightTotal() local weight=opsgroup:GetWeightTotal()
if weight>weightGroup then if weight>weightGroup then
weightGroup=weight weightGroup=weight
end end
TotalWeight=TotalWeight+weight
end end
else else
-- No cargo groups! -- No cargo groups!
@@ -1871,7 +1892,7 @@ function LEGION:RecruitAssetsForTransport(Transport)
-- Recruit assets and legions. -- 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 return recruited, assets, legions
end end
@@ -1932,12 +1953,13 @@ end
-- @param #number RangeMax Max range in meters. -- @param #number RangeMax Max range in meters.
-- @param #number RefuelSystem Refuelsystem. -- @param #number RefuelSystem Refuelsystem.
-- @param #number CargoWeight Cargo weight for recruiting transport carriers. -- @param #number CargoWeight Cargo weight for recruiting transport carriers.
-- @param #number TotalWeight Total cargo weight in kg.
-- @param #table Categories Group categories. -- @param #table Categories Group categories.
-- @param #table Attributes Group attributes. See `GROUP.Attribute.` -- @param #table Attributes Group attributes. See `GROUP.Attribute.`
-- @return #boolean If `true` enough assets could be recruited. -- @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 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. -- @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. -- The recruited assets.
local Assets={} local Assets={}
@@ -2072,10 +2094,30 @@ function LEGION.RecruitCohortAssets(Cohorts, MissionTypeRecruit, MissionTypeOpt,
--- ---
-- Add assets to mission. -- Add assets to mission.
local cargobay=0
for i=1,Nassets do for i=1,Nassets do
local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem local asset=Assets[i] --Functional.Warehouse#WAREHOUSE.Assetitem
asset.isReserved=true asset.isReserved=true
Legions[asset.legion.alias]=asset.legion 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 end
-- Return payloads of not needed assets. -- Return payloads of not needed assets.
@@ -2170,7 +2212,7 @@ function LEGION:AssignAssetsForEscort(Cohorts, Assets, NescortMin, NescortMax)
end end
-- Recruit escort asset for the mission asset. -- 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 if Erecruited then
Escorts[asset.spawngroupname]={EscortLegions=elegions, EscortAssets=eassets, ecategory=asset.category, TargetTypes=TargetTypes} Escorts[asset.spawngroupname]={EscortLegions=elegions, EscortAssets=eassets, ecategory=asset.category, TargetTypes=TargetTypes}
@@ -2281,13 +2323,14 @@ function LEGION:AssignAssetsForTransport(Legions, CargoAssets, NcarriersMin, Nca
end end
-- Get all legions and heaviest cargo group weight -- 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 for _,_asset in pairs(CargoAssets) do
local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem local asset=_asset --Functional.Warehouse#WAREHOUSE.Assetitem
CargoLegions[asset.legion.alias]=asset.legion CargoLegions[asset.legion.alias]=asset.legion
if CargoWeight==nil or asset.weight>CargoWeight then if CargoWeight==nil or asset.weight>CargoWeight then
CargoWeight=asset.weight CargoWeight=asset.weight
end end
TotalWeight=TotalWeight+asset.weight
end end
-- Target is the deploy zone. -- Target is the deploy zone.
@@ -2295,7 +2338,7 @@ function LEGION:AssignAssetsForTransport(Legions, CargoAssets, NcarriersMin, Nca
-- Recruit assets and legions. -- Recruit assets and legions.
local TransportAvail, CarrierAssets, CarrierLegions= 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 if TransportAvail then

View File

@@ -3574,7 +3574,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task)
--Coordinate:MarkToAll("Random Patrol Zone Coordinate") --Coordinate:MarkToAll("Random Patrol Zone Coordinate")
-- Speed and altitude. -- 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 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 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) local Coordinate=zone:GetRandomCoordinate(nil, nil, surfacetypes)
-- Speed and altitude. -- 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 Speed=UTILS.KmphToKnots(speed or self.speedCruise)
local Altitude=UTILS.MetersToFeet(task.dcstask.params.altitude or self.altitudeCruise) 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() local Coordinate=zone:GetRandomCoordinate()
-- Speed and altitude. -- 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 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 local Altitude=task.dcstask.params.altitude and UTILS.MetersToFeet(task.dcstask.params.altitude) or nil