mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
Pathfinding
This commit is contained in:
parent
3737592734
commit
fb1e95ab87
@ -438,9 +438,7 @@ function ASTAR:CreateGrid(ValidSurfaceTypes, BoxHY, SpaceX, deltaX, deltaY, Mark
|
|||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
local text=string.format("Building grid with nx=%d ny=%d => total=%d nodes", nx, nz, nx*nz)
|
local text=string.format("Building grid with nx=%d ny=%d => total=%d nodes", nx, nz, nx*nz)
|
||||||
self:I(self.lid..text)
|
self:T(self.lid..text)
|
||||||
MESSAGE:New(text, 10, "ASTAR"):ToAllIf(self.Debug)
|
|
||||||
|
|
||||||
|
|
||||||
-- Loop over x and z coordinate to create a 2D grid.
|
-- Loop over x and z coordinate to create a 2D grid.
|
||||||
for i=1,nx do
|
for i=1,nx do
|
||||||
@ -479,8 +477,7 @@ function ASTAR:CreateGrid(ValidSurfaceTypes, BoxHY, SpaceX, deltaX, deltaY, Mark
|
|||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
local text=string.format("Done building grid!")
|
local text=string.format("Done building grid!")
|
||||||
self:I(self.lid..text)
|
self:T2(self.lid..text)
|
||||||
MESSAGE:New(text, 10, "ASTAR"):ToAllIf(self.Debug)
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@ -651,7 +648,7 @@ function ASTAR:FindStartNode()
|
|||||||
self.startNode=node
|
self.startNode=node
|
||||||
|
|
||||||
if dist>1000 then
|
if dist>1000 then
|
||||||
self:I(self.lid.."Adding start node to node grid!")
|
self:T(self.lid.."Adding start node to node grid!")
|
||||||
self:AddNode(node)
|
self:AddNode(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -669,7 +666,7 @@ function ASTAR:FindEndNode()
|
|||||||
self.endNode=node
|
self.endNode=node
|
||||||
|
|
||||||
if dist>1000 then
|
if dist>1000 then
|
||||||
self:I(self.lid.."Adding end node to node grid!")
|
self:T(self.lid.."Adding end node to node grid!")
|
||||||
self:AddNode(node)
|
self:AddNode(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -713,8 +710,7 @@ function ASTAR:GetPath(ExcludeStartNode, ExcludeEndNode)
|
|||||||
|
|
||||||
-- Debug message.
|
-- Debug message.
|
||||||
local text=string.format("Starting A* pathfinding with %d Nodes", self.Nnodes)
|
local text=string.format("Starting A* pathfinding with %d Nodes", self.Nnodes)
|
||||||
self:I(self.lid..text)
|
self:T(self.lid..text)
|
||||||
MESSAGE:New(text, 10, "ASTAR"):ToAllIf(self.Debug)
|
|
||||||
|
|
||||||
local Tstart=UTILS.GetOSTime()
|
local Tstart=UTILS.GetOSTime()
|
||||||
|
|
||||||
@ -751,8 +747,7 @@ function ASTAR:GetPath(ExcludeStartNode, ExcludeEndNode)
|
|||||||
end
|
end
|
||||||
text=text..string.format(", Nvalid=%d [%d cached]", self.nvalid, self.nvalidcache)
|
text=text..string.format(", Nvalid=%d [%d cached]", self.nvalid, self.nvalidcache)
|
||||||
text=text..string.format(", Ncost=%d [%d cached]", self.ncost, self.ncostcache)
|
text=text..string.format(", Ncost=%d [%d cached]", self.ncost, self.ncostcache)
|
||||||
self:I(self.lid..text)
|
self:T(self.lid..text)
|
||||||
MESSAGE:New(text, 60, "ASTAR"):ToAllIf(self.Debug)
|
|
||||||
|
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
-- @field #number depth Ordered depth in meters.
|
-- @field #number depth Ordered depth in meters.
|
||||||
-- @field #boolean collisionwarning If true, collition warning.
|
-- @field #boolean collisionwarning If true, collition warning.
|
||||||
-- @field #boolean pathfindingOn If true, enable pathfining.
|
-- @field #boolean pathfindingOn If true, enable pathfining.
|
||||||
|
-- @field #number pathCorridor Path corrdidor width in meters.
|
||||||
-- @field #boolean ispathfinding If true, group is currently path finding.
|
-- @field #boolean ispathfinding If true, group is currently path finding.
|
||||||
-- @extends Ops.OpsGroup#OPSGROUP
|
-- @extends Ops.OpsGroup#OPSGROUP
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ NAVYGROUP = {
|
|||||||
intowind = nil,
|
intowind = nil,
|
||||||
intowindcounter = 0,
|
intowindcounter = 0,
|
||||||
Qintowind = {},
|
Qintowind = {},
|
||||||
|
pathCorridor = 400,
|
||||||
}
|
}
|
||||||
|
|
||||||
--- Navy group element.
|
--- Navy group element.
|
||||||
@ -187,11 +189,32 @@ end
|
|||||||
--- Enable/disable pathfinding.
|
--- Enable/disable pathfinding.
|
||||||
-- @param #NAVYGROUP self
|
-- @param #NAVYGROUP self
|
||||||
-- @param #boolean Switch If true, enable pathfinding.
|
-- @param #boolean Switch If true, enable pathfinding.
|
||||||
|
-- @param #number CorridorWidth Corridor with in meters. Default 400 m.
|
||||||
-- @return #NAVYGROUP self
|
-- @return #NAVYGROUP self
|
||||||
function NAVYGROUP:SetPathfinding(Switch)
|
function NAVYGROUP:SetPathfinding(Switch, CorridorWidth)
|
||||||
self.pathfindingOn=Switch
|
self.pathfindingOn=Switch
|
||||||
|
self.pathCorridor=CorridorWidth or 400
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Enable pathfinding.
|
||||||
|
-- @param #NAVYGROUP self
|
||||||
|
-- @param #number CorridorWidth Corridor with in meters. Default 400 m.
|
||||||
|
-- @return #NAVYGROUP self
|
||||||
|
function NAVYGROUP:SetPathfindingOn(CorridorWidth)
|
||||||
|
self:SetPathfinding(true, CorridorWidth)
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Disable pathfinding.
|
||||||
|
-- @param #NAVYGROUP self
|
||||||
|
-- @return #NAVYGROUP self
|
||||||
|
function NAVYGROUP:SetPathfindingOff()
|
||||||
|
self:SetPathfinding(true, self.pathCorridor)
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Add a *scheduled* task.
|
--- Add a *scheduled* task.
|
||||||
-- @param #NAVYGROUP self
|
-- @param #NAVYGROUP self
|
||||||
-- @param Core.Point#COORDINATE Coordinate Coordinate of the target.
|
-- @param Core.Point#COORDINATE Coordinate Coordinate of the target.
|
||||||
@ -1454,7 +1477,7 @@ function NAVYGROUP:_FindPathToNextWaypoint()
|
|||||||
astar:CreateGrid({land.SurfaceType.WATER}, boxwidth, spacex, delta, delta*2, self.Debug)
|
astar:CreateGrid({land.SurfaceType.WATER}, boxwidth, spacex, delta, delta*2, self.Debug)
|
||||||
|
|
||||||
-- Valid neighbour nodes need to have line of sight.
|
-- Valid neighbour nodes need to have line of sight.
|
||||||
astar:SetValidNeighbourLoS(400)
|
astar:SetValidNeighbourLoS(self.pathCorridor)
|
||||||
|
|
||||||
--- Function to find a path and add waypoints to the group.
|
--- Function to find a path and add waypoints to the group.
|
||||||
local function findpath()
|
local function findpath()
|
||||||
@ -1478,7 +1501,7 @@ function NAVYGROUP:_FindPathToNextWaypoint()
|
|||||||
uid=wp.uid
|
uid=wp.uid
|
||||||
|
|
||||||
-- Debug: smoke and mark path.
|
-- Debug: smoke and mark path.
|
||||||
node.coordinate:MarkToAll(string.format("Path node #%d", i))
|
--node.coordinate:MarkToAll(string.format("Path node #%d", i))
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1489,8 +1512,8 @@ function NAVYGROUP:_FindPathToNextWaypoint()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Return if path was found.
|
||||||
return findpath()
|
return findpath()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -1383,7 +1383,7 @@ function OPSGROUP:RemoveWaypoint(wpindex)
|
|||||||
local n=#self.waypoints
|
local n=#self.waypoints
|
||||||
|
|
||||||
-- Debug info.
|
-- Debug info.
|
||||||
self:I(self.lid..string.format("Removing waypoint index %d, current wp index %d. N %d-->%d", wpindex, self.currentwp, N, n))
|
self:T(self.lid..string.format("Removing waypoint index %d, current wp index %d. N %d-->%d", wpindex, self.currentwp, N, n))
|
||||||
|
|
||||||
-- Waypoint was not reached yet.
|
-- Waypoint was not reached yet.
|
||||||
if wpindex > self.currentwp then
|
if wpindex > self.currentwp then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user