summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHowaner <franzi.moos@googlemail.com>2014-07-17 22:32:23 +0200
committerHowaner <franzi.moos@googlemail.com>2014-07-17 22:32:23 +0200
commit52d4c49d5cd2c15078c84a18821761b723833584 (patch)
tree6c0eebd51cdcbc7a9ba71ad3341e300622d21dc8
parentFixed mob knockback (diff)
downloadcuberite-52d4c49d5cd2c15078c84a18821761b723833584.tar
cuberite-52d4c49d5cd2c15078c84a18821761b723833584.tar.gz
cuberite-52d4c49d5cd2c15078c84a18821761b723833584.tar.bz2
cuberite-52d4c49d5cd2c15078c84a18821761b723833584.tar.lz
cuberite-52d4c49d5cd2c15078c84a18821761b723833584.tar.xz
cuberite-52d4c49d5cd2c15078c84a18821761b723833584.tar.zst
cuberite-52d4c49d5cd2c15078c84a18821761b723833584.zip
-rw-r--r--src/Entities/Entity.cpp5
-rw-r--r--src/Mobs/Slime.cpp68
-rw-r--r--src/Mobs/Slime.h8
3 files changed, 74 insertions, 7 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 4a6de25b7..3433258fd 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1146,10 +1146,7 @@ void cEntity::SetMaxHealth(int a_MaxHealth)
m_MaxHealth = a_MaxHealth;
// Reset health, if too high:
- if (m_Health > a_MaxHealth)
- {
- m_Health = a_MaxHealth;
- }
+ m_Health = std::min(m_Health, a_MaxHealth);
}
diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp
index 52a52bb39..d74b66e5b 100644
--- a/src/Mobs/Slime.cpp
+++ b/src/Mobs/Slime.cpp
@@ -2,6 +2,8 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Slime.h"
+#include "FastRandom.h"
+#include "World.h"
@@ -9,9 +11,11 @@
/// Creates a slime of the specified size; size is 1 .. 3, with 1 being the smallest
cSlime::cSlime(int a_Size) :
- super("Slime", mtSlime, "mob.slime.attack", "mob.slime.attack", 0.6 * a_Size, 0.6 * a_Size),
+ super("Slime", mtSlime, Printf("mob.slime.%s", GetSizeName(a_Size).c_str()), Printf("mob.slime.%s", GetSizeName(a_Size).c_str()), 0.6 * a_Size, 0.6 * a_Size),
m_Size(a_Size)
{
+ SetMaxHealth(a_Size * a_Size);
+ SetAttackDamage(a_Size);
}
@@ -25,6 +29,7 @@ void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
}
+
if (GetSize() == 1)
{
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL);
@@ -34,3 +39,64 @@ void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer)
+
+void cSlime::Attack(float a_Dt)
+{
+ if (m_Size != 1)
+ {
+ // Only slimes with the size 2 and 3 attacks a player.
+ super::Attack(a_Dt);
+ }
+}
+
+
+
+
+
+void cSlime::KilledBy(TakeDamageInfo & a_TDI)
+{
+ if (GetHealth() > 0)
+ {
+ return;
+ }
+
+ if (m_Size != 1)
+ {
+ cFastRandom Random;
+ int SpawnAmount = 2 + Random.NextInt(3);
+
+ for (int i = 0; i < SpawnAmount; ++i)
+ {
+ double AddX = (i % 2 - 0.5) * m_Size / 4.0;
+ double AddZ = (i / 2 - 0.5) * m_Size / 4.0;
+
+ cSlime * NewSlime = new cSlime(m_Size / 2);
+ NewSlime->SetPosition(GetPosX() + AddX, GetPosY() + 0.5, GetPosZ() + AddZ);
+ NewSlime->SetYaw(Random.NextFloat(2.0f) * 360.0f);
+ NewSlime->SetPitch(0.0f);
+
+ m_World->SpawnMobFinalize(NewSlime);
+ }
+ }
+ super::KilledBy(a_TDI);
+}
+
+
+
+
+
+const AString & cSlime::GetSizeName(int a_Size)
+{
+ if (a_Size > 1)
+ {
+ return "big";
+ }
+ else
+ {
+ return "small";
+ }
+}
+
+
+
+
diff --git a/src/Mobs/Slime.h b/src/Mobs/Slime.h
index 782c3113f..1f66d9afb 100644
--- a/src/Mobs/Slime.h
+++ b/src/Mobs/Slime.h
@@ -13,17 +13,21 @@ class cSlime :
typedef cAggressiveMonster super;
public:
- /// Creates a slime of the specified size; size is 1 .. 3, with 1 being the smallest
+ /** Creates a slime of the specified size; size is 1 .. 3, with 1 being the smallest */
cSlime(int a_Size);
CLASS_PROTODEF(cSlime);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
+ virtual void Attack(float a_Dt) override;
+ virtual void KilledBy(TakeDamageInfo & a_TDI) override;
+
int GetSize(void) const { return m_Size; }
+ const AString & GetSizeName(int a_Size);
protected:
- /// Size of the slime, 1 .. 3, with 1 being the smallest
+ /** Size of the slime, 1 .. 3, with 1 being the smallest */
int m_Size;
} ;