Merge pull request #2738 from Gargaj/mobinheritance
Sheep color inheritance
This commit is contained in:
commit
4a212777cb
@ -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));
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user