Merge pull request #71 from 4jcraft/refactor/no-std-wildcard

refactor: remove `using namespace std`
This commit is contained in:
Tropical
2026-03-08 10:09:33 -05:00
committed by GitHub
1972 changed files with 11580 additions and 11580 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ void BodyControl::clientTick()
{
++timeStill;
static const int timeStillBeforeTurn = 10;
if (timeStill > timeStillBeforeTurn) clampAngle = max(1 - (timeStill - timeStillBeforeTurn) / 10.f, 0.0f) * maxClampAngle;
if (timeStill > timeStillBeforeTurn) clampAngle = std::max(1 - (timeStill - timeStillBeforeTurn) / 10.f, 0.0f) * maxClampAngle;
}
mob->yBodyRot = clamp(mob->yHeadRot, mob->yBodyRot, clampAngle);
+2 -2
View File
@@ -13,10 +13,10 @@ LookControl::LookControl(Mob *mob)
this->mob = mob;
}
void LookControl::setLookAt(shared_ptr<Entity> target, float yMax, float xMax)
void LookControl::setLookAt(std::shared_ptr<Entity> target, float yMax, float xMax)
{
this->wantedX = target->x;
shared_ptr<Mob> targetMob = dynamic_pointer_cast<Mob>(target);
std::shared_ptr<Mob> targetMob = std::dynamic_pointer_cast<Mob>(target);
if (targetMob != NULL) this->wantedY = target->y + targetMob->getHeadHeight();
else this->wantedY = (target->bb->y0 + target->bb->y1) / 2;
this->wantedZ = target->z;
+1 -1
View File
@@ -16,7 +16,7 @@ private:
public:
LookControl(Mob *mob);
void setLookAt(shared_ptr<Entity> target, float yMax, float xMax);
void setLookAt(std::shared_ptr<Entity> target, float yMax, float xMax);
void setLookAt(double x, double y, double z, float yMax, float xMax);
virtual void tick();
+3 -3
View File
@@ -13,7 +13,7 @@ void Sensing::tick()
unseen.clear();
}
bool Sensing::canSee(shared_ptr<Entity> target)
bool Sensing::canSee(std::shared_ptr<Entity> target)
{
//if ( find(seen.begin(), seen.end(), target) != seen.end() ) return true;
//if ( find(unseen.begin(), unseen.end(), target) != unseen.end()) return false;
@@ -29,7 +29,7 @@ bool Sensing::canSee(shared_ptr<Entity> target)
//util.Timer.push("canSee");
bool canSee = mob->canSee(target);
//util.Timer.pop();
if (canSee) seen.push_back(weak_ptr<Entity>(target));
else unseen.push_back(weak_ptr<Entity>(target));
if (canSee) seen.push_back(std::weak_ptr<Entity>(target));
else unseen.push_back(std::weak_ptr<Entity>(target));
return canSee;
}
+3 -3
View File
@@ -4,12 +4,12 @@ class Sensing
{
private:
Mob *mob;
vector<weak_ptr<Entity> > seen;
vector<weak_ptr<Entity> > unseen;
std::vector<std::weak_ptr<Entity> > seen;
std::vector<std::weak_ptr<Entity> > unseen;
public:
Sensing(Mob *mob);
void tick();
bool canSee(shared_ptr<Entity> target);
bool canSee(std::shared_ptr<Entity> target);
};
+9 -9
View File
@@ -12,7 +12,7 @@
ArrowAttackGoal::ArrowAttackGoal(Mob *mob, float speed, int projectileType, int attackInterval)
{
// 4J Init
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
attackTime = 0;
seeTime = 0;
@@ -26,9 +26,9 @@ ArrowAttackGoal::ArrowAttackGoal(Mob *mob, float speed, int projectileType, int
bool ArrowAttackGoal::canUse()
{
shared_ptr<Mob> bestTarget = mob->getTarget();
std::shared_ptr<Mob> bestTarget = mob->getTarget();
if (bestTarget == NULL) return false;
target = weak_ptr<Mob>(bestTarget);
target = std::weak_ptr<Mob>(bestTarget);
return true;
}
@@ -39,13 +39,13 @@ bool ArrowAttackGoal::canContinueToUse()
void ArrowAttackGoal::stop()
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
}
void ArrowAttackGoal::tick()
{
double attackRadiusSqr = 10 * 10;
shared_ptr<Mob> tar = target.lock();
std::shared_ptr<Mob> tar = target.lock();
double targetDistSqr = mob->distanceToSqr(tar->x, tar->bb->y0, tar->z);
bool canSee = mob->getSensing()->canSee(tar);
@@ -60,7 +60,7 @@ void ArrowAttackGoal::tick()
mob->getLookControl()->setLookAt(tar, 30, 30);
attackTime = max(attackTime - 1, 0);
attackTime = std::max(attackTime - 1, 0);
if (attackTime > 0) return;
if (targetDistSqr > attackRadiusSqr || !canSee) return;
fireAtTarget();
@@ -69,16 +69,16 @@ void ArrowAttackGoal::tick()
void ArrowAttackGoal::fireAtTarget()
{
shared_ptr<Mob> tar = target.lock();
std::shared_ptr<Mob> tar = target.lock();
if (projectileType == ArrowType)
{
shared_ptr<Arrow> arrow = shared_ptr<Arrow>( new Arrow(level, dynamic_pointer_cast<Mob>(mob->shared_from_this()), tar, 1.60f, 12) );
std::shared_ptr<Arrow> arrow = std::shared_ptr<Arrow>( new Arrow(level, std::dynamic_pointer_cast<Mob>(mob->shared_from_this()), tar, 1.60f, 12) );
level->playSound(mob->shared_from_this(), eSoundType_RANDOM_BOW, 1.0f, 1 / (mob->getRandom()->nextFloat() * 0.4f + 0.8f));
level->addEntity(arrow);
}
else if (projectileType == SnowballType)
{
shared_ptr<Snowball> snowball = shared_ptr<Snowball>( new Snowball(level, dynamic_pointer_cast<Mob>(mob->shared_from_this())) );
std::shared_ptr<Snowball> snowball = std::shared_ptr<Snowball>( new Snowball(level, std::dynamic_pointer_cast<Mob>(mob->shared_from_this())) );
double xd = tar->x - mob->x;
double yd = (tar->y + tar->getHeadHeight() - 1.1f) - snowball->y;
double zd = tar->z - mob->z;
+1 -1
View File
@@ -10,7 +10,7 @@ public:
Level *level;
Mob *mob; // Owner of this goal
weak_ptr<Mob> target;
std::weak_ptr<Mob> target;
int attackTime;
float speed;
int seeTime;
+8 -8
View File
@@ -10,7 +10,7 @@
#include "../../Headers/net.minecraft.world.phys.h"
#include "AvoidPlayerGoal.h"
AvoidPlayerGoal::AvoidPlayerGoal(PathfinderMob *mob, const type_info& avoidType, float maxDist, float walkSpeed, float sprintSpeed) : avoidType(avoidType)
AvoidPlayerGoal::AvoidPlayerGoal(PathfinderMob *mob, const std::type_info& avoidType, float maxDist, float walkSpeed, float sprintSpeed) : avoidType(avoidType)
{
this->mob = mob;
//this->avoidType = avoidType;
@@ -20,7 +20,7 @@ AvoidPlayerGoal::AvoidPlayerGoal(PathfinderMob *mob, const type_info& avoidType,
this->pathNav = mob->getNavigation();
setRequiredControlFlags(Control::MoveControlFlag);
toAvoid = weak_ptr<Entity>();
toAvoid = std::weak_ptr<Entity>();
path = NULL;
}
@@ -33,26 +33,26 @@ bool AvoidPlayerGoal::canUse()
{
if (avoidType == typeid(Player))
{
shared_ptr<TamableAnimal> tamableAnimal = dynamic_pointer_cast<TamableAnimal>(mob->shared_from_this());
std::shared_ptr<TamableAnimal> tamableAnimal = std::dynamic_pointer_cast<TamableAnimal>(mob->shared_from_this());
if (tamableAnimal != NULL && tamableAnimal->isTame()) return false;
toAvoid = weak_ptr<Entity>(mob->level->getNearestPlayer(mob->shared_from_this(), maxDist));
toAvoid = std::weak_ptr<Entity>(mob->level->getNearestPlayer(mob->shared_from_this(), maxDist));
if (toAvoid.lock() == NULL) return false;
}
else
{
vector<shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(avoidType, mob->bb->grow(maxDist, 3, maxDist));
std::vector<std::shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(avoidType, mob->bb->grow(maxDist, 3, maxDist));
if (entities->empty())
{
delete entities;
return false;
}
toAvoid = weak_ptr<Entity>(entities->at(0));
toAvoid = std::weak_ptr<Entity>(entities->at(0));
delete entities;
}
if (!mob->getSensing()->canSee(toAvoid.lock())) return false;
Vec3 *pos = RandomPos::getPosAvoid(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 7, Vec3::newTemp(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z));
Vec3 *pos = RandomPos::getPosAvoid(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 7, Vec3::newTemp(toAvoid.lock()->x, toAvoid.lock()->y, toAvoid.lock()->z));
if (pos == NULL) return false;
if (toAvoid.lock()->distanceToSqr(pos->x, pos->y, pos->z) < toAvoid.lock()->distanceToSqr(mob->shared_from_this())) return false;
delete path;
@@ -75,7 +75,7 @@ void AvoidPlayerGoal::start()
void AvoidPlayerGoal::stop()
{
toAvoid = weak_ptr<Entity>();
toAvoid = std::weak_ptr<Entity>();
}
void AvoidPlayerGoal::tick()
+3 -3
View File
@@ -11,14 +11,14 @@ class AvoidPlayerGoal : public Goal
private:
PathfinderMob *mob; // Owner of this goal
float walkSpeed, sprintSpeed;
weak_ptr<Entity> toAvoid;
std::weak_ptr<Entity> toAvoid;
float maxDist;
Path *path;
PathNavigation *pathNav;
const type_info& avoidType;
const std::type_info& avoidType;
public:
AvoidPlayerGoal(PathfinderMob *mob, const type_info& avoidType, float maxDist, float walkSpeed, float sprintSpeed);
AvoidPlayerGoal(PathfinderMob *mob, const std::type_info& avoidType, float maxDist, float walkSpeed, float sprintSpeed);
~AvoidPlayerGoal();
virtual bool canUse();
+5 -5
View File
@@ -8,7 +8,7 @@
BegGoal::BegGoal(Wolf *wolf, float lookDistance)
{
player = weak_ptr<Player>();
player = std::weak_ptr<Player>();
lookTime = 0;
this->wolf = wolf;
@@ -19,7 +19,7 @@ BegGoal::BegGoal(Wolf *wolf, float lookDistance)
bool BegGoal::canUse()
{
player = weak_ptr<Player>(level->getNearestPlayer(wolf->shared_from_this(), lookDistance));
player = std::weak_ptr<Player>(level->getNearestPlayer(wolf->shared_from_this(), lookDistance));
if (player.lock() == NULL) return false;
wolf->setDespawnProtected();
return playerHoldingInteresting(player.lock());
@@ -42,7 +42,7 @@ void BegGoal::start()
void BegGoal::stop()
{
wolf->setIsInterested(false);
player = weak_ptr<Player>();
player = std::weak_ptr<Player>();
}
void BegGoal::tick()
@@ -51,9 +51,9 @@ void BegGoal::tick()
--lookTime;
}
bool BegGoal::playerHoldingInteresting(shared_ptr<Player> player)
bool BegGoal::playerHoldingInteresting(std::shared_ptr<Player> player)
{
shared_ptr<ItemInstance> item = player->inventory->getSelected();
std::shared_ptr<ItemInstance> item = player->inventory->getSelected();
if (item == NULL) return false;
if (!wolf->isTame() && item->id == Item::bone_Id) return true;
return wolf->isFood(item);
+2 -2
View File
@@ -8,7 +8,7 @@ class BegGoal : public Goal
{
private:
Wolf *wolf; // Owner of this goal
weak_ptr<Player> player;
std::weak_ptr<Player> player;
Level *level;
float lookDistance;
int lookTime;
@@ -23,7 +23,7 @@ public:
virtual void tick();
private:
bool playerHoldingInteresting(shared_ptr<Player> player);
bool playerHoldingInteresting(std::shared_ptr<Player> player);
public:
// 4J Added override to update ai elements when loading entity from schematics
+9 -9
View File
@@ -11,7 +11,7 @@
BreedGoal::BreedGoal(Animal *animal, float speed)
{
partner = weak_ptr<Animal>();
partner = std::weak_ptr<Animal>();
loveTime = 0;
this->animal = animal;
@@ -23,7 +23,7 @@ BreedGoal::BreedGoal(Animal *animal, float speed)
bool BreedGoal::canUse()
{
if (!animal->isInLove()) return false;
partner = weak_ptr<Animal>(getFreePartner());
partner = std::weak_ptr<Animal>(getFreePartner());
return partner.lock() != NULL;
}
@@ -34,7 +34,7 @@ bool BreedGoal::canContinueToUse()
void BreedGoal::stop()
{
partner = weak_ptr<Animal>();
partner = std::weak_ptr<Animal>();
loveTime = 0;
}
@@ -46,13 +46,13 @@ void BreedGoal::tick()
if (loveTime == 20 * 3) breed();
}
shared_ptr<Animal> BreedGoal::getFreePartner()
std::shared_ptr<Animal> BreedGoal::getFreePartner()
{
float r = 8;
vector<shared_ptr<Entity> > *others = level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(r, r, r));
std::vector<std::shared_ptr<Entity> > *others = level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(r, r, r));
for(AUTO_VAR(it, others->begin()); it != others->end(); ++it)
{
shared_ptr<Animal> p = dynamic_pointer_cast<Animal>(*it);
std::shared_ptr<Animal> p = std::dynamic_pointer_cast<Animal>(*it);
if (animal->canMate(p))
{
delete others;
@@ -65,7 +65,7 @@ shared_ptr<Animal> BreedGoal::getFreePartner()
void BreedGoal::breed()
{
shared_ptr<AgableMob> offspring = animal->getBreedOffspring(partner.lock());
std::shared_ptr<AgableMob> offspring = animal->getBreedOffspring(partner.lock());
animal->setDespawnProtected();
partner.lock()->setDespawnProtected();
if (offspring == NULL)
@@ -76,7 +76,7 @@ void BreedGoal::breed()
return;
}
shared_ptr<Player> loveCause = animal->getLoveCause();
std::shared_ptr<Player> loveCause = animal->getLoveCause();
if (loveCause == NULL && partner.lock()->getLoveCause() != NULL)
{
loveCause = partner.lock()->getLoveCause();
@@ -112,5 +112,5 @@ void BreedGoal::breed()
* animal->bbWidth * 2 - animal->bbWidth, xa, ya, za);
}
// 4J-PB - Fix for 106869- Customer Encountered: TU12: Content: Gameplay: Breeding animals does not give any Experience Orbs.
level->addEntity( shared_ptr<ExperienceOrb>( new ExperienceOrb(level, animal->x, animal->y, animal->z, random->nextInt(7) + 1) ) );
level->addEntity( std::shared_ptr<ExperienceOrb>( new ExperienceOrb(level, animal->x, animal->y, animal->z, random->nextInt(7) + 1) ) );
}
+2 -2
View File
@@ -10,7 +10,7 @@ class BreedGoal : public Goal
private:
Animal *animal; // Owner of this goal
Level *level;
weak_ptr<Animal> partner;
std::weak_ptr<Animal> partner;
int loveTime;
float speed;
@@ -23,7 +23,7 @@ public:
virtual void tick();
private:
shared_ptr<Animal> getFreePartner();
std::shared_ptr<Animal> getFreePartner();
void breed();
public:
@@ -36,13 +36,13 @@ void ControlledByPlayerGoal::stop()
bool ControlledByPlayerGoal::canUse()
{
shared_ptr<Player> player = dynamic_pointer_cast<Player>( mob->rider.lock() );
std::shared_ptr<Player> player = std::dynamic_pointer_cast<Player>( mob->rider.lock() );
return mob->isAlive() && player && (boosting || mob->canBeControlledByRider());
}
void ControlledByPlayerGoal::tick()
{
shared_ptr<Player> player = dynamic_pointer_cast<Player>(mob->rider.lock());
std::shared_ptr<Player> player = std::dynamic_pointer_cast<Player>(mob->rider.lock());
PathfinderMob *pig = (PathfinderMob *)mob;
float yrd = Mth::wrapDegrees(player->yRot - mob->yRot) * 0.5f;
@@ -80,7 +80,7 @@ void ControlledByPlayerGoal::tick()
float sin = Mth::sin(pig->yRot * PI / 180);
float cos = Mth::cos(pig->yRot * PI / 180);
float aproxSpeed = pig->getSpeed() * friction2;
float dist = max((int)moveSpeed, 1);
float dist = std::max((int)moveSpeed, 1);
dist = aproxSpeed / dist;
float normMoveSpeed = moveSpeed * dist;
float xa = -(normMoveSpeed * sin);
@@ -116,7 +116,7 @@ void ControlledByPlayerGoal::tick()
if (!player->abilities.instabuild && speed >= maxSpeed * 0.5f && mob->getRandom()->nextFloat() < 0.006f && !boosting)
{
shared_ptr<ItemInstance> carriedItem = player->getCarriedItem();
std::shared_ptr<ItemInstance> carriedItem = player->getCarriedItem();
if (carriedItem != NULL && carriedItem->id == Item::carrotOnAStick_Id)
{
@@ -124,7 +124,7 @@ void ControlledByPlayerGoal::tick()
if (carriedItem->count == 0)
{
shared_ptr<ItemInstance> replacement = shared_ptr<ItemInstance>(new ItemInstance(Item::fishingRod));
std::shared_ptr<ItemInstance> replacement = std::shared_ptr<ItemInstance>(new ItemInstance(Item::fishingRod));
replacement->setTag(carriedItem->tag);
player->inventory->items[player->inventory->selected] = replacement;
}
@@ -11,9 +11,9 @@ DefendVillageTargetGoal::DefendVillageTargetGoal(VillagerGolem *golem) : TargetG
bool DefendVillageTargetGoal::canUse()
{
shared_ptr<Village> village = golem->getVillage();
std::shared_ptr<Village> village = golem->getVillage();
if (village == NULL) return false;
potentialTarget = weak_ptr<Mob>(village->getClosestAggressor(dynamic_pointer_cast<Mob>(golem->shared_from_this())));
potentialTarget = std::weak_ptr<Mob>(village->getClosestAggressor(std::dynamic_pointer_cast<Mob>(golem->shared_from_this())));
return canAttack(potentialTarget.lock(), false);
}
@@ -8,7 +8,7 @@ class DefendVillageTargetGoal : public TargetGoal
{
private:
VillagerGolem *golem; // Owner of this goal
weak_ptr<Mob> potentialTarget;
std::weak_ptr<Mob> potentialTarget;
public:
DefendVillageTargetGoal(VillagerGolem *golem);
@@ -23,7 +23,7 @@ bool DoorInteractGoal::canUse()
Path *path = pathNav->getPath();
if (path == NULL || path->isDone() || !pathNav->canOpenDoors()) return false;
for (int i = 0; i < min(path->getIndex() + 2, path->getSize()); ++i)
for (int i = 0; i < std::min(path->getIndex() + 2, path->getSize()); ++i)
{
Node *n = path->get(i);
doorX = n->x;
+1 -1
View File
@@ -51,7 +51,7 @@ int EatTileGoal::getEatAnimationTick()
void EatTileGoal::tick()
{
eatAnimationTick = max(0, eatAnimationTick - 1);
eatAnimationTick = std::max(0, eatAnimationTick - 1);
if (eatAnimationTick != 4) return;
int xx = Mth::floor(mob->x);
+4 -4
View File
@@ -9,7 +9,7 @@
FollowOwnerGoal::FollowOwnerGoal(TamableAnimal *tamable, float speed, float startDistance, float stopDistance)
{
owner = weak_ptr<Mob>();
owner = std::weak_ptr<Mob>();
timeToRecalcPath = 0;
oldAvoidWater = false;
@@ -24,11 +24,11 @@ FollowOwnerGoal::FollowOwnerGoal(TamableAnimal *tamable, float speed, float star
bool FollowOwnerGoal::canUse()
{
shared_ptr<Mob> owner = tamable->getOwner();
std::shared_ptr<Mob> owner = tamable->getOwner();
if (owner == NULL) return false;
if (tamable->isSitting()) return false;
if (tamable->distanceToSqr(owner) < startDistance * startDistance) return false;
this->owner = weak_ptr<Mob>(owner);
this->owner = std::weak_ptr<Mob>(owner);
return true;
}
@@ -46,7 +46,7 @@ void FollowOwnerGoal::start()
void FollowOwnerGoal::stop()
{
owner = weak_ptr<Mob>();
owner = std::weak_ptr<Mob>();
navigation->stop();
tamable->getNavigation()->setAvoidWater(oldAvoidWater);
}
+1 -1
View File
@@ -12,7 +12,7 @@ public:
private:
TamableAnimal *tamable; // Owner of this goal
weak_ptr<Mob> owner;
std::weak_ptr<Mob> owner;
Level *level;
float speed;
PathNavigation *navigation;
@@ -18,13 +18,13 @@ bool FollowParentGoal::canUse()
{
if (animal->getAge() >= 0) return false;
vector<shared_ptr<Entity> > *parents = animal->level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(8, 4, 8));
std::vector<std::shared_ptr<Entity> > *parents = animal->level->getEntitiesOfClass(typeid(*animal), animal->bb->grow(8, 4, 8));
shared_ptr<Animal> closest = nullptr;
std::shared_ptr<Animal> closest = nullptr;
double closestDistSqr = Double::MAX_VALUE;
for(AUTO_VAR(it, parents->begin()); it != parents->end(); ++it)
{
shared_ptr<Animal> parent = dynamic_pointer_cast<Animal>(*it);
std::shared_ptr<Animal> parent = std::dynamic_pointer_cast<Animal>(*it);
if (parent->getAge() < 0) continue;
double distSqr = animal->distanceToSqr(parent);
if (distSqr > closestDistSqr) continue;
@@ -35,7 +35,7 @@ bool FollowParentGoal::canUse()
if (closest == NULL) return false;
if (closestDistSqr < 3 * 3) return false;
parent = weak_ptr<Animal>(closest);
parent = std::weak_ptr<Animal>(closest);
return true;
}
@@ -54,7 +54,7 @@ void FollowParentGoal::start()
void FollowParentGoal::stop()
{
parent = weak_ptr<Animal>();
parent = std::weak_ptr<Animal>();
}
void FollowParentGoal::tick()
+1 -1
View File
@@ -8,7 +8,7 @@ class FollowParentGoal : public Goal
{
private:
Animal *animal; // Owner of this goal
weak_ptr<Animal> parent;
std::weak_ptr<Animal> parent;
float speed;
int timeToRecalcPath;
+2 -2
View File
@@ -32,7 +32,7 @@ void GoalSelector::addGoal(int prio, Goal *goal, bool canDeletePointer /*= true*
void GoalSelector::tick()
{
vector<InternalGoal *> toStart;
std::vector<InternalGoal *> toStart;
if(tickCount++ % newGoalRate == 0)
{
@@ -97,7 +97,7 @@ void GoalSelector::tick()
}
}
vector<GoalSelector::InternalGoal *> *GoalSelector::getRunningGoals()
std::vector<GoalSelector::InternalGoal *> *GoalSelector::getRunningGoals()
{
return &usingGoals;
}
+4 -4
View File
@@ -1,5 +1,5 @@
#pragma once
using namespace std;
class Goal;
@@ -18,8 +18,8 @@ private:
};
private:
vector<InternalGoal *> goals;
vector<InternalGoal *> usingGoals;
std::vector<InternalGoal *> goals;
std::vector<InternalGoal *> usingGoals;
int tickCount;
int newGoalRate;
@@ -30,7 +30,7 @@ public:
// 4J Added canDelete param
void addGoal(int prio, Goal *goal, bool canDeletePointer = true);
void tick();
vector<InternalGoal *> *getRunningGoals();
std::vector<InternalGoal *> *getRunningGoals();
private:
bool canContinueToUse(InternalGoal *ig);
@@ -22,10 +22,10 @@ void HurtByTargetGoal::start()
if (alertSameType)
{
vector<shared_ptr<Entity> > *nearby = mob->level->getEntitiesOfClass(typeid(*mob), AABB::newTemp(mob->x, mob->y, mob->z, mob->x + 1, mob->y + 1, mob->z + 1)->grow(within, 4, within));
std::vector<std::shared_ptr<Entity> > *nearby = mob->level->getEntitiesOfClass(typeid(*mob), AABB::newTemp(mob->x, mob->y, mob->z, mob->x + 1, mob->y + 1, mob->z + 1)->grow(within, 4, within));
for(AUTO_VAR(it, nearby->begin()); it != nearby->end(); ++it)
{
shared_ptr<Mob> other = dynamic_pointer_cast<Mob>(*it);
std::shared_ptr<Mob> other = std::dynamic_pointer_cast<Mob>(*it);
if (this->mob->shared_from_this() == other) continue;
if (other->getTarget() != NULL) continue;
other->setTarget(mob->getLastHurtByMob());
+1 -1
View File
@@ -6,7 +6,7 @@ class HurtByTargetGoal : public TargetGoal
{
private:
bool alertSameType;
shared_ptr<Mob> oldHurtByMob;
std::shared_ptr<Mob> oldHurtByMob;
public:
HurtByTargetGoal(Mob *mob, bool alertSameType);
+2 -2
View File
@@ -2,12 +2,12 @@
#include "../../Headers/net.minecraft.world.entity.ai.control.h"
#include "InteractGoal.h"
InteractGoal::InteractGoal(Mob *mob, const type_info& lookAtType, float lookDistance) : LookAtPlayerGoal(mob, lookAtType, lookDistance)
InteractGoal::InteractGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance) : LookAtPlayerGoal(mob, lookAtType, lookDistance)
{
setRequiredControlFlags(Control::LookControlFlag | Control::MoveControlFlag);
}
InteractGoal::InteractGoal(Mob *mob, const type_info& lookAtType, float lookDistance, float probability) : LookAtPlayerGoal(mob, lookAtType, lookDistance, probability)
InteractGoal::InteractGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance, float probability) : LookAtPlayerGoal(mob, lookAtType, lookDistance, probability)
{
setRequiredControlFlags(Control::LookControlFlag | Control::MoveControlFlag);
}
+2 -2
View File
@@ -5,6 +5,6 @@
class InteractGoal : public LookAtPlayerGoal
{
public:
InteractGoal(Mob *mob, const type_info& lookAtType, float lookDistance);
InteractGoal(Mob *mob, const type_info& lookAtType, float lookDistance, float probability);
InteractGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance);
InteractGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance, float probability);
};
@@ -5,7 +5,7 @@
LeapAtTargetGoal::LeapAtTargetGoal(Mob *mob, float yd)
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
this->mob = mob;
this->yd = yd;
@@ -14,7 +14,7 @@ LeapAtTargetGoal::LeapAtTargetGoal(Mob *mob, float yd)
bool LeapAtTargetGoal::canUse()
{
target = weak_ptr<Mob>(mob->getTarget());
target = std::weak_ptr<Mob>(mob->getTarget());
if (target.lock() == NULL) return false;
double d = mob->distanceToSqr(target.lock());
if (d < 2 * 2 || d > 4 * 4) return false;
+1 -1
View File
@@ -6,7 +6,7 @@ class LeapAtTargetGoal : public Goal
{
private:
Mob *mob; // Owner of this goal
weak_ptr<Mob> target;
std::weak_ptr<Mob> target;
float yd;
public:
@@ -5,7 +5,7 @@
#include "../../Headers/net.minecraft.world.phys.h"
#include "LookAtPlayerGoal.h"
LookAtPlayerGoal::LookAtPlayerGoal(Mob *mob, const type_info& lookAtType, float lookDistance) : lookAtType(lookAtType)
LookAtPlayerGoal::LookAtPlayerGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance) : lookAtType(lookAtType)
{
this->mob = mob;
this->lookDistance = lookDistance;
@@ -15,7 +15,7 @@ LookAtPlayerGoal::LookAtPlayerGoal(Mob *mob, const type_info& lookAtType, float
lookTime = 0;
}
LookAtPlayerGoal::LookAtPlayerGoal(Mob *mob, const type_info& lookAtType, float lookDistance, float probability) : lookAtType(lookAtType)
LookAtPlayerGoal::LookAtPlayerGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance, float probability) : lookAtType(lookAtType)
{
this->mob = mob;
this->lookDistance = lookDistance;
@@ -29,7 +29,7 @@ bool LookAtPlayerGoal::canUse()
{
if (mob->getRandom()->nextFloat() >= probability) return false;
if (lookAtType == typeid(Player)) lookAt = mob->level->getNearestPlayer(mob->shared_from_this(), lookDistance);
else lookAt = weak_ptr<Entity>(mob->level->getClosestEntityOfClass(lookAtType, mob->bb->grow(lookDistance, 3, lookDistance), mob->shared_from_this()));
else lookAt = std::weak_ptr<Entity>(mob->level->getClosestEntityOfClass(lookAtType, mob->bb->grow(lookDistance, 3, lookDistance), mob->shared_from_this()));
return lookAt.lock() != NULL;
}
@@ -47,7 +47,7 @@ void LookAtPlayerGoal::start()
void LookAtPlayerGoal::stop()
{
lookAt = weak_ptr<Entity>();
lookAt = std::weak_ptr<Entity>();
}
void LookAtPlayerGoal::tick()
+4 -4
View File
@@ -11,17 +11,17 @@ private:
Mob *mob; // Owner of this goal
protected:
weak_ptr<Entity> lookAt;
std::weak_ptr<Entity> lookAt;
private:
float lookDistance;
int lookTime;
float probability;
const type_info& lookAtType;
const std::type_info& lookAtType;
public:
LookAtPlayerGoal(Mob *mob, const type_info& lookAtType, float lookDistance);
LookAtPlayerGoal(Mob *mob, const type_info& lookAtType, float lookDistance, float probability);
LookAtPlayerGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance);
LookAtPlayerGoal(Mob *mob, const std::type_info& lookAtType, float lookDistance, float probability);
virtual ~LookAtPlayerGoal() {}
virtual bool canUse();
@@ -12,7 +12,7 @@ bool LookAtTradingPlayerGoal::canUse()
{
if (villager->isTrading())
{
lookAt = weak_ptr<Entity>(dynamic_pointer_cast<Entity>(villager->getTradingPlayer()));
lookAt = std::weak_ptr<Entity>(std::dynamic_pointer_cast<Entity>(villager->getTradingPlayer()));
return true;
}
return false;
+8 -8
View File
@@ -10,8 +10,8 @@
MakeLoveGoal::MakeLoveGoal(Villager *villager)
{
village = weak_ptr<Village>();
partner = weak_ptr<Villager>();
village = std::weak_ptr<Village>();
partner = std::weak_ptr<Villager>();
loveMakingTime = 0;
this->villager = villager;
@@ -29,10 +29,10 @@ bool MakeLoveGoal::canUse()
if (village.lock() == NULL) return false;
if (!villageNeedsMoreVillagers()) return false;
shared_ptr<Entity> mate = level->getClosestEntityOfClass(typeid(Villager), villager->bb->grow(8, 3, 8), villager->shared_from_this());
std::shared_ptr<Entity> mate = level->getClosestEntityOfClass(typeid(Villager), villager->bb->grow(8, 3, 8), villager->shared_from_this());
if (mate == NULL) return false;
partner = weak_ptr<Villager>(dynamic_pointer_cast<Villager>(mate));
partner = std::weak_ptr<Villager>(std::dynamic_pointer_cast<Villager>(mate));
if (partner.lock()->getAge() != 0) return false;
return true;
@@ -46,8 +46,8 @@ void MakeLoveGoal::start()
void MakeLoveGoal::stop()
{
village = weak_ptr<Village>();
partner = weak_ptr<Villager>();
village = std::weak_ptr<Village>();
partner = std::weak_ptr<Villager>();
villager->setInLove(false);
}
@@ -75,7 +75,7 @@ void MakeLoveGoal::tick()
bool MakeLoveGoal::villageNeedsMoreVillagers()
{
shared_ptr<Village> _village = village.lock();
std::shared_ptr<Village> _village = village.lock();
if( _village == NULL ) return false;
int idealSize = (int) ((float) _village->getDoorCount() * 0.35);
@@ -93,7 +93,7 @@ void MakeLoveGoal::breed()
// 4J - added limit to number of animals that can be bred
if(level->canCreateMore( eTYPE_VILLAGER, Level::eSpawnType_Breed) )
{
shared_ptr<Villager> child = shared_ptr<Villager>( new Villager(level) );
std::shared_ptr<Villager> child = std::shared_ptr<Villager>( new Villager(level) );
child->setAge(-20 * 60 * 20);
child->setProfession(villager->getRandom()->nextInt(Villager::PROFESSION_MAX));
child->moveTo(villager->x, villager->y, villager->z, 0, 0);
+2 -2
View File
@@ -9,10 +9,10 @@ class MakeLoveGoal : public Goal
{
private:
Villager *villager; // Owner of this goal
weak_ptr<Villager> partner;
std::weak_ptr<Villager> partner;
Level *level;
int loveMakingTime;
weak_ptr<Village> village;
std::weak_ptr<Village> village;
public:
MakeLoveGoal(Villager *villager);
+5 -5
View File
@@ -42,11 +42,11 @@ MeleeAttackGoal::~MeleeAttackGoal()
bool MeleeAttackGoal::canUse()
{
shared_ptr<Mob> bestTarget = mob->getTarget();
std::shared_ptr<Mob> bestTarget = mob->getTarget();
if (bestTarget == NULL) return false;
if(!bestTarget->isAlive()) return false;
if (attackType != eTYPE_NOTSET && (attackType & bestTarget->GetType()) != attackType) return false;
target = weak_ptr<Mob>(bestTarget);
target = std::weak_ptr<Mob>(bestTarget);
delete path;
path = mob->getNavigation()->createPath(target.lock());
return path != NULL;
@@ -54,7 +54,7 @@ bool MeleeAttackGoal::canUse()
bool MeleeAttackGoal::canContinueToUse()
{
shared_ptr<Mob> bestTarget = mob->getTarget();
std::shared_ptr<Mob> bestTarget = mob->getTarget();
if (bestTarget == NULL) return false;
if (target.lock() == NULL || !target.lock()->isAlive()) return false;
if (!trackTarget) return !mob->getNavigation()->isDone();
@@ -71,7 +71,7 @@ void MeleeAttackGoal::start()
void MeleeAttackGoal::stop()
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
mob->getNavigation()->stop();
}
@@ -87,7 +87,7 @@ void MeleeAttackGoal::tick()
}
}
attackTime = max(attackTime - 1, 0);
attackTime = std::max(attackTime - 1, 0);
double meleeRadiusSqr = (mob->bbWidth * 2) * (mob->bbWidth * 2);
if (mob->distanceToSqr(target.lock()->x, target.lock()->bb->y0, target.lock()->z) > meleeRadiusSqr) return;
+1 -1
View File
@@ -11,7 +11,7 @@ class MeleeAttackGoal : public Goal
private:
Level *level;
Mob *mob; // Owner of this goal
weak_ptr<Mob> target;
std::weak_ptr<Mob> target;
int attackTime;
float speed;
+8 -8
View File
@@ -21,9 +21,9 @@ bool MoveIndoorsGoal::canUse()
if ((mob->level->isDay() && !mob->level->isRaining()) || mob->level->dimension->hasCeiling) return false;
if (mob->getRandom()->nextInt(50) != 0) return false;
if (insideX != -1 && mob->distanceToSqr(insideX, mob->y, insideZ) < 2 * 2) return false;
shared_ptr<Village> village = mob->level->villages->getClosestVillage(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z), 14);
std::shared_ptr<Village> village = mob->level->villages->getClosestVillage(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z), 14);
if (village == NULL) return false;
shared_ptr<DoorInfo> _doorInfo = village->getBestDoorInfo(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z));
std::shared_ptr<DoorInfo> _doorInfo = village->getBestDoorInfo(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z));
doorInfo = _doorInfo;
return _doorInfo != NULL;
}
@@ -36,15 +36,15 @@ bool MoveIndoorsGoal::canContinueToUse()
void MoveIndoorsGoal::start()
{
insideX = -1;
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
std::shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if( _doorInfo == NULL )
{
doorInfo = weak_ptr<DoorInfo>();
doorInfo = std::weak_ptr<DoorInfo>();
return;
}
if (mob->distanceToSqr(_doorInfo->getIndoorX(), _doorInfo->y, _doorInfo->getIndoorZ()) > 16 * 16)
{
Vec3 *pos = RandomPos::getPosTowards(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 14, 3, Vec3::newTemp(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(), _doorInfo->getIndoorZ() + 0.5));
Vec3 *pos = RandomPos::getPosTowards(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 14, 3, Vec3::newTemp(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(), _doorInfo->getIndoorZ() + 0.5));
if (pos != NULL) mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, 0.3f);
}
else mob->getNavigation()->moveTo(_doorInfo->getIndoorX() + 0.5, _doorInfo->getIndoorY(), _doorInfo->getIndoorZ() + 0.5, 0.3f);
@@ -52,14 +52,14 @@ void MoveIndoorsGoal::start()
void MoveIndoorsGoal::stop()
{
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
std::shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if( _doorInfo == NULL )
{
doorInfo = weak_ptr<DoorInfo>();
doorInfo = std::weak_ptr<DoorInfo>();
return;
}
insideX = _doorInfo->getIndoorX();
insideZ = _doorInfo->getIndoorZ();
doorInfo = weak_ptr<DoorInfo>();
doorInfo = std::weak_ptr<DoorInfo>();
}
+1 -1
View File
@@ -9,7 +9,7 @@ class MoveIndoorsGoal : public Goal
{
private:
PathfinderMob *mob;
weak_ptr<DoorInfo> doorInfo;
std::weak_ptr<DoorInfo> doorInfo;
int insideX, insideZ;
public:
@@ -12,7 +12,7 @@
MoveThroughVillageGoal::MoveThroughVillageGoal(PathfinderMob *mob, float speed, bool onlyAtNight)
{
path = NULL;
doorInfo = weak_ptr<DoorInfo>();
doorInfo = std::weak_ptr<DoorInfo>();
this->mob = mob;
this->speed = speed;
@@ -31,10 +31,10 @@ bool MoveThroughVillageGoal::canUse()
if (onlyAtNight && mob->level->isDay()) return false;
shared_ptr<Village> village = mob->level->villages->getClosestVillage(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z), 0);
std::shared_ptr<Village> village = mob->level->villages->getClosestVillage(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z), 0);
if (village == NULL) return false;
shared_ptr<DoorInfo> _doorInfo = getNextDoorInfo(village);
std::shared_ptr<DoorInfo> _doorInfo = getNextDoorInfo(village);
if (_doorInfo == NULL) return false;
doorInfo = _doorInfo;
@@ -46,7 +46,7 @@ bool MoveThroughVillageGoal::canUse()
mob->getNavigation()->setCanOpenDoors(oldCanOpenDoors);
if (path != NULL) return true;
Vec3 *pos = RandomPos::getPosTowards(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10, 7, Vec3::newTemp(_doorInfo->x, _doorInfo->y, _doorInfo->z));
Vec3 *pos = RandomPos::getPosTowards(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10, 7, Vec3::newTemp(_doorInfo->x, _doorInfo->y, _doorInfo->z));
if (pos == NULL) return false;
mob->getNavigation()->setCanOpenDoors(false);
delete path;
@@ -59,7 +59,7 @@ bool MoveThroughVillageGoal::canContinueToUse()
{
if (mob->getNavigation()->isDone()) return false;
float dist = mob->bbWidth + 4.f;
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
std::shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if( _doorInfo == NULL ) return false;
return mob->distanceToSqr(_doorInfo->x, _doorInfo->y, _doorInfo->z) > dist * dist;
@@ -73,7 +73,7 @@ void MoveThroughVillageGoal::start()
void MoveThroughVillageGoal::stop()
{
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
std::shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if( _doorInfo == NULL ) return;
if (mob->getNavigation()->isDone() || mob->distanceToSqr(_doorInfo->x, _doorInfo->y, _doorInfo->z) < 4 * 4)
@@ -82,15 +82,15 @@ void MoveThroughVillageGoal::stop()
}
}
shared_ptr<DoorInfo> MoveThroughVillageGoal::getNextDoorInfo(shared_ptr<Village> village)
std::shared_ptr<DoorInfo> MoveThroughVillageGoal::getNextDoorInfo(std::shared_ptr<Village> village)
{
shared_ptr<DoorInfo> closest = nullptr;
std::shared_ptr<DoorInfo> closest = nullptr;
int closestDistSqr = Integer::MAX_VALUE;
vector<shared_ptr<DoorInfo> > *doorInfos = village->getDoorInfos();
std::vector<std::shared_ptr<DoorInfo> > *doorInfos = village->getDoorInfos();
//for (DoorInfo di : doorInfos)
for(AUTO_VAR(it, doorInfos->begin()); it != doorInfos->end(); ++it)
{
shared_ptr<DoorInfo> di = *it;
std::shared_ptr<DoorInfo> di = *it;
int distSqr = di->distanceToSqr(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z));
if (distSqr < closestDistSqr)
{
@@ -102,12 +102,12 @@ shared_ptr<DoorInfo> MoveThroughVillageGoal::getNextDoorInfo(shared_ptr<Village>
return closest;
}
bool MoveThroughVillageGoal::hasVisited(shared_ptr<DoorInfo>di)
bool MoveThroughVillageGoal::hasVisited(std::shared_ptr<DoorInfo>di)
{
//for (DoorInfo di2 : visited)
for(AUTO_VAR(it, visited.begin()); it != visited.end(); )
{
shared_ptr<DoorInfo> di2 = (*it).lock();
std::shared_ptr<DoorInfo> di2 = (*it).lock();
if( di2 == NULL )
{
it = visited.erase(it);
@@ -12,9 +12,9 @@ private:
PathfinderMob *mob;
float speed;
Path *path;
weak_ptr<DoorInfo> doorInfo;
std::weak_ptr<DoorInfo> doorInfo;
bool onlyAtNight;
vector< weak_ptr<DoorInfo> > visited;
std::vector< std::weak_ptr<DoorInfo> > visited;
public:
MoveThroughVillageGoal(PathfinderMob *mob, float speed, bool onlyAtNight);
@@ -26,7 +26,7 @@ public:
virtual void stop();
private:
shared_ptr<DoorInfo> getNextDoorInfo(shared_ptr<Village> village);
bool hasVisited(shared_ptr<DoorInfo> di);
std::shared_ptr<DoorInfo> getNextDoorInfo(std::shared_ptr<Village> village);
bool hasVisited(std::shared_ptr<DoorInfo> di);
void updateVisited();
};
@@ -19,7 +19,7 @@ bool MoveTowardsRestrictionGoal::canUse()
{
if (mob->isWithinRestriction()) return false;
Pos *towards = mob->getRestrictCenter();
Vec3 *pos = RandomPos::getPosTowards(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 7, Vec3::newTemp(towards->x, towards->y, towards->z));
Vec3 *pos = RandomPos::getPosTowards(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 7, Vec3::newTemp(towards->x, towards->y, towards->z));
if (pos == NULL) return false;
wantedX = pos->x;
wantedY = pos->y;
@@ -16,10 +16,10 @@ MoveTowardsTargetGoal::MoveTowardsTargetGoal(PathfinderMob *mob, float speed, fl
bool MoveTowardsTargetGoal::canUse()
{
target = weak_ptr<Mob>(mob->getTarget());
target = std::weak_ptr<Mob>(mob->getTarget());
if (target.lock() == NULL) return false;
if (target.lock()->distanceToSqr(mob->shared_from_this()) > within * within) return false;
Vec3 *pos = RandomPos::getPosTowards(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 7, Vec3::newTemp(target.lock()->x, target.lock()->y, target.lock()->z));
Vec3 *pos = RandomPos::getPosTowards(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 7, Vec3::newTemp(target.lock()->x, target.lock()->y, target.lock()->z));
if (pos == NULL) return false;
wantedX = pos->x;
wantedY = pos->y;
@@ -34,7 +34,7 @@ bool MoveTowardsTargetGoal::canContinueToUse()
void MoveTowardsTargetGoal::stop()
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
}
void MoveTowardsTargetGoal::start()
@@ -6,7 +6,7 @@ class MoveTowardsTargetGoal : public Goal
{
private:
PathfinderMob *mob;
weak_ptr<Mob> target;
std::weak_ptr<Mob> target;
double wantedX, wantedY, wantedZ;
float speed, within;
@@ -9,7 +9,7 @@ NearestAttackableTargetGoal::DistComp::DistComp(Entity *source)
this->source = source;
}
bool NearestAttackableTargetGoal::DistComp::operator() (shared_ptr<Entity> e1, shared_ptr<Entity> e2)
bool NearestAttackableTargetGoal::DistComp::operator() (std::shared_ptr<Entity> e1, std::shared_ptr<Entity> e2)
{
// Should return true if e1 comes before e2 in the sorted list
double distSqr1 = source->distanceToSqr(e1);
@@ -19,7 +19,7 @@ bool NearestAttackableTargetGoal::DistComp::operator() (shared_ptr<Entity> e1, s
return true;
}
NearestAttackableTargetGoal::NearestAttackableTargetGoal(Mob *mob, const type_info& targetType, float within, int randomInterval, bool mustSee, bool mustReach /*= false*/) : TargetGoal(mob, within, mustSee, mustReach), targetType(targetType)
NearestAttackableTargetGoal::NearestAttackableTargetGoal(Mob *mob, const std::type_info& targetType, float within, int randomInterval, bool mustSee, bool mustReach /*= false*/) : TargetGoal(mob, within, mustSee, mustReach), targetType(targetType)
{
//this->targetType = targetType;
this->within = within;
@@ -38,24 +38,24 @@ bool NearestAttackableTargetGoal::canUse()
if (randomInterval > 0 && mob->getRandom()->nextInt(randomInterval) != 0) return false;
if (targetType == typeid(Player))
{
shared_ptr<Mob> potentialTarget = mob->level->getNearestAttackablePlayer(mob->shared_from_this(), within);
std::shared_ptr<Mob> potentialTarget = mob->level->getNearestAttackablePlayer(mob->shared_from_this(), within);
if (canAttack(potentialTarget, false))
{
target = weak_ptr<Mob>(potentialTarget);
target = std::weak_ptr<Mob>(potentialTarget);
return true;
}
}
else
{
vector<shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(targetType, mob->bb->grow(within, 4, within));
std::vector<std::shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(targetType, mob->bb->grow(within, 4, within));
//Collections.sort(entities, distComp);
std::sort(entities->begin(), entities->end(), *distComp);
for(AUTO_VAR(it, entities->begin()); it != entities->end(); ++it)
{
shared_ptr<Mob> potTarget = dynamic_pointer_cast<Mob>(*it);
std::shared_ptr<Mob> potTarget = std::dynamic_pointer_cast<Mob>(*it);
if (canAttack(potTarget, false))
{
target = weak_ptr<Mob>(potTarget);
target = std::weak_ptr<Mob>(potTarget);
return true;
}
}
@@ -13,22 +13,22 @@ public:
public:
DistComp(Entity *source);
bool operator() (shared_ptr<Entity> e1, shared_ptr<Entity> e2);
bool operator() (std::shared_ptr<Entity> e1, std::shared_ptr<Entity> e2);
};
private:
weak_ptr<Mob> target;
const type_info& targetType;
std::weak_ptr<Mob> target;
const std::type_info& targetType;
int randomInterval;
DistComp *distComp;
public:
//public NearestAttackableTargetGoal(Mob mob, const type_info& targetType, float within, int randomInterval, bool mustSee)
//public NearestAttackableTargetGoal(Mob mob, const std::type_info& targetType, float within, int randomInterval, bool mustSee)
//{
// this(mob, targetType, within, randomInterval, mustSee, false);
//}
NearestAttackableTargetGoal(Mob *mob, const type_info& targetType, float within, int randomInterval, bool mustSee, bool mustReach = false);
NearestAttackableTargetGoal(Mob *mob, const std::type_info& targetType, float within, int randomInterval, bool mustSee, bool mustReach = false);
virtual ~NearestAttackableTargetGoal();
virtual bool canUse();
@@ -2,7 +2,7 @@
#include "../../Headers/net.minecraft.world.entity.animal.h"
#include "NonTameRandomTargetGoal.h"
NonTameRandomTargetGoal::NonTameRandomTargetGoal(TamableAnimal *mob, const type_info& targetType, float within, int randomInterval, bool mustSee) : NearestAttackableTargetGoal(mob, targetType, within, randomInterval, mustSee)
NonTameRandomTargetGoal::NonTameRandomTargetGoal(TamableAnimal *mob, const std::type_info& targetType, float within, int randomInterval, bool mustSee) : NearestAttackableTargetGoal(mob, targetType, within, randomInterval, mustSee)
{
this->tamableMob = mob;
}
@@ -10,7 +10,7 @@ private:
TamableAnimal *tamableMob; // Owner of this goal
public:
NonTameRandomTargetGoal(TamableAnimal *mob, const type_info& targetType, float within, int randomInterval, bool mustSee);
NonTameRandomTargetGoal(TamableAnimal *mob, const std::type_info& targetType, float within, int randomInterval, bool mustSee);
bool canUse();
};
@@ -8,7 +8,7 @@
OzelotAttackGoal::OzelotAttackGoal(Mob *mob)
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
attackTime = 0;
speed = 0;
trackTarget = false;
@@ -20,9 +20,9 @@ OzelotAttackGoal::OzelotAttackGoal(Mob *mob)
bool OzelotAttackGoal::canUse()
{
shared_ptr<Mob> bestTarget = mob->getTarget();
std::shared_ptr<Mob> bestTarget = mob->getTarget();
if (bestTarget == NULL) return false;
target = weak_ptr<Mob>(bestTarget);
target = std::weak_ptr<Mob>(bestTarget);
return true;
}
@@ -35,7 +35,7 @@ bool OzelotAttackGoal::canContinueToUse()
void OzelotAttackGoal::stop()
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
mob->getNavigation()->stop();
}
@@ -52,7 +52,7 @@ void OzelotAttackGoal::tick()
mob->getNavigation()->moveTo(target.lock(), speed);
attackTime = max(attackTime - 1, 0);
attackTime = std::max(attackTime - 1, 0);
if (distSqr > meleeRadiusSqr) return;
if (attackTime > 0) return;
+1 -1
View File
@@ -7,7 +7,7 @@ class OzelotAttackGoal : public Goal
private:
Level *level;
Mob *mob;
weak_ptr<Mob> target;
std::weak_ptr<Mob> target;
int attackTime;
float speed;
bool trackTarget;
@@ -107,7 +107,7 @@ bool OcelotSitOnTileGoal::isValidTarget(Level *level, int x, int y, int z)
if (tile == Tile::chest_Id)
{
shared_ptr<ChestTileEntity> chest = dynamic_pointer_cast<ChestTileEntity>(level->getTileEntity(x, y, z));
std::shared_ptr<ChestTileEntity> chest = std::dynamic_pointer_cast<ChestTileEntity>(level->getTileEntity(x, y, z));
if (chest->openCount < 1)
{
+2 -2
View File
@@ -16,7 +16,7 @@ bool OfferFlowerGoal::canUse()
{
if (!golem->level->isDay()) return false;
if (golem->getRandom()->nextInt(8000) != 0) return false;
villager = weak_ptr<Villager>(dynamic_pointer_cast<Villager>( golem->level->getClosestEntityOfClass(typeid(Villager), golem->bb->grow(6, 2, 6), golem->shared_from_this()) ));
villager = std::weak_ptr<Villager>(std::dynamic_pointer_cast<Villager>( golem->level->getClosestEntityOfClass(typeid(Villager), golem->bb->grow(6, 2, 6), golem->shared_from_this()) ));
return villager.lock() != NULL;
}
@@ -34,7 +34,7 @@ void OfferFlowerGoal::start()
void OfferFlowerGoal::stop()
{
golem->offerFlower(false);
villager = weak_ptr<Villager>();
villager = std::weak_ptr<Villager>();
}
void OfferFlowerGoal::tick()
+1 -1
View File
@@ -11,7 +11,7 @@ public:
private:
VillagerGolem *golem;
weak_ptr<Villager> villager;
std::weak_ptr<Villager> villager;
int _tick;
public:
@@ -12,9 +12,9 @@ OwnerHurtByTargetGoal::OwnerHurtByTargetGoal(TamableAnimal *tameAnimal) : Target
bool OwnerHurtByTargetGoal::canUse()
{
if (!tameAnimal->isTame()) return false;
shared_ptr<Mob> owner = tameAnimal->getOwner();
std::shared_ptr<Mob> owner = tameAnimal->getOwner();
if (owner == NULL) return false;
ownerLastHurtBy = weak_ptr<Mob>(owner->getLastHurtByMob());
ownerLastHurtBy = std::weak_ptr<Mob>(owner->getLastHurtByMob());
return canAttack(ownerLastHurtBy.lock(), false);
}
@@ -8,7 +8,7 @@ class OwnerHurtByTargetGoal : public TargetGoal
{
private:
TamableAnimal *tameAnimal; // Owner of this goal
weak_ptr<Mob> ownerLastHurtBy;
std::weak_ptr<Mob> ownerLastHurtBy;
public:
OwnerHurtByTargetGoal(TamableAnimal *tameAnimal);
@@ -12,9 +12,9 @@ OwnerHurtTargetGoal::OwnerHurtTargetGoal(TamableAnimal *tameAnimal) : TargetGoal
bool OwnerHurtTargetGoal::canUse()
{
if (!tameAnimal->isTame()) return false;
shared_ptr<Mob> owner = tameAnimal->getOwner();
std::shared_ptr<Mob> owner = tameAnimal->getOwner();
if (owner == NULL) return false;
ownerLastHurt = weak_ptr<Mob>(owner->getLastHurtMob());
ownerLastHurt = std::weak_ptr<Mob>(owner->getLastHurtMob());
return canAttack(ownerLastHurt.lock(), false);
}
@@ -8,7 +8,7 @@ class OwnerHurtTargetGoal : public TargetGoal
{
private:
TamableAnimal *tameAnimal; // Owner of this goal
weak_ptr<Mob> ownerLastHurt;
std::weak_ptr<Mob> ownerLastHurt;
public:
OwnerHurtTargetGoal(TamableAnimal *tameAnimal);
+1 -1
View File
@@ -16,7 +16,7 @@ PanicGoal::PanicGoal(PathfinderMob *mob, float speed)
bool PanicGoal::canUse()
{
if (mob->getLastHurtByMob() == NULL) return false;
Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5, 4);
Vec3 *pos = RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 5, 4);
if (pos == NULL) return false;
posX = pos->x;
posY = pos->y;
+8 -8
View File
@@ -11,7 +11,7 @@
PlayGoal::PlayGoal(Villager *mob, float speed)
{
followFriend = weak_ptr<Mob>();
followFriend = std::weak_ptr<Mob>();
wantedX = wantedY = wantedZ = 0.0;
playTime = 0;
@@ -25,26 +25,26 @@ bool PlayGoal::canUse()
if (mob->getAge() >= 0) return false;
if (mob->getRandom()->nextInt(400) != 0) return false;
vector<shared_ptr<Entity> > *children = mob->level->getEntitiesOfClass(typeid(Villager), mob->bb->grow(6, 3, 6));
std::vector<std::shared_ptr<Entity> > *children = mob->level->getEntitiesOfClass(typeid(Villager), mob->bb->grow(6, 3, 6));
double closestDistSqr = Double::MAX_VALUE;
//for (Entity c : children)
for(AUTO_VAR(it, children->begin()); it != children->end(); ++it)
{
shared_ptr<Entity> c = *it;
std::shared_ptr<Entity> c = *it;
if (c.get() == mob) continue;
shared_ptr<Villager> friendV = dynamic_pointer_cast<Villager>(c);
std::shared_ptr<Villager> friendV = std::dynamic_pointer_cast<Villager>(c);
if (friendV->isChasing()) continue;
if (friendV->getAge() >= 0) continue;
double distSqr = friendV->distanceToSqr(mob->shared_from_this());
if (distSqr > closestDistSqr) continue;
closestDistSqr = distSqr;
followFriend = weak_ptr<Mob>(friendV);
followFriend = std::weak_ptr<Mob>(friendV);
}
delete children;
if (followFriend.lock() == NULL)
{
Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 3);
Vec3 *pos = RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 3);
if (pos == NULL) return false;
}
return true;
@@ -64,7 +64,7 @@ void PlayGoal::start()
void PlayGoal::stop()
{
mob->setChasing(false);
followFriend = weak_ptr<Mob>();
followFriend = std::weak_ptr<Mob>();
}
void PlayGoal::tick()
@@ -78,7 +78,7 @@ void PlayGoal::tick()
{
if (mob->getNavigation()->isDone())
{
Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 3);
Vec3 *pos = RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 16, 3);
if (pos == NULL) return;
mob->getNavigation()->moveTo(pos->x, pos->y, pos->z, speed);
}
+1 -1
View File
@@ -6,7 +6,7 @@ class PlayGoal : public Goal
{
private:
Villager *mob;
weak_ptr<Mob> followFriend;
std::weak_ptr<Mob> followFriend;
float speed;
double wantedX, wantedY, wantedZ;
int playTime;
@@ -21,7 +21,7 @@ bool RandomStrollGoal::canUse()
{
if (mob->getRandom()->nextInt(120) == 0)
{
Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10, 7);
Vec3 *pos = RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10, 7);
if (pos == NULL) return false;
wantedX = pos->x;
wantedY = pos->y;
@@ -37,7 +37,7 @@ bool RandomStrollGoal::canUse()
if( mob->isExtraWanderingEnabled() )
{
Vec3 *pos = RandomPos::getPos(dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10, 7,mob->getWanderingQuadrant());
Vec3 *pos = RandomPos::getPos(std::dynamic_pointer_cast<PathfinderMob>(mob->shared_from_this()), 10, 7,mob->getWanderingQuadrant());
if (pos == NULL) return false;
wantedX = pos->x;
wantedY = pos->y;
@@ -13,9 +13,9 @@ RestrictOpenDoorGoal::RestrictOpenDoorGoal(PathfinderMob *mob)
bool RestrictOpenDoorGoal::canUse()
{
if (mob->level->isDay()) return false;
shared_ptr<Village> village = mob->level->villages->getClosestVillage(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z), 16);
std::shared_ptr<Village> village = mob->level->villages->getClosestVillage(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z), 16);
if (village == NULL) return false;
shared_ptr<DoorInfo> _doorInfo = village->getClosestDoorInfo(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z));
std::shared_ptr<DoorInfo> _doorInfo = village->getClosestDoorInfo(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z));
if (_doorInfo == NULL) return false;
doorInfo = _doorInfo;
return _doorInfo->distanceToInsideSqr(Mth::floor(mob->x), Mth::floor(mob->y), Mth::floor(mob->z)) < 1.5 * 1.5;
@@ -24,7 +24,7 @@ bool RestrictOpenDoorGoal::canUse()
bool RestrictOpenDoorGoal::canContinueToUse()
{
if (mob->level->isDay()) return false;
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
std::shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if ( _doorInfo == NULL ) return false;
return !_doorInfo->removed && _doorInfo->isInsideSide(Mth::floor(mob->x), Mth::floor(mob->z));
}
@@ -39,11 +39,11 @@ void RestrictOpenDoorGoal::stop()
{
mob->getNavigation()->setCanOpenDoors(true);
mob->getNavigation()->setCanPassDoors(true);
doorInfo = weak_ptr<DoorInfo>();
doorInfo = std::weak_ptr<DoorInfo>();
}
void RestrictOpenDoorGoal::tick()
{
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
std::shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if ( _doorInfo ) _doorInfo->incBookingCount();
}
@@ -9,7 +9,7 @@ class RestrictOpenDoorGoal : public Goal
{
private:
PathfinderMob *mob;
weak_ptr<DoorInfo> doorInfo;
std::weak_ptr<DoorInfo> doorInfo;
public:
RestrictOpenDoorGoal(PathfinderMob *mob);
+1 -1
View File
@@ -20,7 +20,7 @@ bool SitGoal::canUse()
if (mob->isInWater()) return false;
if (!mob->onGround) return false;
shared_ptr<Mob> owner = mob->getOwner();
std::shared_ptr<Mob> owner = mob->getOwner();
if (owner == NULL) return true; // owner not on level
if (mob->distanceToSqr(owner) < FollowOwnerGoal::TeleportDistance * FollowOwnerGoal::TeleportDistance && owner->getLastHurtByMob() != NULL) return false;
+4 -4
View File
@@ -7,7 +7,7 @@
SwellGoal::SwellGoal(Creeper *creeper)
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
this->creeper = creeper;
setRequiredControlFlags(Control::MoveControlFlag);
@@ -15,19 +15,19 @@ SwellGoal::SwellGoal(Creeper *creeper)
bool SwellGoal::canUse()
{
shared_ptr<Mob> target = creeper->getTarget();
std::shared_ptr<Mob> target = creeper->getTarget();
return creeper->getSwellDir() > 0 || (target != NULL && (creeper->distanceToSqr(target) < 3 * 3));
}
void SwellGoal::start()
{
creeper->getNavigation()->stop();
target = weak_ptr<Mob>(creeper->getTarget());
target = std::weak_ptr<Mob>(creeper->getTarget());
}
void SwellGoal::stop()
{
target = weak_ptr<Mob>();
target = std::weak_ptr<Mob>();
}
void SwellGoal::tick()
+1 -1
View File
@@ -8,7 +8,7 @@ class SwellGoal : public Goal
{
private:
Creeper *creeper;
weak_ptr<Mob> target;
std::weak_ptr<Mob> target;
public:
SwellGoal(Creeper *creeper);
+5 -5
View File
@@ -12,7 +12,7 @@ TakeFlowerGoal::TakeFlowerGoal(Villager *villager)
{
takeFlower = false;
pickupTick = 0;
golem = weak_ptr<VillagerGolem>();
golem = std::weak_ptr<VillagerGolem>();
this->villager = villager;
setRequiredControlFlags(Control::MoveControlFlag | Control::LookControlFlag);
@@ -23,7 +23,7 @@ bool TakeFlowerGoal::canUse()
if (villager->getAge() >= 0) return false;
if (!villager->level->isDay()) return false;
vector<shared_ptr<Entity> > *golems = villager->level->getEntitiesOfClass(typeid(VillagerGolem), villager->bb->grow(6, 2, 6));
std::vector<std::shared_ptr<Entity> > *golems = villager->level->getEntitiesOfClass(typeid(VillagerGolem), villager->bb->grow(6, 2, 6));
if (golems->size() == 0)
{
delete golems;
@@ -33,10 +33,10 @@ bool TakeFlowerGoal::canUse()
//for (Entity e : golems)
for(AUTO_VAR(it,golems->begin()); it != golems->end(); ++it)
{
shared_ptr<VillagerGolem> vg = dynamic_pointer_cast<VillagerGolem>(*it);
std::shared_ptr<VillagerGolem> vg = std::dynamic_pointer_cast<VillagerGolem>(*it);
if (vg->getOfferFlowerTick() > 0)
{
golem = weak_ptr<VillagerGolem>(vg);
golem = std::weak_ptr<VillagerGolem>(vg);
break;
}
}
@@ -58,7 +58,7 @@ void TakeFlowerGoal::start()
void TakeFlowerGoal::stop()
{
golem = weak_ptr<VillagerGolem>();
golem = std::weak_ptr<VillagerGolem>();
villager->getNavigation()->stop();
}
+1 -1
View File
@@ -6,7 +6,7 @@ class TakeFlowerGoal : public Goal
{
private:
Villager *villager;
weak_ptr<VillagerGolem> golem;
std::weak_ptr<VillagerGolem> golem;
int pickupTick;
bool takeFlower;
+7 -7
View File
@@ -32,7 +32,7 @@ TargetGoal::TargetGoal(Mob *mob, float within, bool mustSee, bool mustReach)
bool TargetGoal::canContinueToUse()
{
shared_ptr<Mob> target = mob->getTarget();
std::shared_ptr<Mob> target = mob->getTarget();
if (target == NULL) return false;
if (!target->isAlive()) return false;
if (mob->distanceToSqr(target) > within * within) return false;
@@ -62,23 +62,23 @@ void TargetGoal::stop()
mob->setTarget(nullptr);
}
bool TargetGoal::canAttack(shared_ptr<Mob> target, bool allowInvulnerable)
bool TargetGoal::canAttack(std::shared_ptr<Mob> target, bool allowInvulnerable)
{
if (target == NULL) return false;
if (target == mob->shared_from_this()) return false;
if (!target->isAlive()) return false;
if (!mob->canAttackType(target->GetType())) return false;
shared_ptr<TamableAnimal> tamableAnimal = dynamic_pointer_cast<TamableAnimal>(mob->shared_from_this());
std::shared_ptr<TamableAnimal> tamableAnimal = std::dynamic_pointer_cast<TamableAnimal>(mob->shared_from_this());
if (tamableAnimal != NULL && tamableAnimal->isTame())
{
shared_ptr<TamableAnimal> tamableTarget = dynamic_pointer_cast<TamableAnimal>(target);
std::shared_ptr<TamableAnimal> tamableTarget = std::dynamic_pointer_cast<TamableAnimal>(target);
if (tamableTarget != NULL && tamableTarget->isTame()) return false;
if (target == tamableAnimal->getOwner()) return false;
}
else if (dynamic_pointer_cast<Player>(target) != NULL)
else if (std::dynamic_pointer_cast<Player>(target) != NULL)
{
if (!allowInvulnerable && (dynamic_pointer_cast<Player>(target))->abilities.invulnerable) return false;
if (!allowInvulnerable && (std::dynamic_pointer_cast<Player>(target))->abilities.invulnerable) return false;
}
if (!mob->isWithinRestriction(Mth::floor(target->x), Mth::floor(target->y), Mth::floor(target->z))) return false;
@@ -95,7 +95,7 @@ bool TargetGoal::canAttack(shared_ptr<Mob> target, bool allowInvulnerable)
return true;
}
bool TargetGoal::canReach(shared_ptr<Mob> target)
bool TargetGoal::canReach(std::shared_ptr<Mob> target)
{
reachCacheTime = 10 + mob->getRandom()->nextInt(5);
Path *path = mob->getNavigation()->createPath(target);
+2 -2
View File
@@ -37,8 +37,8 @@ public:
virtual void stop();
protected:
virtual bool canAttack(shared_ptr<Mob> target, bool allowInvulnerable);
virtual bool canAttack(std::shared_ptr<Mob> target, bool allowInvulnerable);
private:
bool canReach(shared_ptr<Mob> target);
bool canReach(std::shared_ptr<Mob> target);
};
+4 -4
View File
@@ -9,7 +9,7 @@
TemptGoal::TemptGoal(PathfinderMob *mob, float speed, int itemId, bool canScare)
{
px = py = pz = pRotX = pRotY = 0.0;
player = weak_ptr<Player>();
player = std::weak_ptr<Player>();
calmDown = 0;
_isRunning = false;
oldAvoidWater = false;
@@ -28,10 +28,10 @@ bool TemptGoal::canUse()
--calmDown;
return false;
}
player = weak_ptr<Player>(mob->level->getNearestPlayer(mob->shared_from_this(), 10));
player = std::weak_ptr<Player>(mob->level->getNearestPlayer(mob->shared_from_this(), 10));
if (player.lock() == NULL) return false;
mob->setDespawnProtected(); // If we've got a nearby player, then consider this mob as something we'd miss if it despawned
shared_ptr<ItemInstance> item = player.lock()->getSelectedItem();
std::shared_ptr<ItemInstance> item = player.lock()->getSelectedItem();
if (item == NULL) return false;
if (item->id != itemId) return false;
return true;
@@ -71,7 +71,7 @@ void TemptGoal::start()
void TemptGoal::stop()
{
player = weak_ptr<Player>();
player = std::weak_ptr<Player>();
mob->getNavigation()->stop();
calmDown = 100;
_isRunning = false;
+1 -1
View File
@@ -8,7 +8,7 @@ private:
PathfinderMob *mob;
float speed;
double px, py, pz, pRotX, pRotY;
weak_ptr<Player> player;
std::weak_ptr<Player> player;
int calmDown ;
bool _isRunning;
int itemId;
@@ -18,7 +18,7 @@ bool TradeWithPlayerGoal::canUse()
if (!mob->onGround) return false;
if (mob->hurtMarked) return false;
shared_ptr<Player> trader = mob->getTradingPlayer();
std::shared_ptr<Player> trader = mob->getTradingPlayer();
if (trader == NULL)
{
// no interaction
+1 -1
View File
@@ -69,7 +69,7 @@ bool Node::inOpenSet()
return heapIdx >= 0;
}
wstring Node::toString()
std::wstring Node::toString()
{
return _toString<int>(x) + L", " + _toString<int>(y) + L", " + _toString<int>(z);
}
+2 -2
View File
@@ -1,5 +1,5 @@
#pragma once
using namespace std;
class Node
{
@@ -34,5 +34,5 @@ public:
bool equals(Node *o);
int hashCode();
bool inOpenSet();
wstring toString();
std::wstring toString();
};
+2 -2
View File
@@ -74,7 +74,7 @@ void Path::setIndex(int index)
this->index = index;
}
Vec3 *Path::getPos(shared_ptr<Entity> e, int index)
Vec3 *Path::getPos(std::shared_ptr<Entity> e, int index)
{
double x = nodes[index]->x + (int) (e->bbWidth + 1) * 0.5;
double y = nodes[index]->y;
@@ -82,7 +82,7 @@ Vec3 *Path::getPos(shared_ptr<Entity> e, int index)
return Vec3::newTemp(x, y, z);
}
Vec3 *Path::currentPos(shared_ptr<Entity> e)
Vec3 *Path::currentPos(std::shared_ptr<Entity> e)
{
return getPos(e, index);
}
+2 -2
View File
@@ -21,9 +21,9 @@ public:
void setSize(int length);
int getIndex();
void setIndex(int index);
Vec3 *getPos(shared_ptr<Entity> e, int index);
Vec3 *getPos(std::shared_ptr<Entity> e, int index);
NodeArray Getarray();
Vec3 *currentPos(shared_ptr<Entity> e);
Vec3 *currentPos(std::shared_ptr<Entity> e);
Vec3 *currentPos();
bool sameAs(Path *path);
bool endsIn(Vec3 *pos);
+1 -1
View File
@@ -193,7 +193,7 @@ Node *PathFinder::getNode(Entity *entity, int x, int y, int z, Node *size, int j
MemSect(54);
node = new Node(x, y, z);
MemSect(0);
nodes.insert( unordered_map<int, Node *>::value_type(i, node) );
nodes.insert( std::unordered_map<int, Node *>::value_type(i, node) );
}
else
{
+2 -2
View File
@@ -1,6 +1,6 @@
#pragma once
#include "../../Util/JavaIntHash.h"
using namespace std;
class LevelSource;
@@ -12,7 +12,7 @@ private:
BinaryHeap openSet;
// 4J Jev, was a IntHashMap, thought this was close enough.
unordered_map<int, Node *, IntKeyHash, IntKeyEq> nodes;
std::unordered_map<int, Node *, IntKeyHash, IntKeyEq> nodes;
NodeArray *neighbors;
@@ -92,13 +92,13 @@ bool PathNavigation::moveTo(double x, double y, double z, float speed)
return moveTo(newPath, speed);
}
Path *PathNavigation::createPath(shared_ptr<Mob> target)
Path *PathNavigation::createPath(std::shared_ptr<Mob> target)
{
if (!canUpdatePath()) return NULL;
return level->findPath(mob->shared_from_this(), target, maxDist, _canPassDoors, _canOpenDoors, avoidWater, canFloat);
}
bool PathNavigation::moveTo(shared_ptr<Mob> target, float speed)
bool PathNavigation::moveTo(std::shared_ptr<Mob> target, float speed)
{
MemSect(53);
Path *newPath = createPath(target);
@@ -37,8 +37,8 @@ public:
void setCanFloat(bool canFloat);
Path *createPath(double x, double y, double z);
bool moveTo(double x, double y, double z, float speed);
Path *createPath(shared_ptr<Mob> target);
bool moveTo(shared_ptr<Mob> target, float speed);
Path *createPath(std::shared_ptr<Mob> target);
bool moveTo(std::shared_ptr<Mob> target, float speed);
bool moveTo(Path *newPath, float speed);
Path *getPath();
void tick();
+4 -4
View File
@@ -5,12 +5,12 @@
Vec3 *RandomPos::tempDir = Vec3::newPermanent(0, 0, 0);
Vec3 *RandomPos::getPos(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, int quadrant/*=-1*/) // 4J - added quadrant
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);
}
Vec3 *RandomPos::getPosTowards(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *towardsPos)
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;
@@ -18,7 +18,7 @@ Vec3 *RandomPos::getPosTowards(shared_ptr<PathfinderMob> mob, int xzDist, int yD
return generateRandomPos(mob, xzDist, yDist, tempDir);
}
Vec3 *RandomPos::getPosAvoid(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *avoidPos)
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;
@@ -26,7 +26,7 @@ Vec3 *RandomPos::getPosAvoid(shared_ptr<PathfinderMob> mob, int xzDist, int yDis
return generateRandomPos(mob, xzDist, yDist, tempDir);
}
Vec3 *RandomPos::generateRandomPos(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *dir, int quadrant/*=-1*/) // 4J - added quadrant
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;
+4 -4
View File
@@ -8,10 +8,10 @@ private:
static Vec3 *tempDir;
public:
static Vec3 *getPos(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, int quadrant = -1); // 4J added quadrant
static Vec3 *getPosTowards(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *towardsPos);
static Vec3 *getPosAvoid(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *avoidPos);
static Vec3 *getPos(std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, int quadrant = -1); // 4J added quadrant
static Vec3 *getPosTowards(std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *towardsPos);
static Vec3 *getPosAvoid(std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *avoidPos);
private:
static Vec3 *generateRandomPos(shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *dir, int quadrant = -1); // 4J added quadrant
static Vec3 *generateRandomPos(std::shared_ptr<PathfinderMob> mob, int xzDist, int yDist, Vec3 *dir, int quadrant = -1); // 4J added quadrant
};