Waypoints

This commit is contained in:
Frank 2020-07-22 01:05:24 +02:00
parent af023c1994
commit ec809085b4
4 changed files with 53 additions and 39 deletions

View File

@ -141,22 +141,30 @@ end
-- @param #ASTAR.Node nodeB
function ASTAR.LoS(nodeA, nodeB)
local los=nodeA.coordinate:IsLOS(nodeB.coordinate, 0.5)
local offset=0.1
local dx=200
local dy=dx
local cA=nodeA.coordinate:SetAltitude(0, true)
local cB=nodeB.coordinate:SetAltitude(0, true)
local los=cA:IsLOS(cB, offset)
if los then
local heading=nodeA.coordinate:HeadingTo(nodeB.coordinate)
local heading=cA:HeadingTo(cB)
local Ap=nodeA.coordinate:Translate(100, heading+90)
local Bp=nodeA.coordinate:Translate(100, heading+90)
local Ap=cA:Translate(dx, heading+90)
local Bp=cB:Translate(dx, heading+90)
los=Ap:IsLOS(Bp, 0.5)
los=Ap:IsLOS(Bp, offset)
if los then
local Am=nodeA.coordinate:Translate(100, heading-90)
local Bm=nodeA.coordinate:Translate(100, heading-90)
local Am=cA:Translate(dy, heading-90)
local Bm=cB:Translate(dy, heading-90)
los=Am:IsLOS(Bm, 0.5)
los=Am:IsLOS(Bm, offset)
end
end
@ -170,8 +178,9 @@ end
--- Find the closest node from a given coordinate.
-- @param #ASTAR self
-- @param Core.Point#COORDINATE Coordinate.
-- @return #ASTAR.Node Cloest node to the coordinate.
-- @param #number DeltaX Increment in the direction of start to end coordinate in meters. Default 2000 meters.
-- @param #number DeltaY Increment perpendicular to the direction of start to end coordinate in meters. Default is same as DeltaX.
-- @return #ASTAR self
function ASTAR:CreateGrid()
local Dx=20000
@ -218,6 +227,7 @@ function ASTAR:CreateGrid()
end
env.info("FF Done building grid!")
return self
end
--- Find the closest node from a given coordinate.

View File

@ -1699,7 +1699,7 @@ function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
local speed=self.group and self.group:GetVelocityKMH() or 100
-- Set current waypoint or we get problem that the _PassingWaypoint function is triggered too early, i.e. right now and not when passing the next WP.
local current=self.group:GetCoordinate():WaypointAir("BARO", COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, speed, true, nil, {}, "Current")
local current=self.group:GetCoordinate():WaypointAir(COORDINATE.WaypointAltType.BARO, COORDINATE.WaypointType.TurningPoint, COORDINATE.WaypointAction.TurningPoint, speed, true, nil, {}, "Current")
table.insert(wp, current)
-- Add remaining waypoints to route.
@ -1710,7 +1710,7 @@ function FLIGHTGROUP:onafterUpdateRoute(From, Event, To, n)
-- Debug info.
local hb=self.homebase and self.homebase:GetName() or "unknown"
local db=self.destbase and self.destbase:GetName() or "unknown"
self:T(self.lid..string.format("Updating route for WP #%d-%d homebase=%s destination=%s", n, #wp, hb, db))
self:I(self.lid..string.format("Updating route for WP #%d-%d homebase=%s destination=%s", n, #wp, hb, db))
if #wp>1 then
@ -2910,15 +2910,26 @@ end
--- Initialize Mission Editor waypoints.
-- @param #FLIGHTGROUP self
-- @param #table waypoints Table of waypoints. Default is from group template.
-- @return #FLIGHTGROUP self
function FLIGHTGROUP:InitWaypoints(waypoints)
function FLIGHTGROUP:InitWaypoints()
-- Template waypoints.
self.waypoints0=self.group:GetTemplateRoutePoints()
self:I(self.waypoints0)
-- Waypoints of group as defined in the ME.
self.waypoints=waypoints or UTILS.DeepCopy(self.waypoints0)
-- Waypoints
self.waypoints={}
for index,wp in pairs(self.waypoints0) do
env.info("FF index "..index)
local waypoint=self:_CreateWaypoint(wp)
self:_AddWaypoint(waypoint)
end
-- Get home and destination airbases from waypoints.
self.homebase=self.homebase or self:GetHomebaseFromWaypoints()

View File

@ -539,8 +539,8 @@ function NAVYGROUP:onafterUpdateRoute(From, Event, To, n, Speed, Depth)
-- Add remaining waypoints to route.
for i=n, #self.waypoints do
local wp=self.waypoints[i]
local wp=self.waypoints[i] --Ops.OpsGroup#OPSGROUP.Waypoint
-- Set speed.
if i==n then

View File

@ -2185,24 +2185,17 @@ end
-- @param #OPSGROUP self
-- @param #table waypoint DCS waypoint data table.
-- @return #OPSGROUP.Waypoint Waypoint data.
function OPSGROUP:_CreateWaypoint(waypoint)
local wp={} --#OPSGROUP.Waypoint
function OPSGROUP:_CreateWaypoint(waypoint, detour, onroad, formation)
wp.wp=waypoint
wp.uid=self.wpcounter
wp.altitude=altitude
wp.speed=speed
wp.detour=detour
wp.formation=formation
wp.onroad=onroad
wp.coordinate=coordinate
waypoint.uid=self.wpcounter
waypoint.coordinate=COORDINATE:New(waypoint.x, waypoint.alt, waypoint.y)
waypoint.detour=detour and detour or false
waypoint.formation=formation
waypoint.onroad=onroad and onroad or false
self.wpcounter=self.wpcounter+1
return wp
return waypoint
end
--- Initialize Mission Editor waypoints.
@ -2212,17 +2205,18 @@ end
function OPSGROUP:_AddWaypoint(waypoint, wpnumber)
wpnumber=wpnumber or #self.waypoints+1
env.info(string.format("adding waypoint at index=%d", wpnumber))
-- Add waypoint to table.
tabel.insert(self.waypoints, wpnumber, waypoint)
table.insert(self.waypoints, wpnumber, waypoint)
end
--- Initialize Mission Editor waypoints.
-- @param #OPSGROUP self
-- @param #table waypoints Table of waypoints. Default is from group template.
-- @return #OPSGROUP self
function OPSGROUP:InitWaypoints(waypoints)
function OPSGROUP:InitWaypoints()
-- Template waypoints.
self.waypoints0=self.group:GetTemplateRoutePoints()
@ -2232,11 +2226,10 @@ function OPSGROUP:InitWaypoints(waypoints)
for index,wp in pairs(self.waypoints0) do
local waypoint=self:_CreateWaypoint()
local waypoint=self:_CreateWaypoint(wp)
self:_AddWaypoint(waypoint)
end
-- Debug info.
@ -2319,7 +2312,7 @@ function OPSGROUP:_UpdateWaypointTasks(n)
table.insert(taskswp, TaskPassingWaypoint)
-- Waypoint task combo.
wp.wp.task=self.group:TaskCombo(taskswp)
wp.task=self.group:TaskCombo(taskswp)
end