summaryrefslogtreecommitdiffstats
path: root/source/Player.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-12-21 12:04:08 +0100
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-12-21 12:04:08 +0100
commit912a1e7adc650d20b0302a3dfe45816b5e541bc7 (patch)
tree65e7ffbf33d8f1335a4997fc5a727739f9dcdd34 /source/Player.cpp
parentExtended player inventory by direct r/o access to armor slots (diff)
downloadcuberite-912a1e7adc650d20b0302a3dfe45816b5e541bc7.tar
cuberite-912a1e7adc650d20b0302a3dfe45816b5e541bc7.tar.gz
cuberite-912a1e7adc650d20b0302a3dfe45816b5e541bc7.tar.bz2
cuberite-912a1e7adc650d20b0302a3dfe45816b5e541bc7.tar.lz
cuberite-912a1e7adc650d20b0302a3dfe45816b5e541bc7.tar.xz
cuberite-912a1e7adc650d20b0302a3dfe45816b5e541bc7.tar.zst
cuberite-912a1e7adc650d20b0302a3dfe45816b5e541bc7.zip
Diffstat (limited to 'source/Player.cpp')
-rw-r--r--source/Player.cpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/source/Player.cpp b/source/Player.cpp
index 555b8d3f9..9460bfd97 100644
--- a/source/Player.cpp
+++ b/source/Player.cpp
@@ -70,6 +70,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
LOGD("Inventory window for player %p is at %p", this, m_InventoryWindow);
SetMaxHealth(20);
+
m_MaxFoodLevel = 20;
m_MaxFoodSaturationLevel = 20.f;
@@ -222,18 +223,19 @@ void cPlayer::Tick(float a_Dt)
{
m_World->CollectPickupsByPlayer(this);
- //Handle Health:
+ // Handle Health:
m_FoodTickTimer++;
- if(m_FoodTickTimer >= 80)
+ if (m_FoodTickTimer >= 80)
{
m_FoodTickTimer = 0;
- if(m_FoodLevel >= 17)
+ if (m_FoodLevel >= 17)
{
Heal(1);
- }else if(m_FoodLevel == 0)
+ }
+ else if (m_FoodLevel == 0)
{
- TakeDamage(1, NULL);
+ super::TakeDamage(dtStarving, NULL, 1, 1, 0);
}
}
@@ -248,7 +250,7 @@ void cPlayer::Tick(float a_Dt)
}
else
{
- m_FoodLevel = MAX(m_FoodLevel -1, 0);
+ m_FoodLevel = MAX(m_FoodLevel - 1, 0);
}
SendHealth();
@@ -297,7 +299,7 @@ void cPlayer::SetTouchGround(bool a_bTouchGround)
m_LastJumpHeight = (float)m_Pos.y;
if (Damage > 0)
{
- TakeDamage(Damage, 0);
+ super::TakeDamage(dtFalling, NULL, Damage, Damage, 0);
}
m_LastGroundHeight = (float)m_Pos.y;
@@ -353,23 +355,30 @@ void cPlayer::SendHealth()
-void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator )
+void cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI)
{
- if (m_GameMode != eGameMode_Creative)
+ if (m_GameMode == eGameMode_Creative)
{
- cPawn::TakeDamage( a_Damage, a_Instigator );
-
+ // No damage / health in creative mode
+ return;
+ }
+
+ super::DoTakeDamage(a_TDI);
+
+ if (a_TDI.Attacker != NULL)
+ {
+ // Only increase hunger if being attacked by a mob
AddFoodExhaustion(0.3f);
-
- SendHealth();
}
+
+ SendHealth();
}
-void cPlayer::KilledBy(cEntity * a_Killer)
+void cPlayer::KilledBy(cPawn * a_Killer)
{
cPawn::KilledBy(a_Killer);
@@ -544,7 +553,7 @@ void cPlayer::SendMessage(const AString & a_Message)
-void cPlayer::TeleportTo(const double & a_PosX, const double & a_PosY, const double & a_PosZ)
+void cPlayer::TeleportTo(double a_PosX, double a_PosY, double a_PosZ)
{
SetPosition( a_PosX, a_PosY, a_PosZ );