mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-09-23 11:18:07 +00:00
refactor: remove new Vec3
This commit is contained in:
@@ -20,7 +20,7 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) {
|
||||
avoidSun = false;
|
||||
_tick = 0;
|
||||
lastStuckCheck = 0;
|
||||
lastStuckCheckPos = new Vec3(0, 0, 0);
|
||||
lastStuckCheckPos = Vec3(0, 0, 0);
|
||||
_canPassDoors = true;
|
||||
_canOpenDoors = false;
|
||||
avoidWater = false;
|
||||
@@ -29,7 +29,6 @@ PathNavigation::PathNavigation(Mob* mob, Level* level) {
|
||||
|
||||
PathNavigation::~PathNavigation() {
|
||||
if (path != NULL) delete path;
|
||||
delete lastStuckCheckPos;
|
||||
}
|
||||
|
||||
void PathNavigation::setAvoidWater(bool avoidWater) {
|
||||
@@ -112,9 +111,9 @@ bool PathNavigation::moveTo(Path* newPath, double speedModifier) {
|
||||
this->speedModifier = speedModifier;
|
||||
Vec3 mobPos = getTempMobPos();
|
||||
lastStuckCheck = _tick;
|
||||
lastStuckCheckPos->x = mobPos.x;
|
||||
lastStuckCheckPos->y = mobPos.y;
|
||||
lastStuckCheckPos->z = mobPos.z;
|
||||
lastStuckCheckPos.x = mobPos.x;
|
||||
lastStuckCheckPos.y = mobPos.y;
|
||||
lastStuckCheckPos.z = mobPos.z;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -161,8 +160,7 @@ void PathNavigation::updatePath() {
|
||||
int sz = sx;
|
||||
for (int i = firstElevation - 1; i >= path->getIndex(); --i) {
|
||||
Vec3 mob_pos = path->getPos(mob->shared_from_this(), i);
|
||||
if (canMoveDirectly(&mobPos, &mob_pos,
|
||||
sx, sy, sz)) {
|
||||
if (canMoveDirectly(&mobPos, &mob_pos, sx, sy, sz)) {
|
||||
path->setIndex(i);
|
||||
break;
|
||||
}
|
||||
@@ -170,11 +168,11 @@ void PathNavigation::updatePath() {
|
||||
|
||||
// stuck detection (probably pushed off path)
|
||||
if (_tick - lastStuckCheck > 100) {
|
||||
if (mobPos.distanceToSqr(*lastStuckCheckPos) < 1.5 * 1.5) stop();
|
||||
if (mobPos.distanceToSqr(lastStuckCheckPos) < 1.5 * 1.5) stop();
|
||||
lastStuckCheck = _tick;
|
||||
lastStuckCheckPos->x = mobPos.x;
|
||||
lastStuckCheckPos->y = mobPos.y;
|
||||
lastStuckCheckPos->z = mobPos.z;
|
||||
lastStuckCheckPos.x = mobPos.x;
|
||||
lastStuckCheckPos.y = mobPos.y;
|
||||
lastStuckCheckPos.z = mobPos.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ private:
|
||||
bool avoidSun;
|
||||
int _tick;
|
||||
int lastStuckCheck;
|
||||
Vec3* lastStuckCheckPos;
|
||||
Vec3 lastStuckCheckPos;
|
||||
|
||||
bool _canPassDoors;
|
||||
bool _canOpenDoors;
|
||||
|
||||
@@ -4,33 +4,36 @@
|
||||
#include "RandomPos.h"
|
||||
#include <optional>
|
||||
|
||||
Vec3* RandomPos::tempDir = new Vec3(0, 0, 0);
|
||||
Vec3 RandomPos::tempDir = Vec3(0, 0, 0);
|
||||
|
||||
std::optional<Vec3> RandomPos::getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
|
||||
int yDist, int quadrant /*=-1*/) // 4J - added quadrant
|
||||
std::optional<Vec3> RandomPos::getPos(
|
||||
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist,
|
||||
int quadrant /*=-1*/) // 4J - added quadrant
|
||||
{
|
||||
return generateRandomPos(mob, xzDist, yDist, NULL, quadrant);
|
||||
}
|
||||
|
||||
std::optional<Vec3> RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
|
||||
int yDist, Vec3* towardsPos) {
|
||||
tempDir->x = towardsPos->x - mob->x;
|
||||
tempDir->y = towardsPos->y - mob->y;
|
||||
tempDir->z = towardsPos->z - mob->z;
|
||||
return generateRandomPos(mob, xzDist, yDist, tempDir);
|
||||
std::optional<Vec3> RandomPos::getPosTowards(std::shared_ptr<PathfinderMob> mob,
|
||||
int xzDist, int yDist,
|
||||
Vec3* towardsPos) {
|
||||
tempDir.x = towardsPos->x - mob->x;
|
||||
tempDir.y = towardsPos->y - mob->y;
|
||||
tempDir.z = towardsPos->z - mob->z;
|
||||
return generateRandomPos(mob, xzDist, yDist, &tempDir);
|
||||
}
|
||||
|
||||
std::optional<Vec3> RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
|
||||
int yDist, Vec3* avoidPos) {
|
||||
tempDir->x = mob->x - avoidPos->x;
|
||||
tempDir->y = mob->y - avoidPos->y;
|
||||
tempDir->z = mob->z - avoidPos->z;
|
||||
return generateRandomPos(mob, xzDist, yDist, tempDir);
|
||||
std::optional<Vec3> RandomPos::getPosAvoid(std::shared_ptr<PathfinderMob> mob,
|
||||
int xzDist, int yDist,
|
||||
Vec3* avoidPos) {
|
||||
tempDir.x = mob->x - avoidPos->x;
|
||||
tempDir.y = mob->y - avoidPos->y;
|
||||
tempDir.z = mob->z - avoidPos->z;
|
||||
return generateRandomPos(mob, xzDist, yDist, &tempDir);
|
||||
}
|
||||
|
||||
std::optional<Vec3> RandomPos::generateRandomPos(std::shared_ptr<PathfinderMob> mob,
|
||||
int xzDist, int yDist, Vec3* dir,
|
||||
int quadrant /*=-1*/) // 4J - added quadrant
|
||||
std::optional<Vec3> RandomPos::generateRandomPos(
|
||||
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3* dir,
|
||||
int quadrant /*=-1*/) // 4J - added quadrant
|
||||
{
|
||||
Random* random = mob->getRandom();
|
||||
bool hasBest = false;
|
||||
|
||||
@@ -5,17 +5,21 @@ class PathfinderMob;
|
||||
|
||||
class RandomPos {
|
||||
private:
|
||||
static Vec3* tempDir;
|
||||
static Vec3 tempDir;
|
||||
|
||||
public:
|
||||
static std::optional<Vec3> getPos(std::shared_ptr<PathfinderMob> mob, int xzDist,
|
||||
int yDist, int quadrant = -1); // 4J added quadrant
|
||||
static std::optional<Vec3> getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist,
|
||||
int yDist, Vec3* towardsPos);
|
||||
static std::optional<Vec3> getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist,
|
||||
int yDist, Vec3* avoidPos);
|
||||
static std::optional<Vec3> getPos(std::shared_ptr<PathfinderMob> mob,
|
||||
int xzDist, int yDist,
|
||||
int quadrant = -1); // 4J added quadrant
|
||||
static std::optional<Vec3> getPosTowards(std::shared_ptr<PathfinderMob> mob,
|
||||
int xzDist, int yDist,
|
||||
Vec3* towardsPos);
|
||||
static std::optional<Vec3> getPosAvoid(std::shared_ptr<PathfinderMob> mob,
|
||||
int xzDist, int yDist,
|
||||
Vec3* avoidPos);
|
||||
|
||||
private:
|
||||
static std::optional<Vec3> generateRandomPos(std::shared_ptr<PathfinderMob> mob,
|
||||
int xzDist, int yDist, Vec3* dir,
|
||||
int quadrant = -1); // 4J added quadrant
|
||||
static std::optional<Vec3> generateRandomPos(
|
||||
std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3* dir,
|
||||
int quadrant = -1); // 4J added quadrant
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user