summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Horse.cpp
diff options
context:
space:
mode:
authorLogicParrot <LogicParrot@users.noreply.github.com>2017-08-29 19:32:25 +0200
committerLogicParrot <LogicParrot@users.noreply.github.com>2017-08-29 19:32:25 +0200
commitd0a2f22bc40b9a1c961d57962056501591d5b49f (patch)
tree69af4bab3021203536aab57bad1308f17636fd4c /src/Mobs/Horse.cpp
parentImplemented chickens (diff)
downloadcuberite-d0a2f22bc40b9a1c961d57962056501591d5b49f.tar
cuberite-d0a2f22bc40b9a1c961d57962056501591d5b49f.tar.gz
cuberite-d0a2f22bc40b9a1c961d57962056501591d5b49f.tar.bz2
cuberite-d0a2f22bc40b9a1c961d57962056501591d5b49f.tar.lz
cuberite-d0a2f22bc40b9a1c961d57962056501591d5b49f.tar.xz
cuberite-d0a2f22bc40b9a1c961d57962056501591d5b49f.tar.zst
cuberite-d0a2f22bc40b9a1c961d57962056501591d5b49f.zip
Diffstat (limited to 'src/Mobs/Horse.cpp')
-rw-r--r--src/Mobs/Horse.cpp295
1 files changed, 148 insertions, 147 deletions
diff --git a/src/Mobs/Horse.cpp b/src/Mobs/Horse.cpp
index 21a58489d..484864afe 100644
--- a/src/Mobs/Horse.cpp
+++ b/src/Mobs/Horse.cpp
@@ -11,22 +11,23 @@
cHorse::cHorse(int Type, int Color, int Style, int TameTimes) :
- super("Horse", mtHorse, "entity.horse.hurt", "entity.horse.death", 1.4, 1.6),
- m_bHasChest(false),
- m_bIsEating(false),
- m_bIsRearing(false),
- m_bIsMouthOpen(false),
- m_bIsTame(false),
- m_bIsSaddled(false),
- m_Type(Type),
- m_Color(Color),
- m_Style(Style),
- m_Armour(0),
- m_TimesToTame(TameTimes),
- m_TameAttemptTimes(0),
- m_RearTickCount(0),
- m_MaxSpeed(14.0)
+ super("Horse", mtHorse, "entity.horse.hurt", "entity.horse.death", 1.4, 1.6),
+ m_bHasChest(false),
+ m_bIsEating(false),
+ m_bIsRearing(false),
+ m_bIsMouthOpen(false),
+ m_bIsTame(false),
+ m_bIsSaddled(false),
+ m_Type(Type),
+ m_Color(Color),
+ m_Style(Style),
+ m_Armour(0),
+ m_TimesToTame(TameTimes),
+ m_TameAttemptTimes(0),
+ m_RearTickCount(0),
+ m_MaxSpeed(14.0)
{
+ m_EMPersonality = PASSIVE;
}
@@ -35,67 +36,67 @@ cHorse::cHorse(int Type, int Color, int Style, int TameTimes) :
void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
- super::Tick(a_Dt, a_Chunk);
- if (!IsTicking())
- {
- // The base class tick destroyed us
- return;
- }
-
- auto & Random = GetRandomProvider();
-
- if (!m_bIsMouthOpen)
- {
- if (Random.RandBool(0.02))
- {
- m_bIsMouthOpen = true;
- }
- }
- else
- {
- if (Random.RandBool(0.10))
- {
- m_bIsMouthOpen = false;
- }
- }
-
- if ((m_Attachee != nullptr) && (!m_bIsTame))
- {
- if (m_TameAttemptTimes < m_TimesToTame)
- {
- if (Random.RandBool(0.02))
- {
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_EAST));
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_WEST));
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_EAST));
- m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_WEST));
-
- m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f);
- m_Attachee->Detach();
- m_bIsRearing = true;
- }
- }
- else
- {
- m_World->GetBroadcaster().BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5);
- m_bIsTame = true;
- }
- }
-
- if (m_bIsRearing)
- {
- if (m_RearTickCount == 20)
- {
- m_bIsRearing = false;
- m_RearTickCount = 0;
- }
- else
- {
- m_RearTickCount++;
- }
- }
-
- m_World->BroadcastEntityMetadata(*this);
+ super::Tick(a_Dt, a_Chunk);
+ if (!IsTicking())
+ {
+ // The base class tick destroyed us
+ return;
+ }
+
+ auto & Random = GetRandomProvider();
+
+ if (!m_bIsMouthOpen)
+ {
+ if (Random.RandBool(0.02))
+ {
+ m_bIsMouthOpen = true;
+ }
+ }
+ else
+ {
+ if (Random.RandBool(0.10))
+ {
+ m_bIsMouthOpen = false;
+ }
+ }
+
+ if ((m_Attachee != nullptr) && (!m_bIsTame))
+ {
+ if (m_TameAttemptTimes < m_TimesToTame)
+ {
+ if (Random.RandBool(0.02))
+ {
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_EAST));
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::SOUTH_WEST));
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_EAST));
+ m_World->BroadcastSoundParticleEffect(EffectID::PARTICLE_SMOKE, FloorC(GetPosX()), FloorC(GetPosY()), FloorC(GetPosZ()), int(SmokeDirection::NORTH_WEST));
+
+ m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 1.0f);
+ m_Attachee->Detach();
+ m_bIsRearing = true;
+ }
+ }
+ else
+ {
+ m_World->GetBroadcaster().BroadcastParticleEffect("heart", static_cast<Vector3f>(GetPosition()), Vector3f{}, 0, 5);
+ m_bIsTame = true;
+ }
+ }
+
+ if (m_bIsRearing)
+ {
+ if (m_RearTickCount == 20)
+ {
+ m_bIsRearing = false;
+ m_RearTickCount = 0;
+ }
+ else
+ {
+ m_RearTickCount++;
+ }
+ }
+
+ m_World->BroadcastEntityMetadata(*this);
}
@@ -104,63 +105,63 @@ void cHorse::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cHorse::OnRightClicked(cPlayer & a_Player)
{
- super::OnRightClicked(a_Player);
-
- if (m_bIsTame)
- {
- if (!m_bIsSaddled)
- {
- if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE)
- {
- // Saddle the horse:
- if (!a_Player.IsGameModeCreative())
- {
- a_Player.GetInventory().RemoveOneEquippedItem();
- }
- m_bIsSaddled = true;
- m_World->BroadcastEntityMetadata(*this);
- }
- else
- {
- a_Player.AttachTo(this);
- }
- }
- else
- {
- a_Player.AttachTo(this);
- }
- }
- else if (a_Player.GetEquippedItem().IsEmpty())
- {
- // Check if leashed / unleashed to player before try to ride
- if (!m_IsLeashActionJustDone)
- {
- if (m_Attachee != nullptr)
- {
- if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
- {
- a_Player.Detach();
- return;
- }
-
- if (m_Attachee->IsPlayer())
- {
- return;
- }
-
- m_Attachee->Detach();
- }
-
- m_TameAttemptTimes++;
- a_Player.AttachTo(this);
- }
- }
- else
- {
- m_bIsRearing = true;
- m_RearTickCount = 0;
- m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 0.8f);
- }
+ super::OnRightClicked(a_Player);
+
+ if (m_bIsTame)
+ {
+ if (!m_bIsSaddled)
+ {
+ if (a_Player.GetEquippedItem().m_ItemType == E_ITEM_SADDLE)
+ {
+ // Saddle the horse:
+ if (!a_Player.IsGameModeCreative())
+ {
+ a_Player.GetInventory().RemoveOneEquippedItem();
+ }
+ m_bIsSaddled = true;
+ m_World->BroadcastEntityMetadata(*this);
+ }
+ else
+ {
+ a_Player.AttachTo(this);
+ }
+ }
+ else
+ {
+ a_Player.AttachTo(this);
+ }
+ }
+ else if (a_Player.GetEquippedItem().IsEmpty())
+ {
+ // Check if leashed / unleashed to player before try to ride
+ if (!m_IsLeashActionJustDone)
+ {
+ if (m_Attachee != nullptr)
+ {
+ if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID())
+ {
+ a_Player.Detach();
+ return;
+ }
+
+ if (m_Attachee->IsPlayer())
+ {
+ return;
+ }
+
+ m_Attachee->Detach();
+ }
+
+ m_TameAttemptTimes++;
+ a_Player.AttachTo(this);
+ }
+ }
+ else
+ {
+ m_bIsRearing = true;
+ m_RearTickCount = 0;
+ m_World->BroadcastSoundEffect("entity.horse.angry", GetPosX(), GetPosY(), GetPosZ(), 1.0f, 0.8f);
+ }
}
@@ -169,16 +170,16 @@ void cHorse::OnRightClicked(cPlayer & a_Player)
void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
- unsigned int LootingLevel = 0;
- if (a_Killer != nullptr)
- {
- LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
- }
- AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER);
- if (m_bIsSaddled)
- {
- a_Drops.push_back(cItem(E_ITEM_SADDLE, 1));
- }
+ unsigned int LootingLevel = 0;
+ if (a_Killer != nullptr)
+ {
+ LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
+ }
+ AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_LEATHER);
+ if (m_bIsSaddled)
+ {
+ a_Drops.push_back(cItem(E_ITEM_SADDLE, 1));
+ }
}
@@ -187,8 +188,8 @@ void cHorse::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cHorse::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
{
- if ((m_bIsTame) && (m_bIsSaddled))
- {
- super::HandleSpeedFromAttachee(a_Forward * m_MaxSpeed, a_Sideways * m_MaxSpeed);
- }
+ if ((m_bIsTame) && (m_bIsSaddled))
+ {
+ super::HandleSpeedFromAttachee(a_Forward * m_MaxSpeed, a_Sideways * m_MaxSpeed);
+ }
}