1
0

modified: src/Entities/Player.cpp

modified:   src/Entities/Player.h
This commit is contained in:
DevToaster 2015-03-01 03:03:41 +10:30
parent 958834f5e9
commit b65a6ef210
2 changed files with 27 additions and 27 deletions

View File

@ -296,7 +296,7 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
short cPlayer::CalcLevelFromXp(short a_XpTotal) int cPlayer::CalcLevelFromXp(int a_XpTotal)
{ {
// level 0 to 15 // level 0 to 15
if (a_XpTotal <= XP_TO_LEVEL15) if (a_XpTotal <= XP_TO_LEVEL15)
@ -307,18 +307,18 @@ short cPlayer::CalcLevelFromXp(short a_XpTotal)
// level 30+ // level 30+
if (a_XpTotal > XP_TO_LEVEL30) if (a_XpTotal > XP_TO_LEVEL30)
{ {
return (short) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7; return (int) (151.5 + sqrt( 22952.25 - (14 * (2220 - a_XpTotal)))) / 7;
} }
// level 16 to 30 // level 16 to 30
return (short) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal)))) / 3; return (int) ( 29.5 + sqrt( 870.25 - (6 * ( 360 - a_XpTotal)))) / 3;
} }
short cPlayer::XpForLevel(short a_Level) int cPlayer::XpForLevel(int a_Level)
{ {
// level 0 to 15 // level 0 to 15
if (a_Level <= 15) if (a_Level <= 15)
@ -329,18 +329,18 @@ short cPlayer::XpForLevel(short a_Level)
// level 30+ // level 30+
if (a_Level >= 31) if (a_Level >= 31)
{ {
return (short) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220); return (int) ( (3.5 * a_Level * a_Level) - (151.5 * a_Level) + 2220);
} }
// level 16 to 30 // level 16 to 30
return (short) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360); return (int) ( (1.5 * a_Level * a_Level) - (29.5 * a_Level) + 360);
} }
short cPlayer::GetXpLevel() int cPlayer::GetXpLevel()
{ {
return CalcLevelFromXp(m_CurrentXp); return CalcLevelFromXp(m_CurrentXp);
} }
@ -351,8 +351,8 @@ short cPlayer::GetXpLevel()
float cPlayer::GetXpPercentage() float cPlayer::GetXpPercentage()
{ {
short int currentLevel = CalcLevelFromXp(m_CurrentXp); int currentLevel = CalcLevelFromXp(m_CurrentXp);
short int currentLevel_XpBase = XpForLevel(currentLevel); int currentLevel_XpBase = XpForLevel(currentLevel);
return (float)(m_CurrentXp - currentLevel_XpBase) / return (float)(m_CurrentXp - currentLevel_XpBase) /
(float)(XpForLevel(1+currentLevel) - currentLevel_XpBase); (float)(XpForLevel(1+currentLevel) - currentLevel_XpBase);
@ -362,9 +362,9 @@ float cPlayer::GetXpPercentage()
bool cPlayer::SetCurrentExperience(short int a_CurrentXp) bool cPlayer::SetCurrentExperience(int a_CurrentXp)
{ {
if (!(a_CurrentXp >= 0) || (a_CurrentXp > (std::numeric_limits<short>().max() - m_LifetimeTotalXp))) if (!(a_CurrentXp >= 0) || (a_CurrentXp > (std::numeric_limits<int>().max() - m_LifetimeTotalXp)))
{ {
LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_CurrentXp); LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_CurrentXp);
return false; // oops, they gave us a dodgey number return false; // oops, they gave us a dodgey number
@ -382,19 +382,19 @@ bool cPlayer::SetCurrentExperience(short int a_CurrentXp)
short cPlayer::DeltaExperience(short a_Xp_delta) int cPlayer::DeltaExperience(int a_Xp_delta)
{ {
if (a_Xp_delta > (std::numeric_limits<short>().max() - m_CurrentXp)) if (a_Xp_delta > (std::numeric_limits<int>().max() - m_CurrentXp))
{ {
// Value was bad, abort and report // Value was bad, abort and report
LOGWARNING("Attempt was made to increment Xp by %d, which overflowed the short datatype. Ignoring.", a_Xp_delta); LOGWARNING("Attempt was made to increment Xp by %d, which overflowed the int datatype. Ignoring.", a_Xp_delta);
return -1; // Should we instead just return the current Xp? return -1; // Should we instead just return the current Xp?
} }
m_CurrentXp += a_Xp_delta; m_CurrentXp += a_Xp_delta;
// Make sure they didn't subtract too much // Make sure they didn't subtract too much
m_CurrentXp = std::max<short>(m_CurrentXp, 0); m_CurrentXp = std::max<int>(m_CurrentXp, 0);
// Update total for score calculation // Update total for score calculation
if (a_Xp_delta > 0) if (a_Xp_delta > 0)
@ -1725,8 +1725,8 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
m_FoodSaturationLevel = root.get("foodSaturation", MAX_FOOD_LEVEL).asDouble(); m_FoodSaturationLevel = root.get("foodSaturation", MAX_FOOD_LEVEL).asDouble();
m_FoodTickTimer = root.get("foodTickTimer", 0).asInt(); m_FoodTickTimer = root.get("foodTickTimer", 0).asInt();
m_FoodExhaustionLevel = root.get("foodExhaustion", 0).asDouble(); m_FoodExhaustionLevel = root.get("foodExhaustion", 0).asDouble();
m_LifetimeTotalXp = (short) root.get("xpTotal", 0).asInt(); m_LifetimeTotalXp = (int) root.get("xpTotal", 0).asInt();
m_CurrentXp = (short) root.get("xpCurrent", 0).asInt(); m_CurrentXp = (int) root.get("xpCurrent", 0).asInt();
m_IsFlying = root.get("isflying", 0).asBool(); m_IsFlying = root.get("isflying", 0).asBool();
m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt(); m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt();

View File

@ -72,22 +72,22 @@ public:
Returns true on success Returns true on success
"should" really only be called at init or player death, plugins excepted "should" really only be called at init or player death, plugins excepted
*/ */
bool SetCurrentExperience(short a_XpTotal); bool SetCurrentExperience(int a_XpTotal);
/* changes Xp by Xp_delta, you "shouldn't" inc more than MAX_EXPERIENCE_ORB_SIZE /* changes Xp by Xp_delta, you "shouldn't" inc more than MAX_EXPERIENCE_ORB_SIZE
Wont't allow xp to go negative Wont't allow xp to go negative
Returns the new current experience, -1 on error Returns the new current experience, -1 on error
*/ */
short DeltaExperience(short a_Xp_delta); int DeltaExperience(int a_Xp_delta);
/** Gets the experience total - XpTotal for score on death */ /** Gets the experience total - XpTotal for score on death */
inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; } inline int GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; }
/** Gets the currrent experience */ /** Gets the currrent experience */
inline short GetCurrentXp(void) { return m_CurrentXp; } inline int GetCurrentXp(void) { return m_CurrentXp; }
/** Gets the current level - XpLevel */ /** Gets the current level - XpLevel */
short GetXpLevel(void); int GetXpLevel(void);
/** Gets the experience bar percentage - XpP */ /** Gets the experience bar percentage - XpP */
float GetXpPercentage(void); float GetXpPercentage(void);
@ -95,13 +95,13 @@ public:
/** Caculates the amount of XP needed for a given level /** Caculates the amount of XP needed for a given level
Ref: http://minecraft.gamepedia.com/XP Ref: http://minecraft.gamepedia.com/XP
*/ */
static short XpForLevel(short int a_Level); static int XpForLevel(int a_Level);
/** Inverse of XpForLevel /** Inverse of XpForLevel
Ref: http://minecraft.gamepedia.com/XP Ref: http://minecraft.gamepedia.com/XP
values are as per this with pre-calculations values are as per this with pre-calculations
*/ */
static short CalcLevelFromXp(short int a_CurrentXp); static int CalcLevelFromXp(int a_CurrentXp);
// tolua_end // tolua_end
@ -581,8 +581,8 @@ protected:
Int64 m_EatingFinishTick; Int64 m_EatingFinishTick;
/** Player Xp level */ /** Player Xp level */
short int m_LifetimeTotalXp; int m_LifetimeTotalXp;
short int m_CurrentXp; int m_CurrentXp;
// flag saying we need to send a xp update to client // flag saying we need to send a xp update to client
bool m_bDirtyExperience; bool m_bDirtyExperience;
@ -609,7 +609,7 @@ protected:
*/ */
bool m_bIsTeleporting; bool m_bIsTeleporting;
/** The short UUID (no dashes) of the player, as read from the ClientHandle. /** The int UUID (no dashes) of the player, as read from the ClientHandle.
If no ClientHandle is given, the UUID is initialized to empty. */ If no ClientHandle is given, the UUID is initialized to empty. */
AString m_UUID; AString m_UUID;