X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fscores.qc;h=83c5d5ee5339e96aaef7405e4206837655767d6f;hb=8141387a9bf057652453a8d4dc530116cf4cc31a;hp=512f61ad231ae5d4255ec197a7b4d0667416220a;hpb=d126fd4da497fb8c7cbd5939ed9c6ee07cd2df9c;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 512f61ad2..83c5d5ee5 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -23,36 +23,35 @@ var .float scores_primary; var .float teamscores_primary; float scores_flags_primary; float teamscores_flags_primary; +var .float scores_secondary; +float scores_flags_secondary; -vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, vector previous, bool strict) // returns: cmp value, best prio +// returns cmp value +int ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, int previous) { - if(!strict && !(fieldflags & SFL_SORT_PRIO_MASK)) // column does not sort - return previous; - if((fieldflags & SFL_SORT_PRIO_MASK) < previous.y) + if(fieldflags & SFL_NOT_SORTABLE) // column does not sort return previous; if (t1.(field) == t2.(field)) return previous; - previous.y = fieldflags & SFL_SORT_PRIO_MASK; - if(fieldflags & SFL_ZERO_IS_WORST) { if (t1.(field) == 0) { - previous.x = -1; + previous = -1; return previous; } else if (t2.(field) == 0) { - previous.x = +1; + previous = +1; return previous; } } if (fieldflags & SFL_LOWER_IS_BETTER) - previous.x = (t2.(field) - t1.(field)); + previous = (t2.(field) - t1.(field)); else - previous.x = (t1.(field) - t2.(field)); + previous = (t1.(field) - t2.(field)); return previous; } @@ -139,23 +138,28 @@ float TeamScore_Add(entity player, float scorefield, float score) return TeamScore_AddToTeam(player.team, scorefield, score); } -float TeamScore_Compare(entity t1, entity t2, bool strict) +// strict: compare others fields too besides primary and secondary +int TeamScore_Compare(entity t1, entity t2, bool strict) { if(!t1 || !t2) return (!t2) - !t1; - vector result = '0 0 0'; - float i; - for(i = 0; i < MAX_TEAMSCORE; ++i) + // supporting MAX_TEAMSCORE > 2 requires keeping track of primary and secondary teamscore + if (MAX_TEAMSCORE > 2) + error("MAX_TEAMSCORE > 2 not supported"); + + // first compare primary, then others (don't check secondary flag since there are only 2 teamscores) + int result = 0; + int i = boolean(teamscores_primary && teamscores_primary == teamscores(1)); + result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result); + if (result == 0 && strict) { - var .float f; - f = teamscores(i); - result = ScoreField_Compare(t1, t2, f, teamscores_flags(i), result, strict); + i = (i + 1) % MAX_TEAMSCORE; + result = ScoreField_Compare(t1, t2, teamscores(i), teamscores_flags(i), result); + if (result == 0) + result = t1.team - t2.team; } - if (result.x == 0 && strict) - result.x = t1.team - t2.team; - - return result.x; + return result; } /* @@ -171,6 +175,11 @@ void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scor scores_primary = scores(i); scores_flags_primary = scoreflags; } + else if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY) + { + scores_secondary = scores(i); + scores_flags_secondary = scoreflags; + } if(label != "") { PlayerStats_GameReport_AddEvent(strcat(PLAYERSTATS_TOTAL, label)); @@ -283,8 +292,8 @@ float PlayerScore_Clear(entity player) sk = CS(player).scorekeeper; FOREACH(Scores, true, { if(sk.(scores(it)) != 0) - if(scores_label(it) != "") - sk.SendFlags |= BIT(i % 16); + //if(scores_label(it) != "") + sk.SendFlags |= (2 ** (i % 16)); if(i != SP_ELO.m_id) sk.(scores(it)) = 0; }); @@ -301,8 +310,8 @@ void Score_ClearAll() if (!sk) continue; FOREACH(Scores, true, { if(sk.(scores(it)) != 0) - if(scores_label(it) != "") - sk.SendFlags |= BIT(i % 16); + //if(scores_label(it) != "") + sk.SendFlags |= (2 ** (i % 16)); if(i != SP_ELO.m_id) sk.(scores(it)) = 0; }); @@ -315,8 +324,8 @@ void Score_ClearAll() for(int j = 0; j < MAX_TEAMSCORE; ++j) { if(sk.(teamscores(j)) != 0) - if(teamscores_label(j) != "") - sk.SendFlags |= BIT(j); + //if(teamscores_label(j) != "") + sk.SendFlags |= (2 ** j); sk.(teamscores(j)) = 0; } } @@ -363,8 +372,8 @@ float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score) { return s.(scores(scorefield)); } - if(scores_label(scorefield) != "") - s.SendFlags |= BIT(scorefield.m_id % 16); + //if(scores_label(scorefield) != "") + s.SendFlags |= (2 ** (scorefield.m_id % 16)); if(!warmup_stage) PlayerStats_GameReport_Event_Player(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score); s.(scores(scorefield)) += score; @@ -403,20 +412,51 @@ float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tsc return r; } +// strict: compare others fields too besides primary and secondary float PlayerScore_Compare(entity t1, entity t2, bool strict) { if(!t1 || !t2) return (!t2) - !t1; - vector result = '0 0 0'; - FOREACH(Scores, true, { - var .float f = scores(it); - result = ScoreField_Compare(t1, t2, f, scores_flags(it), result, strict); - }); + int result = 0; + result = ScoreField_Compare(t1, t2, scores_primary, scores_flags_primary, result); + // NOTE: if (scores_secondary) doesn't work because it's a field pointer + if (result == 0 && scores_flags_secondary) + result = ScoreField_Compare(t1, t2, scores_secondary, scores_flags_secondary, result); - if (result.x == 0 && strict) - result.x = t1.owner.playerid - t2.owner.playerid; + if (result == 0 && strict) + { + FOREACH(Scores, true, { + if (scores_flags(it) & SFL_SORT_PRIO_MASK) + continue; + if (scores_label(it) == "") + continue; + var .float f = scores(it); + result = ScoreField_Compare(t1, t2, f, scores_flags(it), result); + if (result) break; + }); + if (result == 0) + result = t1.owner.playerid - t2.owner.playerid; + } - return result.x; + return result; +} + +bool Score_NewLeader() +{ + if(teamplay) { + if (WinningConditionHelper_winnerteam != WinningConditionHelper_winnerteam_last && (WinningConditionHelper_secondteam || WinningConditionHelper_equality)) + { + WinningConditionHelper_winnerteam_last = WinningConditionHelper_winnerteam; + return true; + } + } else { + if (WinningConditionHelper_winner != WinningConditionHelper_winner_last && (WinningConditionHelper_second || WinningConditionHelper_equality)) + { + WinningConditionHelper_winner_last = WinningConditionHelper_winner; + return true; + } + } + return false; } void WinningConditionHelper(entity this) @@ -461,7 +501,7 @@ void WinningConditionHelper(entity this) for(t = 0; t < 16; ++t) { sk = teamscorekeepers[t]; - c = TeamScore_Compare(winnerscorekeeper, sk, 1); + c = TeamScore_Compare(winnerscorekeeper, sk, true); if(c < 0) { WinningConditionHelper_secondteam = WinningConditionHelper_winnerteam; @@ -471,7 +511,7 @@ void WinningConditionHelper(entity this) } else { - c = TeamScore_Compare(secondscorekeeper, sk, 1); + c = TeamScore_Compare(secondscorekeeper, sk, true); if(c < 0) { WinningConditionHelper_secondteam = t + 1; @@ -480,7 +520,7 @@ void WinningConditionHelper(entity this) } } - WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0); + WinningConditionHelper_equality = (TeamScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0); if(WinningConditionHelper_equality) WinningConditionHelper_winnerteam = WinningConditionHelper_secondteam = -1; @@ -521,7 +561,15 @@ void WinningConditionHelper(entity this) WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, false) == 0); if(WinningConditionHelper_equality) + { + WinningConditionHelper_equality_one = WinningConditionHelper_winner; + WinningConditionHelper_equality_two = WinningConditionHelper_second; WinningConditionHelper_winner = WinningConditionHelper_second = NULL; + } + else + { + WinningConditionHelper_equality_one = WinningConditionHelper_equality_two = NULL; + } WinningConditionHelper_topscore = winnerscorekeeper.scores_primary; WinningConditionHelper_secondscore = secondscorekeeper.scores_primary; @@ -708,7 +756,8 @@ string GetTeamScoreString(float tm, float shortString) return out; } -float PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict) +// strict: compare others fields too besides primary and secondary +int PlayerTeamScore_Compare(entity p1, entity p2, float teams, bool strict) { if(teams && teamscores_entities_count) { @@ -841,7 +890,7 @@ void Score_NicePrint_Team(entity to, float t, float w) { fl = teamscores_flags(i); sc = sk.(teamscores(i)); - s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc)); + s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc, 0)); } } else @@ -889,7 +938,7 @@ void Score_NicePrint_Player(entity to, entity p, float w) { fl = scores_flags(it); sc = sk.(scores(it)); - s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc))); + s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc, 0))); } });