mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
2159
This commit is contained in:
parent
0f72601891
commit
2573e4f90d
14 changed files with 65 additions and 57 deletions
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
interface ITileNavigator
|
||||
{
|
||||
public function navigate(PathTile $from, PathTile $to);
|
||||
public function navigate(PathTile $from, PathTile $to, $maxDist);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ class PathTileXYZ extends PathTile
|
|||
return new Vector3($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function asArray(){
|
||||
return ["x" => $this->x, "y" => $this->y, "z" => $this->z];
|
||||
}
|
||||
|
||||
public function addOffset($offset){
|
||||
$this->x += $offset[0];
|
||||
$this->y += $offset[1];
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class TileNavigator implements ITileNavigator
|
|||
return array_reverse($totalPath);
|
||||
}
|
||||
|
||||
public function navigate(PathTile $from, PathTile $to)
|
||||
public function navigate(PathTile $from, PathTile $to, $maxDist) //TODO optimizations, no arraylist
|
||||
{
|
||||
$closed = new ArrayList();
|
||||
$open = new ArrayList();
|
||||
|
|
@ -54,14 +54,20 @@ class TileNavigator implements ITileNavigator
|
|||
$closed->add($current);
|
||||
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
|
||||
{
|
||||
|
||||
if(in_array($neighbor, $visited)){
|
||||
continue;
|
||||
}
|
||||
|
||||
$visited[] = $neighbor;
|
||||
if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(in_array($neighbor, $visited)){
|
||||
if(!Utils::in_range(Utils::distance($neighbor->asArray(), $from->asArray()), -$maxDist, $maxDist)){
|
||||
continue;
|
||||
}
|
||||
$visited[] = $neighbor;
|
||||
|
||||
$tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor);
|
||||
|
||||
if (!$open->has($neighbor))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue