X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fgamemodes%2Fsv_rules.qc;h=84d89909fe98274f47eb44e51999758f9371dbb6;hb=6b66ed2b7dbd4fb177cb78e2b688045a0dc54cd8;hp=a4a4bcd196deb0ac37eb3dad58e807a980908b89;hpb=b2d3d16a9a3e5df1c518ecd2fce0bfa741db190a;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/gamemodes/sv_rules.qc b/qcsrc/common/gamemodes/sv_rules.qc index a4a4bcd19..84d89909f 100644 --- a/qcsrc/common/gamemodes/sv_rules.qc +++ b/qcsrc/common/gamemodes/sv_rules.qc @@ -1,5 +1,6 @@ #include "sv_rules.qh" +#include #include void GameRules_teams(bool value) @@ -8,6 +9,7 @@ void GameRules_teams(bool value) serverflags |= SERVERFLAG_TEAMPLAY; teamplay = 1; cvar_set("teamplay", "2"); // DP needs this for sending proper getstatus replies. + Team_InitTeams(); GameRules_spawning_teams(true); } else { serverflags &= ~SERVERFLAG_TEAMPLAY; @@ -102,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);