Added documentation for breeding code
This commit is contained in:
parent
1a9c023d6c
commit
dbda48ead4
@ -77,17 +77,20 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|||||||
{
|
{
|
||||||
m_LovePartner = nullptr;
|
m_LovePartner = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if we have a partner, mate
|
||||||
if (m_LovePartner != nullptr)
|
if (m_LovePartner != nullptr)
|
||||||
{
|
{
|
||||||
// if we have a partner, bump into them until baby is made
|
|
||||||
if (m_MatingTimer > 0)
|
if (m_MatingTimer > 0)
|
||||||
{
|
{
|
||||||
|
// If we should still mate, keep bumping into them until baby is made
|
||||||
Vector3d Pos = m_LovePartner->GetPosition();
|
Vector3d Pos = m_LovePartner->GetPosition();
|
||||||
MoveToPosition(Pos);
|
MoveToPosition(Pos);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// spawn baby
|
// Mating finished. Spawn baby
|
||||||
Vector3f Pos = (GetPosition() + m_LovePartner->GetPosition()) * 0.5;
|
Vector3f Pos = (GetPosition() + m_LovePartner->GetPosition()) * 0.5;
|
||||||
m_World->SpawnMob(Pos.x, Pos.y, Pos.z, GetMobType(), true);
|
m_World->SpawnMob(Pos.x, Pos.y, Pos.z, GetMobType(), true);
|
||||||
|
|
||||||
@ -100,6 +103,7 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// We have no partner, so we just chase the player if they have our breeding item
|
||||||
cItems FollowedItems;
|
cItems FollowedItems;
|
||||||
GetFollowedItems(FollowedItems);
|
GetFollowedItems(FollowedItems);
|
||||||
if (FollowedItems.Size() > 0)
|
if (FollowedItems.Size() > 0)
|
||||||
@ -117,6 +121,7 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are in love mode but we have no partner, search for a partner neabry
|
||||||
if (m_LoveTimer > 0)
|
if (m_LoveTimer > 0)
|
||||||
{
|
{
|
||||||
if (m_LovePartner == nullptr)
|
if (m_LovePartner == nullptr)
|
||||||
@ -133,7 +138,7 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
|
|||||||
|
|
||||||
virtual bool Item(cEntity * a_Entity) override
|
virtual bool Item(cEntity * a_Entity) override
|
||||||
{
|
{
|
||||||
// if we're the same species as someone around and they dont have a partner, swipe right
|
// if we're the same species as someone around and they don't have a partner, start mating with them
|
||||||
if ((a_Entity->GetEntityType() == m_Me->GetEntityType()) && (a_Entity != m_Me))
|
if ((a_Entity->GetEntityType() == m_Me->GetEntityType()) && (a_Entity != m_Me))
|
||||||
{
|
{
|
||||||
cPassiveMonster * Me = static_cast<cPassiveMonster*>(m_Me);
|
cPassiveMonster * Me = static_cast<cPassiveMonster*>(m_Me);
|
||||||
@ -172,7 +177,7 @@ void cPassiveMonster::OnRightClicked(cPlayer & a_Player)
|
|||||||
{
|
{
|
||||||
super::OnRightClicked(a_Player);
|
super::OnRightClicked(a_Player);
|
||||||
|
|
||||||
// if right clicked on the player with breeding items, go into lovemode
|
// If a player holding breeding items right-clicked me, go into love mode
|
||||||
if ((m_LoveCooldown == 0) && !IsInLove() && !IsBaby())
|
if ((m_LoveCooldown == 0) && !IsInLove() && !IsBaby())
|
||||||
{
|
{
|
||||||
short HeldItem = a_Player.GetEquippedItem().m_ItemType;
|
short HeldItem = a_Player.GetEquippedItem().m_ItemType;
|
||||||
|
@ -27,17 +27,32 @@ 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. */
|
/** 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); }
|
virtual void GetBreedingItems(cItems & a_Items) { GetFollowedItems(a_Items); }
|
||||||
|
|
||||||
|
/** Returns the partner which the monster is currently mating with. */
|
||||||
cPassiveMonster * GetPartner(void) const { return m_LovePartner; }
|
cPassiveMonster * GetPartner(void) const { return m_LovePartner; }
|
||||||
|
|
||||||
|
/** Start the mating process. Causes the monster to keep bumping into the partner until m_MatingTimer reaches zero. */
|
||||||
void EngageLoveMode(cPassiveMonster * a_Partner);
|
void EngageLoveMode(cPassiveMonster * a_Partner);
|
||||||
|
|
||||||
|
/** Finish the mating process. Called after a baby is born. Resets all breeding related timers and sets m_LoveCooldown to 20 minutes. */
|
||||||
void ResetLoveMode();
|
void ResetLoveMode();
|
||||||
|
|
||||||
|
/** Returns whether the monster has just been fed and is ready to mate. If this is "true" and GetPartner isn't "nullptr", then the monster is mating. */
|
||||||
bool IsInLove() const { return (m_LoveTimer > 0); }
|
bool IsInLove() const { return (m_LoveTimer > 0); }
|
||||||
|
|
||||||
|
/** Returns whether the monster is tired of breeding and is in the cooldown state. */
|
||||||
bool IsInLoveCooldown() const { return (m_LoveCooldown > 0); }
|
bool IsInLoveCooldown() const { return (m_LoveCooldown > 0); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/** The monster's breeding partner. */
|
||||||
cPassiveMonster * m_LovePartner;
|
cPassiveMonster * m_LovePartner;
|
||||||
|
|
||||||
|
/** If above 0, the monster is in love mode, and will breed if a nearby monster is also in love mode. Decrements by 1 per tick till reaching zero. */
|
||||||
int m_LoveTimer;
|
int m_LoveTimer;
|
||||||
|
|
||||||
|
/** If above 0, the monster is in cooldown mode and will refuse to breed. Decrements by 1 per tick till reaching zero. */
|
||||||
int m_LoveCooldown;
|
int m_LoveCooldown;
|
||||||
|
|
||||||
|
/** The monster is engaged in mating, once this reaches zero, a baby will be born. Decrements by 1 per tick till reaching zero, then a baby is made and ResetLoveMode() is called. */
|
||||||
int m_MatingTimer;
|
int m_MatingTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user