summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
authorSafwat Halaby <SafwatHalaby@users.noreply.github.com>2015-12-13 13:12:25 +0100
committerSafwat Halaby <SafwatHalaby@users.noreply.github.com>2015-12-13 13:12:25 +0100
commit4a212777cbda77e87b22ad312557aa4b6331f429 (patch)
tree1853aaa787b482c9d12e9de6ce40d84772b7527a /src/Mobs
parentMerge pull request #2741 from SafwatHalaby/mTarget2 (diff)
parentsheep color inheritance (diff)
downloadcuberite-4a212777cbda77e87b22ad312557aa4b6331f429.tar
cuberite-4a212777cbda77e87b22ad312557aa4b6331f429.tar.gz
cuberite-4a212777cbda77e87b22ad312557aa4b6331f429.tar.bz2
cuberite-4a212777cbda77e87b22ad312557aa4b6331f429.tar.lz
cuberite-4a212777cbda77e87b22ad312557aa4b6331f429.tar.xz
cuberite-4a212777cbda77e87b22ad312557aa4b6331f429.tar.zst
cuberite-4a212777cbda77e87b22ad312557aa4b6331f429.zip
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/PassiveMonster.cpp21
-rw-r--r--src/Mobs/PassiveMonster.h3
-rw-r--r--src/Mobs/Sheep.cpp40
-rw-r--r--src/Mobs/Sheep.h1
4 files changed, 64 insertions, 1 deletions
diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp
index b700c0c5d..30b46500d 100644
--- a/src/Mobs/PassiveMonster.cpp
+++ b/src/Mobs/PassiveMonster.cpp
@@ -92,7 +92,26 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
// Mating finished. Spawn baby
Vector3f Pos = (GetPosition() + m_LovePartner->GetPosition()) * 0.5;
- m_World->SpawnMob(Pos.x, Pos.y, Pos.z, GetMobType(), true);
+ 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
+ {
+ Baby = static_cast<cPassiveMonster *>(a_Entity);
+ return true;
+ }
+ } Callback;
+
+ m_World->DoWithEntityByID(BabyID, Callback);
+ if (Callback.Baby != nullptr)
+ {
+ Callback.Baby->InheritFromParents(this, m_LovePartner);
+ }
cFastRandom Random;
m_World->SpawnExperienceOrb(Pos.x, Pos.y, Pos.z, 1 + Random.NextInt(6));
diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h
index 0e9250e6c..1106ffb91 100644
--- a/src/Mobs/PassiveMonster.h
+++ b/src/Mobs/PassiveMonster.h
@@ -27,6 +27,9 @@ public:
/** Returns the items that make the animal breed - this is usually the same as the ones that make the animal follow, but not necessarily. */
virtual void GetBreedingItems(cItems & a_Items) { GetFollowedItems(a_Items); }
+ /** Called after the baby is born, allows the baby to inherit the parents' properties (color, etc.) */
+ virtual void InheritFromParents(cPassiveMonster * a_Parent1, cPassiveMonster * a_Parent2) { }
+
/** Returns the partner which the monster is currently mating with. */
cPassiveMonster * GetPartner(void) const { return m_LovePartner; }
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index 5f763508b..7bca03e7e 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -131,6 +131,46 @@ void cSheep::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
+void cSheep::InheritFromParents(cPassiveMonster * a_Parent1, cPassiveMonster * a_Parent2)
+{
+ static const struct
+ {
+ short Parent1, Parent2, Child;
+ } ColorInheritance[] =
+ {
+ { E_META_WOOL_BLUE, E_META_WOOL_RED, E_META_WOOL_PURPLE },
+ { E_META_WOOL_BLUE, E_META_WOOL_GREEN, E_META_WOOL_CYAN },
+ { E_META_WOOL_YELLOW, E_META_WOOL_RED, E_META_WOOL_ORANGE },
+ { E_META_WOOL_GREEN, E_META_WOOL_WHITE, E_META_WOOL_LIGHTGREEN },
+ { E_META_WOOL_RED, E_META_WOOL_WHITE, E_META_WOOL_PINK },
+ { E_META_WOOL_WHITE, E_META_WOOL_BLACK, E_META_WOOL_GRAY },
+ { E_META_WOOL_PURPLE, E_META_WOOL_PINK, E_META_WOOL_MAGENTA },
+ { E_META_WOOL_WHITE, E_META_WOOL_GRAY, E_META_WOOL_LIGHTGRAY },
+ { E_META_WOOL_BLUE, E_META_WOOL_WHITE, E_META_WOOL_LIGHTBLUE },
+ };
+ cSheep * Parent1 = static_cast<cSheep *>(a_Parent1);
+ cSheep * Parent2 = static_cast<cSheep *>(a_Parent2);
+ for (size_t i = 0; i < ARRAYCOUNT(ColorInheritance); i++)
+ {
+ if (
+ ((Parent1->GetFurColor() == ColorInheritance[i].Parent1) && (Parent2->GetFurColor() == ColorInheritance[i].Parent2)) ||
+ ((Parent1->GetFurColor() == ColorInheritance[i].Parent2) && (Parent2->GetFurColor() == ColorInheritance[i].Parent1))
+ )
+ {
+ SetFurColor(ColorInheritance[i].Child);
+ m_World->BroadcastEntityMetadata(*this);
+ return;
+ }
+ }
+ cFastRandom Random;
+ SetFurColor((Random.NextInt(100) < 50) ? Parent1->GetFurColor() : Parent2->GetFurColor());
+ m_World->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
NIBBLETYPE cSheep::GenerateNaturalRandomColor(void)
{
cFastRandom Random;
diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h
index ff7632eb7..97f481bec 100644
--- a/src/Mobs/Sheep.h
+++ b/src/Mobs/Sheep.h
@@ -25,6 +25,7 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
+ virtual void InheritFromParents(cPassiveMonster * a_Parent1, cPassiveMonster * a_Parent2) override;
virtual void GetFollowedItems(cItems & a_Items) override
{