Removed the need to recalculate whether player is under water in ApplyFoodExhaustion
This commit is contained in:
parent
dace1f7bd2
commit
ffce5d143f
@ -192,7 +192,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
|
|||||||
if (m_bDirtyPosition)
|
if (m_bDirtyPosition)
|
||||||
{
|
{
|
||||||
// Apply food exhaustion from movement:
|
// Apply food exhaustion from movement:
|
||||||
ApplyFoodExhaustionFromMovement(a_Chunk);
|
ApplyFoodExhaustionFromMovement();
|
||||||
|
|
||||||
cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this);
|
cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this);
|
||||||
BroadcastMovementUpdate(m_ClientHandle);
|
BroadcastMovementUpdate(m_ClientHandle);
|
||||||
@ -1445,7 +1445,7 @@ void cPlayer::HandleFood(void)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cPlayer::ApplyFoodExhaustionFromMovement(cChunk & a_Chunk)
|
void cPlayer::ApplyFoodExhaustionFromMovement()
|
||||||
{
|
{
|
||||||
if (IsGameModeCreative())
|
if (IsGameModeCreative())
|
||||||
{
|
{
|
||||||
@ -1463,14 +1463,6 @@ void cPlayer::ApplyFoodExhaustionFromMovement(cChunk & a_Chunk)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the type of block the player's standing in:
|
|
||||||
BLOCKTYPE BlockIn;
|
|
||||||
int RelX = (int)floor(m_LastPosX) - a_Chunk.GetPosX() * cChunkDef::Width;
|
|
||||||
int RelY = (int)floor(m_LastPosY + 0.1);
|
|
||||||
int RelZ = (int)floor(m_LastPosZ) - a_Chunk.GetPosZ() * cChunkDef::Width;
|
|
||||||
// Use Unbounded, because we're being called *after* processing super::Tick(), which could have changed our chunk
|
|
||||||
VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY, RelZ, BlockIn));
|
|
||||||
|
|
||||||
// Apply the exhaustion based on distance travelled:
|
// Apply the exhaustion based on distance travelled:
|
||||||
double BaseExhaustion = Movement.Length();
|
double BaseExhaustion = Movement.Length();
|
||||||
if (IsSprinting())
|
if (IsSprinting())
|
||||||
@ -1478,7 +1470,7 @@ void cPlayer::ApplyFoodExhaustionFromMovement(cChunk & a_Chunk)
|
|||||||
// 0.1 pt per meter sprinted
|
// 0.1 pt per meter sprinted
|
||||||
BaseExhaustion = BaseExhaustion * 0.1;
|
BaseExhaustion = BaseExhaustion * 0.1;
|
||||||
}
|
}
|
||||||
else if (IsBlockWater(BlockIn))
|
else if (IsSwimming())
|
||||||
{
|
{
|
||||||
// 0.015 pt per meter swum
|
// 0.015 pt per meter swum
|
||||||
BaseExhaustion = BaseExhaustion * 0.015;
|
BaseExhaustion = BaseExhaustion * 0.015;
|
||||||
|
@ -253,6 +253,12 @@ public:
|
|||||||
/// Starts or stops sprinting, sends the max speed update to the client, if needed
|
/// Starts or stops sprinting, sends the max speed update to the client, if needed
|
||||||
void SetSprint(bool a_IsSprinting);
|
void SetSprint(bool a_IsSprinting);
|
||||||
|
|
||||||
|
/// Returns whether the player is swimming or not
|
||||||
|
virtual bool IsSwimming(void) const{ return m_IsSwimming; }
|
||||||
|
|
||||||
|
/// Return whether the player is under water or not
|
||||||
|
virtual bool IsSubmerged(void) const{ return m_IsSubmerged; }
|
||||||
|
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
// cEntity overrides:
|
// cEntity overrides:
|
||||||
@ -260,11 +266,7 @@ public:
|
|||||||
virtual bool IsSprinting(void) const { return m_IsSprinting; }
|
virtual bool IsSprinting(void) const { return m_IsSprinting; }
|
||||||
virtual bool IsRclking (void) const { return IsEating(); }
|
virtual bool IsRclking (void) const { return IsEating(); }
|
||||||
|
|
||||||
/// Returns whether the player is swimming or not
|
|
||||||
virtual bool IsSwimming(void) const{ return m_IsSwimming; }
|
|
||||||
|
|
||||||
/// Return whether the player is under water or not
|
|
||||||
virtual bool IsSubmerged(void) const{ return m_IsSubmerged; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::map< std::string, bool > PermissionMap;
|
typedef std::map< std::string, bool > PermissionMap;
|
||||||
@ -362,7 +364,7 @@ protected:
|
|||||||
void SetSwimState(cChunk & a_Chunk);
|
void SetSwimState(cChunk & a_Chunk);
|
||||||
|
|
||||||
/// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block)
|
/// Adds food exhaustion based on the difference between Pos and LastPos, sprinting status and swimming (in water block)
|
||||||
void ApplyFoodExhaustionFromMovement(cChunk & a_Chunk);
|
void ApplyFoodExhaustionFromMovement();
|
||||||
} ; // tolua_export
|
} ; // tolua_export
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user