Index: source/cPawn.cpp =================================================================== --- source/cPawn.cpp (revision 154) +++ source/cPawn.cpp (working copy) @@ -28,6 +28,7 @@ , m_FireDamageInterval(0.f) { SetMaxHealth(20); + SetMaxFoodLevel(125); } cPawn::~cPawn() @@ -175,4 +176,12 @@ m_Health = a_MaxHealth; } +void cPawn::SetMaxFoodLevel(short a_MaxFoodLevel) +{ + this->m_MaxFoodLevel = a_MaxFoodLevel; + //Reset food level + m_FoodLevel = a_MaxFoodLevel; +} + + Index: source/cPawn.h =================================================================== --- source/cPawn.h (revision 154) +++ source/cPawn.h (working copy) @@ -1,5 +1,6 @@ #pragma once #include "cEntity.h" +#include "math.h" struct TakeDamageInfo //tolua_export { //tolua_export @@ -37,9 +38,22 @@ 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; Index: source/cPlayer.cpp =================================================================== --- source/cPlayer.cpp (revision 154) +++ source/cPlayer.cpp (working copy) @@ -81,6 +81,7 @@ { m_EntityType = E_PLAYER; SetMaxHealth(20); + SetMaxFoodLevel(125); m_Inventory = new cInventory( this ); cTimer t1; m_LastPlayerListTime = t1.GetNowTime(); @@ -290,10 +291,26 @@ 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 ); + } +} + void cPlayer::TakeDamage( int a_Damage, cEntity* a_Instigator ) { if ( !(m_GameMode == 1) ) { @@ -301,6 +318,8 @@ 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 @@ } 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 @@ root["rotation"] = JSON_PlayerRotation; root["inventory"] = JSON_Inventory; root["health"] = m_Health; + root["food"] = m_FoodLevel; root["world"] = GetWorld()->GetName(); Json::StyledWriter writer; Index: source/cClientHandle.cpp =================================================================== --- source/cClientHandle.cpp (revision 154) +++ source/cClientHandle.cpp (working copy) @@ -784,51 +784,63 @@ 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 @@ 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(); } Index: source/cPlayer.h =================================================================== --- source/cPlayer.h (revision 154) +++ source/cPlayer.h (working copy) @@ -68,6 +68,7 @@ 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