mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 04:59:46 +00:00
jump test for pathfinder
This commit is contained in:
parent
d0ec32dc02
commit
dd4264998d
5 changed files with 28 additions and 15 deletions
|
|
@ -58,10 +58,10 @@ class TileNavigator implements ITileNavigator
|
||||||
}
|
}
|
||||||
|
|
||||||
$visited[(string)$neighbor] = $neighbor;
|
$visited[(string)$neighbor] = $neighbor;
|
||||||
if ($this->blockedProvider->isBlocked($neighbor))
|
//if ($this->blockedProvider->isBlocked($neighbor)) shouldnt be neccessary now
|
||||||
{
|
//{
|
||||||
continue;
|
// continue;
|
||||||
}
|
//}
|
||||||
$distbetweenCost = $this->distanceAlgorithm->calculate($current, $neighbor);
|
$distbetweenCost = $this->distanceAlgorithm->calculate($current, $neighbor);
|
||||||
$tentativeG = $gScore[(string) $current] + $distbetweenCost;
|
$tentativeG = $gScore[(string) $current] + $distbetweenCost;
|
||||||
$tentativeF = $distbetweenCost + $this->heuristicAlgorithm->calculate($neighbor, $to);
|
$tentativeF = $distbetweenCost + $this->heuristicAlgorithm->calculate($neighbor, $to);
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,28 @@
|
||||||
|
|
||||||
class MCDiagonalProvider implements INeighborProvider
|
class MCDiagonalProvider implements INeighborProvider
|
||||||
{
|
{
|
||||||
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ], [ -1, 0, -1 ], [ 1, 0, -1 ], [ 1, 0, 1 ], [ -1, 0, 1 ]);
|
private static $neighbors = array([ 0, 0, -1 ], [ 1, 0, 0 ], [ 0, 0, 1 ], [ -1, 0, 0 ]);
|
||||||
|
private static $jumpOffset = [0, 1, 0];
|
||||||
|
private static $moveDownOffset = [0, -1, 0];
|
||||||
public function getNeighbors(PathTile $tile)
|
public function getNeighbors(PathTile $tile)
|
||||||
{
|
{
|
||||||
|
|
||||||
if($tile instanceof PathTileXYZ){
|
if($tile instanceof PathTileXYZ){
|
||||||
return array_map(function($offset) use($tile){
|
$pnts = [];
|
||||||
return $tile->addOffset($offset);
|
foreach(MCDiagonalProvider::$neighbors as $offset){
|
||||||
}, MCDiagonalProvider::$neighbors);
|
$pnt = $tile->addOffset($offset);
|
||||||
|
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y, $pnt->z)->isSolid){
|
||||||
|
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y - 1, $pnt->z)->isSolid){
|
||||||
|
--$pnt->y;
|
||||||
|
}
|
||||||
|
$pnts[] = $pnt;
|
||||||
|
}else{
|
||||||
|
if(!$tile->level->getBlockWithoutVector($pnt->x, $pnt->y + 1, $pnt->z)->isSolid){
|
||||||
|
$pnts[] = $pnt->addOffset(self::$jumpOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $pnts;
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1368,7 +1368,7 @@ class Entity extends Position
|
||||||
public function moveEntityWithOffset($oX, $oY, $oZ)
|
public function moveEntityWithOffset($oX, $oY, $oZ)
|
||||||
{
|
{
|
||||||
$oX = $oX === 0 ? $this->speedX : $this->getSpeedModifer() * $oX * $this->getSpeed();
|
$oX = $oX === 0 ? $this->speedX : $this->getSpeedModifer() * $oX * $this->getSpeed();
|
||||||
$oY = $oY === 0 ? $this->speedY : $this->getSpeedModifer() * $oY * $this->getSpeed();
|
$oY = $oY <= 0 ? $this->speedY : (0.5);
|
||||||
$oZ = $oZ === 0 ? $this->speedZ : $this->getSpeedModifer() * $oZ * $this->getSpeed();
|
$oZ = $oZ === 0 ? $this->speedZ : $this->getSpeedModifer() * $oZ * $this->getSpeed();
|
||||||
$this->setVelocity($oX, $oY, $oZ);
|
$this->setVelocity($oX, $oY, $oZ);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
||||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
|
||||||
$this->target = false;
|
$this->target = false;
|
||||||
$this->ai = new EntityAI($this);
|
$this->ai = new EntityAI($this);
|
||||||
$this->pathFinder = new TileNavigator(new MCBlockedProvider(), new MCDiagonalProvider(), new ManhattanHeuristic3D(), new ManhattanHeuristic3D());
|
$this->pathFinder = new TileNavigator(new MCBlockedProvider(), new MCDiagonalProvider(), new Pythagoras3D(), new ManhattanHeuristic3D());
|
||||||
$this->pathFollower = new PathFollower($this);
|
$this->pathFollower = new PathFollower($this);
|
||||||
parent::__construct($level, $eid, $class, $type, $data);
|
parent::__construct($level, $eid, $class, $type, $data);
|
||||||
$this->canBeAttacked = true;
|
$this->canBeAttacked = true;
|
||||||
|
|
@ -30,10 +30,9 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
||||||
if(Entity::$allowedAI && $this->idleTime <= 0) {
|
if(Entity::$allowedAI && $this->idleTime <= 0) {
|
||||||
$this->ai->updateTasks();
|
$this->ai->updateTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->onGround){
|
if($this->onGround){
|
||||||
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){
|
//if(!$this->hasPath() && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){
|
||||||
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level), 10);
|
// $this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y + mt_rand(-1, 1), $this->z + mt_rand(-10, 10), $this->level), 10);
|
||||||
//}
|
//}
|
||||||
$this->pathFollower->followPath();
|
$this->pathFollower->followPath();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,14 +33,14 @@ class MobController
|
||||||
$dx = $d->x;
|
$dx = $d->x;
|
||||||
$dz = $d->z;
|
$dz = $d->z;
|
||||||
|
|
||||||
$tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg($dx / $dz));
|
$tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg(atan($dx / $dz)));
|
||||||
$thetaOffset = $dz <= 0 ? 90 : 270;
|
$thetaOffset = $dz < 0 ? 90 : 270;
|
||||||
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
|
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function lookOffset($x, $y, $z, $pitch = true){
|
public function lookOffset($x, $y, $z, $pitch = true){
|
||||||
$tan = $z == 0 ? ($x < 0 ? 180 : 0) : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/
|
$tan = $z == 0 ? ($x < 0 ? 180 : 0) : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/
|
||||||
$thetaOffset = $z <= 0 ? 90 : 270;
|
$thetaOffset = $z < 0 ? 90 : 270;
|
||||||
$calcYaw = $tan + $thetaOffset;
|
$calcYaw = $tan + $thetaOffset;
|
||||||
$this->entity->headYaw = $calcYaw;
|
$this->entity->headYaw = $calcYaw;
|
||||||
if($pitch){
|
if($pitch){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue