]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Move code adding score as int to a dedicated function that can be used by other game...
authorterencehill <piuntn@gmail.com>
Wed, 16 Feb 2022 16:52:48 +0000 (17:52 +0100)
committerterencehill <piuntn@gmail.com>
Wed, 16 Feb 2022 16:52:48 +0000 (17:52 +0100)
qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc
qcsrc/common/gamemodes/sv_rules.qc
qcsrc/common/gamemodes/sv_rules.qh

index 800c26f121d235c834162f967ee7a858e10b82f0..3b823dfdf14c8142fb041c16b27f40cd6cc481fe 100644 (file)
@@ -263,11 +263,6 @@ MUTATOR_HOOKFUNCTION(ca, PlayerDies)
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(ca, ClientConnect)
-{
-       entity player = M_ARGV(0, entity);
-       player.ca_damage_counter = 0;
-}
 
 MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
 {
@@ -409,18 +404,7 @@ MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor)
        }
 
        if (scorer)
-       {
-               // assign damage score in units (rounded) to avoid bugs with float score
-               scorer.ca_damage_counter += scorer_damage;
-               float score_counter = scorer.ca_damage_counter / autocvar_g_ca_damage2score;
-               if (score_counter >= -0.5 && score_counter < 0.5)
-                       return;
-               // NOTE: this code works for subtracting score too
-               int points = floor(score_counter + 0.5);
-               GameRules_scoring_add(scorer, SCORE, points);
-
-               scorer.ca_damage_counter -= points * autocvar_g_ca_damage2score;
-       }
+               GameRules_scoring_add_float2int(scorer, SCORE, scorer_damage, ca_damage_counter, autocvar_g_ca_damage2score);
 }
 
 MUTATOR_HOOKFUNCTION(ca, CalculateRespawnTime)
index 898ef3a4f581f0811828192b313495db0c8423e4..84d89909fe98274f47eb44e51999758f9371dbb6 100644 (file)
@@ -104,6 +104,25 @@ bool GameRules_scoring_is_vip(entity player)
     return player.m_GameRules_scoring_vip;
 }
 
+// Uses client.float_field to accumulate and consume float score and adds score to the player as int (rounded)
+// only when at least one unit of score has been accumulated. It works with negative score too
+// Float scores can't be used as score because they aren't supported by the QC score networking system
+// and online server browsers (e.g. qstat)
+float _GameRules_scoring_add_float2int(entity client, entity sp, float value, .float float_field, float score_factor)
+{
+       client.(float_field) += value;
+       float score_counter = client.(float_field) / score_factor;
+       if (score_counter >= -0.5 && score_counter < 0.5)
+               return 0;
+
+       // NOTE: this code works for subtracting score too
+       int points = floor(score_counter + 0.5);
+       client.(float_field) -= points * score_factor;
+       if (!points)
+               return 0;
+       return PlayerScore_Add(client, sp, points);
+}
+
 float _GameRules_scoring_add(entity client, entity sp, float value)
 {
     return PlayerScore_Add(client, sp, value);
index 4fabea39ce9fed03f52e9299bae034a5e9f1ab19..2efcf19738aa34ee1b4d2aee1e22a3c74db1274f 100644 (file)
@@ -72,6 +72,9 @@ void _GameRules_scoring_end();
 void GameRules_scoring_vip(entity player, bool value);
 bool GameRules_scoring_is_vip(entity player);
 
+#define GameRules_scoring_add_float2int(client, fld, value, float_field, score_factor) \
+       _GameRules_scoring_add_float2int(client, SP_##fld, value, float_field, score_factor)
+float _GameRules_scoring_add_float2int(entity client, entity sp, float value, .float field, float score_factor);
 #define GameRules_scoring_add(client, fld, value) _GameRules_scoring_add(client, SP_##fld, value)
 float _GameRules_scoring_add(entity client, entity sp, float value);
 #define GameRules_scoring_add_team(client, fld, value) _GameRules_scoring_add_team(client, SP_##fld, ST_##fld, value)