summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/cClientHandle.cpp43
-rw-r--r--source/cPawn.cpp7
-rw-r--r--source/cPawn.h14
-rw-r--r--source/cPlayer.cpp21
-rw-r--r--source/cPlayer.h1
5 files changed, 73 insertions, 13 deletions
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 920963c28..6badd5ae1 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -784,51 +784,63 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
switch( Item.m_ItemID )
{
case E_ITEM_APPLE:
- m_Player->Heal( 4 ); // 2 hearts
+ //m_Player->Heal( 4 ); // 2 hearts
+ m_Player->Feed( 24 ); // 2 food bars
bEat = true;
break;
case E_ITEM_GOLDEN_APPLE:
- m_Player->Heal( 20 ); // 10 hearts
+ //m_Player->Heal( 20 ); // 10 hearts
+ m_Player->Feed(60); // 5 food
bEat = true;
break;
case E_ITEM_MUSHROOM_SOUP:
- m_Player->Heal( 10 ); // 5 hearts
+ ///m_Player->Heal( 10 ); // 5 hearts
+ m_Player->Feed( 48 ); // 4 food
bEat = true;
break;
case E_ITEM_BREAD:
- m_Player->Heal( 5 ); // 2.5 hearts
+ //m_Player->Heal( 5 ); // 2.5 hearts
+ m_Player->Feed( 30 ); // 2.5 food
bEat = true;
break;
case E_ITEM_RAW_MEAT:
- m_Player->Heal( 3 ); // 1.5 hearts
+ //m_Player->Heal( 3 ); // 1.5 hearts
+ m_Player->Feed( 18 ); // 1.5 food
bEat = true;
break;
case E_ITEM_COOKED_MEAT:
- m_Player->Heal( 8 ); // 4 hearts
+ //m_Player->Heal( 8 ); // 4 hearts
+ m_Player->Feed( 48 ); // 4 food
bEat = true;
break;
case E_ITEM_RAW_FISH:
- m_Player->Heal( 2 ); // 1 heart
+ //m_Player->Heal( 2 ); // 1 heart
+ m_Player->Feed( 12 ); // 1 food
bEat = true;
break;
case E_ITEM_COOKED_FISH:
- m_Player->Heal( 5 ); // 2.5 hearts
+ //m_Player->Heal( 5 ); // 2.5 hearts
+ m_Player->Feed( 30 ); // 2.5 food
bEat = true;
break;
case E_ITEM_RAW_CHICKEN:
- m_Player->Heal(3);
+ //m_Player->Heal(3);
+ m_Player->Feed( 12 ); // 1 food
bEat = true;
break;
case E_ITEM_COOKED_CHICKEN:
- m_Player->Heal( 8 );
+ //m_Player->Heal( 8 );
+ m_Player->Feed( 36 ); // 3 food
bEat = true;
break;
case E_ITEM_RAW_BEEF:
- m_Player->Heal(3);
+ //m_Player->Heal(3);
+ m_Player->Feed( 18 ); // 1.5 food
bEat = true;
break;
case E_ITEM_STEAK:
- m_Player->Heal( 8 );
+ //m_Player->Heal( 8 );
+ m_Player->Feed( 48 ); // 4 food
bEat = true;
break;
default:
@@ -1293,7 +1305,12 @@ void cClientHandle::Tick(float a_Dt)
m_Player->GetInventory().SendWholeInventory( this );
// Send health
- Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) );
+ cPacket_UpdateHealth Health;
+ Health.m_Health = (short)m_Player->GetHealth();
+ Health.m_Food = m_Player->GetFood();
+ Health.m_Saturation = m_Player->GetFoodSaturation();
+ Send(Health);
+ //Send( cPacket_UpdateHealth( (short)m_Player->GetHealth() ) );
World->UnlockEntities();
}
diff --git a/source/cPawn.cpp b/source/cPawn.cpp
index e696ffc18..8b1c951bb 100644
--- a/source/cPawn.cpp
+++ b/source/cPawn.cpp
@@ -28,6 +28,7 @@ cPawn::cPawn()
, m_FireDamageInterval(0.f)
{
SetMaxHealth(20);
+ SetMaxFoodLevel(125);
}
cPawn::~cPawn()
@@ -175,4 +176,10 @@ void cPawn::SetMaxHealth(short a_MaxHealth)
m_Health = a_MaxHealth;
}
+void cPawn::SetMaxFoodLevel(short a_MaxFoodLevel)
+{
+ m_MaxFoodLevel = a_MaxFoodLevel;
+ //Reset food level
+ m_FoodLevel = a_MaxFoodLevel;
+}
diff --git a/source/cPawn.h b/source/cPawn.h
index 24209dc76..e075b422e 100644
--- a/source/cPawn.h
+++ b/source/cPawn.h
@@ -1,5 +1,6 @@
#pragma once
#include "cEntity.h"
+#include "math.h"
struct TakeDamageInfo //tolua_export
{ //tolua_export
@@ -37,9 +38,22 @@ public:
virtual inline void SetMaxHealth(short a_MaxHealth);
virtual inline short GetMaxHealth() { return m_MaxHealth; }
+ //virtual inline void SetMaxFood(short a_MaxFood);
+ virtual inline short GetMaxFood() { return m_MaxFoodLevel/6; }
+ virtual inline short GetFood() { return m_FoodLevel/6; }
+
+ //virtual inline void SetMaxFoodSaturation(float a_MaxFoodSaturation);
+ virtual inline float GetMaxFoodSaturation() { return fmod(m_MaxFoodLevel, 6.f); }
+ virtual inline float GetFoodSaturation() { return fmod(m_FoodLevel, 6.f); }
+
+ virtual inline void SetMaxFoodLevel(short a_MaxFoodLevel);
+ virtual inline short GetMaxFoodLevel() { return m_MaxFoodLevel; }
+
protected:
short m_Health;
+ short m_FoodLevel;
short m_MaxHealth;
+ short m_MaxFoodLevel;
bool m_bBurnable;
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index 820b11f8b..baba0174a 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -81,6 +81,7 @@ cPlayer::cPlayer(cClientHandle* a_Client, const char* a_PlayerName)
{
m_EntityType = E_PLAYER;
SetMaxHealth(20);
+ SetMaxFoodLevel(125);
m_Inventory = new cInventory( this );
cTimer t1;
m_LastPlayerListTime = t1.GetNowTime();
@@ -290,6 +291,22 @@ void cPlayer::Heal( int a_Health )
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
+ Health.m_Food = GetFood();
+ Health.m_Saturation = GetFoodSaturation();
+ m_ClientHandle->Send( Health );
+ }
+}
+
+void cPlayer::Feed( short a_Food )
+{
+ if( m_FoodLevel < GetMaxFoodLevel() )
+ {
+ m_FoodLevel = MIN(a_Food + m_FoodLevel, GetMaxFoodLevel());
+
+ cPacket_UpdateHealth Health;
+ Health.m_Health = m_Health;
+ Health.m_Food = GetFood();
+ Health.m_Saturation = GetFoodSaturation();
m_ClientHandle->Send( Health );
}
}
@@ -301,6 +318,8 @@ void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator )
cPacket_UpdateHealth Health;
Health.m_Health = m_Health;
+ Health.m_Food = GetFood();
+ Health.m_Saturation = GetFoodSaturation();
//TODO: Causes problems sometimes O.o (E.G. Disconnecting when attacked)
if(m_ClientHandle != 0)
m_ClientHandle->Send( Health );
@@ -772,6 +791,7 @@ bool cPlayer::LoadFromDisk() // TODO - This should also get/set/whatever the cor
}
m_Health = (short)root.get("health", 0 ).asInt();
+ m_FoodLevel = (short)root.get("food", 0 ).asInt();
m_Inventory->LoadFromJson(root["inventory"]);
m_pState->LoadedWorldName = root.get("world", "world").asString();
@@ -804,6 +824,7 @@ bool cPlayer::SaveToDisk()
root["rotation"] = JSON_PlayerRotation;
root["inventory"] = JSON_Inventory;
root["health"] = m_Health;
+ root["food"] = m_FoodLevel;
root["world"] = GetWorld()->GetName();
Json::StyledWriter writer;
diff --git a/source/cPlayer.h b/source/cPlayer.h
index 9f7535d7c..4d348c2ad 100644
--- a/source/cPlayer.h
+++ b/source/cPlayer.h
@@ -68,6 +68,7 @@ public:
void TossItem( bool a_bDraggingItem, int a_Amount = 1 ); //tolua_export
void Heal( int a_Health ); //tolua_export
+ void Feed( short a_Food );
void TakeDamage( int a_Damage, cEntity* a_Instigator ); //tolua_export
void KilledBy( cEntity* a_Killer ); //tolua_export
void Respawn(); //tolua_export