From 90be4e7efdb455dc4bf4e150c403586a5c73d3f1 Mon Sep 17 00:00:00 2001 From: LogicParrot Date: Sat, 3 Sep 2016 14:31:27 +0300 Subject: Entities now bail out of ticks if destroyed (#3363) --- src/Mobs/AggressiveMonster.cpp | 5 +++++ src/Mobs/CaveSpider.cpp | 5 +++++ src/Mobs/Chicken.cpp | 5 +++++ src/Mobs/Creeper.cpp | 5 +++++ src/Mobs/Enderman.cpp | 5 +++++ src/Mobs/Horse.cpp | 5 +++++ src/Mobs/Monster.cpp | 5 +++++ src/Mobs/PassiveMonster.cpp | 5 +++++ src/Mobs/Pig.cpp | 5 +++++ src/Mobs/Sheep.cpp | 5 +++++ src/Mobs/SnowGolem.cpp | 5 +++++ src/Mobs/Villager.cpp | 5 +++++ src/Mobs/Wither.cpp | 5 +++++ src/Mobs/Wolf.cpp | 6 ++++++ 14 files changed, 71 insertions(+) (limited to 'src/Mobs') diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index c67f01b8f..109ad274c 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -52,6 +52,11 @@ void cAggressiveMonster::EventSeePlayer(cEntity * a_Entity, cChunk & a_Chunk) void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if (m_EMState == CHASING) { diff --git a/src/Mobs/CaveSpider.cpp b/src/Mobs/CaveSpider.cpp index 2a4975126..9f2524c1b 100644 --- a/src/Mobs/CaveSpider.cpp +++ b/src/Mobs/CaveSpider.cpp @@ -19,6 +19,11 @@ cCaveSpider::cCaveSpider(void) : void cCaveSpider::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } m_EMPersonality = (GetWorld()->GetTimeOfDay() < (12000 + 1000)) ? PASSIVE : AGGRESSIVE; } diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp index 5393a8a35..2c9e86e85 100644 --- a/src/Mobs/Chicken.cpp +++ b/src/Mobs/Chicken.cpp @@ -23,6 +23,11 @@ cChicken::cChicken(void) : void cChicken::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if (IsBaby()) { diff --git a/src/Mobs/Creeper.cpp b/src/Mobs/Creeper.cpp index 47d294a30..2e7d35ed3 100644 --- a/src/Mobs/Creeper.cpp +++ b/src/Mobs/Creeper.cpp @@ -26,6 +26,11 @@ cCreeper::cCreeper(void) : void cCreeper::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if ((GetTarget() == nullptr) || (!TargetIsInRange() && !m_BurnedWithFlintAndSteel)) { diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index ccfd44110..2ff547c3c 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -189,6 +189,11 @@ bool cEnderman::CheckLight() void cEnderman::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } // TODO take damage in rain diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index dd40f1da2..ce4121a45 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -35,6 +35,11 @@ cHorse::cHorse(int Type, int Color, int Style, int TameTimes) : void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if (!m_bIsMouthOpen) { diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 98c22e299..acd8f0145 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -231,6 +231,11 @@ void cMonster::StopMovingToPosition() void cMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } GET_AND_VERIFY_CURRENT_CHUNK(Chunk, POSX_TOINT, POSZ_TOINT); ASSERT((GetTarget() == nullptr) || (GetTarget()->IsPawn() && (GetTarget()->GetWorld() == GetWorld()))); diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index 071352532..42884fb56 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -81,6 +81,11 @@ void cPassiveMonster::Destroyed() void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if (m_EMState == ESCAPING) { diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp index b67b29d87..6b420b235 100644 --- a/src/Mobs/Pig.cpp +++ b/src/Mobs/Pig.cpp @@ -85,6 +85,11 @@ void cPig::OnRightClicked(cPlayer & a_Player) void cPig::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } // If the attachee player is holding a carrot-on-stick, let them drive this pig: if (m_bIsSaddled && (m_Attachee != nullptr)) diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp index 7bca03e7e..b0fc68d44 100644 --- a/src/Mobs/Sheep.cpp +++ b/src/Mobs/Sheep.cpp @@ -88,6 +88,11 @@ void cSheep::OnRightClicked(cPlayer & a_Player) void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } int PosX = POSX_TOINT; int PosY = POSY_TOINT - 1; int PosZ = POSZ_TOINT; diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 6afe3fda0..b4089d179 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -30,6 +30,11 @@ void cSnowGolem::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSnowGolem::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if (IsBiomeNoDownfall(m_World->GetBiomeAt(POSX_TOINT, POSZ_TOINT))) { TakeDamage(*this); diff --git a/src/Mobs/Villager.cpp b/src/Mobs/Villager.cpp index 41807e335..4e762a55a 100644 --- a/src/Mobs/Villager.cpp +++ b/src/Mobs/Villager.cpp @@ -54,6 +54,11 @@ bool cVillager::DoTakeDamage(TakeDamageInfo & a_TDI) void cVillager::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if (m_ActionCountDown > -1) { diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 6ef81ce1b..19399953e 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -69,6 +69,11 @@ bool cWither::DoTakeDamage(TakeDamageInfo & a_TDI) void cWither::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } if (m_WitherInvulnerableTicks > 0) { diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp index da21468ca..e62ec6c30 100644 --- a/src/Mobs/Wolf.cpp +++ b/src/Mobs/Wolf.cpp @@ -263,6 +263,12 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) super::Tick(a_Dt, a_Chunk); } + if (!IsTicking()) + { + // The base class tick destroyed us + return; + } + if (GetTarget() == nullptr) { cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast(m_SightDistance)); -- cgit v1.2.3