mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-10-29 16:58:06 +00:00
xxx
This commit is contained in:
parent
f022c87f25
commit
639c5bc71a
@ -594,7 +594,7 @@ end
|
|||||||
-- @param #STRATEGO self
|
-- @param #STRATEGO self
|
||||||
-- @return #STRATEGO self
|
-- @return #STRATEGO self
|
||||||
function STRATEGO:GetToFrom(StartPoint,EndPoint)
|
function STRATEGO:GetToFrom(StartPoint,EndPoint)
|
||||||
self:T(self.lid.."GetToFrom")
|
self:T(self.lid.."GetToFrom "..tostring(StartPoint).." "..tostring(EndPoint))
|
||||||
local pstart = string.gsub(StartPoint,"[%p%s]",".")
|
local pstart = string.gsub(StartPoint,"[%p%s]",".")
|
||||||
local pend = string.gsub(EndPoint,"[%p%s]",".")
|
local pend = string.gsub(EndPoint,"[%p%s]",".")
|
||||||
local fromto = pstart..";"..pend
|
local fromto = pstart..";"..pend
|
||||||
@ -630,7 +630,7 @@ end
|
|||||||
-- @param #STRATEGO self
|
-- @param #STRATEGO self
|
||||||
-- @param #string Startpoint Starting Point, e.g. AIRBASE.Syria.Hatay
|
-- @param #string Startpoint Starting Point, e.g. AIRBASE.Syria.Hatay
|
||||||
-- @param #string Endpoint End Point, e.g. AIRBASE.Syria.H4
|
-- @param #string Endpoint End Point, e.g. AIRBASE.Syria.H4
|
||||||
-- @param #table Color (Optional) RGB color table {r, g, b}, e.g. {1,0,0} for red. Defaults to lila.
|
-- @param #table Color (Optional) RGB color table {r, g, b}, e.g. {1,0,0} for red. Defaults to violet.
|
||||||
-- @param #number Linetype (Optional) Line type: 0=No line, 1=Solid, 2=Dashed, 3=Dotted, 4=Dot dash, 5=Long dash, 6=Two dash. Default 5.
|
-- @param #number Linetype (Optional) Line type: 0=No line, 1=Solid, 2=Dashed, 3=Dotted, 4=Dot dash, 5=Long dash, 6=Two dash. Default 5.
|
||||||
-- @param #boolean Draw (Optional) If true, draw route on the F10 map. Defaukt false.
|
-- @param #boolean Draw (Optional) If true, draw route on the F10 map. Defaukt false.
|
||||||
-- @return #STRATEGO self
|
-- @return #STRATEGO self
|
||||||
@ -1241,6 +1241,33 @@ function STRATEGO:FindNeighborNodes(Name,Enemies,Friends)
|
|||||||
return neighbors, nearest, shortestdist
|
return neighbors, nearest, shortestdist
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- [INTERNAL] Route Finding - Find the next hop towards an end node from a start node
|
||||||
|
-- @param #STRATEGO self
|
||||||
|
-- @param #string Start The name of the start node.
|
||||||
|
-- @param #string End The name of the end node.
|
||||||
|
-- @param #table InRoute Table of node names making up the route so far.
|
||||||
|
-- @return #string Name of the next closest node
|
||||||
|
function STRATEGO:_GetNextClosest(Start,End,InRoute)
|
||||||
|
local ecoord = self.airbasetable[End].coord
|
||||||
|
local nodes,nearest = self:FindNeighborNodes(Start)
|
||||||
|
--self:I(tostring(nearest))
|
||||||
|
local closest = nil
|
||||||
|
local closedist = 1000*1000
|
||||||
|
for _name,_dist in pairs(nodes) do
|
||||||
|
local kcoord = self.airbasetable[_name].coord
|
||||||
|
local nnodes = self.airbasetable[_name].connections > 2 and true or false
|
||||||
|
if _name == End then nnodes = true end
|
||||||
|
if kcoord ~= nil and ecoord ~= nil and nnodes == true then
|
||||||
|
local dist = math.floor((kcoord:Get2DDistance(ecoord)/1000)+0.5)
|
||||||
|
if (dist < closedist and InRoute[_name] ~= true) then
|
||||||
|
closedist = dist
|
||||||
|
closest = _name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return closest
|
||||||
|
end
|
||||||
|
|
||||||
--- [USER] Find a route between two nodes.
|
--- [USER] Find a route between two nodes.
|
||||||
-- @param #STRATEGO self
|
-- @param #STRATEGO self
|
||||||
-- @param #string Start The name of the start node.
|
-- @param #string Start The name of the start node.
|
||||||
@ -1272,28 +1299,6 @@ function STRATEGO:FindRoute(Start,End,Hops,Draw,Color,LineType)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local function NextClosest(Start,End)
|
|
||||||
local ecoord = self.airbasetable[End].coord
|
|
||||||
local nodes,nearest = self:FindNeighborNodes(Start)
|
|
||||||
--self:I(tostring(nearest))
|
|
||||||
local closest = nil
|
|
||||||
local closedist = 1000*1000
|
|
||||||
for _name,_dist in pairs(nodes) do
|
|
||||||
local kcoord = self.airbasetable[_name].coord
|
|
||||||
local nnodes = self.airbasetable[_name].connections > 2 and true or false
|
|
||||||
if _name == End then nnodes = true end
|
|
||||||
local dist = math.floor((kcoord:Get2DDistance(ecoord)/1000)+0.5)
|
|
||||||
if (dist < closedist and nnodes and InRoute[_name] ~= true) then
|
|
||||||
closedist = dist
|
|
||||||
closest = _name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if closest then
|
|
||||||
--MESSAGE:New(string.format("Start %s | End %s | Nextclosest %s",Start,End,closest),10,"STRATEGO"):ToLog():ToAll()
|
|
||||||
return closest
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function DrawRoute(Route)
|
local function DrawRoute(Route)
|
||||||
for i=1,#Route-1 do
|
for i=1,#Route-1 do
|
||||||
local p1=Route[i]
|
local p1=Route[i]
|
||||||
@ -1319,8 +1324,8 @@ function STRATEGO:FindRoute(Start,End,Hops,Draw,Color,LineType)
|
|||||||
local spoint = Start
|
local spoint = Start
|
||||||
for i=1,hops do
|
for i=1,hops do
|
||||||
--self:I("Start="..tostring(spoint))
|
--self:I("Start="..tostring(spoint))
|
||||||
local Next = NextClosest(spoint,End)
|
local Next = self:_GetNextClosest(spoint,End,InRoute)
|
||||||
if Next then
|
if Next ~= nil then
|
||||||
Route[#Route+1] = Next
|
Route[#Route+1] = Next
|
||||||
InRoute[Next] = true
|
InRoute[Next] = true
|
||||||
local nodes = self:FindNeighborNodes(Next)
|
local nodes = self:FindNeighborNodes(Next)
|
||||||
@ -1332,6 +1337,8 @@ function STRATEGO:FindRoute(Start,End,Hops,Draw,Color,LineType)
|
|||||||
else
|
else
|
||||||
spoint = Next
|
spoint = Next
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user