From 52d4c49d5cd2c15078c84a18821761b723833584 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 17 Jul 2014 22:32:23 +0200 Subject: Fixed many slime bugs. - Fixed slime hurt/death sound - Added slime spawning on death. - Fixed the max health. - Fixed the attack damage. - Little slimes should not attack players. --- src/Entities/Entity.cpp | 5 +--- src/Mobs/Slime.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- src/Mobs/Slime.h | 8 ++++-- 3 files changed, 74 insertions(+), 7 deletions(-) (limited to 'src') 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; } ; -- cgit v1.2.3 From fba93aac2aa90fa654fef9fe4252042aae53893f Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 17 Jul 2014 23:32:01 +0200 Subject: Split into more lines. --- src/Mobs/Slime.cpp | 14 +++++++++----- src/Mobs/Slime.h | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index d74b66e5b..4e12fca51 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -11,7 +11,13 @@ /// Creates a slime of the specified size; size is 1 .. 3, with 1 being the smallest cSlime::cSlime(int 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), + 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); @@ -72,9 +78,7 @@ void cSlime::KilledBy(TakeDamageInfo & a_TDI) 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); - + NewSlime->SetYaw(Random.NextFloat(1.0f) * 360.0f); m_World->SpawnMobFinalize(NewSlime); } } @@ -85,7 +89,7 @@ void cSlime::KilledBy(TakeDamageInfo & a_TDI) -const AString & cSlime::GetSizeName(int a_Size) +const AString cSlime::GetSizeName(int a_Size) const { if (a_Size > 1) { diff --git a/src/Mobs/Slime.h b/src/Mobs/Slime.h index 1f66d9afb..87c5a8e5e 100644 --- a/src/Mobs/Slime.h +++ b/src/Mobs/Slime.h @@ -23,7 +23,7 @@ public: virtual void KilledBy(TakeDamageInfo & a_TDI) override; int GetSize(void) const { return m_Size; } - const AString & GetSizeName(int a_Size); + const AString GetSizeName(int a_Size) const; protected: -- cgit v1.2.3 From 509d3d3b62c2dc5b328cf122c0fc5f0595b73721 Mon Sep 17 00:00:00 2001 From: Howaner Date: Fri, 18 Jul 2014 16:55:28 +0200 Subject: Slime sizes are 1, 2 or 4 and not 1, 2 or 3. --- src/Mobs/Monster.cpp | 2 +- src/Mobs/Slime.cpp | 4 ++-- src/Mobs/Slime.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index e36634c73..2a796e8eb 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -867,7 +867,7 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) } case mtSlime: { - toReturn = new cSlime(Random.NextInt(2) + 1); + toReturn = new cSlime(1 << Random.NextInt(3)); break; } case mtSkeleton: diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 4e12fca51..4b123df12 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -9,7 +9,6 @@ -/// Creates a slime of the specified size; size is 1 .. 3, with 1 being the smallest cSlime::cSlime(int a_Size) : super("Slime", mtSlime, @@ -36,7 +35,8 @@ 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); } diff --git a/src/Mobs/Slime.h b/src/Mobs/Slime.h index 87c5a8e5e..b0e2f627c 100644 --- a/src/Mobs/Slime.h +++ b/src/Mobs/Slime.h @@ -13,7 +13,7 @@ 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 can be 1, 2 or 4, with 1 is the smallest and 4 is the tallest. */ cSlime(int a_Size); CLASS_PROTODEF(cSlime); -- cgit v1.2.3 From 19d012c96ec13498d97d8e43136cc09eca3dca2e Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 18 Jul 2014 23:20:42 +0200 Subject: Fixed slime-related comments. --- src/Mobs/Monster.cpp | 4 ++-- src/Mobs/Slime.cpp | 4 ++-- src/Mobs/Slime.h | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 2a796e8eb..19851e064 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -867,13 +867,13 @@ cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) } case mtSlime: { - toReturn = new cSlime(1 << Random.NextInt(3)); + toReturn = new cSlime(1 << Random.NextInt(3)); // Size 1, 2 or 4 break; } case mtSkeleton: { // TODO: Actual detection of spawning in Nether - toReturn = new cSkeleton(Random.NextInt(1) == 0 ? false : true); + toReturn = new cSkeleton((Random.NextInt(1) == 0) ? false : true); break; } case mtVillager: diff --git a/src/Mobs/Slime.cpp b/src/Mobs/Slime.cpp index 4b123df12..b709ec664 100644 --- a/src/Mobs/Slime.cpp +++ b/src/Mobs/Slime.cpp @@ -48,9 +48,9 @@ void cSlime::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cSlime::Attack(float a_Dt) { - if (m_Size != 1) + if (m_Size > 1) { - // Only slimes with the size 2 and 3 attacks a player. + // Only slimes larger than size 1 attack a player. super::Attack(a_Dt); } } diff --git a/src/Mobs/Slime.h b/src/Mobs/Slime.h index b0e2f627c..15ae113dc 100644 --- a/src/Mobs/Slime.h +++ b/src/Mobs/Slime.h @@ -18,16 +18,21 @@ public: CLASS_PROTODEF(cSlime); + // cAggressiveMonster overrides: 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; } + + /** Returns the text describing the slime's size, as used by the client's resource subsystem for sounds. + Returns either "big" or "small". */ const AString GetSizeName(int a_Size) const; protected: - /** Size of the slime, 1 .. 3, with 1 being the smallest */ + /** Size of the slime, with 1 being the smallest. + Vanilla uses sizes 1, 2 and 4 only. */ int m_Size; } ; -- cgit v1.2.3