diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-09-11 23:20:49 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-09-11 23:20:49 +0200 |
commit | e225b7f8262df48ad4d7094bc295add3007b0649 (patch) | |
tree | a42e9afcc88cfe6e9d1258458e3ad42764083d0e /src/Mobs/PassiveMonster.cpp | |
parent | cBlockArea: change MakeIndex to return size_t (diff) | |
download | cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.gz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.bz2 cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.lz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.xz cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.tar.zst cuberite-e225b7f8262df48ad4d7094bc295add3007b0649.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/PassiveMonster.cpp | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp index a2089e13f..c9345662d 100644 --- a/src/Mobs/PassiveMonster.cpp +++ b/src/Mobs/PassiveMonster.cpp @@ -109,23 +109,18 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3f Pos = (GetPosition() + m_LovePartner->GetPosition()) * 0.5; UInt32 BabyID = m_World->SpawnMob(Pos.x, Pos.y, Pos.z, GetMobType(), true); - class cBabyInheritCallback : - public cEntityCallback - { - public: - cPassiveMonster * Baby; - cBabyInheritCallback() : Baby(nullptr) { } - virtual bool Item(cEntity * a_Entity) override + cPassiveMonster * Baby = nullptr; + + m_World->DoWithEntityByID(BabyID, [&](cEntity & a_Entity) { - Baby = static_cast<cPassiveMonster *>(a_Entity); + Baby = static_cast<cPassiveMonster *>(&a_Entity); return true; } - } Callback; + ); - m_World->DoWithEntityByID(BabyID, Callback); - if (Callback.Baby != nullptr) + if (Baby != nullptr) { - Callback.Baby->InheritFromParents(this, m_LovePartner); + Baby->InheritFromParents(this, m_LovePartner); } m_World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, GetRandomProvider().RandInt(1, 6)); @@ -159,49 +154,37 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { if (m_LovePartner == nullptr) { - class LookForLover : public cEntityCallback - { - public: - cEntity * m_Me; - - LookForLover(cEntity * a_Me) : - m_Me(a_Me) - { - } - - virtual bool Item(cEntity * a_Entity) override + m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 8, 8), [=](cEntity & a_Entity) { // If the entity is not a monster, don't breed with it // Also, do not self-breed - if ((a_Entity->GetEntityType() != etMonster) || (a_Entity == m_Me)) + if ((a_Entity.GetEntityType() != etMonster) || (&a_Entity == this)) { return false; } - cPassiveMonster * Me = static_cast<cPassiveMonster*>(m_Me); - cPassiveMonster * PotentialPartner = static_cast<cPassiveMonster*>(a_Entity); + auto & Me = static_cast<cPassiveMonster&>(*this); + auto & PotentialPartner = static_cast<cPassiveMonster&>(a_Entity); // If the potential partner is not of the same species, don't breed with it - if (PotentialPartner->GetMobType() != Me->GetMobType()) + if (PotentialPartner.GetMobType() != Me.GetMobType()) { return false; } // If the potential partner is not in love // Or they already have a mate, do not breed with them - if ((!PotentialPartner->IsInLove()) || (PotentialPartner->GetPartner() != nullptr)) + if ((!PotentialPartner.IsInLove()) || (PotentialPartner.GetPartner() != nullptr)) { return false; } // All conditions met, let's breed! - PotentialPartner->EngageLoveMode(Me); - Me->EngageLoveMode(PotentialPartner); + PotentialPartner.EngageLoveMode(&Me); + Me.EngageLoveMode(&PotentialPartner); return true; } - } Callback(this); - - m_World->ForEachEntityInBox(cBoundingBox(GetPosition(), 8, 8, -4), Callback); + ); } m_LoveTimer--; |