diff --git a/Moose Development/Moose/Ops/CTLD.lua b/Moose Development/Moose/Ops/CTLD.lua index 372d32afc..062804662 100644 --- a/Moose Development/Moose/Ops/CTLD.lua +++ b/Moose Development/Moose/Ops/CTLD.lua @@ -1561,9 +1561,8 @@ function CTLD:New(Coalition, Prefixes, Alias) self.movetroopsdistance = 5000 self.returntroopstobase = true -- if set to false, troops would stay after deployment inside a load zone. self.troopdropzoneradius = 100 - + self.buildPairSeparation = 25 self.loadSavedCrates = true - self.VehicleMoveFormation = AI.Task.VehicleFormation.VEE -- added support Hercules Mod @@ -4235,23 +4234,62 @@ function CTLD:_BuildCrates(Group, Unit,Engineering,MultiDrop) end -- let\'s get going if canbuild then + local notified=false -- loop again for _,_build in pairs(buildables) do local build = _build -- #CTLD.Buildable if build.CanBuild then - self:_CleanUpCrates(crates,build,number) - self:_RefreshLoadCratesMenu(Group,Unit) - if self.buildtime and self.buildtime > 0 then + local required = build.Required or 1 + if required < 1 then required = 1 end + local full = math.floor((build.Found or 0)/required) + if full < 1 then full = 1 end + + local sep = self.buildPairSeparation or 25 + local hdg = (Unit:GetHeading()+180)%360 + local lat = (hdg+90)%360 + local base = Unit:GetCoordinate():Translate(20,hdg) + + if full == 1 then + local cratesNow, numberNow = self:_FindCratesNearby(Group,Unit, finddist,true,true) + self:_CleanUpCrates(cratesNow,build,numberNow) + self:_RefreshLoadCratesMenu(Group,Unit) + if self.buildtime and self.buildtime > 0 then local buildtimer = TIMER:New(self._BuildObjectFromCrates,self,Group,Unit,build,false,Group:GetCoordinate(),MultiDrop) buildtimer:Start(self.buildtime) - self:_SendMessage(string.format("Build started, ready in %d seconds!",self.buildtime),15,false,Group) + if not notified then + self:_SendMessage(string.format("Build started, ready in %d seconds!",self.buildtime),15,false,Group) + notified=true + end self:__CratesBuildStarted(1,Group,Unit,build.Name) + else + self:_BuildObjectFromCrates(Group,Unit,build,false,nil,MultiDrop) + end else - self:_BuildObjectFromCrates(Group,Unit,build,false,nil,MultiDrop) + local start = -((full-1)*sep)/2 + for n=1,full do + local cratesNow, numberNow = self:_FindCratesNearby(Group,Unit, finddist,true,true) + self:_CleanUpCrates(cratesNow,build,numberNow) + self:_RefreshLoadCratesMenu(Group,Unit) + local off = start + (n-1)*sep + local coord = base:Translate(off,lat):GetVec2() + local b = { Name=build.Name, Required=build.Required, Template=build.Template, CanBuild=true, Type=build.Type, Coord=coord } + if self.buildtime and self.buildtime > 0 then + local buildtimer = TIMER:New(self._BuildObjectFromCrates,self,Group,Unit,b,false,Group:GetCoordinate(),MultiDrop) + buildtimer:Start(self.buildtime) + if not notified then + self:_SendMessage(string.format("Build started, ready in %d seconds!",self.buildtime),15,false,Group) + notified=true + end + self:__CratesBuildStarted(1,Group,Unit,build.Name) + else + self:_BuildObjectFromCrates(Group,Unit,b,false,nil,MultiDrop) + end + end end end end end + else if not Engineering then self:_SendMessage(string.format("No crates within %d meters!",finddist), 10, false, Group) end end -- number > 0 @@ -4273,28 +4311,37 @@ function CTLD:_PackCratesNearby(Group, Unit) -- get nearby vehicles local location = Group:GetCoordinate() -- get coordinate of group using function - local nearestGroups = SET_GROUP:New():FilterCoalitions("blue"):FilterZones({ZONE_RADIUS:New("TempZone", location:GetVec2(), self.PackDistance, false)}):FilterOnce() -- get all groups withing PackDistance from group using function - -- get template name of all vehicles in zone + local nearestGroups = SET_GROUP:New():FilterCoalitions("blue"):FilterZones({ZONE_RADIUS:New("TempZone", location:GetVec2(), self.PackDistance, false)}):FilterOnce() + + local packedAny = false -- determine if group is packable for _, _Group in pairs(nearestGroups.Set) do -- convert #SET_GROUP to a list of Wrapper.Group#GROUP + local didPackThisGroup = false for _, _Template in pairs(_DATABASE.Templates.Groups) do -- iterate through the database of templates - if (string.match(_Group:GetName(), _Template.GroupName)) then -- check if the Wrapper.Group#GROUP near the player is in the list of templates by name - -- generate crates and destroy group + if string.match(_Group:GetName(), _Template.GroupName) then -- check if the Wrapper.Group#GROUP near the player is in the list of templates by name for _, _entry in pairs(self.Cargo_Crates) do -- iterate through #CTLD_CARGO - if (_entry.Templates[1] == _Template.GroupName) then -- check if the #CTLD_CARGO matches the template name - _Group:Destroy() -- if a match is found destroy the Wrapper.Group#GROUP near the player + if _entry.Templates[1] == _Template.GroupName then -- check if the #CTLD_CARGO matches the template name + _Group:Destroy() self:_GetCrates(Group, Unit, _entry, nil, false, true) -- spawn the appropriate crates near the player self:_RefreshLoadCratesMenu(Group,Unit) -- call the refresher to show the crates in the menu self:__CratesPacked(1,Group,Unit,_entry) - return true + packedAny = true + didPackThisGroup = true + break end end end + if didPackThisGroup then break end end end + + if not packedAny then self:_SendMessage("Nothing to pack at this distance pilot!",10,false,Group) return false + end + + return true end --- (Internal) Function to repair nearby vehicles / FOBs @@ -4513,7 +4560,8 @@ function CTLD:_CleanUpCrates(Crates,Build,Number) if name == nametype then -- matching crate type table.insert(destIDs,thisID) found = found + 1 - nowcrate:GetPositionable():Destroy(false) + local pos = nowcrate:GetPositionable() + if pos then pos:Destroy(false) end nowcrate.Positionable = nil nowcrate.HasBeenDropped = false end @@ -5597,34 +5645,50 @@ function CTLD:_RefreshDropCratesMenu(Group, Unit) local needed=list[1]:GetCratesNeeded() or 1 table.sort(list,function(a,b)return a:GetID()=needed then + local sets=math.floor(#list/(needed>0 and needed or 1)) + if sets>0 then + local parentLabel=string.format("%d. %s (%d SET)",lineIndex,cName,sets) + local parentMenu=MENU_GROUP:New(Group,parentLabel,dropCratesMenu) + for s=1,sets do local chunk={} - for n=i,i+needed-1 do - table.insert(chunk,list[n]) - end - local label=string.format("%d. %s",lineIndex,cName) + for n=i,i+needed-1 do table.insert(chunk,list[n]) end table.insert(self.CrateGroupList[Unit:GetName()],chunk) - local setIndex=#self.CrateGroupList[Unit:GetName()] - MENU_GROUP_COMMAND:New(Group,label,dropCratesMenu,self._UnloadSingleCrateSet,self,Group,Unit,setIndex) i=i+needed - else - local chunk={} - for n=i,#list do - table.insert(chunk,list[n]) - end - local label=string.format("%d. %s %d/%d",lineIndex,cName,left,needed) - table.insert(self.CrateGroupList[Unit:GetName()],chunk) - local setIndex=#self.CrateGroupList[Unit:GetName()] - MENU_GROUP_COMMAND:New(Group,label,dropCratesMenu,self._UnloadSingleCrateSet,self,Group,Unit,setIndex) - i=#list+1 end + for q=1,sets do + local qm=MENU_GROUP:New(Group,string.format("Drop %d Set%s",q,q>1 and "s" or ""),parentMenu) + MENU_GROUP_COMMAND:New(Group,"Drop",qm,function(selfArg,GroupArg,UnitArg,cNameArg,neededArg,qty) + local uName=UnitArg:GetName() + for k=1,qty do + local lst=selfArg.CrateGroupList and selfArg.CrateGroupList[uName] + if not lst then break end + local idx=nil + for j=1,#lst do + local ch=lst[j] + local first=ch and ch[1] + if first and (not first:WasDropped()) and first:GetName()==cNameArg and #ch>=neededArg then idx=j break end + end + if not idx then break end + selfArg:_UnloadSingleCrateSet(GroupArg,UnitArg,idx) + end + end,self,Group,Unit,cName,needed,q) + end + lineIndex=lineIndex+1 + end + if i<=#list then + local left=#list-i+1 + local chunk={} + for n=i,#list do table.insert(chunk,list[n]) end + table.insert(self.CrateGroupList[Unit:GetName()],chunk) + local setIndex=#self.CrateGroupList[Unit:GetName()] + local label=string.format("%d. %s %d/%d",lineIndex,cName,left,needed) + MENU_GROUP_COMMAND:New(Group,label,dropCratesMenu,self._UnloadSingleCrateSet,self,Group,Unit,setIndex) lineIndex=lineIndex+1 end end else + -------------------------------------------------------------------- -------------------------------------------------------------------- -- one-step (enhanced) menu -------------------------------------------------------------------- @@ -5642,39 +5706,69 @@ function CTLD:_RefreshDropCratesMenu(Group, Unit) local needed=list[1]:GetCratesNeeded() or 1 table.sort(list,function(a,b)return a:GetID()=needed then + local sets=math.floor(#list/(needed>0 and needed or 1)) + if sets>0 then + local parentLabel=string.format("%d. %s (%d SET)",lineIndex,cName,sets) + local parentMenu=MENU_GROUP:New(Group,parentLabel,dropCratesMenu) + for s=1,sets do local chunk={} - for n=i,i+needed-1 do - table.insert(chunk,list[n]) - end - local label=string.format("%d. %s",lineIndex,cName) + for n=i,i+needed-1 do table.insert(chunk,list[n]) end table.insert(self.CrateGroupList[Unit:GetName()],chunk) - local setIndex=#self.CrateGroupList[Unit:GetName()] - local mSet=MENU_GROUP:New(Group,label,dropCratesMenu) - MENU_GROUP_COMMAND:New(Group,"Drop",mSet,self._UnloadSingleCrateSet,self,Group,Unit,setIndex) - if not ( self:IsUnitInAir(Unit) and self:IsFixedWing(Unit) ) then - MENU_GROUP_COMMAND:New(Group,"Drop and build",mSet,self._DropSingleAndBuild,self,Group,Unit,setIndex) - end i=i+needed - else - local chunk={} - for n=i,#list do - table.insert(chunk,list[n]) - end - local label=string.format("%d. %s %d/%d",lineIndex,cName,left,needed) - table.insert(self.CrateGroupList[Unit:GetName()],chunk) - local setIndex=#self.CrateGroupList[Unit:GetName()] - MENU_GROUP_COMMAND:New(Group,label,dropCratesMenu,self._UnloadSingleCrateSet,self,Group,Unit,setIndex) - i=#list+1 end + for q=1,sets do + local qm=MENU_GROUP:New(Group,string.format("Drop %d Set%s",q,q>1 and "s" or ""),parentMenu) + MENU_GROUP_COMMAND:New(Group,"Drop",qm,function(selfArg,GroupArg,UnitArg,cNameArg,neededArg,qty) + local uName=UnitArg:GetName() + for k=1,qty do + local lst=selfArg.CrateGroupList and selfArg.CrateGroupList[uName] + if not lst then break end + local idx=nil + for j=1,#lst do + local ch=lst[j] + local first=ch and ch[1] + if first and (not first:WasDropped()) and first:GetName()==cNameArg and #ch>=neededArg then idx=j break end + end + if not idx then break end + selfArg:_UnloadSingleCrateSet(GroupArg,UnitArg,idx) + end + end,self,Group,Unit,cName,needed,q) + if not ( self:IsUnitInAir(Unit) and self:IsFixedWing(Unit) ) then + MENU_GROUP_COMMAND:New(Group,"Drop and build",qm,function(selfArg,GroupArg,UnitArg,cNameArg,neededArg,qty) + local uName=UnitArg:GetName() + for k=1,qty do + local lst=selfArg.CrateGroupList and selfArg.CrateGroupList[uName] + if not lst then break end + local idx=nil + for j=1,#lst do + local ch=lst[j] + local first=ch and ch[1] + if first and (not first:WasDropped()) and first:GetName()==cNameArg and #ch>=neededArg then idx=j break end + end + if not idx then break end + selfArg:_UnloadSingleCrateSet(GroupArg,UnitArg,idx) + end + selfArg:_BuildCrates(GroupArg,UnitArg) + end,self,Group,Unit,cName,needed,q) + end + end + lineIndex=lineIndex+1 + end + if i<=#list then + local left=#list-i+1 + local chunk={} + for n=i,#list do table.insert(chunk,list[n]) end + table.insert(self.CrateGroupList[Unit:GetName()],chunk) + local setIndex=#self.CrateGroupList[Unit:GetName()] + local label=string.format("%d. %s %d/%d",lineIndex,cName,left,needed) + MENU_GROUP_COMMAND:New(Group,label,dropCratesMenu,self._UnloadSingleCrateSet,self,Group,Unit,setIndex) lineIndex=lineIndex+1 end end end end + --- (Internal) Function to unload a single Troop group by ID. -- @param #CTLD self -- @param Wrapper.Group#GROUP Group The calling group. @@ -8472,7 +8566,7 @@ end local injecttroops = CTLD_CARGO:New(nil,cargoname,cargotemplates,cargotype,true,true,size,nil,true,mass) self:InjectTroops(dropzone,injecttroops,self.surfacetypes,self.useprecisecoordloads,structure,timestamp) end - elseif self.loadSavedCrates and ((type(groupname) == "string" and groupname == "STATIC") or cargotype == CTLD_CARGO.Enum.REPAIR) then + elseif self.loadSavedCrates and (type(groupname) == "string" and groupname == "STATIC") or cargotype == CTLD_CARGO.Enum.REPAIR then local dropzone = ZONE_RADIUS:New("DropZone",vec2,20) local injectstatic = nil if cargotype == CTLD_CARGO.Enum.VEHICLE or cargotype == CTLD_CARGO.Enum.FOB then