summaryrefslogtreecommitdiffstats
path: root/source/Mobs
diff options
context:
space:
mode:
Diffstat (limited to 'source/Mobs')
-rw-r--r--source/Mobs/Monster.cpp74
-rw-r--r--source/Mobs/Sheep.cpp15
-rw-r--r--source/Mobs/Wolf.cpp133
-rw-r--r--source/Mobs/Wolf.h40
4 files changed, 197 insertions, 65 deletions
diff --git a/source/Mobs/Monster.cpp b/source/Mobs/Monster.cpp
index 167a07486..8a5717e27 100644
--- a/source/Mobs/Monster.cpp
+++ b/source/Mobs/Monster.cpp
@@ -624,61 +624,73 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily)
cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType)
{
+ cFastRandom Random;
cMonster * toReturn = NULL;
- cFastRandom RandomDerps;
// Create the mob entity
switch (a_MobType)
{
case mtMagmaCube:
- case mtSlime: toReturn = new cSlime (RandomDerps.NextInt(2) + 1); break; // Size parameter
- case mtSheep: toReturn = new cSheep (RandomDerps.NextInt(15)); break; // Colour parameter
- case mtZombie: toReturn = new cZombie (false); break; // TODO: Infected zombie parameter
+ case mtSlime:
+ {
+ toReturn = new cSlime (Random.NextInt(2) + 1);
+ break;
+ }
case mtSkeleton:
{
// TODO: Actual detection of spawning in Nether
- toReturn = new cSkeleton(RandomDerps.NextInt(1) == 0 ? false : true);
+ toReturn = new cSkeleton(Random.NextInt(1) == 0 ? false : true);
break;
}
case mtVillager:
{
- int VilType = RandomDerps.NextInt(6);
- if (VilType == 6) { VilType = 0; } // Give farmers a better chance of spawning
+ int VillagerType = Random.NextInt(6);
+ if (VillagerType == 6)
+ {
+ // Give farmers a better chance of spawning
+ VillagerType = 0;
+ }
- toReturn = new cVillager(cVillager::eVillagerType(VilType)); // Type (blacksmith, butcher, etc.) parameter
+ toReturn = new cVillager((cVillager::eVillagerType)VillagerType);
break;
}
case mtHorse:
{
// Horses take a type (species), a colour, and a style (dots, stripes, etc.)
- int HseType = RandomDerps.NextInt(7);
- int HseColor = RandomDerps.NextInt(6);
- int HseStyle = RandomDerps.NextInt(6);
- int HseTameTimes = RandomDerps.NextInt(6) + 1;
+ int HorseType = Random.NextInt(7);
+ int HorseColor = Random.NextInt(6);
+ int HorseStyle = Random.NextInt(6);
+ int HorseTameTimes = Random.NextInt(6) + 1;
- if ((HseType == 5) || (HseType == 6) || (HseType == 7)) { HseType = 0; } // Increase chances of normal horse (zero)
+ if ((HorseType == 5) || (HorseType == 6) || (HorseType == 7))
+ {
+ // Increase chances of normal horse (zero)
+ HorseType = 0;
+ }
- toReturn = new cHorse(HseType, HseColor, HseStyle, HseTameTimes);
+ toReturn = new cHorse(HorseType, HorseColor, HorseStyle, HorseTameTimes);
break;
}
- case mtBat: toReturn = new cBat(); break;
- case mtBlaze: toReturn = new cBlaze(); break;
- case mtCaveSpider: toReturn = new cCavespider(); break;
- case mtChicken: toReturn = new cChicken(); break;
- case mtCow: toReturn = new cCow(); break;
- case mtCreeper: toReturn = new cCreeper(); break;
- case mtEnderman: toReturn = new cEnderman(); break;
- case mtGhast: toReturn = new cGhast(); break;
- case mtMooshroom: toReturn = new cMooshroom(); break;
- case mtOcelot: toReturn = new cOcelot(); break;
- case mtPig: toReturn = new cPig(); break;
- case mtSilverfish: toReturn = new cSilverfish(); break;
- case mtSpider: toReturn = new cSpider(); break;
- case mtSquid: toReturn = new cSquid(); break;
- case mtWitch: toReturn = new cWitch(); break;
- case mtWolf: toReturn = new cWolf(); break;
- case mtZombiePigman: toReturn = new cZombiePigman(); break;
+ case mtBat: toReturn = new cBat(); break;
+ case mtBlaze: toReturn = new cBlaze(); break;
+ case mtCaveSpider: toReturn = new cCavespider(); break;
+ case mtChicken: toReturn = new cChicken(); break;
+ case mtCow: toReturn = new cCow(); break;
+ case mtCreeper: toReturn = new cCreeper(); break;
+ case mtEnderman: toReturn = new cEnderman(); break;
+ case mtGhast: toReturn = new cGhast(); break;
+ case mtMooshroom: toReturn = new cMooshroom(); break;
+ case mtOcelot: toReturn = new cOcelot(); break;
+ case mtPig: toReturn = new cPig(); break;
+ case mtSheep: toReturn = new cSheep (Random.NextInt(15)); break; // Colour parameter
+ case mtSilverfish: toReturn = new cSilverfish(); break;
+ case mtSpider: toReturn = new cSpider(); break;
+ case mtSquid: toReturn = new cSquid(); break;
+ case mtWitch: toReturn = new cWitch(); break;
+ case mtWolf: toReturn = new cWolf(); break;
+ case mtZombie: toReturn = new cZombie(false); break; // TODO: Infected zombie parameter
+ case mtZombiePigman: toReturn = new cZombiePigman(); break;
default:
{
ASSERT(!"Unhandled mob type whilst trying to spawn mob!");
diff --git a/source/Mobs/Sheep.cpp b/source/Mobs/Sheep.cpp
index 703482ddb..bda4ccff8 100644
--- a/source/Mobs/Sheep.cpp
+++ b/source/Mobs/Sheep.cpp
@@ -33,7 +33,6 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer)
-
void cSheep::OnRightClicked(cPlayer & a_Player)
{
if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_SHEARS) && (!m_IsSheared))
@@ -51,9 +50,13 @@ void cSheep::OnRightClicked(cPlayer & a_Player)
Drops.push_back(cItem(E_BLOCK_WOOL, NumDrops, m_WoolColor));
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY(), GetPosZ(), 10);
}
+ if ((a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE) && (m_WoolColor != 15 - a_Player.GetEquippedItem().m_ItemDamage))
+ {
+ m_WoolColor = 15 - a_Player.GetEquippedItem().m_ItemDamage;
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.GetInventory().RemoveOneEquippedItem();
+ }
+ m_World->BroadcastEntityMetadata(*this);
+ }
}
-
-
-
-
-
diff --git a/source/Mobs/Wolf.cpp b/source/Mobs/Wolf.cpp
index 2baeb4b7b..b9db53c7f 100644
--- a/source/Mobs/Wolf.cpp
+++ b/source/Mobs/Wolf.cpp
@@ -11,10 +11,12 @@
cWolf::cWolf(void) :
super("Wolf", mtWolf, "mob.wolf.hurt", "mob.wolf.death", 0.6, 0.8),
- m_bIsAngry(false),
- m_bIsTame(false),
- m_bIsSitting(false),
- m_bIsBegging(false)
+ m_IsAngry(false),
+ m_IsTame(false),
+ m_IsSitting(false),
+ m_IsBegging(false),
+ m_Owner(""),
+ m_CollarColor(14)
{
}
@@ -25,9 +27,9 @@ cWolf::cWolf(void) :
void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI)
{
super::DoTakeDamage(a_TDI);
- if (!m_bIsTame)
+ if (!m_IsTame)
{
- m_bIsAngry = true;
+ m_IsAngry = true;
}
m_World->BroadcastEntityMetadata(*this); // Broadcast health and possibly angry face
}
@@ -38,7 +40,7 @@ void cWolf::DoTakeDamage(TakeDamageInfo & a_TDI)
void cWolf::OnRightClicked(cPlayer & a_Player)
{
- if ((!m_bIsTame) && (!m_bIsAngry))
+ if (!IsTame() && !IsAngry())
{
if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_BONE)
{
@@ -47,10 +49,11 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
a_Player.GetInventory().RemoveOneEquippedItem();
}
- if (m_World->GetTickRandomNumber(10) == 5)
+ if (m_World->GetTickRandomNumber(7) == 0)
{
SetMaxHealth(20);
- m_bIsTame = true;
+ SetIsTame(true);
+ SetOwner(a_Player.GetName());
m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_WOLF_TAMED);
}
else
@@ -59,19 +62,119 @@ void cWolf::OnRightClicked(cPlayer & a_Player)
}
}
}
- else if (m_bIsTame)
+ else if (IsTame())
{
- if (m_bIsSitting)
+ if (a_Player.GetName() == m_Owner) // Is the player the owner of the dog?
{
- m_bIsSitting = false;
+ if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_DYE)
+ {
+ m_CollarColor = 15 - a_Player.GetEquippedItem().m_ItemDamage;
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.GetInventory().RemoveOneEquippedItem();
+ }
+ }
+ else if (IsSitting())
+ {
+ SetIsSitting(false);
+ }
+ else
+ {
+ SetIsSitting(true);
+ }
}
- else
+ }
+
+ m_World->BroadcastEntityMetadata(*this);
+}
+
+
+
+
+
+void cWolf::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ if (!IsAngry())
+ {
+ cMonster::Tick(a_Dt, a_Chunk);
+ }
+ else
+ {
+ super::Tick(a_Dt, a_Chunk);
+ }
+
+ if (IsSitting())
+ {
+ m_bMovingToDestination = false;
+ }
+
+ cPlayer * a_Closest_Player = FindClosestPlayer();
+ if (a_Closest_Player != NULL)
+ {
+ switch (a_Closest_Player->GetEquippedItem().m_ItemType)
{
- m_bIsSitting = true;
+ case E_ITEM_BONE:
+ case E_ITEM_RAW_BEEF:
+ case E_ITEM_STEAK:
+ case E_ITEM_RAW_CHICKEN:
+ case E_ITEM_COOKED_CHICKEN:
+ case E_ITEM_ROTTEN_FLESH:
+ {
+ if (!IsBegging())
+ {
+ SetIsBegging(true);
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ Vector3f a_NewDestination = a_Closest_Player->GetPosition();
+ a_NewDestination.y = a_NewDestination.y + 1; // Look at the head of the player, not his feet.
+ m_Destination = Vector3f(a_NewDestination);
+ m_bMovingToDestination = false;
+ break;
+ }
+ default:
+ {
+ if (IsBegging())
+ {
+ SetIsBegging(false);
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ }
}
}
- m_World->BroadcastEntityMetadata(*this);
+ class cCallback :
+ public cPlayerListCallback
+ {
+ virtual bool Item(cPlayer * Player) override
+ {
+ OwnerCoords = Player->GetPosition();
+ return false;
+ }
+ public:
+ Vector3f OwnerCoords;
+ } Callback;
+ m_World->DoWithPlayer(m_Owner, Callback);
+ Vector3f OwnerCoords = Callback.OwnerCoords;
+
+ if (IsTame())
+ {
+ if (m_Owner != "")
+ {
+ double Distance = (OwnerCoords - GetPosition()).Length();
+ if (Distance < 3)
+ {
+ m_bMovingToDestination = false;
+ }
+ else if ((Distance > 30) && (!IsSitting()))
+ {
+ TeleportToCoords(OwnerCoords.x, OwnerCoords.y, OwnerCoords.z);
+ }
+ else
+ {
+ m_Destination = OwnerCoords;
+ }
+ }
+ }
}
diff --git a/source/Mobs/Wolf.h b/source/Mobs/Wolf.h
index 98074ba11..d51d4e78a 100644
--- a/source/Mobs/Wolf.h
+++ b/source/Mobs/Wolf.h
@@ -2,6 +2,7 @@
#pragma once
#include "PassiveAggressiveMonster.h"
+#include "../Entities/Entity.h"
@@ -19,19 +20,32 @@ public:
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
-
- bool IsSitting(void) const { return m_bIsSitting; }
- bool IsTame(void) const { return m_bIsTame; }
- bool IsBegging(void) const { return m_bIsBegging; }
- bool IsAngry(void) const { return m_bIsAngry; }
-
-private:
-
- bool m_bIsSitting;
- bool m_bIsTame;
- bool m_bIsBegging;
- bool m_bIsAngry;
-
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+
+ // Get functions
+ bool IsSitting (void) const { return m_IsSitting; }
+ bool IsTame (void) const { return m_IsTame; }
+ bool IsBegging (void) const { return m_IsBegging; }
+ bool IsAngry (void) const { return m_IsAngry; }
+ AString GetOwner (void) const { return m_Owner; }
+ int GetCollarColor(void) const { return m_CollarColor; }
+
+ // Set functions
+ void SetIsSitting (bool a_IsSitting) { m_IsSitting = a_IsSitting; }
+ void SetIsTame (bool a_IsTame) { m_IsTame = a_IsTame; }
+ void SetIsBegging (bool a_IsBegging) { m_IsBegging = a_IsBegging; }
+ void SetIsAngry (bool a_IsAngry) { m_IsAngry = a_IsAngry; }
+ void SetOwner (AString a_NewOwner) { m_Owner = a_NewOwner; }
+ void SetCollarColor(int a_CollarColor) { m_CollarColor = a_CollarColor; }
+
+protected:
+
+ bool m_IsSitting;
+ bool m_IsTame;
+ bool m_IsBegging;
+ bool m_IsAngry;
+ AString m_Owner;
+ int m_CollarColor;
} ;