From 81391a493d094c5550653cf1826ed5e3172ed291 Mon Sep 17 00:00:00 2001 From: div0 Date: Fri, 25 Jul 2008 15:31:52 +0000 Subject: [PATCH] make the score adding functions return the new score (may help LMS implementation) git-svn-id: svn://svn.icculus.org/nexuiz/trunk@3909 f962a42d-fe04-0410-a3ab-8c8b0445ebaa --- data/qcsrc/server/scores.qc | 22 ++++++++++++---------- data/qcsrc/server/scores.qh | 9 ++++++--- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/data/qcsrc/server/scores.qc b/data/qcsrc/server/scores.qc index cdccb2559..28921e5a4 100644 --- a/data/qcsrc/server/scores.qc +++ b/data/qcsrc/server/scores.qc @@ -68,20 +68,21 @@ void TeamScore_Spawn(float t, string name) ++teamscores_entities_count; } -void TeamScore_AddToTeam(float t, float scorefield, float score) +float TeamScore_AddToTeam(float t, float scorefield, float score) { entity s; - if(!scores_initialized) return; // FIXME remove this when everything uses this system + if(!scores_initialized) return 0; // FIXME remove this when everything uses this system s = teamscorekeepers[t]; if(!s) error("Adding score to unknown team!"); - s.(teamscores[scorefield]) += score; - s.Version += 1; + if(score) + s.Version += 1; + return (s.(teamscores[scorefield]) += score); } -void TeamScore_Add(entity player, float scorefield, float score) +float TeamScore_Add(entity player, float scorefield, float score) { - TeamScore_AddToTeam(player.team, scorefield, score); + return TeamScore_AddToTeam(player.team, scorefield, score); } float TeamScore_Compare(entity t1, entity t2) @@ -227,15 +228,16 @@ void PlayerScore_Detach(entity player) player.scorekeeper = world; } -void PlayerScore_Add(entity player, float scorefield, float score) +float PlayerScore_Add(entity player, float scorefield, float score) { entity s; - if(!scores_initialized) return; // FIXME remove this when everything uses this system + if(!scores_initialized) return 0; // FIXME remove this when everything uses this system s = player.scorekeeper; if(!s) error("Adding score to unknown player!"); - s.(scores[scorefield]) += score; - s.Version += 1; + if(score) + s.Version += 1; + return (s.(scores[scorefield]) += score); } void PlayerTeamScore_Add(entity player, float pscorefield, float tscorefield, float score) diff --git a/data/qcsrc/server/scores.qh b/data/qcsrc/server/scores.qh index 39a6ba948..f3847b0ca 100644 --- a/data/qcsrc/server/scores.qh +++ b/data/qcsrc/server/scores.qh @@ -13,8 +13,9 @@ void PlayerScore_Detach(entity player); * Adds a score to the player's scores. * NEVER call this if PlayerScore_Attach has not been called yet! * Means: FIXME make players unable to join the game when not called ClientConnect yet. + * Returns the new score. */ -void PlayerScore_Add(entity player, float scorefield, float score); +float PlayerScore_Add(entity player, float scorefield, float score); /** * Initialize the score of this player if needed. @@ -26,14 +27,16 @@ void PlayerScore_Clear(entity player); /** * Adds a score to the player's team's scores. * NEVER call this if team has not been set yet! + * Returns the new score. */ -void TeamScore_Add(entity player, float scorefield, float score); +float TeamScore_Add(entity player, float scorefield, float score); /** * Adds a score to the given team. * NEVER call this if team has not been set yet! + * Returns the new score. */ -void TeamScore_AddToTeam(float t, float scorefield, float score); +float TeamScore_AddToTeam(float t, float scorefield, float score); /** * Adds a score to both the player and the team. -- 2.39.2