diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-01-02 14:50:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-02 14:50:34 +0100 |
commit | 16aeb84cd35996a6b41f10cbc48a677eeccc911c (patch) | |
tree | ae877926559d59a534bbf3c22651e6df7ffe8d71 /src/Mobs | |
parent | Fix version typo in CMakeLists.txt (#5098) (diff) | |
download | cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.gz cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.bz2 cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.lz cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.xz cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.zst cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.zip |
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/Horse.cpp | 28 | ||||
-rw-r--r-- | src/Mobs/Horse.h | 6 | ||||
-rw-r--r-- | src/Mobs/Monster.cpp | 44 | ||||
-rw-r--r-- | src/Mobs/Monster.h | 6 | ||||
-rw-r--r-- | src/Mobs/PassiveMonster.cpp | 9 | ||||
-rw-r--r-- | src/Mobs/PassiveMonster.h | 6 |
6 files changed, 27 insertions, 72 deletions
diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp index e42241700..d3ba066cc 100644 --- a/src/Mobs/Horse.cpp +++ b/src/Mobs/Horse.cpp @@ -32,19 +32,6 @@ cHorse::cHorse(int Type, int Color, int Style, int TameTimes) : -cHorse::~cHorse() -{ - auto Window = GetWindow(); - if (Window != nullptr) - { - Window->OwnerDestroyed(); - } -} - - - - - void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { Super::Tick(a_Dt, a_Chunk); @@ -123,6 +110,21 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) +void cHorse::OnRemoveFromWorld(cWorld & a_World) +{ + const auto Window = GetWindow(); + if (Window != nullptr) + { + Window->OwnerDestroyed(); + } + + Super::OnRemoveFromWorld(a_World); +} + + + + + void cHorse::OnRightClicked(cPlayer & a_Player) { Super::OnRightClicked(a_Player); diff --git a/src/Mobs/Horse.h b/src/Mobs/Horse.h index f9c236ffc..4f35071c0 100644 --- a/src/Mobs/Horse.h +++ b/src/Mobs/Horse.h @@ -17,7 +17,6 @@ class cHorse: public: cHorse(int Type, int Color, int Style, int TameTimes); - virtual ~cHorse() override; CLASS_PROTODEF(cHorse) @@ -25,6 +24,7 @@ public: virtual void InStateIdle(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override; virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + virtual void OnRemoveFromWorld(cWorld & a_World) override; virtual void OnRightClicked(cPlayer & a_Player) override; bool IsSaddled (void) const {return !m_Saddle.IsEmpty(); } @@ -66,7 +66,3 @@ private: cItem m_Armor; } ; - - - - diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 048393e67..7e8e7eba3 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -135,17 +135,15 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A -cMonster::~cMonster() +void cMonster::OnRemoveFromWorld(cWorld & a_World) { - ASSERT(GetTarget() == nullptr); -} - - - + SetTarget(nullptr); // Tell them we're no longer targeting them. + if (m_LovePartner != nullptr) + { + m_LovePartner->ResetLoveMode(); + } -void cMonster::OnRemoveFromWorld(cWorld & a_World) -{ if (IsLeashed()) { cEntity * LeashedTo = GetLeashedTo(); @@ -165,20 +163,6 @@ void cMonster::OnRemoveFromWorld(cWorld & a_World) -void cMonster::Destroyed() -{ - SetTarget(nullptr); // Tell them we're no longer targeting them. - if (m_LovePartner != nullptr) - { - m_LovePartner->ResetLoveMode(); - } - Super::Destroyed(); -} - - - - - void cMonster::SpawnOn(cClientHandle & a_Client) { a_Client.SendSpawnMob(*this); @@ -762,22 +746,14 @@ void cMonster::CheckEventSeePlayer(cChunk & a_Chunk) const auto MyHeadPosition = GetPosition().addedY(GetHeight()); // Enumerate all players within sight: - m_World->ForEachEntityInBox({ GetPosition(), m_SightDistance * 2.0 }, [this, &TargetPlayer, &ClosestDistance, MyHeadPosition](cEntity & a_Entity) + m_World->ForEachPlayer([this, &TargetPlayer, &ClosestDistance, MyHeadPosition](cPlayer & a_Player) { - if (!a_Entity.IsPlayer()) - { - // Continue iteration: - return false; - } - - const auto Player = static_cast<cPlayer *>(&a_Entity); - - if (!Player->CanMobsTarget()) + if (!a_Player.CanMobsTarget()) { return false; } - const auto TargetHeadPosition = a_Entity.GetPosition().addedY(a_Entity.GetHeight()); + const auto TargetHeadPosition = a_Player.GetPosition().addedY(a_Player.GetHeight()); const auto TargetDistance = (TargetHeadPosition - MyHeadPosition).SqrLength(); // TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to. @@ -786,7 +762,7 @@ void cMonster::CheckEventSeePlayer(cChunk & a_Chunk) cLineBlockTracer::LineOfSightTrace(*GetWorld(), MyHeadPosition, TargetHeadPosition, cLineBlockTracer::losAirWaterLava) ) { - TargetPlayer = Player; + TargetPlayer = &a_Player; ClosestDistance = TargetDistance; } diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index aeb8a3bf9..eb8905ae3 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -48,14 +48,10 @@ public: */ cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, const AString & a_SoundAmbient, double a_Width, double a_Height); - virtual ~cMonster() override; + CLASS_PROTODEF(cMonster) virtual void OnRemoveFromWorld(cWorld & a_World) override; - virtual void Destroyed() override; - - CLASS_PROTODEF(cMonster) - virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index e9c4070db..90d88024d 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -37,15 +37,6 @@ bool cPassiveMonster::DoTakeDamage(TakeDamageInfo & a_TDI) -void cPassiveMonster::Destroyed() -{ - Super::Destroyed(); -} - - - - - void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { Super::Tick(a_Dt, a_Chunk); diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h index 15900a95d..400cc3885 100644 --- a/src/Mobs/PassiveMonster.h +++ b/src/Mobs/PassiveMonster.h @@ -30,10 +30,4 @@ public: /** When hit by someone, run away */ virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; - - virtual void Destroyed(void) override; }; - - - - |