From 6167c79e7a822cb14431985a82f4cc5b463e556f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 18 May 2014 22:41:42 +0100 Subject: Implemented cacti damage + Implemented cacti damage * Fixed pickup tossing (PR #994 bug) --- src/ClientHandle.cpp | 5 +++-- src/Entities/Entity.cpp | 23 +++++++++++++++++++++++ src/Entities/Entity.h | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index 1009cdbd6..6d0fae3ae 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -816,9 +816,10 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB } if ( - (Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) || + ((a_Status == DIG_STATUS_STARTED) || (a_Status == DIG_STATUS_FINISHED)) && // Only do a radius check for block destruction - things like pickup tossing send coordinates that are to be ignored + ((Diff(m_Player->GetPosX(), (double)a_BlockX) > 6) || (Diff(m_Player->GetPosY(), (double)a_BlockY) > 6) || - (Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6) + (Diff(m_Player->GetPosZ(), (double)a_BlockZ) > 6)) ) { m_Player->GetWorld()->SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, m_Player); diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 4cf10a219..b7cb2c3d9 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -601,6 +601,10 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk) m_TicksSinceLastVoidDamage = 0; } + if (IsMob() || IsPlayer() || IsPickup() || IsExpOrb()) + { + DetectCacti(); + } if (IsMob() || IsPlayer()) { // Set swimming state @@ -998,6 +1002,25 @@ void cEntity::TickInVoid(cChunk & a_Chunk) +void cEntity::DetectCacti() +{ + int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT; + if ( + ((X + 1) - GetPosX() < 0.3) && (GetWorld()->GetBlock(X + 1, Y, Z) == E_BLOCK_CACTUS) || + ((GetPosX() - (X - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X - 1, Y, Z) == E_BLOCK_CACTUS) || + ((Z + 1) - GetPosZ() < 0.3) && (GetWorld()->GetBlock(X, Y, Z + 1) == E_BLOCK_CACTUS) || + ((GetPosZ() - (Z - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X, Y, Z - 1) == E_BLOCK_CACTUS) || + (((Y > 0) && (Y < cChunkDef::Height)) && ((GetPosY() - Y < 1) && (GetWorld()->GetBlock(X, Y, Z) == E_BLOCK_CACTUS))) + ) + { + TakeDamage(dtCactus, NULL, 1, 0); + } +} + + + + + void cEntity::SetSwimState(cChunk & a_Chunk) { int RelY = (int)floor(GetPosY() + 0.1); diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index df03d635b..d5e7cf5c1 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -317,6 +317,9 @@ public: /// Updates the state related to this entity being on fire virtual void TickBurning(cChunk & a_Chunk); + + /** Detects the time for application of cacti damage */ + virtual void DetectCacti(void); /// Handles when the entity is in the void virtual void TickInVoid(cChunk & a_Chunk); -- cgit v1.2.3 From 70cf4a5eafaf91f9b6d0b71f607270b7df86e6d9 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 19 May 2014 07:31:53 +0100 Subject: Fixed clanging errors. Please @tigerw make sure this is correct. --- src/Entities/Entity.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index b7cb2c3d9..1a91639ac 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1006,14 +1006,14 @@ void cEntity::DetectCacti() { int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT; if ( - ((X + 1) - GetPosX() < 0.3) && (GetWorld()->GetBlock(X + 1, Y, Z) == E_BLOCK_CACTUS) || - ((GetPosX() - (X - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X - 1, Y, Z) == E_BLOCK_CACTUS) || - ((Z + 1) - GetPosZ() < 0.3) && (GetWorld()->GetBlock(X, Y, Z + 1) == E_BLOCK_CACTUS) || - ((GetPosZ() - (Z - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X, Y, Z - 1) == E_BLOCK_CACTUS) || + (((X + 1) - GetPosX() < 0.3) && (GetWorld()->GetBlock(X + 1, Y, Z) == E_BLOCK_CACTUS)) || + (((GetPosX() - (X - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X - 1, Y, Z) == E_BLOCK_CACTUS)) || + (((Z + 1) - GetPosZ() < 0.3) && (GetWorld()->GetBlock(X, Y, Z + 1) == E_BLOCK_CACTUS)) || + (((GetPosZ() - (Z - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X, Y, Z - 1) == E_BLOCK_CACTUS)) || (((Y > 0) && (Y < cChunkDef::Height)) && ((GetPosY() - Y < 1) && (GetWorld()->GetBlock(X, Y, Z) == E_BLOCK_CACTUS))) ) { - TakeDamage(dtCactus, NULL, 1, 0); + TakeDamage(dtCactusContact, NULL, 1, 0); } } -- cgit v1.2.3 From dc39d88d3f5951479084c1ea4d51079015777f01 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 19 May 2014 10:35:21 +0100 Subject: Should have fixed assumptions about entity width. @madmaxoft can you comment? --- src/Entities/Entity.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 1a91639ac..71b9f63a7 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1005,11 +1005,12 @@ void cEntity::TickInVoid(cChunk & a_Chunk) void cEntity::DetectCacti() { int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT; + float w = m_Width / 2 if ( - (((X + 1) - GetPosX() < 0.3) && (GetWorld()->GetBlock(X + 1, Y, Z) == E_BLOCK_CACTUS)) || - (((GetPosX() - (X - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X - 1, Y, Z) == E_BLOCK_CACTUS)) || - (((Z + 1) - GetPosZ() < 0.3) && (GetWorld()->GetBlock(X, Y, Z + 1) == E_BLOCK_CACTUS)) || - (((GetPosZ() - (Z - 1)) - 1 < 0.3) && (GetWorld()->GetBlock(X, Y, Z - 1) == E_BLOCK_CACTUS)) || + (((X + 1) - GetPosX() < w) && (GetWorld()->GetBlock(X + 1, Y, Z) == E_BLOCK_CACTUS)) || + (((GetPosX() - (X - 1)) - 1 < w) && (GetWorld()->GetBlock(X - 1, Y, Z) == E_BLOCK_CACTUS)) || + (((Z + 1) - GetPosZ() < w) && (GetWorld()->GetBlock(X, Y, Z + 1) == E_BLOCK_CACTUS)) || + (((GetPosZ() - (Z - 1)) - 1 < w) && (GetWorld()->GetBlock(X, Y, Z - 1) == E_BLOCK_CACTUS)) || (((Y > 0) && (Y < cChunkDef::Height)) && ((GetPosY() - Y < 1) && (GetWorld()->GetBlock(X, Y, Z) == E_BLOCK_CACTUS))) ) { -- cgit v1.2.3 From 6de0257bbe1f0c676e9cc1401298f08b96b54e73 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Mon, 19 May 2014 13:31:19 +0100 Subject: Derp --- src/Entities/Entity.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 71b9f63a7..aa671bf35 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1005,7 +1005,7 @@ void cEntity::TickInVoid(cChunk & a_Chunk) void cEntity::DetectCacti() { int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT; - float w = m_Width / 2 + float w = m_Width / 2; if ( (((X + 1) - GetPosX() < w) && (GetWorld()->GetBlock(X + 1, Y, Z) == E_BLOCK_CACTUS)) || (((GetPosX() - (X - 1)) - 1 < w) && (GetWorld()->GetBlock(X - 1, Y, Z) == E_BLOCK_CACTUS)) || -- cgit v1.2.3 From 4aec5c9450180271bcac547287042d96f01eb4cd Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Tue, 20 May 2014 09:37:21 +0200 Subject: Fixed MCADefrag compilation. --- Tools/MCADefrag/Globals.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Tools/MCADefrag/Globals.h b/Tools/MCADefrag/Globals.h index 0f31de7e3..f70a90d17 100644 --- a/Tools/MCADefrag/Globals.h +++ b/Tools/MCADefrag/Globals.h @@ -22,6 +22,15 @@ #define ALIGN_8 #define ALIGN_16 + #define FORMATSTRING(formatIndex, va_argsIndex) + + // MSVC has its own custom version of zu format + #define SIZE_T_FMT "%Iu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "Iu" + #define SIZE_T_FMT_HEX "%Ix" + + #define NORETURN __declspec(noreturn) + #elif defined(__GNUC__) // TODO: Can GCC explicitly mark classes as abstract (no instances can be created)? @@ -39,6 +48,12 @@ #define stricmp strcasecmp #define FORMATSTRING(formatIndex,va_argsIndex) + + #define SIZE_T_FMT "%zu" + #define SIZE_T_FMT_PRECISION(x) "%" #x "zu" + #define SIZE_T_FMT_HEX "%zx" + + #define NORETURN __attribute((__noreturn__)) #else #error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler" -- cgit v1.2.3 From 07baf9bdd3b04e3aec6e77f367eb38c0547f54ca Mon Sep 17 00:00:00 2001 From: andrew Date: Tue, 20 May 2014 15:52:59 +0300 Subject: Cleaned up cPlayer::UpdateMovementStats; Wither achievements --- src/Blocks/BlockMobHead.h | 27 ++++++++++++++++++ src/Entities/Player.cpp | 71 +++++++++++++++++++++++++++++++++++++--------- src/Entities/Player.h | 3 ++ src/Items/ItemFishingRod.h | 6 ++++ src/Mobs/Wither.cpp | 33 +++++++++++++++++++++ src/Mobs/Wither.h | 1 + src/Statistics.cpp | 2 +- 7 files changed, 128 insertions(+), 15 deletions(-) diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index acd1c88fb..552c0491c 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -46,8 +46,29 @@ public: bool IsWither(void) const { return m_IsWither; } void Reset(void) { m_IsWither = false; } + } CallbackA, CallbackB; + class cPlayerCallback : public cPlayerListCallback + { + Vector3f m_Pos; + + virtual bool Item(cPlayer * a_Player) + { + double Dist = (a_Player->GetPosition() - m_Pos).Length(); + if (Dist < 50.0) + { + // If player is close, award achievement + a_Player->AwardAchievement(achSpawnWither); + } + return false; + } + + public: + cPlayerCallback(const Vector3f & a_Pos) : m_Pos(a_Pos) {} + + } PlayerCallback(Vector3f(a_BlockX, a_BlockY, a_BlockZ)); + a_World->DoWithMobHeadAt(a_BlockX, a_BlockY, a_BlockZ, CallbackA); if (!CallbackA.IsWither()) @@ -86,6 +107,9 @@ public: // Spawn the wither: a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); + // Award Achievement + a_World->ForEachPlayer(PlayerCallback); + return true; } @@ -113,6 +137,9 @@ public: // Spawn the wither: a_World->SpawnMob(a_BlockX + 0.5, a_BlockY - 2, a_BlockZ + 0.5, cMonster::mtWither); + // Award Achievement + a_World->ForEachPlayer(PlayerCallback); + return true; } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index c3b763278..0eacb67f9 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -456,8 +456,18 @@ void cPlayer::SetTouchGround(bool a_bTouchGround) else { float Dist = (float)(m_LastGroundHeight - floor(GetPosY())); + + if (Dist >= 2.0) // At least two blocks - TODO: Use m_LastJumpHeight instead of m_LastGroundHeight above + { + // Increment statistic + m_Stats.AddValue(statDistFallen, (StatValue)floor(Dist * 100 + 0.5)); + } + int Damage = (int)(Dist - 3.f); - if (m_LastJumpHeight > m_LastGroundHeight) Damage++; + if (m_LastJumpHeight > m_LastGroundHeight) + { + Damage++; + } m_LastJumpHeight = (float)GetPosY(); if (Damage > 0) @@ -1951,32 +1961,65 @@ void cPlayer::HandleFloater() +bool cPlayer::IsClimbing(void) const +{ + int PosX = POSX_TOINT; + int PosY = POSY_TOINT; + int PosZ = POSZ_TOINT; + + if ((PosY < 0) || (PosY >= cChunkDef::Height)) + { + return false; + } + + BLOCKTYPE Block = m_World->GetBlock(PosX, PosY, PosZ); + switch (Block) + { + case E_BLOCK_LADDER: + case E_BLOCK_VINES: + { + return true; + } + default: return false; + } +} + + + + + void cPlayer::UpdateMovementStats(const Vector3d & a_DeltaPos) { StatValue Value = (StatValue)floor(a_DeltaPos.Length() * 100 + 0.5); if (m_AttachedTo == NULL) { - int PosX = POSX_TOINT; - int PosY = POSY_TOINT; - int PosZ = POSZ_TOINT; - - BLOCKTYPE Block; - NIBBLETYPE Meta; - if (!m_World->GetBlockTypeMeta(PosX, PosY, PosZ, Block, Meta)) + if (IsClimbing()) { - return; + if (a_DeltaPos.y > 0.0) // Going up + { + m_Stats.AddValue(statDistClimbed, (StatValue)floor(a_DeltaPos.y * 100 + 0.5)); + } } - - if ((Block == E_BLOCK_LADDER) && (a_DeltaPos.y > 0.0)) // Going up + else if (IsSubmerged()) { - m_Stats.AddValue(statDistClimbed, (StatValue)floor(a_DeltaPos.y * 100 + 0.5)); + m_Stats.AddValue(statDistDove, Value); } - else + else if (IsSwimming()) + { + m_Stats.AddValue(statDistSwum, Value); + } + else if (IsOnGround()) { - // TODO 2014-05-12 xdot: Other types m_Stats.AddValue(statDistWalked, Value); } + else + { + if (Value >= 25) // Ignore small/slow movement + { + m_Stats.AddValue(statDistFlown, Value); + } + } } else { diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 78b534d83..b7cb27d6c 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -127,6 +127,9 @@ public: inline const cItem & GetEquippedItem(void) const { return GetInventory().GetEquippedItem(); } // tolua_export + /** Returns whether the player is climbing (ladders, vines e.t.c). */ + bool IsClimbing(void) const; + virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override; // tolua_begin diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h index 0431b88b7..32c151db5 100644 --- a/src/Items/ItemFishingRod.h +++ b/src/Items/ItemFishingRod.h @@ -142,6 +142,8 @@ public: break; } } + + a_Player->GetStatManager().AddValue(statTreasureFished, 1); } else if (ItemCategory <= 14) // Junk 10% { @@ -190,6 +192,8 @@ public: { Drops.Add(cItem(E_BLOCK_TRIPWIRE_HOOK)); } + + a_Player->GetStatManager().AddValue(statJunkFished, 1); } else // Fish { @@ -210,6 +214,8 @@ public: { Drops.Add(cItem(E_ITEM_RAW_FISH, 1, E_META_RAW_FISH_FISH)); } + + a_Player->GetStatManager().AddValue(statFishCaught, 1); } if (cRoot::Get()->GetPluginManager()->CallHookPlayerFishing(*a_Player, Drops)) diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index 5b6e895e1..deb2cf34e 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -2,7 +2,9 @@ #include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules #include "Wither.h" + #include "../World.h" +#include "../Entities/Player.h" @@ -100,3 +102,34 @@ void cWither::GetDrops(cItems & a_Drops, cEntity * a_Killer) + +void cWither::KilledBy(cEntity * a_Killer) +{ + UNUSED(a_Killer); + + class cPlayerCallback : public cPlayerListCallback + { + Vector3f m_Pos; + + virtual bool Item(cPlayer * a_Player) + { + double Dist = (a_Player->GetPosition() - m_Pos).Length(); + if (Dist < 50.0) + { + // If player is close, award achievement + a_Player->AwardAchievement(achKillWither); + } + return false; + } + + public: + cPlayerCallback(const Vector3f & a_Pos) : m_Pos(a_Pos) {} + + } PlayerCallback(GetPosition()); + + m_World->ForEachPlayer(PlayerCallback); +} + + + + diff --git a/src/Mobs/Wither.h b/src/Mobs/Wither.h index 08b460009..93b4f8bfc 100644 --- a/src/Mobs/Wither.h +++ b/src/Mobs/Wither.h @@ -29,6 +29,7 @@ public: virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override; virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void KilledBy(cEntity * a_Killer) override; private: diff --git a/src/Statistics.cpp b/src/Statistics.cpp index 5950eb96c..5c0524f9e 100644 --- a/src/Statistics.cpp +++ b/src/Statistics.cpp @@ -52,7 +52,7 @@ cStatInfo cStatInfo::ms_Info[statCount] = { /* Type | Name */ cStatInfo(statGamesQuit, "stat.leaveGame"), cStatInfo(statMinutesPlayed, "stat.playOneMinute"), - cStatInfo(statDistWalked, "stat.walkOnCm"), + cStatInfo(statDistWalked, "stat.walkOneCm"), cStatInfo(statDistSwum, "stat.swimOneCm"), cStatInfo(statDistFallen, "stat.fallOneCm"), cStatInfo(statDistClimbed, "stat.climbOneCm"), -- cgit v1.2.3 From 7aeb8ce9936e8ebd203d67100de8635d391bd8a1 Mon Sep 17 00:00:00 2001 From: andrew Date: Wed, 21 May 2014 10:59:14 +0300 Subject: Fixed cWither::KilledBy --- src/Blocks/BlockMobHead.h | 1 + src/Mobs/Wither.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h index 552c0491c..b7629b07c 100644 --- a/src/Blocks/BlockMobHead.h +++ b/src/Blocks/BlockMobHead.h @@ -55,6 +55,7 @@ public: virtual bool Item(cPlayer * a_Player) { + // TODO 2014-05-21 xdot: Vanilla minecraft uses an AABB check instead of a radius one double Dist = (a_Player->GetPosition() - m_Pos).Length(); if (Dist < 50.0) { diff --git a/src/Mobs/Wither.cpp b/src/Mobs/Wither.cpp index deb2cf34e..170f4fdc0 100644 --- a/src/Mobs/Wither.cpp +++ b/src/Mobs/Wither.cpp @@ -105,7 +105,7 @@ void cWither::GetDrops(cItems & a_Drops, cEntity * a_Killer) void cWither::KilledBy(cEntity * a_Killer) { - UNUSED(a_Killer); + super::KilledBy(a_Killer); class cPlayerCallback : public cPlayerListCallback { @@ -113,6 +113,7 @@ void cWither::KilledBy(cEntity * a_Killer) virtual bool Item(cPlayer * a_Player) { + // TODO 2014-05-21 xdot: Vanilla minecraft uses an AABB check instead of a radius one double Dist = (a_Player->GetPosition() - m_Pos).Length(); if (Dist < 50.0) { -- cgit v1.2.3 From f03cbb5e04d8dc4ccbb51cf63200ff3ac597f0f9 Mon Sep 17 00:00:00 2001 From: Mattes D Date: Fri, 23 May 2014 11:22:48 +0200 Subject: Fixed profiling flags for MSVC. The profiler output contained no useful symbols before, because there were no symbols in the PDBs. --- SetFlags.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SetFlags.cmake b/SetFlags.cmake index 4eed529bd..fe867f9af 100644 --- a/SetFlags.cmake +++ b/SetFlags.cmake @@ -118,8 +118,8 @@ endmacro() macro(enable_profile) # Declare the flags used for profiling builds: if (MSVC) - set (CXX_PROFILING "") - set (LNK_PROFILING "/PROFILE") + set (CXX_PROFILING "/Zi") + set (LNK_PROFILING "/PROFILE /DEBUG") else() set (CXX_PROFILING "-pg") set (LNK_PROFILING "-pg") -- cgit v1.2.3