mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Merge branch 'FF/Ops' into develop
This commit is contained in:
commit
f9721e501a
@ -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. 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)
|
||||
AIRBOSS.CarrierType={
|
||||
ROOSEVELT="CVN_71",
|
||||
LINCOLN="CVN_72",
|
||||
WASHINGTON="CVN_73",
|
||||
TRUMAN="CVN_75",
|
||||
STENNIS="Stennis",
|
||||
VINSON="VINSON",
|
||||
TARAWA="LHA_Tarawa",
|
||||
@ -1944,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()
|
||||
|
||||
@ -40,7 +40,7 @@ ARMYGROUP = {
|
||||
|
||||
--- Army Group version.
|
||||
-- @field #string version
|
||||
ARMYGROUP.version="0.1.0"
|
||||
ARMYGROUP.version="0.3.0"
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- TODO list
|
||||
@ -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
|
||||
@ -338,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)
|
||||
@ -349,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
|
||||
|
||||
@ -372,95 +384,97 @@ 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
|
||||
|
||||
---
|
||||
-- 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))
|
||||
-- Do we want to drive on road to the next wp?
|
||||
local onroad=wp.action==ENUMS.Formation.Vehicle.OnRoad
|
||||
|
||||
-- Add waypoint.
|
||||
table.insert(waypoints, wp)
|
||||
-- Speed.
|
||||
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
|
||||
|
||||
|
||||
-- Current waypoint.
|
||||
local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), self.option.Formation)
|
||||
-- Current point.
|
||||
local current=self:GetCoordinate():WaypointGround(UTILS.MpsToKmph(self.speedWp), 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
|
||||
-- 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",
|
||||
self.currentwp, n, #self.waypoints, #waypoints-2, UTILS.MpsToKnots(self.speedWp), tostring(self.option.Formation)))
|
||||
-- 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: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.
|
||||
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
|
||||
@ -646,7 +660,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 +697,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
|
||||
@ -739,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)
|
||||
@ -808,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
|
||||
|
||||
@ -824,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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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,75 +609,49 @@ 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)
|
||||
|
||||
-- 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))
|
||||
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)
|
||||
@ -684,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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1674,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()
|
||||
@ -2542,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)
|
||||
@ -2572,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.
|
||||
@ -2674,15 +2702,17 @@ 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
|
||||
|
||||
-- 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)
|
||||
-- Set switch to true.
|
||||
if not self.adinfinitum or #self.waypoints<=1 then
|
||||
self.passedfinalwp=true
|
||||
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
|
||||
|
||||
-- Debug info.
|
||||
@ -3058,92 +3088,81 @@ 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 current waypoint.
|
||||
local waypoint=self:GetWaypoint(self.currentwp)
|
||||
|
||||
-- Get positive speed to first waypoint.
|
||||
local speed=self:GetSpeedToWaypoint(1)
|
||||
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 ==> 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.
|
||||
self:__UpdateRoute(-1, 1, speed)
|
||||
|
||||
self.passedfinalwp=false
|
||||
|
||||
else
|
||||
-- Get positive speed to first waypoint.
|
||||
local speed=self:GetSpeedToWaypoint(i)
|
||||
|
||||
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)
|
||||
|
||||
end
|
||||
self:T(self.lid..string.format("Adinfinitum=TRUE ==> Goto WP index=%d at speed=%d knots", i, speed))
|
||||
|
||||
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)
|
||||
|
||||
self:E(self.lid..string.format("WARNING: No waypoints left! Commanding a Full Stop"))
|
||||
self:__FullStop(-1)
|
||||
end
|
||||
|
||||
|
||||
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, 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
|
||||
@ -3283,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
|
||||
@ -3368,7 +3388,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 +3421,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 +3470,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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user