Reimplemented Pathfinder to use A* instead of spawning an entity
#closes 788
This commit is contained in:
1 parent
db406cacbf
commit
da9eb2b3dd
6 files changed
+318
-10
No files matched your search
@@ -0,0 +1,52 @@
|
||||
|
||||
local FindVector = {}
|
||||
FindVector.__index = FindVector
|
||||
|
||||
local function newFindVector( x, y )
|
||||
return setmetatable( { x = x or 0, y = y or 0 }, FindVector )
|
||||
end
|
||||
|
||||
function FindVector.__unm( vTbl )
|
||||
return newFindVector( -vTbl.x, -vTbl.y )
|
||||
end
|
||||
|
||||
function FindVector.__add( a, b )
|
||||
return newFindVector( a.x + b.x, a.y + b.y )
|
||||
end
|
||||
|
||||
function FindVector.__sub( a, b )
|
||||
return newFindVector( a.x - b.x, a.y - b.y )
|
||||
end
|
||||
|
||||
function FindVector.__mul( a, b )
|
||||
if type( a ) == "number" then
|
||||
return newFindVector( a * b.x, a * b.y )
|
||||
elseif type( b ) == "number" then
|
||||
return newFindVector( a.x * b, a.y * b )
|
||||
else
|
||||
return newFindVector( a.x * b.x, a.y * b.y )
|
||||
end
|
||||
end
|
||||
|
||||
function FindVector.__div( a, b )
|
||||
return newFindVector( a.x / b, a.y / b )
|
||||
end
|
||||
|
||||
function FindVector.__eq( a, b )
|
||||
return a.x == b.x and a.y == b.y
|
||||
end
|
||||
|
||||
function FindVector:__tostring()
|
||||
return "(" .. self.x .. ", " .. self.y .. ")"
|
||||
end
|
||||
|
||||
function FindVector:ID()
|
||||
if self._ID == nil then
|
||||
local x, y = self.x, self.y
|
||||
self._ID = 0.5 * ( ( x + y ) * ( x + y + 1 ) + y )
|
||||
end
|
||||
|
||||
return self._ID
|
||||
end
|
||||
|
||||
return setmetatable( FindVector, { __call = function( _, ... ) return newFindVector( ... ) end } )
|
||||
Reference in new issue
Block a user