From c865fc8ca501e7405da2ce8353628373e4526053 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 1 Aug 2014 22:05:40 +0100 Subject: Improved endermen code a little --- src/Mobs/Monster.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 622a67816..94df991a3 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -276,7 +276,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) if (DoesPosYRequireJump((int)floor(m_Destination.y))) { m_bOnGround = false; - AddSpeedY(5.2); // Jump!! + + // TODO: Change to AddSpeedY once collision detection is fixed - currently, mobs will go into blocks attempting to jump without a teleport + AddPosY(1.2); // Jump!! } } -- cgit v1.2.3 From 0911072d27820bd608bb908088419d3ec5151434 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 4 Aug 2014 01:34:12 +0200 Subject: Attempt to fix knockback and swimming. --- src/Mobs/Monster.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 94df991a3..66c9aadeb 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -292,6 +292,10 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) { Distance *= 2.5; } + else if (IsSwimming()) + { + Distance *= 1.3; + } else { // Don't let the mob move too much if he's falling. @@ -301,11 +305,13 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) AddSpeedX(Distance.x); AddSpeedZ(Distance.z); - if (m_EMState == ESCAPING) - { // Runs Faster when escaping :D otherwise they just walk away + /* It's too buggy! */ + /** if (m_EMState == ESCAPING) + { + // Runs Faster when escaping :D otherwise they just walk away SetSpeedX (GetSpeedX() * 2.f); SetSpeedZ (GetSpeedZ() * 2.f); - } + } */ } else { -- cgit v1.2.3 From 7bea90d6caca9f9b4389fe14ab49720f22cb9273 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 4 Aug 2014 01:35:25 +0200 Subject: Fixed warnings --- src/Mobs/Monster.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 66c9aadeb..54ad869c2 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -290,16 +290,16 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) if (m_bOnGround) { - Distance *= 2.5; + Distance *= 2.5f; } else if (IsSwimming()) { - Distance *= 1.3; + Distance *= 1.3f; } else { // Don't let the mob move too much if he's falling. - Distance *= 0.25; + Distance *= 0.25f; } AddSpeedX(Distance.x); -- cgit v1.2.3 From e70077361d239f3f3a9d8a94c8262d663018f901 Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 4 Aug 2014 11:23:35 +0200 Subject: Changed /** to /* --- src/Mobs/Monster.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 54ad869c2..a9889b62f 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -305,13 +305,15 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) AddSpeedX(Distance.x); AddSpeedZ(Distance.z); - /* It's too buggy! */ - /** if (m_EMState == ESCAPING) + // It's too buggy! + /* + if (m_EMState == ESCAPING) { // Runs Faster when escaping :D otherwise they just walk away SetSpeedX (GetSpeedX() * 2.f); SetSpeedZ (GetSpeedZ() * 2.f); - } */ + } + */ } else { -- cgit v1.2.3 From 1fa210c7f91030ac18fd880fcf131e8104c0b889 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Mon, 4 Aug 2014 11:16:19 +0200 Subject: Refactored case-conversion functions. StrToLower() returns a modified copy of the string, InPlaceLowercase() modifies the string in-place. --- src/Mobs/Monster.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 94df991a3..53334753a 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -710,8 +710,7 @@ AString cMonster::MobTypeToString(cMonster::eType a_MobType) cMonster::eType cMonster::StringToMobType(const AString & a_Name) { - AString lcName(a_Name); - StrToLower(lcName); + AString lcName = StrToLower(a_Name); // Binary-search for the lowercase name: int lo = 0, hi = ARRAYCOUNT(g_MobTypeNames) - 1; -- cgit v1.2.3 From 690e6cb6f8d0c67f3725de8398659115ab823f4c Mon Sep 17 00:00:00 2001 From: reiter Date: Thu, 28 Aug 2014 00:01:01 +0200 Subject: Fixed mob burning. Fixes #1298 --- src/Mobs/Monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index fe8a7346f..f7ee0b0c0 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -1024,7 +1024,7 @@ void cMonster::HandleDaylightBurning(cChunk & a_Chunk) (a_Chunk.GetBlock(RelX, RelY, RelZ) != E_BLOCK_SOULSAND) && // Not on soulsand (GetWorld()->GetTimeOfDay() < (12000 + 1000)) && // It is nighttime !IsOnFire() && // Not already burning - GetWorld()->IsWeatherWetAt(POSX_TOINT, POSZ_TOINT) // Not raining + GetWorld()->IsWeatherSunnyAt(POSX_TOINT, POSZ_TOINT) // Not raining ) { // Burn for 100 ticks, then decide again -- cgit v1.2.3 From d7ee2245e89ce9e71f0172d5a0edf605060bcf2a Mon Sep 17 00:00:00 2001 From: Howaner Date: Sat, 30 Aug 2014 12:44:54 +0200 Subject: Added SetWalkSpeed() to cMonster. --- src/Mobs/Monster.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f7ee0b0c0..09a22cd35 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -89,6 +89,7 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_DropChanceBoots(0.085f) , m_CanPickUpLoot(true) , m_BurnsInDaylight(false) + , m_WalkSpeed(1.0) { if (!a_ConfigName.empty()) { @@ -302,6 +303,9 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) Distance *= 0.25f; } + // Apply walk speed: + Distance *= m_WalkSpeed; + AddSpeedX(Distance.x); AddSpeedZ(Distance.z); -- cgit v1.2.3 From 7c4cb9a3852e33d8bcc5f8283485e833c6eab93e Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Sep 2014 20:12:56 +0200 Subject: Added CustomName to cMonster. --- src/Mobs/Monster.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f7ee0b0c0..6a477ca1c 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -75,6 +75,8 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_IdleInterval(0) , m_DestroyTimer(0) , m_MobType(a_MobType) + , m_CustomName("") + , m_CustomNameAlwaysVisible(false) , m_SoundHurt(a_SoundHurt) , m_SoundDeath(a_SoundDeath) , m_AttackRate(3) @@ -679,6 +681,33 @@ void cMonster::InStateEscaping(float a_Dt) +void cMonster::SetCustomName(const AString & a_CustomName) +{ + m_CustomName = a_CustomName; + + // The maximal length is 64 + if (a_CustomName.length() > 64) + { + m_CustomName = a_CustomName.substr(0, 64); + } + + m_World->BroadcastEntityMetadata(*this); +} + + + + + +void cMonster::SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible) +{ + m_CustomNameAlwaysVisible = a_CustomNameAlwaysVisible; + m_World->BroadcastEntityMetadata(*this); +} + + + + + void cMonster::GetMonsterConfig(const AString & a_Name) { cRoot::Get()->GetMonsterConfig()->AssignAttributes(this, a_Name); -- cgit v1.2.3 From dfed6f94ca78f2e104ed316d83400b0ca74cb79a Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Sep 2014 21:05:45 +0200 Subject: Added name tag --- src/Mobs/Monster.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 6a477ca1c..a89fa32a3 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -553,6 +553,25 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI) +void cMonster::OnRightClicked(cPlayer & a_Player) +{ + super::OnRightClicked(a_Player); + + const cItem & EquippedItem = a_Player.GetEquippedItem(); + if ((EquippedItem.m_ItemType == E_ITEM_NAME_TAG) && !EquippedItem.m_CustomName.empty()) + { + SetCustomName(EquippedItem.m_CustomName); + if (!a_Player.IsGameModeCreative()) + { + a_Player.GetInventory().RemoveOneEquippedItem(); + } + } +} + + + + + // Checks to see if EventSeePlayer should be fired // monster sez: Do I see the player void cMonster::CheckEventSeePlayer(void) -- cgit v1.2.3 From 5c53608dd0e59d67a9aad5b03a58e1ff48d619b3 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 2 Sep 2014 19:34:58 +0200 Subject: Added CustomName saving. --- src/Mobs/Monster.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index a89fa32a3..b0b836dff 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -710,7 +710,10 @@ void cMonster::SetCustomName(const AString & a_CustomName) m_CustomName = a_CustomName.substr(0, 64); } - m_World->BroadcastEntityMetadata(*this); + if (m_World != NULL) + { + m_World->BroadcastEntityMetadata(*this); + } } @@ -720,7 +723,10 @@ void cMonster::SetCustomName(const AString & a_CustomName) void cMonster::SetCustomNameAlwaysVisible(bool a_CustomNameAlwaysVisible) { m_CustomNameAlwaysVisible = a_CustomNameAlwaysVisible; - m_World->BroadcastEntityMetadata(*this); + if (m_World != NULL) + { + m_World->BroadcastEntityMetadata(*this); + } } -- cgit v1.2.3 From 38e824dbcfa66ee63670f6e8aa708e7a4aa58f5e Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 2 Sep 2014 20:10:41 +0200 Subject: Renamed SetWalkSpeed() to SetRelativeWalkSpeed() --- src/Mobs/Monster.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 09a22cd35..7e40794b1 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -89,7 +89,7 @@ cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString , m_DropChanceBoots(0.085f) , m_CanPickUpLoot(true) , m_BurnsInDaylight(false) - , m_WalkSpeed(1.0) + , m_RelativeWalkSpeed(1.0) { if (!a_ConfigName.empty()) { @@ -304,7 +304,7 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) } // Apply walk speed: - Distance *= m_WalkSpeed; + Distance *= m_RelativeWalkSpeed; AddSpeedX(Distance.x); AddSpeedZ(Distance.z); -- cgit v1.2.3 From fdabfd77e22397e149740bb5cb09a2f77805f05f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 13 Sep 2014 22:49:27 +0100 Subject: Improved cBlockHandler::DropBlock --- src/Mobs/Monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 7e40794b1..81acf1a93 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -283,7 +283,7 @@ void cMonster::Tick(float a_Dt, cChunk & a_Chunk) } } - Vector3f Distance = m_Destination - GetPosition(); + Vector3d Distance = m_Destination - GetPosition(); if (!ReachedDestination() && !ReachedFinalDestination()) // If we haven't reached any sort of destination, move { Distance.y = 0; -- cgit v1.2.3 From 6e7c0e33b5dd6d86d66ac2eb1a07a33652a708fd Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 17 Sep 2014 18:40:10 +0100 Subject: Added first test to show the object can be created --- src/Mobs/Monster.cpp | 116 +++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index f7ee0b0c0..b6e22c0ee 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -24,38 +24,38 @@ The strings need to be lowercase (for more efficient comparisons in StringToMobT */ static const struct { - cMonster::eType m_Type; + eMonsterType m_Type; const char * m_lcName; } g_MobTypeNames[] = { - {cMonster::mtBat, "bat"}, - {cMonster::mtBlaze, "blaze"}, - {cMonster::mtCaveSpider, "cavespider"}, - {cMonster::mtChicken, "chicken"}, - {cMonster::mtCow, "cow"}, - {cMonster::mtCreeper, "creeper"}, - {cMonster::mtEnderman, "enderman"}, - {cMonster::mtEnderDragon, "enderdragon"}, - {cMonster::mtGhast, "ghast"}, - {cMonster::mtHorse, "horse"}, - {cMonster::mtIronGolem, "irongolem"}, - {cMonster::mtMagmaCube, "magmacube"}, - {cMonster::mtMooshroom, "mooshroom"}, - {cMonster::mtOcelot, "ocelot"}, - {cMonster::mtPig, "pig"}, - {cMonster::mtSheep, "sheep"}, - {cMonster::mtSilverfish, "silverfish"}, - {cMonster::mtSkeleton, "skeleton"}, - {cMonster::mtSlime, "slime"}, - {cMonster::mtSnowGolem, "snowgolem"}, - {cMonster::mtSpider, "spider"}, - {cMonster::mtSquid, "squid"}, - {cMonster::mtVillager, "villager"}, - {cMonster::mtWitch, "witch"}, - {cMonster::mtWither, "wither"}, - {cMonster::mtWolf, "wolf"}, - {cMonster::mtZombie, "zombie"}, - {cMonster::mtZombiePigman, "zombiepigman"}, + {mtBat, "bat"}, + {mtBlaze, "blaze"}, + {mtCaveSpider, "cavespider"}, + {mtChicken, "chicken"}, + {mtCow, "cow"}, + {mtCreeper, "creeper"}, + {mtEnderman, "enderman"}, + {mtEnderDragon, "enderdragon"}, + {mtGhast, "ghast"}, + {mtHorse, "horse"}, + {mtIronGolem, "irongolem"}, + {mtMagmaCube, "magmacube"}, + {mtMooshroom, "mooshroom"}, + {mtOcelot, "ocelot"}, + {mtPig, "pig"}, + {mtSheep, "sheep"}, + {mtSilverfish, "silverfish"}, + {mtSkeleton, "skeleton"}, + {mtSlime, "slime"}, + {mtSnowGolem, "snowgolem"}, + {mtSpider, "spider"}, + {mtSquid, "squid"}, + {mtVillager, "villager"}, + {mtWitch, "witch"}, + {mtWither, "wither"}, + {mtWolf, "wolf"}, + {mtZombie, "zombie"}, + {mtZombiePigman, "zombiepigman"}, } ; @@ -65,7 +65,7 @@ static const struct //////////////////////////////////////////////////////////////////////////////// // cMonster: -cMonster::cMonster(const AString & a_ConfigName, eType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) +cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const AString & a_SoundHurt, const AString & a_SoundDeath, double a_Width, double a_Height) : super(etMonster, a_Width, a_Height) , m_EMState(IDLE) , m_EMPersonality(AGGRESSIVE) @@ -485,50 +485,50 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI) switch (m_MobType) { // Animals - case cMonster::mtChicken: - case cMonster::mtCow: - case cMonster::mtHorse: - case cMonster::mtPig: - case cMonster::mtSheep: - case cMonster::mtSquid: - case cMonster::mtMooshroom: - case cMonster::mtOcelot: - case cMonster::mtWolf: + case mtChicken: + case mtCow: + case mtHorse: + case mtPig: + case mtSheep: + case mtSquid: + case mtMooshroom: + case mtOcelot: + case mtWolf: { Reward = m_World->GetTickRandomNumber(2) + 1; break; } // Monsters - case cMonster::mtCaveSpider: - case cMonster::mtCreeper: - case cMonster::mtEnderman: - case cMonster::mtGhast: - case cMonster::mtSilverfish: - case cMonster::mtSkeleton: - case cMonster::mtSpider: - case cMonster::mtWitch: - case cMonster::mtZombie: - case cMonster::mtZombiePigman: - case cMonster::mtSlime: - case cMonster::mtMagmaCube: + case mtCaveSpider: + case mtCreeper: + case mtEnderman: + case mtGhast: + case mtSilverfish: + case mtSkeleton: + case mtSpider: + case mtWitch: + case mtZombie: + case mtZombiePigman: + case mtSlime: + case mtMagmaCube: { Reward = 6 + (m_World->GetTickRandomNumber(2)); break; } - case cMonster::mtBlaze: + case mtBlaze: { Reward = 10; break; } // Bosses - case cMonster::mtEnderDragon: + case mtEnderDragon: { Reward = 12000; break; } - case cMonster::mtWither: + case mtWither: { Reward = 50; break; @@ -697,7 +697,7 @@ bool cMonster::IsUndead(void) -AString cMonster::MobTypeToString(cMonster::eType a_MobType) +AString cMonster::MobTypeToString(eMonsterType a_MobType) { // Mob types aren't sorted, so we need to search linearly: for (size_t i = 0; i < ARRAYCOUNT(g_MobTypeNames); i++) @@ -716,7 +716,7 @@ AString cMonster::MobTypeToString(cMonster::eType a_MobType) -cMonster::eType cMonster::StringToMobType(const AString & a_Name) +eMonsterType cMonster::StringToMobType(const AString & a_Name) { AString lcName = StrToLower(a_Name); @@ -757,7 +757,7 @@ cMonster::eType cMonster::StringToMobType(const AString & a_Name) -cMonster::eFamily cMonster::FamilyFromType(eType a_Type) +cMonster::eFamily cMonster::FamilyFromType(eMonsterType a_Type) { // Passive-agressive mobs are counted in mob spawning code as passive @@ -822,7 +822,7 @@ int cMonster::GetSpawnDelay(cMonster::eFamily a_MobFamily) -cMonster * cMonster::NewMonsterFromType(cMonster::eType a_MobType) +cMonster * cMonster::NewMonsterFromType(eMonsterType a_MobType) { cFastRandom Random; cMonster * toReturn = NULL; -- cgit v1.2.3 From 77c5b410e653433a17c7cf25b115dae4c25bdbd2 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 5 Oct 2014 22:09:19 +0200 Subject: Fixed eMonsterType Lua API mismatch. --- src/Mobs/Monster.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 12ca6bbbe..cc48dba5e 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -62,6 +62,16 @@ static const struct +eMonsterType StringToMobType(const AString & a_MobString) +{ + LOGWARNING("%s: Function is obsolete, use cMonster::StringToMobType() instead"); + return cMonster::StringToMobType(a_MobString); +} + + + + + //////////////////////////////////////////////////////////////////////////////// // cMonster: -- cgit v1.2.3 From c94e82980e0c21f9a7ed18c5f3279e63849e8433 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 5 Oct 2014 22:56:56 +0200 Subject: Fixed a missed value. --- src/Mobs/Monster.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Mobs/Monster.cpp') diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index cc48dba5e..73dbcb3c3 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -64,7 +64,7 @@ static const struct eMonsterType StringToMobType(const AString & a_MobString) { - LOGWARNING("%s: Function is obsolete, use cMonster::StringToMobType() instead"); + LOGWARNING("%s: Function is obsolete, use cMonster::StringToMobType() instead", __FUNCTION__); return cMonster::StringToMobType(a_MobString); } -- cgit v1.2.3