From 65e852f341cd8c6826a60afba42c4bfa39012e9b Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 24 Jul 2021 01:06:44 +0200 Subject: [PATCH] OPS Transport --- Moose Development/Moose/Ops/Auftrag.lua | 7 ++- Moose Development/Moose/Ops/OpsGroup.lua | 78 ++++++++++++++++++++++-- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index 4c55f5119..6dd08b4e6 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -3149,8 +3149,9 @@ end --- Get coordinate of target. First unit/group of the set is used. -- @param #AUFTRAG self -- @param Wrapper.Group#GROUP group Group. +-- @param #number randomradius Random radius in meters. -- @return Core.Point#COORDINATE Coordinate where the mission is executed. -function AUFTRAG:GetMissionWaypointCoord(group) +function AUFTRAG:GetMissionWaypointCoord(group, randomradius) -- Check if a coord has been explicitly set. if self.missionWaypointCoord then @@ -3166,7 +3167,9 @@ function AUFTRAG:GetMissionWaypointCoord(group) local alt=waypointcoord.y -- Add some randomization. - waypointcoord=ZONE_RADIUS:New("Temp", waypointcoord:GetVec2(), 1000):GetRandomCoordinate():SetAltitude(alt, false) + if randomradius then + waypointcoord=ZONE_RADIUS:New("Temp", waypointcoord:GetVec2(), randomradius):GetRandomCoordinate():SetAltitude(alt, false) + end -- Set altitude of mission waypoint. if self.missionAltitude then diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 6983f7dba..a4ec949b2 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -3009,6 +3009,7 @@ function OPSGROUP:onafterTaskExecute(From, Event, To, Task) -- Parameters. local zone=Task.dcstask.params.zone --Core.Zone#ZONE local Coordinate=zone:GetRandomCoordinate() + Coordinate:MarkToAll("Random Patrol Zone Coordinate") 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 @@ -3695,15 +3696,21 @@ function OPSGROUP:RouteToMission(mission, delay) self:ScheduleOnce(delay, OPSGROUP.RouteToMission, self, mission) else - if self:IsDead() then + if self:IsDead() or self:IsStopped() then return end -- ID of current waypoint. local uid=self:GetWaypointCurrent().uid - + + -- Random radius. + local randomradius=1000 + if mission.type==AUFTRAG.Type.PATROLZONE then + randomradius=nil + end + -- Get coordinate where the mission is executed. - local waypointcoord=mission:GetMissionWaypointCoord(self.group) + local waypointcoord=mission:GetMissionWaypointCoord(self.group, randomradius) -- Add enroute tasks. for _,task in pairs(mission.enrouteTasks) do @@ -5423,6 +5430,39 @@ function OPSGROUP:_CheckDelivered(CargoTransport) return done end + +--- Check if all cargo of this transport assignment was delivered. +-- @param #OPSGROUP self +-- @param Ops.OpsTransport#OPSTRANSPORT CargoTransport The next due cargo transport or `nil`. +-- @return #boolean If true, all cargo was delivered. +function OPSGROUP:_CheckGoPickup(CargoTransport) + + local done=true + for _,_cargo in pairs(CargoTransport.cargos) do + local cargo=_cargo --Ops.OpsGroup#OPSGROUP.CargoGroup + + if self:CanCargo(cargo.opsgroup) then + + if cargo.delivered then + -- This one is delivered. + elseif cargo.opsgroup==nil or cargo.opsgroup:IsDead() or cargo.opsgroup:IsStopped() then + -- This one is dead. + elseif cargo.opsgroup:IsLoaded() then + -- This one is loaded into a(nother) carrier. + else + done=false --Someone is not done! + end + + end + + end + + -- Debug info. + self:T(self.lid..string.format("Cargotransport UID=%d Status=%s: delivered=%s", CargoTransport.uid, CargoTransport:GetState(), tostring(done))) + + return done +end + --- Create a cargo transport assignment. -- @param #OPSGROUP self -- @param Ops.OpsTransport#OPSTRANSPORT OpsTransport The troop transport assignment. @@ -5517,6 +5557,32 @@ function OPSGROUP:GetFreeCargobay(UnitName, IncludeReserved) return Free end +--- Get relative free cargo bay in percent. +-- @param #OPSGROUP self +-- @param #string UnitName Name of the unit. Default is of the whole group. +-- @param #boolean IncludeReserved If `false`, cargo weight that is only *reserved* is **not** counted. By default (`true` or `nil`), the reserved cargo is included. +-- @return #number Free cargo bay in percent. +function OPSGROUP:GetFreeCargobayRelative(UnitName, IncludeReserved) + + local free=self:GetFreeCargobay(UnitName, IncludeReserved) + + local total=self:GetWeightCargoMax(UnitName) + + local percent=free/total*100 + + return percent +end + +--- Get relative used (loaded) cargo bay in percent. +-- @param #OPSGROUP self +-- @param #string UnitName Name of the unit. Default is of the whole group. +-- @param #boolean IncludeReserved If `false`, cargo weight that is only *reserved* is **not** counted. By default (`true` or `nil`), the reserved cargo is included. +-- @return #number Used cargo bay in percent. +function OPSGROUP:GetUsedCargobayRelative(UnitName, IncludeReserved) + local free=self:GetFreeCargobayRelative(UnitName, IncludeReserved) + return 100-free +end + --- Get max weight of cargo (group) this group can load. This is the largest free cargo bay of any (not dead) element of the group. -- Optionally, you can calculate the current max weight possible, which accounts for currently loaded cargo. -- @param #OPSGROUP self @@ -6563,7 +6629,7 @@ function OPSGROUP:onafterUnloaded(From, Event, To) end -- Check everything was delivered (or is dead). - local delivered=self:_CheckDelivered(self.cargoTransport) + local delivered=self:_CheckGoPickup(self.cargoTransport) if not delivered then @@ -9295,9 +9361,11 @@ end -- @return #OPSGROUP self function OPSGROUP:_SetTemplate(Template) + -- Set the template. self.template=Template or self.group:GetTemplate() - self:I(self.lid.."Setting group template") + -- Debug info. + self:T3(self.lid.."Setting group template") return self end