summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Bindings.cpp51
-rw-r--r--source/Bindings.h2
-rw-r--r--source/Entities/Player.cpp37
-rw-r--r--source/Entities/Player.h7
4 files changed, 19 insertions, 78 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index a03ee37e0..9fdd28383 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/16/13 21:19:32.
+** Generated automatically by tolua++-1.0.92 on 11/16/13 21:58:48.
*/
#ifndef __cplusplus
@@ -7684,9 +7684,9 @@ static int tolua_AllToLua_cPlayer_SetCurrentExperience00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: AddExperience of class cPlayer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_AddExperience00
-static int tolua_AllToLua_cPlayer_AddExperience00(lua_State* tolua_S)
+/* method: DeltaExperience of class cPlayer */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_DeltaExperience00
+static int tolua_AllToLua_cPlayer_DeltaExperience00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
tolua_Error tolua_err;
@@ -7702,51 +7702,17 @@ static int tolua_AllToLua_cPlayer_AddExperience00(lua_State* tolua_S)
cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
short a_Xp_delta = ((short) tolua_tonumber(tolua_S,2,0));
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'AddExperience'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'DeltaExperience'", NULL);
#endif
{
- short tolua_ret = (short) self->AddExperience(a_Xp_delta);
+ short tolua_ret = (short) self->DeltaExperience(a_Xp_delta);
tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'AddExperience'.",&tolua_err);
- return 0;
-#endif
-}
-#endif //#ifndef TOLUA_DISABLE
-
-/* method: SpendExperience of class cPlayer */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlayer_SpendExperience00
-static int tolua_AllToLua_cPlayer_SpendExperience00(lua_State* tolua_S)
-{
-#ifndef TOLUA_RELEASE
- tolua_Error tolua_err;
- if (
- !tolua_isusertype(tolua_S,1,"cPlayer",0,&tolua_err) ||
- !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
- !tolua_isnoobj(tolua_S,3,&tolua_err)
- )
- goto tolua_lerror;
- else
-#endif
- {
- cPlayer* self = (cPlayer*) tolua_tousertype(tolua_S,1,0);
- short a_Xp_delta = ((short) tolua_tonumber(tolua_S,2,0));
-#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SpendExperience'", NULL);
-#endif
- {
- short tolua_ret = (short) self->SpendExperience(a_Xp_delta);
- tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
- }
- }
- return 1;
-#ifndef TOLUA_RELEASE
- tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'SpendExperience'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'DeltaExperience'.",&tolua_err);
return 0;
#endif
}
@@ -30485,8 +30451,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"DROWNING_TICKS",cPlayer::DROWNING_TICKS);
tolua_constant(tolua_S,"MIN_EXPERIENCE",cPlayer::MIN_EXPERIENCE);
tolua_function(tolua_S,"SetCurrentExperience",tolua_AllToLua_cPlayer_SetCurrentExperience00);
- tolua_function(tolua_S,"AddExperience",tolua_AllToLua_cPlayer_AddExperience00);
- tolua_function(tolua_S,"SpendExperience",tolua_AllToLua_cPlayer_SpendExperience00);
+ tolua_function(tolua_S,"DeltaExperience",tolua_AllToLua_cPlayer_DeltaExperience00);
tolua_function(tolua_S,"GetXpLifetimeTotal",tolua_AllToLua_cPlayer_GetXpLifetimeTotal00);
tolua_function(tolua_S,"GetCurrentXp",tolua_AllToLua_cPlayer_GetCurrentXp00);
tolua_function(tolua_S,"GetXpLevel",tolua_AllToLua_cPlayer_GetXpLevel00);
diff --git a/source/Bindings.h b/source/Bindings.h
index fd1ac3242..996207055 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 11/16/13 21:19:33.
+** Generated automatically by tolua++-1.0.92 on 11/16/13 21:58:48.
*/
/* Exported function */
diff --git a/source/Entities/Player.cpp b/source/Entities/Player.cpp
index e8fc795d7..bdcf0aae9 100644
--- a/source/Entities/Player.cpp
+++ b/source/Entities/Player.cpp
@@ -338,7 +338,7 @@ float cPlayer::GetXpPercentage()
bool cPlayer::SetCurrentExperience(short int a_XpTotal)
{
- if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_CurrentXp)))
+ if(!(a_XpTotal >= 0) || (a_XpTotal > (SHRT_MAX - m_LifetimeTotalXp)))
{
LOGWARNING("Tried to update experiece with an invalid Xp value: %d", a_XpTotal);
return false; //oops, they gave us a dodgey number
@@ -356,12 +356,13 @@ bool cPlayer::SetCurrentExperience(short int a_XpTotal)
-short cPlayer::AddExperience(short a_Xp_delta)
+short cPlayer::DeltaExperience(short a_Xp_delta)
{
- if(a_Xp_delta < 0)
+ //ToDo: figure out a better name?...
+ if(a_Xp_delta > (SHRT_MAX - m_LifetimeTotalXp) || (m_CurrentXp + a_Xp_delta) < MIN_EXPERIENCE)
{
// Value was negative, abort and report
- LOGWARNING("Attempt was made to increment Xp by %d, must be positive",
+ LOGWARNING("Attempt was made to increment Xp by %d, which was invalid",
a_Xp_delta);
return -1; // Should we instead just return the current Xp?
}
@@ -369,34 +370,12 @@ short cPlayer::AddExperience(short a_Xp_delta)
m_CurrentXp += a_Xp_delta;
// Update total for score calculation
- m_LifetimeTotalXp += a_Xp_delta;
-
- LOGD("Player \"%s\" earnt %d experience, total is now: %d",
- m_PlayerName.c_str(), a_Xp_delta, m_XpTotal);
-
- // Set experience to be updated
- m_bDirtyExperience = true;
-
- return m_CurrentXp;
-}
-
-
-
-
-
-short cPlayer::SpendExperience(short a_Xp_delta)
-{
- if(a_Xp_delta < 0)
+ if(a_Xp_delta > 0)
{
- // Value was negative, abort and report
- LOGWARNING("Attempt was made to decrement Xp by %d, must be positive",
- a_Xp_delta);
- return -1; // Should we instead just return the current Xp?
+ m_LifetimeTotalXp += a_Xp_delta;
}
- m_CurrentXp -= a_Xp_delta;
-
- LOGD("Player \"%s\" spent %d experience, total is now: %d",
+ LOGD("Player \"%s\" earnt %d experience, total is now: %d",
m_PlayerName.c_str(), a_Xp_delta, m_XpTotal);
// Set experience to be updated
diff --git a/source/Entities/Player.h b/source/Entities/Player.h
index 01a864149..463a6d8dc 100644
--- a/source/Entities/Player.h
+++ b/source/Entities/Player.h
@@ -74,13 +74,10 @@ public:
*/
bool SetCurrentExperience(short a_XpTotal);
- /* Adds Xp, "should" not inc more than MAX_EXPERIENCE_ORB_SIZE unless you're a plugin being funny, *cough* cheating
+ /* changes Xp by Xp_delta, you "shouldn't" not inc more than MAX_EXPERIENCE_ORB_SIZE
Returns the new current experience, -1 on error
*/
- short AddExperience(short a_Xp_delta);
-
- /// "Spend" some experience - ie on enchanting, returns new currentXp
- short SpendExperience(short a_Xp_delta);
+ short DeltaExperience(short a_Xp_delta);
/// Gets the experience total - XpTotal for score on death
inline short GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; }