Merge branch 'FF/Ops' into develop

This commit is contained in:
Frank 2020-10-12 00:22:47 +02:00
commit f9721e501a
5 changed files with 279 additions and 250 deletions

View File

@ -1273,17 +1273,19 @@ AIRBOSS.AircraftCarrier={
--- Carrier types. --- Carrier types.
-- @type AIRBOSS.CarrierType -- @type AIRBOSS.CarrierType
-- @field #string ROOSEVELT USS Theodore Roosevelt (CVN-71) -- @field #string ROOSEVELT USS Theodore Roosevelt (CVN-71) [Super Carrier Module]
-- @field #string LINCOLN USS Abraham Lincoln (CVN-72) -- @field #string LINCOLN USS Abraham Lincoln (CVN-72) [Super Carrier Module]
-- @field #string WASHINGTON USS George Washington (CVN-73) -- @field #string WASHINGTON USS George Washington (CVN-73) [Super Carrier Module]
-- @field #string STENNIS USS John C. Stennis (CVN-74) -- @field #string STENNIS USS John C. Stennis (CVN-74)
-- @field #string VINSON USS Carl Vinson (CVN-70) -- @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 TARAWA USS Tarawa (LHA-1)
-- @field #string KUZNETSOV Admiral Kuznetsov (CV 1143.5) -- @field #string KUZNETSOV Admiral Kuznetsov (CV 1143.5)
AIRBOSS.CarrierType={ AIRBOSS.CarrierType={
ROOSEVELT="CVN_71", ROOSEVELT="CVN_71",
LINCOLN="CVN_72", LINCOLN="CVN_72",
WASHINGTON="CVN_73", WASHINGTON="CVN_73",
TRUMAN="CVN_75",
STENNIS="Stennis", STENNIS="Stennis",
VINSON="VINSON", VINSON="VINSON",
TARAWA="LHA_Tarawa", TARAWA="LHA_Tarawa",
@ -1944,8 +1946,10 @@ function AIRBOSS:New(carriername, alias)
self:_InitNimitz() self:_InitNimitz()
elseif self.carriertype==AIRBOSS.CarrierType.LINCOLN then elseif self.carriertype==AIRBOSS.CarrierType.LINCOLN then
self:_InitNimitz() self:_InitNimitz()
elseif self.carriertype==AIRBOSS.CarrierType.WASHINGTON then elseif self.carriertype==AIRBOSS.CarrierType.WASHINGTON then
self:_InitNimitz() self:_InitNimitz()
elseif self.carriertype==AIRBOSS.CarrierType.TRUMAN then
self:_InitNimitz()
elseif self.carriertype==AIRBOSS.CarrierType.VINSON then elseif self.carriertype==AIRBOSS.CarrierType.VINSON then
-- TODO: Carl Vinson parameters. -- TODO: Carl Vinson parameters.
self:_InitStennis() self:_InitStennis()

View File

@ -40,7 +40,7 @@ ARMYGROUP = {
--- Army Group version. --- Army Group version.
-- @field #string version -- @field #string version
ARMYGROUP.version="0.1.0" ARMYGROUP.version="0.3.0"
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-- TODO list -- TODO list
@ -140,6 +140,18 @@ function ARMYGROUP:GetClosestRoad()
return self:GetCoordinate():GetClosestPointToRoad() return self:GetCoordinate():GetClosestPointToRoad()
end 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. --- Add a *scheduled* task to fire at a given coordinate.
-- @param #ARMYGROUP self -- @param #ARMYGROUP self
@ -338,7 +350,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To)
-- Set TACAN to default. -- Set TACAN to default.
self:_SwitchTACAN() self:_SwitchTACAN()
-- Turn on the radio. -- Turn on the radio.
if self.radioDefault then if self.radioDefault then
self:SwitchRadio(self.radioDefault.Freq, self.radioDefault.Modu) self:SwitchRadio(self.radioDefault.Freq, self.radioDefault.Modu)
@ -349,7 +361,7 @@ function ARMYGROUP:onafterSpawned(From, Event, To)
end end
-- Update route. -- Update route.
self:Cruise() self:Cruise(nil, self.option.Formation or self.optionDefault.Formation)
end end
@ -372,95 +384,97 @@ function ARMYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Formation)
-- Waypoints. -- Waypoints.
local waypoints={} local waypoints={}
-- Total number of waypoints -- Next waypoint.
local N=#self.waypoints local wp=UTILS.DeepCopy(self.waypoints[n]) --Ops.OpsGroup#OPSGROUP.Waypoint
-- Add remaining waypoints to route.
for i=n, N do
-- Copy waypoint. -- Do we want to drive on road to the next wp?
local wp=UTILS.DeepCopy(self.waypoints[i]) --Ops.OpsGroup#OPSGROUP.Waypoint local onroad=wp.action==ENUMS.Formation.Vehicle.OnRoad
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
---
-- 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
-- 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. -- Speed.
table.insert(waypoints, wp) if Speed then
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
-- 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)
-- 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 end
-- Current point.
-- Current waypoint. local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), formation)
local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), self.option.Formation)
table.insert(waypoints, 1, current) 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 -- 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
self:T(self.lid..string.format("Updateing route: WP %d-->%d-->%d (#%d), Speed=%.1f knots, Formation=%s", -- Debug output.
self.currentwp, n, #self.waypoints, #waypoints-2, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation))) 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:T(text)
if false and wp.coordinate then
wp.coordinate:MarkToAll(text)
end
end
end
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, #waypoints, #self.waypoints, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation)))
-- Route group to all defined waypoints remaining. -- Route group to all defined waypoints remaining.
self:Route(waypoints) self:Route(waypoints)
else else
--- ---
-- No waypoints left -- 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() self:FullStop()
end end
end end
@ -646,7 +660,7 @@ end
--- Add an a waypoint to the route. --- Add an a waypoint to the route.
-- @param #ARMYGROUP self -- @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 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 AfterWaypointWithID Insert waypoint after waypoint given ID. Default is to insert as last waypoint.
-- @param #number Formation Formation the group will use. -- @param #number Formation Formation the group will use.
@ -683,7 +697,7 @@ function ARMYGROUP:AddWaypoint(Coordinate, Speed, AfterWaypointWithID, Formation
end end
-- Debug info. -- 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. -- Update route.
if Updateroute==nil or Updateroute==true then if Updateroute==nil or Updateroute==true then
@ -739,8 +753,7 @@ function ARMYGROUP:_InitGroup()
self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On) self:SetDefaultRadio(self.radio.Freq, self.radio.Modu, self.radio.On)
-- Set default formation from first waypoint. -- Set default formation from first waypoint.
self.option.Formation=self:GetWaypoint(1).action self.optionDefault.Formation=self:GetWaypoint(1).action
self.optionDefault.Formation=self.option.Formation
-- Default TACAN off. -- Default TACAN off.
self:SetDefaultTACAN(nil, nil, nil, nil, true) self:SetDefaultTACAN(nil, nil, nil, nil, true)
@ -808,10 +821,11 @@ end
-- @param #ARMYGROUP self -- @param #ARMYGROUP self
-- @param #number Formation New formation the group will fly in. Default is the setting of `SetDefaultFormation()`. -- @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 Permanently If true, formation always used from now on.
-- @param #boolean NoRouteUpdate If true, route is not updated.
-- @return #ARMYGROUP self -- @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 Formation=Formation or self.optionDefault.Formation
@ -824,11 +838,20 @@ function ARMYGROUP:SwitchFormation(Formation, Permanently)
-- Set current formation. -- Set current formation.
self.option.Formation=Formation self.option.Formation=Formation
-- Update route with the new formation. if self:IsInUtero() then
self:__UpdateRoute(-1, nil, nil, Formation) 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. -- Update route with the new formation.
self:T(self.lid..string.format("Switching formation to %s (permanently=%s)", self.option.Formation, tostring(Permanently))) 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 end

View File

@ -1166,6 +1166,8 @@ function AUFTRAG:NewARTY(Target, Nshots, Radius)
mission.artyShots=Nshots or 3 mission.artyShots=Nshots or 3
mission.artyRadius=Radius or 100 mission.artyRadius=Radius or 100
mission.engageWeaponType=ENUMS.WeaponFlag.Auto
mission.optionROE=ENUMS.ROE.OpenFire -- Ground/naval need open fire! mission.optionROE=ENUMS.ROE.OpenFire -- Ground/naval need open fire!
mission.optionAlarm=0 mission.optionAlarm=0

View File

@ -241,14 +241,15 @@ end
-- @param #number Nshots Number of shots to fire. Default 3. -- @param #number Nshots Number of shots to fire. Default 3.
-- @param #number WeaponType Type of weapon. Default auto. -- @param #number WeaponType Type of weapon. Default auto.
-- @param #number Prio Priority of the task. -- @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. -- @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() Waypoint=Waypoint or self:GetWaypointNext()
local DCStask=CONTROLLABLE.TaskFireAtPoint(nil, Coordinate:GetVec2(), Radius, Nshots, WeaponType) 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 return task
end end
@ -608,75 +609,49 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth)
-- Update route from this waypoint number onwards. -- Update route from this waypoint number onwards.
n=n or self:GetWaypointIndexNext() 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. -- Update waypoint tasks, i.e. inject WP tasks into waypoint table.
self:_UpdateWaypointTasks(n) self:_UpdateWaypointTasks(n)
-- Waypoints. -- Waypoints.
local waypoints={} local waypoints={}
-- Add remaining waypoints to route. -- Waypoint.
local depth=nil local wp=UTILS.DeepCopy(self.waypoints[n]) --Ops.OpsGroup#OPSGROUP.Waypoint
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
-- Speed. -- Speed.
if Speed then if Speed then
-- Take speed specified. -- Take speed specified.
wp.speed=UTILS.KnotsToMps(Speed) wp.speed=UTILS.KnotsToMps(Speed)
else else
-- Take default waypoint speed. But make sure speed>0 if patrol ad infinitum. -- Take default waypoint speed. But make sure speed>0 if patrol ad infinitum.
if self.adinfinitum and wp.speed<0.1 then if self.adinfinitum and wp.speed<0.1 then
wp.speed=UTILS.KmphToMps(self.speedCruise) 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
end end
-- Add waypoint.
table.insert(waypoints, wp)
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
-- Add waypoint.
table.insert(waypoints, wp)
-- Current waypoint. -- 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) table.insert(waypoints, 1, current)
if #waypoints>1 then if not self.passedfinalwp 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))
-- 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. -- Route group to all defined waypoints remaining.
self:Route(waypoints) self:Route(waypoints)
@ -684,10 +659,10 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth)
else 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() self:FullStop()
end end

View File

@ -479,11 +479,11 @@ function OPSGROUP:AddCheckZone(CheckZone)
end 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 #OPSGROUP self
-- @param #number RangeMin -- @param #number RangeMin Minimum range in kilometers. Default 0 km.
-- @param #number RangeMax -- @param #number RangeMax Maximum range in kilometers. Default 10 km.
-- @param #number BitType -- @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 -- @return #OPSGROUP self
function OPSGROUP:AddWeaponRange(RangeMin, RangeMax, BitType) function OPSGROUP:AddWeaponRange(RangeMin, RangeMax, BitType)
@ -1133,18 +1133,21 @@ end
--- Get next waypoint index. --- Get next waypoint index.
-- @param #OPSGROUP self -- @param #OPSGROUP self
-- @param #boolean cyclic If true, return first waypoint if last waypoint was reached. Default is patrol ad infinitum value set. -- @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. -- @return #number Next waypoint index.
function OPSGROUP:GetWaypointIndexNext(cyclic) function OPSGROUP:GetWaypointIndexNext(cyclic, i)
if cyclic==nil then if cyclic==nil then
cyclic=self.adinfinitum cyclic=self.adinfinitum
end end
local N=#self.waypoints 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 n=1
end end
@ -1674,6 +1677,26 @@ function OPSGROUP:GetTasksWaypoint(id)
return tasks return tasks
end 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. --- Sort task queue.
-- @param #OPSGROUP self -- @param #OPSGROUP self
function OPSGROUP:_SortTaskQueue() function OPSGROUP:_SortTaskQueue()
@ -2542,9 +2565,14 @@ function OPSGROUP:RouteToMission(mission, delay)
end end
end end
local formation=nil
if self.isGround and mission.optionFormation then
formation=mission.optionFormation
end
-- Add waypoint. -- 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. -- Add waypoint task. UpdateRoute is called inside.
local waypointtask=self:AddTaskWaypoint(mission.DCStask, waypoint, mission.name, mission.prio, mission.duration) local waypointtask=self:AddTaskWaypoint(mission.DCStask, waypoint, mission.name, mission.prio, mission.duration)
@ -2572,7 +2600,7 @@ function OPSGROUP:RouteToMission(mission, delay)
self:SwitchAlarmstate(mission.optionAlarm) self:SwitchAlarmstate(mission.optionAlarm)
end end
-- Formation -- Formation
if mission.optionFormation then if mission.optionFormation and self.isAircraft then
self:SwitchFormation(mission.optionFormation) self:SwitchFormation(mission.optionFormation)
end end
-- Radio frequency and modulation. -- Radio frequency and modulation.
@ -2674,15 +2702,17 @@ function OPSGROUP:onafterPassingWaypoint(From, Event, To, Waypoint)
-- Final waypoint reached? -- Final waypoint reached?
if wpindex==nil or wpindex==#self.waypoints then if wpindex==nil or wpindex==#self.waypoints then
-- Set switch to true. -- Set switch to true.
self.passedfinalwp=true if not self.adinfinitum or #self.waypoints<=1 then
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
end
-- 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(0.1)
end end
-- Debug info. -- Debug info.
@ -3058,92 +3088,81 @@ function OPSGROUP:_CheckGroupDone(delay)
self:ScheduleOnce(delay, self._CheckGroupDone, self) self:ScheduleOnce(delay, self._CheckGroupDone, self)
else else
if self.passedfinalwp then -- Get current waypoint.
local waypoint=self:GetWaypoint(self.currentwp)
---
-- 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. if waypoint then
local speed=self:GetSpeedToWaypoint(1)
-- 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 ==> RETURN (no action)", ntasks, waypoint.uid))
return
end
end
if self.adinfinitum then
---
-- Parol Ad Infinitum
---
if #self.waypoints>0 then
-- Next waypoint index.
local i=self:GetWaypointIndexNext(true)
-- Start route at first waypoint. -- Get positive speed to first waypoint.
self:__UpdateRoute(-1, 1, speed) local speed=self:GetSpeedToWaypoint(i)
self.passedfinalwp=false
else
self:T(self.lid..string.format("Passed final WP, #WP=1, adinfinitum=FALSE or dist<1000 ==> Full Stop")) -- Start route at first waypoint.
self:UpdateRoute(i, speed)
self:__FullStop(-1) self:T(self.lid..string.format("Adinfinitum=TRUE ==> Goto WP index=%d at speed=%d knots", i, speed))
end
else else
self:E(self.lid..string.format("WARNING: No waypoints left! Commanding a Full Stop"))
--- No waypoints left self:__FullStop(-1)
-- No further waypoints. Command a full stop.
self:T(self.lid..string.format("No waypoints left ==> Full Stop"))
self:__FullStop(-1)
end end
else else
--- ---
-- Final waypoint NOT passed yet -- Finite Patrol
--- ---
if #self.waypoints>0 then if self.passedfinalwp then
self:T(self.lid..string.format("NOT Passed final WP, #WP>0 ==> Update Route"))
self:__UpdateRoute(-1) ---
else -- Passed FINAL waypoint
self:E(self.lid..string.format("WARNING: No waypoints left! Commanding a Full Stop")) ---
-- No further waypoints. Command a full stop.
self:__FullStop(-1) self:__FullStop(-1)
self:T(self.lid..string.format("Passed final WP, 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
end end
end end
@ -3283,17 +3302,18 @@ function OPSGROUP:InitWaypoints()
self.waypoints={} self.waypoints={}
for index,wp in pairs(self.waypoints0) do for index,wp in pairs(self.waypoints0) do
--local waypoint=self:_CreateWaypoint(wp) -- Coordinate of the waypoint.
--self:_AddWaypoint(waypoint)
local coordinate=COORDINATE:New(wp.x, wp.alt, wp.y) local coordinate=COORDINATE:New(wp.x, wp.alt, wp.y)
-- Speed at the waypoint.
local speedknots=UTILS.MpsToKnots(wp.speed) local speedknots=UTILS.MpsToKnots(wp.speed)
if index==1 then if index==1 then
self.speedWp=wp.speed self.speedWp=wp.speed
end end
-- Add waypoint.
self:AddWaypoint(coordinate, speedknots, index-1, nil, false) self:AddWaypoint(coordinate, speedknots, index-1, nil, false)
end end
@ -3368,7 +3388,7 @@ function OPSGROUP:_UpdateWaypointTasks(n)
if i>=n or nwaypoints==1 then if i>=n or nwaypoints==1 then
-- Debug info. -- 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 -- Tasks of this waypoint
local taskswp={} local taskswp={}
@ -3401,12 +3421,12 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid)
if waypoint then if waypoint then
-- Current wp.
local currentwp=opsgroup.currentwp
-- Get the current waypoint index. -- Get the current waypoint index.
opsgroup.currentwp=opsgroup:GetWaypointIndex(uid) opsgroup.currentwp=opsgroup:GetWaypointIndex(uid)
-- Increase passing counter.
waypoint.npassed=waypoint.npassed+1
-- Set expected speed and formation from the next WP. -- Set expected speed and formation from the next WP.
local wpnext=opsgroup:GetWaypointNext() local wpnext=opsgroup:GetWaypointNext()
if wpnext then if wpnext then
@ -3450,13 +3470,18 @@ function OPSGROUP._PassingWaypoint(group, opsgroup, uid)
-- Debug message. -- Debug message.
local text=string.format("Group passing waypoint uid=%d", uid) local text=string.format("Group passing waypoint uid=%d", uid)
opsgroup:T2(opsgroup.lid..text) opsgroup:T(opsgroup.lid..text)
-- Trigger PassingWaypoint event. -- Trigger PassingWaypoint event.
if not (waypoint.astar or waypoint.detour) then if not (waypoint.astar or waypoint.detour) then
-- Increase passing counter.
waypoint.npassed=waypoint.npassed+1
-- Call event function.
opsgroup:PassingWaypoint(waypoint) opsgroup:PassingWaypoint(waypoint)
end end
end end
end end