refactor: unglob std::shared_ptr

This commit is contained in:
Tropical
2026-03-06 11:20:45 -06:00
parent 0dd1654dec
commit 67ceccf2d4
1065 changed files with 5754 additions and 5749 deletions
+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 = 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();
+1 -1
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;
+1 -1
View File
@@ -11,5 +11,5 @@ public:
Sensing(Mob *mob);
void tick();
bool canSee(shared_ptr<Entity> target);
bool canSee(std::shared_ptr<Entity> target);
};
+5 -5
View File
@@ -26,7 +26,7 @@ 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);
return true;
@@ -45,7 +45,7 @@ void ArrowAttackGoal::stop()
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);
@@ -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, 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, 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;
+2 -2
View File
@@ -33,14 +33,14 @@ bool AvoidPlayerGoal::canUse()
{
if (avoidType == typeid(Player))
{
shared_ptr<TamableAnimal> tamableAnimal = dynamic_pointer_cast<TamableAnimal>(mob->shared_from_this());
std::shared_ptr<TamableAnimal> tamableAnimal = 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));
if (toAvoid.lock() == NULL) return false;
}
else
{
vector<shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(avoidType, mob->bb->grow(maxDist, 3, maxDist));
vector<std::shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(avoidType, mob->bb->grow(maxDist, 3, maxDist));
if (entities->empty())
{
delete entities;
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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
+6 -6
View File
@@ -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));
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 = 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) ) );
}
+1 -1
View File
@@ -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 = 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 = dynamic_pointer_cast<Player>(mob->rider.lock());
PathfinderMob *pig = (PathfinderMob *)mob;
float yrd = Mth::wrapDegrees(player->yRot - mob->yRot) * 0.5f;
@@ -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,7 +11,7 @@ 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())));
return canAttack(potentialTarget.lock(), false);
+1 -1
View File
@@ -24,7 +24,7 @@ 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;
@@ -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));
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 = dynamic_pointer_cast<Animal>(*it);
if (parent->getAge() < 0) continue;
double distSqr = animal->distanceToSqr(parent);
if (distSqr > closestDistSqr) continue;
@@ -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));
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 = 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);
+3 -3
View File
@@ -29,7 +29,7 @@ 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));
@@ -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
@@ -41,7 +41,7 @@ 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;
@@ -53,7 +53,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();
+4 -4
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,7 +36,7 @@ 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>();
@@ -52,7 +52,7 @@ 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>();
@@ -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;
@@ -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();
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);
@@ -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();
};
@@ -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);
@@ -38,7 +38,7 @@ 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);
@@ -47,12 +47,12 @@ bool NearestAttackableTargetGoal::canUse()
}
else
{
vector<shared_ptr<Entity> > *entities = mob->level->getEntitiesOfClass(targetType, mob->bb->grow(within, 4, within));
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 = dynamic_pointer_cast<Mob>(*it);
if (canAttack(potTarget, false))
{
target = weak_ptr<Mob>(potTarget);
@@ -13,7 +13,7 @@ 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:
@@ -20,7 +20,7 @@ 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);
return true;
@@ -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 = dynamic_pointer_cast<ChestTileEntity>(level->getTileEntity(x, y, z));
if (chest->openCount < 1)
{
@@ -12,7 +12,7 @@ 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());
return canAttack(ownerLastHurtBy.lock(), false);
@@ -12,7 +12,7 @@ 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());
return canAttack(ownerLastHurt.lock(), false);
+3 -3
View File
@@ -25,14 +25,14 @@ 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));
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 = dynamic_pointer_cast<Villager>(c);
if (friendV->isChasing()) continue;
if (friendV->getAge() >= 0) continue;
double distSqr = friendV->distanceToSqr(mob->shared_from_this());
@@ -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));
}
@@ -44,6 +44,6 @@ void RestrictOpenDoorGoal::stop()
void RestrictOpenDoorGoal::tick()
{
shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
std::shared_ptr<DoorInfo> _doorInfo = doorInfo.lock();
if ( _doorInfo ) _doorInfo->incBookingCount();
}
+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;
+1 -1
View File
@@ -15,7 +15,7 @@ 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));
}
+2 -2
View File
@@ -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));
vector<std::shared_ptr<Entity> > *golems = villager->level->getEntitiesOfClass(typeid(VillagerGolem), villager->bb->grow(6, 2, 6));
if (golems->size() == 0)
{
delete golems;
@@ -33,7 +33,7 @@ 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 = dynamic_pointer_cast<VillagerGolem>(*it);
if (vg->getOfferFlowerTick() > 0)
{
golem = weak_ptr<VillagerGolem>(vg);
+5 -5
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,17 +62,17 @@ 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 = 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 = dynamic_pointer_cast<TamableAnimal>(target);
if (tamableTarget != NULL && tamableTarget->isTame()) return false;
if (target == tamableAnimal->getOwner()) 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);
};
+1 -1
View File
@@ -31,7 +31,7 @@ bool TemptGoal::canUse()
player = 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;
@@ -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
+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);
@@ -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
};