aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Animal.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Minecraft.World/Animal.cpp')
-rw-r--r--Minecraft.World/Animal.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/Minecraft.World/Animal.cpp b/Minecraft.World/Animal.cpp
index 31de7d75..ecda8fc5 100644
--- a/Minecraft.World/Animal.cpp
+++ b/Minecraft.World/Animal.cpp
@@ -229,51 +229,58 @@ shared_ptr<Entity> Animal::findAttackTarget()
if (getInLoveValue() > 0)
{
vector<shared_ptr<Entity> > *others = level->getEntitiesOfClass(typeid(*this), bb->grow(r, r, r));
- //for (int i = 0; i < others->size(); i++)
- for(AUTO_VAR(it, others->begin()); it != others->end(); ++it)
+ if ( others )
{
- shared_ptr<Animal> p = dynamic_pointer_cast<Animal>(*it);
- if (p != shared_from_this() && p->getInLoveValue() > 0)
+ for (auto& it : *others)
{
- delete others;
- return p;
+ shared_ptr<Animal> p = dynamic_pointer_cast<Animal>(it);
+ if (p != shared_from_this() && p->getInLoveValue() > 0)
+ {
+ delete others;
+ return p;
+ }
}
+ delete others;
}
- delete others;
}
else
{
if (getAge() == 0)
{
vector<shared_ptr<Entity> > *players = level->getEntitiesOfClass(typeid(Player), bb->grow(r, r, r));
- //for (int i = 0; i < players.size(); i++)
- for(AUTO_VAR(it, players->begin()); it != players->end(); ++it)
+ if ( players )
{
- setDespawnProtected();
-
- shared_ptr<Player> p = dynamic_pointer_cast<Player>(*it);
- if (p->getSelectedItem() != NULL && this->isFood(p->getSelectedItem()))
+ for (auto& it : *players)
{
- delete players;
- return p;
+ setDespawnProtected();
+
+ shared_ptr<Player> p = dynamic_pointer_cast<Player>(it);
+ if (p->getSelectedItem() != NULL && this->isFood(p->getSelectedItem()))
+ {
+ delete players;
+ return p;
+ }
}
+ delete players;
}
- delete players;
}
else if (getAge() > 0)
{
vector<shared_ptr<Entity> > *others = level->getEntitiesOfClass(typeid(*this), bb->grow(r, r, r));
- //for (int i = 0; i < others.size(); i++)
- for(AUTO_VAR(it, others->begin()); it != others->end(); ++it)
+
+ if ( others )
{
- shared_ptr<Animal> p = dynamic_pointer_cast<Animal>(*it);
- if (p != shared_from_this() && p->getAge() < 0)
+ for (auto& it : *others)
{
- delete others;
- return p;
+ shared_ptr<Animal> p = dynamic_pointer_cast<Animal>(it);
+ if (p != shared_from_this() && p->getAge() < 0)
+ {
+ delete others;
+ return p;
+ }
}
+ delete others;
}
- delete others;
}
}
return nullptr;