summaryrefslogtreecommitdiffstats
path: root/src/Entities/Pawn.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2016-08-20 14:34:29 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2016-08-20 14:34:29 +0200
commit7175b9e435a54cff33914d21384625a445cc5cf0 (patch)
tree7feb44f1e8e4ed7ea4d5bf0ba1d173abd3417f34 /src/Entities/Pawn.cpp
parentAdded cWorld:SetSpawn() API and Lua binding (#3316) (diff)
downloadcuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.gz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.bz2
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.lz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.xz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.zst
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.zip
Diffstat (limited to 'src/Entities/Pawn.cpp')
-rw-r--r--src/Entities/Pawn.cpp63
1 files changed, 26 insertions, 37 deletions
diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp
index 04425dd51..70c9c7131 100644
--- a/src/Entities/Pawn.cpp
+++ b/src/Entities/Pawn.cpp
@@ -27,9 +27,10 @@ cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) :
-cPawn::~cPawn()
+bool cPawn::OnPreWorldTravel(cWorld & a_NewWorld)
{
- ASSERT(m_TargetingMe.size() == 0);
+ UnsetAllTargeters();
+ return super::OnPreWorldTravel(a_NewWorld);
}
@@ -38,7 +39,7 @@ cPawn::~cPawn()
void cPawn::Destroyed()
{
- StopEveryoneFromTargetingMe();
+ UnsetAllTargeters();
super::Destroyed();
}
@@ -219,32 +220,37 @@ void cPawn::ClearEntityEffects()
-void cPawn::NoLongerTargetingMe(cMonster * a_Monster)
+void cPawn::UnsetAllTargeters()
{
- ASSERT(IsTicking()); // Our destroy override is supposed to clear all targets before we're destroyed.
- for (auto i = m_TargetingMe.begin(); i != m_TargetingMe.end(); ++i)
+ class Callback : public cEntityCallback
{
- cMonster * Monster = *i;
- if (Monster == a_Monster)
+ public:
+ Callback(cPawn & a_Pawn) :
+ m_Pawn(a_Pawn)
{
- ASSERT(Monster->GetTarget() != this); // The monster is notifying us it is no longer targeting us, assert if that's a lie
- m_TargetingMe.erase(i);
- return;
}
- }
- ASSERT(false); // If this happens, something is wrong. Perhaps the monster never called TargetingMe() or called NoLongerTargetingMe() twice.
-}
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ if (!a_Entity->IsMob())
+ {
+ return false;
+ }
+ auto Monster = static_cast<cMonster *>(a_Entity);
+ if (Monster->GetTarget() == &m_Pawn)
+ {
+ Monster->SetTarget(nullptr);
+ }
+ return false;
+ }
+ private:
+ cPawn & m_Pawn;
+ } Callback(*this);
-void cPawn::TargetingMe(cMonster * a_Monster)
-{
- ASSERT(IsTicking());
- ASSERT(m_TargetingMe.size() < 10000);
- ASSERT(a_Monster->GetTarget() == this);
- m_TargetingMe.push_back(a_Monster);
+ GetWorld()->ForEachEntity(Callback);
}
@@ -416,20 +422,3 @@ void cPawn::HandleFalling(void)
because of the client skipping an update about the lava block. This can only be resolved by
somehow integrating these above checks into the tracer in HandlePhysics. */
}
-
-
-
-
-
-void cPawn::StopEveryoneFromTargetingMe()
-{
- std::vector<cMonster*>::iterator i = m_TargetingMe.begin();
- while (i != m_TargetingMe.end())
- {
- cMonster * Monster = *i;
- ASSERT(Monster->GetTarget() == this);
- Monster->UnsafeUnsetTarget();
- i = m_TargetingMe.erase(i);
- }
- ASSERT(m_TargetingMe.size() == 0);
-}