summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-05-25 00:21:39 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-05-25 00:21:39 +0200
commitf55f5ec47f67dcc31e56bc364297aaf60d75b0c3 (patch)
tree62262220c9342b0eab368f553a836d736a39d972 /src
parentUpdate CompositeChat.h (diff)
parentUpdate README.md (diff)
downloadcuberite-f55f5ec47f67dcc31e56bc364297aaf60d75b0c3.tar
cuberite-f55f5ec47f67dcc31e56bc364297aaf60d75b0c3.tar.gz
cuberite-f55f5ec47f67dcc31e56bc364297aaf60d75b0c3.tar.bz2
cuberite-f55f5ec47f67dcc31e56bc364297aaf60d75b0c3.tar.lz
cuberite-f55f5ec47f67dcc31e56bc364297aaf60d75b0c3.tar.xz
cuberite-f55f5ec47f67dcc31e56bc364297aaf60d75b0c3.tar.zst
cuberite-f55f5ec47f67dcc31e56bc364297aaf60d75b0c3.zip
Diffstat (limited to 'src')
-rw-r--r--src/Blocks/BlockMobHead.h28
-rw-r--r--src/Entities/Entity.cpp4
-rw-r--r--src/Entities/Player.cpp71
-rw-r--r--src/Entities/Player.h3
-rw-r--r--src/Generating/GridStructGen.cpp9
-rw-r--r--src/Generating/MineShafts.cpp2
-rw-r--r--src/Items/ItemFishingRod.h6
-rw-r--r--src/Mobs/Wither.cpp34
-rw-r--r--src/Mobs/Wither.h1
-rw-r--r--src/Statistics.cpp2
10 files changed, 142 insertions, 18 deletions
diff --git a/src/Blocks/BlockMobHead.h b/src/Blocks/BlockMobHead.h
index acd1c88fb..b7629b07c 100644
--- a/src/Blocks/BlockMobHead.h
+++ b/src/Blocks/BlockMobHead.h
@@ -46,8 +46,30 @@ 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)
+ {
+ // 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)
+ {
+ // 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 +108,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 +138,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/Entity.cpp b/src/Entities/Entity.cpp
index 8a584d2ca..1226a2319 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1018,10 +1018,10 @@ void cEntity::TickInVoid(cChunk & a_Chunk)
-void cEntity::DetectCacti()
+void cEntity::DetectCacti(void)
{
int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT;
- float w = m_Width / 2;
+ double w = m_Width / 2;
if (
((Y > 0) && (Y < cChunkDef::Height)) &&
((((X + 1) - GetPosX() < w) && (GetWorld()->GetBlock(X + 1, Y, Z) == E_BLOCK_CACTUS)) ||
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index c27456397..0dfdcfd8b 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 ((PosY < 0) || (PosY > cChunkDef::Height) || !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/Generating/GridStructGen.cpp b/src/Generating/GridStructGen.cpp
index 3bbc89054..bfa6bccb1 100644
--- a/src/Generating/GridStructGen.cpp
+++ b/src/Generating/GridStructGen.cpp
@@ -22,6 +22,15 @@ cGridStructGen::cGridStructGen(
m_MaxStructureSizeZ(a_MaxStructureSizeZ),
m_MaxCacheSize(a_MaxCacheSize)
{
+ size_t NumStructuresPerQuery = (size_t)((m_MaxStructureSizeX / m_GridSizeX + 1) * (m_MaxStructureSizeZ / m_GridSizeZ + 1));
+ if (NumStructuresPerQuery > m_MaxCacheSize)
+ {
+ m_MaxCacheSize = NumStructuresPerQuery * 4;
+ LOGINFO(
+ "cGridStructGen: The cache size is too small (%u), increasing the cache size to %u to avoid inefficiency.",
+ (unsigned)a_MaxCacheSize, (unsigned)m_MaxCacheSize
+ );
+ }
}
diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp
index 391e4c04f..81ae6481d 100644
--- a/src/Generating/MineShafts.cpp
+++ b/src/Generating/MineShafts.cpp
@@ -1283,7 +1283,7 @@ cStructGenMineShafts::cStructGenMineShafts(
int a_Seed, int a_GridSize, int a_MaxSystemSize,
int a_ChanceCorridor, int a_ChanceCrossing, int a_ChanceStaircase
) :
- super(a_Seed, a_GridSize, a_GridSize, 120 + a_MaxSystemSize * 10, 120 + a_MaxSystemSize * 10, 100),
+ super(a_Seed, a_GridSize, a_GridSize, a_MaxSystemSize, a_MaxSystemSize, 100),
m_Noise(a_Seed),
m_GridSize(a_GridSize),
m_MaxSystemSize(a_MaxSystemSize),
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..170f4fdc0 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,35 @@ void cWither::GetDrops(cItems & a_Drops, cEntity * a_Killer)
+
+void cWither::KilledBy(cEntity * a_Killer)
+{
+ super::KilledBy(a_Killer);
+
+ class cPlayerCallback : public cPlayerListCallback
+ {
+ Vector3f m_Pos;
+
+ 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)
+ {
+ // 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"),