summaryrefslogtreecommitdiffstats
path: root/src/Mobs/Slime.cpp
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-07-18 23:21:04 +0200
committermadmaxoft <github@xoft.cz>2014-07-18 23:21:04 +0200
commit44a4a83292f8d0f9011e76fce2e604587e1c3711 (patch)
treee5fb8b4386162f5265406f8eb35b4100002a2568 /src/Mobs/Slime.cpp
parentMerge branch 'Sign' (diff)
parentFixed slime-related comments. (diff)
downloadcuberite-44a4a83292f8d0f9011e76fce2e604587e1c3711.tar
cuberite-44a4a83292f8d0f9011e76fce2e604587e1c3711.tar.gz
cuberite-44a4a83292f8d0f9011e76fce2e604587e1c3711.tar.bz2
cuberite-44a4a83292f8d0f9011e76fce2e604587e1c3711.tar.lz
cuberite-44a4a83292f8d0f9011e76fce2e604587e1c3711.tar.xz
cuberite-44a4a83292f8d0f9011e76fce2e604587e1c3711.tar.zst
cuberite-44a4a83292f8d0f9011e76fce2e604587e1c3711.zip
Diffstat (limited to '')
-rw-r--r--src/Mobs/Slime.cpp76
1 files changed, 73 insertions, 3 deletions
diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp
index 52a52bb39..b709ec664 100644
--- a/src/Mobs/Slime.cpp
+++ b/src/Mobs/Slime.cpp
@@ -2,16 +2,25 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#include "Slime.h"
+#include "FastRandom.h"
+#include "World.h"
-/// 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,7 +34,9 @@ void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
}
- if (GetSize() == 1)
+
+ // Only slimes with the size 1 can drop slimeballs.
+ if (m_Size == 1)
{
AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_SLIMEBALL);
}
@@ -34,3 +45,62 @@ void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer)
+
+void cSlime::Attack(float a_Dt)
+{
+ if (m_Size > 1)
+ {
+ // Only slimes larger than size 1 attack 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(1.0f) * 360.0f);
+ m_World->SpawnMobFinalize(NewSlime);
+ }
+ }
+ super::KilledBy(a_TDI);
+}
+
+
+
+
+
+const AString cSlime::GetSizeName(int a_Size) const
+{
+ if (a_Size > 1)
+ {
+ return "big";
+ }
+ else
+ {
+ return "small";
+ }
+}
+
+
+
+