From ce10390406bc05082fd2671d304f9b5ae5d6c45c Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 7 Oct 2020 23:26:46 +0200 Subject: [PATCH 1/5] ARMYGROUP --- Moose Development/Moose/Ops/ArmyGroup.lua | 143 ++++++++++--------- Moose Development/Moose/Ops/OpsGroup.lua | 166 +++++++++------------- 2 files changed, 146 insertions(+), 163 deletions(-) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index c566c5b1c..c063d3c18 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -140,6 +140,18 @@ function ARMYGROUP:GetClosestRoad() return self:GetCoordinate():GetClosestPointToRoad() end +--- Get 2D distance to the closest road. +-- @param #ARMYGROUP self +-- @return #number Distance in meters to the closest road. +function ARMYGROUP:GetClosestRoadDist() + local road=self:GetClosestRoad() + if road then + local dist=road:Get2DDistance(self:GetCoordinate()) + return dist + end + return math.huge +end + --- Add a *scheduled* task to fire at a given coordinate. -- @param #ARMYGROUP self @@ -372,80 +384,75 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) -- Waypoints. local waypoints={} - -- Total number of waypoints - local N=#self.waypoints - - -- Add remaining waypoints to route. - for i=n, N do + -- Next waypoint. + local wp=UTILS.DeepCopy(self.waypoints[n]) --Ops.OpsGroup#OPSGROUP.Waypoint - -- Copy waypoint. - local wp=UTILS.DeepCopy(self.waypoints[i]) --Ops.OpsGroup#OPSGROUP.Waypoint - - if i==n then - - --- - -- Next Waypoint - --- - - if Speed then - wp.speed=UTILS.KnotsToMps(Speed) - else - -- Take default waypoint speed. - end - - if self.formationPerma then - --if self.formationPerma==ENUMS.Formation.Vehicle.OnRoad then - wp.action=self.formationPerma - --end - elseif Formation then - wp.action=Formation - end - - -- Current set formation. - self.option.Formation=wp.action - - -- Current set speed in m/s. - self.speedWp=wp.speed - - else + -- Do we want to drive on road to the next wp? + local onroad=wp.action==ENUMS.Formation.Vehicle.OnRoad - --- - -- Later Waypoint(s) - --- - - if self.formationPerma then - wp.action=self.formationPerma - else - -- Take default waypoint speed. - end - - end - - if wp.roaddist>100 and wp.action==ENUMS.Formation.Vehicle.OnRoad then - - -- Waypoint is actually off road! - wp.action=ENUMS.Formation.Vehicle.OffRoad + -- Current point. + local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OffRoad) + table.insert(waypoints, current) + + -- Insert a point on road. + if onroad then + local current=self:GetClosestRoad():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OnRoad) + table.insert(waypoints, current) + end - -- Add "On Road" waypoint in between. - local wproad=wp.roadcoord:WaypointGround(wp.speed, ENUMS.Formation.Vehicle.OnRoad) - table.insert(waypoints, wproad) - end - - -- Debug info. - self:T(string.format("WP %d %s: Speed=%d m/s, alt=%d m, Action=%s", i, wp.type, wp.speed, wp.alt, wp.action)) - -- Add waypoint. - table.insert(waypoints, wp) + -- Speed. + if Speed then + wp.speed=UTILS.KnotsToMps(Speed) + else + -- Take default waypoint speed. + end + + -- Formation. + if self.formationPerma then + wp.action=self.formationPerma + elseif Formation then + wp.action=Formation + end + + -- Current set formation. + self.option.Formation=wp.action + + -- Current set speed in m/s. + self.speedWp=wp.speed + + -- Add waypoint in between because this waypoint is "On Road" but lies "Off Road". + if onroad then + + -- The real waypoint is actually off road. + wp.action=ENUMS.Formation.Vehicle.OffRoad + + -- Add "On Road" waypoint in between. + local wproad=wp.roadcoord:WaypointGround(wp.speed, ENUMS.Formation.Vehicle.OnRoad) --Ops.OpsGroup#OPSGROUP.Waypoint + + -- Insert road waypoint. + table.insert(waypoints, wproad) + end + + -- Add waypoint. + table.insert(waypoints, wp) + + -- Debug output. + if false then + for i,_wp in pairs(waypoints) do + local wp=_wp + local text=string.format("WP #%d UID=%d type=%s: Speed=%d m/s, alt=%d m, Action=%s", i, wp.uid and wp.uid or 0, wp.type, wp.speed, wp.alt, wp.action) + self:I(text) + if wp.coordinate then + wp.coordinate:MarkToAll(text) + end + end end - -- Current waypoint. - local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), self.option.Formation) - table.insert(waypoints, 1, current) - table.insert(waypoints, 1, current) -- Seems to be better to add this twice. Otherwise, the passing waypoint functions is triggered to early! - - if #waypoints>2 then + if #waypoints>=2 then + -- Debug info. self:T(self.lid..string.format("Updateing route: WP %d-->%d-->%d (#%d), Speed=%.1f knots, Formation=%s", self.currentwp, n, #self.waypoints, #waypoints-2, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation))) @@ -646,7 +653,7 @@ end --- Add an a waypoint to the route. -- @param #ARMYGROUP self --- @param Core.Point#COORDINATE Coordinate The coordinate of the waypoint. Use COORDINATE:SetAltitude(altitude) to define the altitude. +-- @param Core.Point#COORDINATE Coordinate The coordinate of the waypoint. -- @param #number Speed Speed in knots. Default is default cruise speed or 70% of max speed. -- @param #number AfterWaypointWithID Insert waypoint after waypoint given ID. Default is to insert as last waypoint. -- @param #number Formation Formation the group will use. @@ -683,7 +690,7 @@ function ARMYGROUP:AddWaypoint(Coordinate, Speed, AfterWaypointWithID, Formation end -- Debug info. - self:T(self.lid..string.format("Adding waypoint UID=%d (index=%d), Speed=%.1f knots, Dist2Road=%d m, Action=%s", waypoint.uid, wpnumber, Speed, waypoint.roaddist, waypoint.action)) + self:I(self.lid..string.format("Adding waypoint UID=%d (index=%d), Speed=%.1f knots, Dist2Road=%d m, Action=%s", waypoint.uid, wpnumber, Speed, waypoint.roaddist, waypoint.action)) -- Update route. if Updateroute==nil or Updateroute==true then diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 67b6335b1..2d0010b78 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -1133,18 +1133,21 @@ end --- Get next waypoint index. -- @param #OPSGROUP self -- @param #boolean cyclic If true, return first waypoint if last waypoint was reached. Default is patrol ad infinitum value set. +-- @param #number i Waypoint index from which the next index is returned. Default is the last waypoint passed. -- @return #number Next waypoint index. -function OPSGROUP:GetWaypointIndexNext(cyclic) +function OPSGROUP:GetWaypointIndexNext(cyclic, i) if cyclic==nil then cyclic=self.adinfinitum end local N=#self.waypoints - - local n=math.min(self.currentwp+1, N) - if cyclic and self.currentwp==N then + i=i or self.currentwp + + local n=math.min(i+1, N) + + if cyclic and i==N then n=1 end @@ -2677,18 +2680,18 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) -- Set switch to true. self.passedfinalwp=true - -- Check if all tasks/mission are done? If so, RTB or WAIT. - -- Note, we delay it for a second to let the OnAfterPassingwaypoint function to be executed in case someone wants to add another waypoint there. - if ntasks==0 then - self:_CheckGroupDone(1) - end + end + -- Check if all tasks/mission are done? If so, RTB or WAIT. + -- Note, we delay it for a second to let the OnAfterPassingwaypoint function to be executed in case someone wants to add another waypoint there. + if ntasks==0 then + self:_CheckGroupDone() end -- Debug info. local text=string.format("Group passed waypoint %s/%d ID=%d: final=%s detour=%s astar=%s", tostring(wpindex), #self.waypoints, Waypoint.uid, tostring(self.passedfinalwp), tostring(Waypoint.detour), tostring(Waypoint.astar)) - self:T(self.lid..text) + self:I(self.lid..text) end @@ -3058,92 +3061,60 @@ function OPSGROUP:_CheckGroupDone(delay) self:ScheduleOnce(delay, self._CheckGroupDone, self) else - if self.passedfinalwp then - - --- - -- Passed FINAL waypoint - --- - - if #self.waypoints>1 then - - if self.adinfinitum then - - -- Get positive speed to first waypoint. - local speed=self:GetSpeedToWaypoint(1) - - -- Start route at first waypoint. - self:__UpdateRoute(-1, 1, speed) - - self:T(self.lid..string.format("Passed final WP, #WP>1, adinfinitum=TRUE ==> Goto WP 1 at speed>0")) - - self.passedfinalwp=false - - else - -- No further waypoints. Command a full stop. - self:__FullStop(-1) - - self:T(self.lid..string.format("Passed final WP, #WP>1, adinfinitum=FALSE ==> Full Stop")) - end - - elseif #self.waypoints==1 then - - --- Only one WP left - - -- The last waypoint. - local waypoint=self.waypoints[1] --Ops.OpsGroup#OPSGROUP.Waypoint - - local dist=self:GetCoordinate():Get2DDistance(waypoint.coordinate) - - - if self.adinfinitum and dist>1000 then -- Note that dist>100 caused the same wp to be passed a lot of times. - - self:T(self.lid..string.format("Passed final WP, #WP=1, adinfinitum=TRUE dist>1000 ==> Goto WP 1 at speed>0")) - - -- Get positive speed to first waypoint. - local speed=self:GetSpeedToWaypoint(1) - - -- Start route at first waypoint. - self:__UpdateRoute(-1, 1, speed) - - self.passedfinalwp=false - - else - - self:T(self.lid..string.format("Passed final WP, #WP=1, adinfinitum=FALSE or dist<1000 ==> Full Stop")) - - self:__FullStop(-1) - - end - - else - - --- No waypoints left - - -- No further waypoints. Command a full stop. - self:T(self.lid..string.format("No waypoints left ==> Full Stop")) - - self:__FullStop(-1) - - end + if self.adinfinitum then + + --- + -- Parol Ad Infinitum + --- + + -- Next waypoint index. + local i=self:GetWaypointIndexNext(true) + + -- Get positive speed to first waypoint. + local speed=self:GetSpeedToWaypoint(i) + + -- Start route at first waypoint. + self:UpdateRoute(i, speed) + + self:T(self.lid..string.format("Adinfinitum=TRUE ==> Goto WP index=%d at speed=%d knots", i, speed)) + else --- - -- Final waypoint NOT passed yet + -- Finite Patrol --- - - if #self.waypoints>0 then - self:T(self.lid..string.format("NOT Passed final WP, #WP>0 ==> Update Route")) - self:__UpdateRoute(-1) - else - self:E(self.lid..string.format("WARNING: No waypoints left! Commanding a Full Stop")) + + if self.passedfinalwp then + + --- + -- Passed FINAL waypoint + --- + + -- No further waypoints. Command a full stop. self:__FullStop(-1) + + self:T(self.lid..string.format("Passed final WP, #WP>1, adinfinitum=FALSE ==> Full Stop")) + + else + + --- + -- Final waypoint NOT passed yet + --- + + if #self.waypoints>0 then + self:T(self.lid..string.format("NOT Passed final WP, #WP>0 ==> Update Route")) + self:UpdateRoute() + else + self:E(self.lid..string.format("WARNING: No waypoints left! Commanding a Full Stop")) + self:__FullStop(-1) + end + end end - - end - + + end end end @@ -3368,7 +3339,7 @@ function OPSGROUP:_UpdateWaypointTasks(n) if i>=n or nwaypoints==1 then -- Debug info. - self:T(self.lid..string.format("Updating waypoint task for waypoint %d/%d ID=%d. Last waypoint passed %d", i, nwaypoints, wp.uid, self.currentwp)) + self:T2(self.lid..string.format("Updating waypoint task for waypoint %d/%d ID=%d. Last waypoint passed %d", i, nwaypoints, wp.uid, self.currentwp)) -- Tasks of this waypoint local taskswp={} @@ -3401,12 +3372,12 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid) if waypoint then + -- Current wp. + local currentwp=opsgroup.currentwp + -- Get the current waypoint index. opsgroup.currentwp=opsgroup:GetWaypointIndex(uid) - - -- Increase passing counter. - waypoint.npassed=waypoint.npassed+1 - + -- Set expected speed and formation from the next WP. local wpnext=opsgroup:GetWaypointNext() if wpnext then @@ -3450,13 +3421,18 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid) -- Debug message. local text=string.format("Group passing waypoint uid=%d", uid) - opsgroup:T2(opsgroup.lid..text) - + opsgroup:T(opsgroup.lid..text) + -- Trigger PassingWaypoint event. if not (waypoint.astar or waypoint.detour) then + + -- Increase passing counter. + waypoint.npassed=waypoint.npassed+1 + + -- Call event function. opsgroup:PassingWaypoint(waypoint) end - + end end From 591dd128ce4d00808684196ea0186f390b5b0672 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 9 Oct 2020 00:15:19 +0200 Subject: [PATCH 2/5] Navygroup --- Moose Development/Moose/Ops/NavyGroup.lua | 74 ++++++++--------------- Moose Development/Moose/Ops/OpsGroup.lua | 35 +++++++---- 2 files changed, 49 insertions(+), 60 deletions(-) diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index 4dcf3f739..fad6bd75a 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -617,65 +617,43 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth) -- Waypoints. local waypoints={} - -- Add remaining waypoints to route. - local depth=nil - for i=n, #self.waypoints do - - -- Waypoint. - local wp=UTILS.DeepCopy(self.waypoints[i]) --Ops.OpsGroup#OPSGROUP.Waypoint - - -- Check if next wp. - if i==n then + -- Waypoint. + local wp=UTILS.DeepCopy(self.waypoints[n]) --Ops.OpsGroup#OPSGROUP.Waypoint - -- Speed. - if Speed then - -- Take speed specified. - wp.speed=UTILS.KnotsToMps(Speed) - else - -- Take default waypoint speed. But make sure speed>0 if patrol ad infinitum. - if self.adinfinitum and wp.speed<0.1 then - wp.speed=UTILS.KmphToMps(self.speedCruise) - end - end - - if Depth then - wp.alt=-Depth - elseif self.depth then - wp.alt=-self.depth - else - -- Take default waypoint alt. - end - - -- Current set speed in m/s. - self.speedWp=wp.speed - - -- Current set depth. - depth=wp.alt - - else - - -- Dive depth is applied to all other waypoints. - if self.depth then - wp.alt=-self.depth - else - -- Take default waypoint depth. - end - + -- Speed. + if Speed then + -- Take speed specified. + wp.speed=UTILS.KnotsToMps(Speed) + else + -- Take default waypoint speed. But make sure speed>0 if patrol ad infinitum. + if self.adinfinitum and wp.speed<0.1 then + wp.speed=UTILS.KmphToMps(self.speedCruise) end - - -- Add waypoint. - table.insert(waypoints, wp) end + if Depth then + wp.alt=-Depth + elseif self.depth then + wp.alt=-self.depth + else + -- Take default waypoint alt. + end + + -- Current set speed in m/s. + self.speedWp=wp.speed + + -- Add waypoint. + table.insert(waypoints, wp) + -- Current waypoint. - local current=self:GetCoordinate():WaypointNaval(UTILS.MpsToKmph(self.speedWp), depth) + local current=self:GetCoordinate():WaypointNaval(UTILS.MpsToKmph(self.speedWp), wp.alt) table.insert(waypoints, 1, current) if #waypoints>1 then self:T(self.lid..string.format("Updateing route: WP %d-->%d-->%d (#%d), Speed=%.1f knots, Depth=%d m", - self.currentwp, n, #self.waypoints, #waypoints-1, UTILS.MpsToKnots(self.speedWp), depth)) + self.currentwp, n, #self.waypoints, #waypoints-1, UTILS.MpsToKnots(self.speedWp), wp.alt)) -- Route group to all defined waypoints remaining. diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 2d0010b78..6d10ae8e1 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -2682,10 +2682,10 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) end - -- Check if all tasks/mission are done? If so, RTB or WAIT. + -- Check if all tasks/mission are done? -- Note, we delay it for a second to let the OnAfterPassingwaypoint function to be executed in case someone wants to add another waypoint there. if ntasks==0 then - self:_CheckGroupDone() + self:_CheckGroupDone(0.1) end -- Debug info. @@ -3061,23 +3061,34 @@ function OPSGROUP:_CheckGroupDone(delay) self:ScheduleOnce(delay, self._CheckGroupDone, self) else + local waypoint=self:GetWaypoint(self.currentwp) + + local n=self:GetTasksWaypoint(id) + if self.adinfinitum then --- -- Parol Ad Infinitum --- + + if #self.waypoints>0 then - -- Next waypoint index. - local i=self:GetWaypointIndexNext(true) - - -- Get positive speed to first waypoint. - local speed=self:GetSpeedToWaypoint(i) - - -- Start route at first waypoint. - self:UpdateRoute(i, speed) - - self:T(self.lid..string.format("Adinfinitum=TRUE ==> Goto WP index=%d at speed=%d knots", i, speed)) + -- Next waypoint index. + local i=self:GetWaypointIndexNext(true) + + -- Get positive speed to first waypoint. + local speed=self:GetSpeedToWaypoint(i) + + -- Start route at first waypoint. + self:UpdateRoute(i, speed) + + self:T(self.lid..string.format("Adinfinitum=TRUE ==> Goto WP index=%d at speed=%d knots", i, speed)) + + else + self:E(self.lid..string.format("WARNING: No waypoints left! Commanding a Full Stop")) + self:__FullStop(-1) + end else From 7792381c36d64cb6e8b969e5a9703b0c7fb7af1f Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 9 Oct 2020 17:10:24 +0200 Subject: [PATCH 3/5] OPS --- Moose Development/Moose/Ops/ArmyGroup.lua | 24 +++++++-------- Moose Development/Moose/Ops/OpsGroup.lua | 36 +++++++++++++++++++++-- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index c063d3c18..f655563f0 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -388,18 +388,7 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) local wp=UTILS.DeepCopy(self.waypoints[n]) --Ops.OpsGroup#OPSGROUP.Waypoint -- Do we want to drive on road to the next wp? - local onroad=wp.action==ENUMS.Formation.Vehicle.OnRoad - - -- Current point. - local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OffRoad) - table.insert(waypoints, current) - - -- Insert a point on road. - if onroad then - local current=self:GetClosestRoad():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OnRoad) - table.insert(waypoints, current) - end - + local onroad=wp.action==ENUMS.Formation.Vehicle.OnRoad -- Speed. if Speed then @@ -436,6 +425,17 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) -- Add waypoint. table.insert(waypoints, wp) + + + -- Current point. + local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OffRoad) + table.insert(waypoints, 1, current) + + -- Insert a point on road. + if onroad then + local current=self:GetClosestRoad():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OnRoad) + table.insert(waypoints, 2, current) + end -- Debug output. if false then diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 6d10ae8e1..9281907e0 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -1677,6 +1677,26 @@ function OPSGROUP:GetTasksWaypoint(id) return tasks end +--- Count remaining waypoint tasks. +-- @param #OPSGROUP self +-- @param #number uid Unique waypoint ID. +-- @return #number Number of waypoint tasks. +function OPSGROUP:CountTasksWaypoint(id) + + -- Tasks table. + local n=0 + + -- Look for first task that SCHEDULED. + for _,_task in pairs(self.taskqueue) do + local task=_task --#OPSGROUP.Task + if task.type==OPSGROUP.TaskType.WAYPOINT and task.status==OPSGROUP.TaskStatus.SCHEDULED and task.waypoint==id then + n=n+1 + end + end + + return n +end + --- Sort task queue. -- @param #OPSGROUP self function OPSGROUP:_SortTaskQueue() @@ -3061,10 +3081,20 @@ function OPSGROUP:_CheckGroupDone(delay) self:ScheduleOnce(delay, self._CheckGroupDone, self) else + -- Get current waypoint. local waypoint=self:GetWaypoint(self.currentwp) - - local n=self:GetTasksWaypoint(id) - + + if waypoint then + + -- Number of tasks remaining for this waypoint. + local ntasks=self:CountTasksWaypoint(waypoint.uid) + + -- We only want to update the route if there are no more tasks to be done. + if ntasks>0 then + self:T(self.lid..string.format("Still got %d tasks for the current waypoint UID=%d", ntasks, waypoint.uid)) + return + end + end if self.adinfinitum then From 2ad81ca49934fe09847114aeec026ea10993ee04 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 12 Oct 2020 00:09:02 +0200 Subject: [PATCH 4/5] Ops --- Moose Development/Moose/Ops/Airboss.lua | 10 ++-- Moose Development/Moose/Ops/ArmyGroup.lua | 68 ++++++++++++++--------- Moose Development/Moose/Ops/Auftrag.lua | 2 + Moose Development/Moose/Ops/NavyGroup.lua | 19 +++---- Moose Development/Moose/Ops/OpsGroup.lua | 38 ++++++++----- 5 files changed, 81 insertions(+), 56 deletions(-) diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index c5fa5ce49..4b7c3fe3f 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -1273,17 +1273,19 @@ AIRBOSS.AircraftCarrier={ --- Carrier types. -- @type AIRBOSS.CarrierType --- @field #string ROOSEVELT USS Theodore Roosevelt (CVN-71) --- @field #string LINCOLN USS Abraham Lincoln (CVN-72) --- @field #string WASHINGTON USS George Washington (CVN-73) +-- @field #string ROOSEVELT USS Theodore Roosevelt (CVN-71) [Super Carrier Module] +-- @field #string LINCOLN USS Abraham Lincoln (CVN-72) [Super Carrier Module] +-- @field #string WASHINGTON USS George Washington (CVN-73) [Super Carrier Module] -- @field #string STENNIS USS John C. Stennis (CVN-74) --- @field #string VINSON USS Carl Vinson (CVN-70) +-- @field #string TRUMAN USS Harry S. Trueman (CVN-75) [Super Carrier Module] +-- @field #string VINSON USS Carl Vinson (CVN-70) [Obsolete] -- @field #string TARAWA USS Tarawa (LHA-1) -- @field #string KUZNETSOV Admiral Kuznetsov (CV 1143.5) AIRBOSS.CarrierType={ ROOSEVELT="CVN_71", LINCOLN="CVN_72", WASHINGTON="CVN_73", + TRUMAN="CVN_75", STENNIS="Stennis", VINSON="VINSON", TARAWA="LHA_Tarawa", diff --git a/Moose Development/Moose/Ops/ArmyGroup.lua b/Moose Development/Moose/Ops/ArmyGroup.lua index f655563f0..115607b46 100644 --- a/Moose Development/Moose/Ops/ArmyGroup.lua +++ b/Moose Development/Moose/Ops/ArmyGroup.lua @@ -40,7 +40,7 @@ ARMYGROUP = { --- Army Group version. -- @field #string version -ARMYGROUP.version="0.1.0" +ARMYGROUP.version="0.3.0" ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- TODO list @@ -350,7 +350,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To) -- Set TACAN to default. self:_SwitchTACAN() - + -- Turn on the radio. if self.radioDefault then self:SwitchRadio(self.radioDefault.Freq, self.radioDefault.Modu) @@ -361,7 +361,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To) end -- Update route. - self:Cruise() + self:Cruise(nil, self.option.Formation or self.optionDefault.Formation) end @@ -394,7 +394,10 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) if Speed then wp.speed=UTILS.KnotsToMps(Speed) else - -- Take default waypoint speed. + -- Take default waypoint speed. But make sure speed>0 if patrol ad infinitum. + if self.adinfinitum and wp.speed<0.1 then + wp.speed=UTILS.KmphToMps(self.speedCruise) + end end -- Formation. @@ -425,10 +428,15 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) -- Add waypoint. table.insert(waypoints, wp) - + + -- Apply formation at the current position or it will only be changed when reaching the next waypoint. + local formation=ENUMS.Formation.Vehicle.OffRoad + if wp.action~=ENUMS.Formation.Vehicle.OnRoad then + formation=wp.action + end -- Current point. - local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), ENUMS.Formation.Vehicle.OffRoad) + local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), formation) table.insert(waypoints, 1, current) -- Insert a point on road. @@ -442,32 +450,31 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation) for i,_wp in pairs(waypoints) do local wp=_wp local text=string.format("WP #%d UID=%d type=%s: Speed=%d m/s, alt=%d m, Action=%s", i, wp.uid and wp.uid or 0, wp.type, wp.speed, wp.alt, wp.action) - self:I(text) - if wp.coordinate then + self:T(text) + if false and wp.coordinate then wp.coordinate:MarkToAll(text) end end end - - if #waypoints>=2 then + if not self.passedfinalwp then -- Debug info. - self:T(self.lid..string.format("Updateing route: WP %d-->%d-->%d (#%d), Speed=%.1f knots, Formation=%s", - self.currentwp, n, #self.waypoints, #waypoints-2, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation))) - + self:T(self.lid..string.format("Updateing route: WP %d-->%d (%d/%d), Speed=%.1f knots, Formation=%s", + self.currentwp, n, #waypoints, #self.waypoints, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation))) + -- Route group to all defined waypoints remaining. self:Route(waypoints) else - + --- - -- No waypoints left + -- Passed final WP ==> Full Stop --- - self:E(self.lid..string.format("WARNING: No waypoints left ==> Full Stop!")) - self:FullStop() - + self:E(self.lid..string.format("WARNING: Passed final WP ==> Full Stop!")) + self:FullStop() + end end @@ -746,8 +753,7 @@ function ARMYGROUP:_InitGroup() self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On) -- Set default formation from first waypoint. - self.option.Formation=self:GetWaypoint(1).action - self.optionDefault.Formation=self.option.Formation + self.optionDefault.Formation=self:GetWaypoint(1).action -- Default TACAN off. self:SetDefaultTACAN(nil, nil, nil, nil, true) @@ -815,10 +821,11 @@ end -- @param #ARMYGROUP self -- @param #number Formation New formation the group will fly in. Default is the setting of `SetDefaultFormation()`. -- @param #boolean Permanently If true, formation always used from now on. +-- @param #boolean NoRouteUpdate If true, route is not updated. -- @return #ARMYGROUP self -function ARMYGROUP:SwitchFormation(Formation, Permanently) +function ARMYGROUP:SwitchFormation(Formation, Permanently, NoRouteUpdate) - if self:IsAlive() then + if self:IsAlive() or self:IsInUtero() then Formation=Formation or self.optionDefault.Formation @@ -831,11 +838,20 @@ function ARMYGROUP:SwitchFormation(Formation, Permanently) -- Set current formation. self.option.Formation=Formation - -- Update route with the new formation. - self:__UpdateRoute(-1, nil, nil, Formation) + if self:IsInUtero() then + self:T(self.lid..string.format("Will switch formation to %s (permanently=%s) when group is spawned", self.option.Formation, tostring(Permanently))) + else - -- Debug info. - self:T(self.lid..string.format("Switching formation to %s (permanently=%s)", self.option.Formation, tostring(Permanently))) + -- Update route with the new formation. + if NoRouteUpdate then + else + self:__UpdateRoute(-1, nil, nil, Formation) + end + + -- Debug info. + self:T(self.lid..string.format("Switching formation to %s (permanently=%s)", self.option.Formation, tostring(Permanently))) + + end end diff --git a/Moose Development/Moose/Ops/Auftrag.lua b/Moose Development/Moose/Ops/Auftrag.lua index affd7e1b3..002509c7d 100644 --- a/Moose Development/Moose/Ops/Auftrag.lua +++ b/Moose Development/Moose/Ops/Auftrag.lua @@ -1166,6 +1166,8 @@ function AUFTRAG:NewARTY(Target, Nshots, Radius) mission.artyShots=Nshots or 3 mission.artyRadius=Radius or 100 + mission.engageWeaponType=ENUMS.WeaponFlag.Auto + mission.optionROE=ENUMS.ROE.OpenFire -- Ground/naval need open fire! mission.optionAlarm=0 diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index fad6bd75a..1ef4a3473 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -241,14 +241,15 @@ end -- @param #number Nshots Number of shots to fire. Default 3. -- @param #number WeaponType Type of weapon. Default auto. -- @param #number Prio Priority of the task. +-- @param #number Duration Duration in seconds after which the task is cancelled. Default *never*. -- @return Ops.OpsGroup#OPSGROUP.Task The task table. -function NAVYGROUP:AddTaskWaypointFireAtPoint(Coordinate, Waypoint, Radius, Nshots, WeaponType, Prio) +function NAVYGROUP:AddTaskWaypointFireAtPoint(Coordinate, Waypoint, Radius, Nshots, WeaponType, Prio, Duration) Waypoint=Waypoint or self:GetWaypointNext() local DCStask=CONTROLLABLE.TaskFireAtPoint(nil, Coordinate:GetVec2(), Radius, Nshots, WeaponType) - local task=self:AddTaskWaypoint(DCStask, Waypoint, nil, Prio) + local task=self:AddTaskWaypoint(DCStask, Waypoint, nil, Prio, Duration) return task end @@ -608,9 +609,6 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth) -- Update route from this waypoint number onwards. n=n or self:GetWaypointIndexNext() - -- Debug info. - self:T(self.lid..string.format("Update route n=%d", n)) - -- Update waypoint tasks, i.e. inject WP tasks into waypoint table. self:_UpdateWaypointTasks(n) @@ -650,11 +648,10 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth) table.insert(waypoints, 1, current) - if #waypoints>1 then - - self:T(self.lid..string.format("Updateing route: WP %d-->%d-->%d (#%d), Speed=%.1f knots, Depth=%d m", - self.currentwp, n, #self.waypoints, #waypoints-1, UTILS.MpsToKnots(self.speedWp), wp.alt)) + if not self.passedfinalwp then + -- Debug info. + self:T(self.lid..string.format("Updateing route: WP %d-->%d (%d/%d), Speed=%.1f knots, Depth=%d m", self.currentwp, n, #waypoints, #self.waypoints, UTILS.MpsToKnots(self.speedWp), wp.alt)) -- Route group to all defined waypoints remaining. self:Route(waypoints) @@ -662,10 +659,10 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth) else --- - -- No waypoints left ==> Full Stop + -- Passed final WP ==> Full Stop --- - self:E(self.lid..string.format("WARNING: No waypoints left ==> Full Stop!")) + self:E(self.lid..string.format("WARNING: Passed final WP ==> Full Stop!")) self:FullStop() end diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index 9281907e0..733cdd056 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -479,11 +479,11 @@ function OPSGROUP:AddCheckZone(CheckZone) end ---- Add a zone that triggers and event if the group enters or leaves any of the zones. +--- Add a weapon range for ARTY auftrag. -- @param #OPSGROUP self --- @param #number RangeMin --- @param #number RangeMax --- @param #number BitType +-- @param #number RangeMin Minimum range in kilometers. Default 0 km. +-- @param #number RangeMax Maximum range in kilometers. Default 10 km. +-- @param #number BitType Bit mask of weapon type for which the given min/max ranges apply. Default is `ENUMS.WeaponFlag.Auto`, i.e. for all weapon types. -- @return #OPSGROUP self function OPSGROUP:AddWeaponRange(RangeMin, RangeMax, BitType) @@ -2565,9 +2565,14 @@ function OPSGROUP:RouteToMission(mission, delay) end end + + local formation=nil + if self.isGround and mission.optionFormation then + formation=mission.optionFormation + end -- Add waypoint. - local waypoint=self:AddWaypoint(waypointcoord, SpeedToMission, nil, nil, false) + local waypoint=self:AddWaypoint(waypointcoord, SpeedToMission, nil, formation, false) -- Add waypoint task. UpdateRoute is called inside. local waypointtask=self:AddTaskWaypoint(mission.DCStask, waypoint, mission.name, mission.prio, mission.duration) @@ -2595,7 +2600,7 @@ function OPSGROUP:RouteToMission(mission, delay) self:SwitchAlarmstate(mission.optionAlarm) end -- Formation - if mission.optionFormation then + if mission.optionFormation and self.isAircraft then self:SwitchFormation(mission.optionFormation) end -- Radio frequency and modulation. @@ -2697,8 +2702,10 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) -- Final waypoint reached? if wpindex==nil or wpindex==#self.waypoints then - -- Set switch to true. - self.passedfinalwp=true + -- Set switch to true. + if not self.adinfinitum or #self.waypoints<=1 then + self.passedfinalwp=true + end end @@ -2711,7 +2718,7 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint) -- Debug info. local text=string.format("Group passed waypoint %s/%d ID=%d: final=%s detour=%s astar=%s", tostring(wpindex), #self.waypoints, Waypoint.uid, tostring(self.passedfinalwp), tostring(Waypoint.detour), tostring(Waypoint.astar)) - self:I(self.lid..text) + self:T(self.lid..text) end @@ -3091,7 +3098,7 @@ function OPSGROUP:_CheckGroupDone(delay) -- We only want to update the route if there are no more tasks to be done. if ntasks>0 then - self:T(self.lid..string.format("Still got %d tasks for the current waypoint UID=%d", ntasks, waypoint.uid)) + self:T(self.lid..string.format("Still got %d tasks for the current waypoint UID=%d ==> RETURN (no action)", ntasks, waypoint.uid)) return end end @@ -3135,7 +3142,7 @@ function OPSGROUP:_CheckGroupDone(delay) -- No further waypoints. Command a full stop. self:__FullStop(-1) - self:T(self.lid..string.format("Passed final WP, #WP>1, adinfinitum=FALSE ==> Full Stop")) + self:T(self.lid..string.format("Passed final WP, adinfinitum=FALSE ==> Full Stop")) else @@ -3295,17 +3302,18 @@ function OPSGROUP:InitWaypoints() self.waypoints={} for index,wp in pairs(self.waypoints0) do - - --local waypoint=self:_CreateWaypoint(wp) - --self:_AddWaypoint(waypoint) - + + -- Coordinate of the waypoint. local coordinate=COORDINATE:New(wp.x, wp.alt, wp.y) + + -- Speed at the waypoint. local speedknots=UTILS.MpsToKnots(wp.speed) if index==1 then self.speedWp=wp.speed end + -- Add waypoint. self:AddWaypoint(coordinate, speedknots, index-1, nil, false) end From 23c22651be30de6b33c5764db7fbced43de2bfca Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 12 Oct 2020 00:21:47 +0200 Subject: [PATCH 5/5] Update Airboss.lua - Added USS Harry S. Truman (CVN-75) as SC type. --- Moose Development/Moose/Ops/Airboss.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Ops/Airboss.lua b/Moose Development/Moose/Ops/Airboss.lua index 4b7c3fe3f..b40da4fbb 100644 --- a/Moose Development/Moose/Ops/Airboss.lua +++ b/Moose Development/Moose/Ops/Airboss.lua @@ -1277,7 +1277,7 @@ AIRBOSS.AircraftCarrier={ -- @field #string LINCOLN USS Abraham Lincoln (CVN-72) [Super Carrier Module] -- @field #string WASHINGTON USS George Washington (CVN-73) [Super Carrier Module] -- @field #string STENNIS USS John C. Stennis (CVN-74) --- @field #string TRUMAN USS Harry S. Trueman (CVN-75) [Super Carrier Module] +-- @field #string TRUMAN USS Harry S. Truman (CVN-75) [Super Carrier Module] -- @field #string VINSON USS Carl Vinson (CVN-70) [Obsolete] -- @field #string TARAWA USS Tarawa (LHA-1) -- @field #string KUZNETSOV Admiral Kuznetsov (CV 1143.5) @@ -1946,8 +1946,10 @@ function AIRBOSS:New(carriername, alias) self:_InitNimitz() elseif self.carriertype==AIRBOSS.CarrierType.LINCOLN then self:_InitNimitz() - elseif self.carriertype==AIRBOSS.CarrierType.WASHINGTON then + elseif self.carriertype==AIRBOSS.CarrierType.WASHINGTON then self:_InitNimitz() + elseif self.carriertype==AIRBOSS.CarrierType.TRUMAN then + self:_InitNimitz() elseif self.carriertype==AIRBOSS.CarrierType.VINSON then -- TODO: Carl Vinson parameters. self:_InitStennis()