summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-05-25 19:02:33 +0200
committerTycho <work.tycho+git@gmail.com>2014-05-25 19:02:33 +0200
commit8133efd7f9def01b81ef2a52c05d8ec5b7f89632 (patch)
treea56f6889aea8de8759fab87abdee2eef778873ed /src/Entities/Entity.cpp
parentFixed bug in freeing NULL pointers (diff)
parentinject TestGlobals.h correctly (diff)
downloadcuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.gz
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.bz2
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.lz
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.xz
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.tar.zst
cuberite-8133efd7f9def01b81ef2a52c05d8ec5b7f89632.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 4cf10a219..2567b7adc 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -312,12 +312,16 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
if ((a_TDI.Attacker != NULL) && (a_TDI.Attacker->IsPlayer()))
{
+ cPlayer * Player = (cPlayer *)a_TDI.Attacker;
+
// IsOnGround() only is false if the player is moving downwards
- if (!((cPlayer *)a_TDI.Attacker)->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain)
+ if (!Player->IsOnGround()) // TODO: Better damage increase, and check for enchantments (and use magic critical instead of plain)
{
a_TDI.FinalDamage += 2;
m_World->BroadcastEntityAnimation(*this, 4); // Critical hit
}
+
+ Player->GetStatManager().AddValue(statDamageDealt, (StatValue)floor(a_TDI.FinalDamage * 10 + 0.5));
}
m_Health -= (short)a_TDI.FinalDamage;
@@ -370,6 +374,11 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
if (m_Health <= 0)
{
KilledBy(a_TDI.Attacker);
+
+ if (a_TDI.Attacker != NULL)
+ {
+ a_TDI.Attacker->Killed(this);
+ }
}
return true;
}
@@ -575,9 +584,16 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
if (m_AttachedTo != NULL)
{
- if ((m_Pos - m_AttachedTo->GetPosition()).Length() > 0.5)
+ Vector3d DeltaPos = m_Pos - m_AttachedTo->GetPosition();
+ if (DeltaPos.Length() > 0.5)
{
SetPosition(m_AttachedTo->GetPosition());
+
+ if (IsPlayer())
+ {
+ cPlayer * Player = (cPlayer *)this;
+ Player->UpdateMovementStats(DeltaPos);
+ }
}
}
else
@@ -601,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
@@ -998,6 +1018,26 @@ void cEntity::TickInVoid(cChunk & a_Chunk)
+void cEntity::DetectCacti(void)
+{
+ int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT;
+ double 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);