From ec809085b42fa9413af6c32e954ef7d2c6485ecf Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 22 Jul 2020 01:05:24 +0200 Subject: [PATCH] Waypoints --- Moose Development/Moose/Core/Astar.lua | 30 ++++++++++++------ Moose Development/Moose/Ops/FlightGroup.lua | 23 ++++++++++---- Moose Development/Moose/Ops/NavyGroup.lua | 4 +-- Moose Development/Moose/Ops/OpsGroup.lua | 35 +++++++++------------ 4 files changed, 53 insertions(+), 39 deletions(-) diff --git a/Moose Development/Moose/Core/Astar.lua b/Moose Development/Moose/Core/Astar.lua index 3ee069619..409bed41b 100644 --- a/Moose Development/Moose/Core/Astar.lua +++ b/Moose Development/Moose/Core/Astar.lua @@ -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. diff --git a/Moose Development/Moose/Ops/FlightGroup.lua b/Moose Development/Moose/Ops/FlightGroup.lua index 1d0f2c05c..c08bf7a22 100644 --- a/Moose Development/Moose/Ops/FlightGroup.lua +++ b/Moose Development/Moose/Ops/FlightGroup.lua @@ -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() diff --git a/Moose Development/Moose/Ops/NavyGroup.lua b/Moose Development/Moose/Ops/NavyGroup.lua index 046cf4f8b..bab3034c9 100644 --- a/Moose Development/Moose/Ops/NavyGroup.lua +++ b/Moose Development/Moose/Ops/NavyGroup.lua @@ -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 diff --git a/Moose Development/Moose/Ops/OpsGroup.lua b/Moose Development/Moose/Ops/OpsGroup.lua index c625458a6..29845a1f5 100644 --- a/Moose Development/Moose/Ops/OpsGroup.lua +++ b/Moose Development/Moose/Ops/OpsGroup.lua @@ -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