summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-05-23 11:25:42 +0200
committerMattes D <github@xoft.cz>2014-05-23 11:25:42 +0200
commit64dbc45a00b0c8d24a48293cbd3ff116d7b51735 (patch)
tree857bbe55266e9cc97eb8fc836698692bda51f221 /src/Entities
parentUpdated plains village prefabs. (diff)
parentFixed profiling flags for MSVC. (diff)
downloadcuberite-64dbc45a00b0c8d24a48293cbd3ff116d7b51735.tar
cuberite-64dbc45a00b0c8d24a48293cbd3ff116d7b51735.tar.gz
cuberite-64dbc45a00b0c8d24a48293cbd3ff116d7b51735.tar.bz2
cuberite-64dbc45a00b0c8d24a48293cbd3ff116d7b51735.tar.lz
cuberite-64dbc45a00b0c8d24a48293cbd3ff116d7b51735.tar.xz
cuberite-64dbc45a00b0c8d24a48293cbd3ff116d7b51735.tar.zst
cuberite-64dbc45a00b0c8d24a48293cbd3ff116d7b51735.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Entity.cpp24
-rw-r--r--src/Entities/Entity.h3
-rw-r--r--src/Entities/Player.cpp71
-rw-r--r--src/Entities/Player.h3
4 files changed, 87 insertions, 14 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 31ad66779..15f456332 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -617,6 +617,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
@@ -1014,6 +1018,26 @@ 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() < 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)))
+ )
+ {
+ TakeDamage(dtCactusContact, 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 a111b128d..0c393c0f5 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -320,6 +320,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);
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