diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-01 22:39:59 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-09-01 22:39:59 +0200 |
commit | c0fb0414d557c55b783c316ecde3041c873e4fba (patch) | |
tree | d60a1ebf4668611ec89bdd339c376a187604b969 /src/Mobs | |
parent | Sunlight fixes, config fixes (diff) | |
download | cuberite-c0fb0414d557c55b783c316ecde3041c873e4fba.tar cuberite-c0fb0414d557c55b783c316ecde3041c873e4fba.tar.gz cuberite-c0fb0414d557c55b783c316ecde3041c873e4fba.tar.bz2 cuberite-c0fb0414d557c55b783c316ecde3041c873e4fba.tar.lz cuberite-c0fb0414d557c55b783c316ecde3041c873e4fba.tar.xz cuberite-c0fb0414d557c55b783c316ecde3041c873e4fba.tar.zst cuberite-c0fb0414d557c55b783c316ecde3041c873e4fba.zip |
Diffstat (limited to 'src/Mobs')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorBreeder.cpp | 92 |
1 files changed, 39 insertions, 53 deletions
diff --git a/src/Mobs/Behaviors/BehaviorBreeder.cpp b/src/Mobs/Behaviors/BehaviorBreeder.cpp index 7ede92c52..7479c6d78 100644 --- a/src/Mobs/Behaviors/BehaviorBreeder.cpp +++ b/src/Mobs/Behaviors/BehaviorBreeder.cpp @@ -54,23 +54,17 @@ void cBehaviorBreeder::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) Vector3f Pos = (m_Parent->GetPosition() + m_LovePartner->GetPosition()) * 0.5; UInt32 BabyID = World->SpawnMob(Pos.x, Pos.y, Pos.z, m_Parent->GetMobType(), true); - class cBabyInheritCallback : - public cEntityCallback + cMonster * Baby = nullptr; + + m_Parent->GetWorld()->DoWithEntityByID(BabyID, [&](cEntity & a_Entity) { - public: - cMonster * Baby; - cBabyInheritCallback() : Baby(nullptr) { } - virtual bool Item(cEntity * a_Entity) override - { - Baby = static_cast<cMonster *>(a_Entity); - return true; - } - } Callback; - - m_Parent->GetWorld()->DoWithEntityByID(BabyID, Callback); - if (Callback.Baby != nullptr) + Baby = static_cast<cMonster *>(&a_Entity); + return true; + }); + + if (Baby != nullptr) { - Callback.Baby->InheritFromParents(m_Parent, m_LovePartner); + Baby->InheritFromParents(m_Parent, m_LovePartner); } cFastRandom Random; @@ -86,6 +80,8 @@ void cBehaviorBreeder::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) + + void cBehaviorBreeder::PostTick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { UNUSED(a_Dt); @@ -123,51 +119,41 @@ bool cBehaviorBreeder::IsControlDesired(std::chrono::milliseconds a_Dt, cChunk & // If we are in love mode and we have no partner, try to find one if (m_LoveTimer > 0) { - class LookForLover : public cEntityCallback + m_Parent->GetWorld()->ForEachEntityInBox(cBoundingBox(m_Parent->GetPosition(), 8, 8), [=](cEntity & a_Entity) { - public: - cMonster * m_Me; - LookForLover(cMonster * a_Me) : - m_Me(a_Me) + // If the entity is not a monster, don't breed with it + // Also, do not self-breed + if ((a_Entity.GetEntityType() != cEntity::eEntityType::etMonster) || (&a_Entity == m_Parent)) { + return false; } - virtual bool Item(cEntity * a_Entity) override + auto PotentialPartner = static_cast<cMonster*>(&a_Entity); + + // If the potential partner is not of the same species, don't breed with it + if (PotentialPartner->GetMobType() != m_Parent->GetMobType()) { - // If the entity is not a monster, don't breed with it - // Also, do not self-breed - if ((a_Entity->GetEntityType() != cEntity::eEntityType::etMonster) || (a_Entity == m_Me)) - { - return false; - } - - auto PotentialPartner = static_cast<cMonster*>(a_Entity); - - // If the potential partner is not of the same species, don't breed with it - if (PotentialPartner->GetMobType() != m_Me->GetMobType()) - { - return false; - } - - auto PartnerBreedingBehavior = PotentialPartner->GetBehaviorBreeder(); - auto MyBreedingBehavior = m_Me->GetBehaviorBreeder(); - - // If the potential partner is not in love - // Or they already have a mate, do not breed with them - - if ((!PartnerBreedingBehavior->IsInLove()) || (PartnerBreedingBehavior->GetPartner() != nullptr)) - { - return false; - } - - // All conditions met, let's breed! - PartnerBreedingBehavior->EngageLoveMode(m_Me); - MyBreedingBehavior->EngageLoveMode(PotentialPartner); - return true; + return false; } - } Callback(m_Parent); - World->ForEachEntityInBox(cBoundingBox(m_Parent->GetPosition(), 8, 8), Callback); + auto PartnerBreedingBehavior = PotentialPartner->GetBehaviorBreeder(); + auto MyBreedingBehavior = m_Parent->GetBehaviorBreeder(); + + // If the potential partner is not in love + // Or they already have a mate, do not breed with them + + if ((!PartnerBreedingBehavior->IsInLove()) || (PartnerBreedingBehavior->GetPartner() != nullptr)) + { + return false; + } + + // All conditions met, let's breed! + PartnerBreedingBehavior->EngageLoveMode(m_Parent); + MyBreedingBehavior->EngageLoveMode(PotentialPartner); + return true; + }); + + if (m_LovePartner != nullptr) { return true; // We found love and took control of the monster, prevent other Behaviors from doing so |