X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fscores.qc;h=af2f4b574f43a57f0c098d19c47b5fe2754428ac;hb=e2206feb6fec163ffee9c87d50d8d9580393cd88;hp=59c76513d524c3be9cb991aa2f346fb439d2ef5e;hpb=61bd69dc7a8e218b6beff349fd332eb7ac8a81ae;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 59c76513d..af2f4b574 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -1,9 +1,18 @@ #include "scores.qh" #include "command/common.qh" -#include "mutators/all.qh" +#include "defs.qh" +#include +#include +#include +#include #include "../common/playerstats.qh" #include "../common/teams.qh" +#include +#include +#include +#include +#include .entity scorekeeper; entity teamscorekeepers[16]; @@ -52,7 +61,7 @@ vector ScoreField_Compare(entity t1, entity t2, .float field, float fieldflags, bool TeamScore_SendEntity(entity this, entity to, float sendflags) { - float i, p, longflags; + float i, longflags; WriteHeader(MSG_ENTITY, ENT_CLIENT_TEAMSCORES); int t = this.team - 1; @@ -60,9 +69,9 @@ bool TeamScore_SendEntity(entity this, entity to, float sendflags) WriteByte(MSG_ENTITY, t); longflags = 0; - for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2) - if(self.(teamscores(i)) > 127 || self.(teamscores(i)) <= -128) - longflags |= p; + for(i = 0; i < MAX_TEAMSCORE; ++i) + if(this.(teamscores(i)) > 127 || this.(teamscores(i)) <= -128) + longflags |= BIT(i); #if MAX_TEAMSCORE <= 8 WriteByte(MSG_ENTITY, sendflags); @@ -71,13 +80,13 @@ bool TeamScore_SendEntity(entity this, entity to, float sendflags) WriteShort(MSG_ENTITY, sendflags); WriteShort(MSG_ENTITY, longflags); #endif - for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2) - if(sendflags & p) + for(i = 0; i < MAX_TEAMSCORE; ++i) + if(sendflags & BIT(i)) { - if(longflags & p) - WriteInt24_t(MSG_ENTITY, self.(teamscores(i))); + if(longflags & BIT(i)) + WriteInt24_t(MSG_ENTITY, this.(teamscores(i))); else - WriteChar(MSG_ENTITY, self.(teamscores(i))); + WriteChar(MSG_ENTITY, this.(teamscores(i))); } return true; @@ -94,30 +103,30 @@ void TeamScore_Spawn(float t, string name) PlayerStats_GameReport_AddTeam(t); } -float TeamScore_AddToTeam(float t, float scorefield, float score) +float TeamScore_AddToTeam(int t, float scorefield, float score) { entity s; - if(gameover) + if(game_stopped) score = 0; if(!scores_initialized) return 0; // FIXME remove this when everything uses this system if(t <= 0 || t >= 16) { - if(gameover) + if(game_stopped) return 0; error("Adding score to invalid team!"); } s = teamscorekeepers[t - 1]; if(!s) { - if(gameover) + if(game_stopped) return 0; error("Adding score to unknown team!"); } if(score) if(teamscores_label(scorefield) != "") - s.SendFlags |= pow(2, scorefield); + s.SendFlags |= (2 ** scorefield); return (s.(teamscores(scorefield)) += score); } @@ -185,7 +194,7 @@ bool ScoreInfo_SendEntity(entity this, entity to, int sf) { float i; WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES_INFO); - WriteInt24_t(MSG_ENTITY, MapInfo_LoadedGametype); + WriteRegistered(Gametypes, MSG_ENTITY, MapInfo_LoadedGametype); FOREACH(Scores, true, { WriteString(MSG_ENTITY, scores_label(it)); WriteByte(MSG_ENTITY, scores_flags(it)); @@ -198,7 +207,7 @@ bool ScoreInfo_SendEntity(entity this, entity to, int sf) return true; } -void ScoreInfo_Init(float teams) +void ScoreInfo_Init(int teams) { if(scores_initialized) { @@ -209,13 +218,13 @@ void ScoreInfo_Init(float teams) scores_initialized = new_pure(ent_client_scoreinfo); Net_LinkEntity(scores_initialized, false, 0, ScoreInfo_SendEntity); } - if(teams >= 1) + if(teams & BIT(0)) TeamScore_Spawn(NUM_TEAM_1, "Red"); - if(teams >= 2) + if(teams & BIT(1)) TeamScore_Spawn(NUM_TEAM_2, "Blue"); - if(teams >= 3) + if(teams & BIT(2)) TeamScore_Spawn(NUM_TEAM_3, "Yellow"); - if(teams >= 4) + if(teams & BIT(3)) TeamScore_Spawn(NUM_TEAM_4, "Pink"); } @@ -226,12 +235,12 @@ void ScoreInfo_Init(float teams) bool PlayerScore_SendEntity(entity this, entity to, float sendflags) { WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES); - WriteByte(MSG_ENTITY, etof(self.owner)); + WriteByte(MSG_ENTITY, etof(this.owner)); int longflags = 0; FOREACH(Scores, true, { int p = 1 << (i % 16); - if (self.(scores(it)) > 127 || self.(scores(it)) <= -128) + if (this.(scores(it)) > 127 || this.(scores(it)) <= -128) longflags |= p; }); @@ -242,9 +251,9 @@ bool PlayerScore_SendEntity(entity this, entity to, float sendflags) if (sendflags & p) { if(longflags & p) - WriteInt24_t(MSG_ENTITY, self.(scores(it))); + WriteInt24_t(MSG_ENTITY, this.(scores(it))); else - WriteChar(MSG_ENTITY, self.(scores(it))); + WriteChar(MSG_ENTITY, this.(scores(it))); } }); @@ -260,12 +269,13 @@ float PlayerScore_Clear(entity player) if(MUTATOR_CALLHOOK(ForbidPlayerScore_Clear)) return 0; - sk = player.scorekeeper; + sk = CS(player).scorekeeper; FOREACH(Scores, true, { if(sk.(scores(it)) != 0) if(scores_label(it) != "") - sk.SendFlags |= pow(2, i % 16); - sk.(scores(it)) = 0; + sk.SendFlags |= (2 ** (i % 16)); + if(i != SP_ELO.m_id) + sk.(scores(it)) = 0; }); return 1; @@ -276,13 +286,14 @@ void Score_ClearAll() entity sk; float t; FOREACH_CLIENTSLOT(true, { - sk = it.scorekeeper; + sk = CS(it).scorekeeper; if (!sk) continue; FOREACH(Scores, true, { if(sk.(scores(it)) != 0) if(scores_label(it) != "") - sk.SendFlags |= pow(2, i % 16); - sk.(scores(it)) = 0; + sk.SendFlags |= (2 ** (i % 16)); + if(i != SP_ELO.m_id) + sk.(scores(it)) = 0; }); }); for(t = 0; t < 16; ++t) @@ -294,7 +305,7 @@ void Score_ClearAll() { if(sk.(teamscores(j)) != 0) if(teamscores_label(j) != "") - sk.SendFlags |= pow(2, j); + sk.SendFlags |= (2 ** j); sk.(teamscores(j)) = 0; } } @@ -302,46 +313,73 @@ void Score_ClearAll() void PlayerScore_Attach(entity player) { - if(player.scorekeeper) + if(CS(player).scorekeeper) error("player already has a scorekeeper"); entity sk = new_pure(scorekeeper); sk.owner = player; Net_LinkEntity(sk, false, 0, PlayerScore_SendEntity); - player.scorekeeper = sk; + CS(player).scorekeeper = sk; } void PlayerScore_Detach(entity player) { - if(!player.scorekeeper) + if(!CS(player).scorekeeper) error("player has no scorekeeper"); - remove(player.scorekeeper); - player.scorekeeper = world; + delete(CS(player).scorekeeper); + CS(player).scorekeeper = NULL; } float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score) { - bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score); - score = ret_float; + bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score, player); + score = M_ARGV(1, float); - if(gameover) + if(game_stopped) if(!mutator_returnvalue) score = 0; if(!scores_initialized) return 0; // FIXME remove this when everything uses this system - entity s = player.scorekeeper; + entity s = CS(player).scorekeeper; if(!s) { - if(gameover) + if(game_stopped) return 0; - LOG_WARNING("Adding score to unknown player!"); + LOG_WARN("Adding score to unknown player!"); return 0; } - if(score) - if(scores_label(scorefield) != "") - s.SendFlags |= pow(2, scorefield.m_id % 16); + if(!score) + { + return s.(scores(scorefield)); + } + if(scores_label(scorefield) != "") + s.SendFlags |= (2 ** (scorefield.m_id % 16)); if(!warmup_stage) - PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score); - return (s.(scores(scorefield)) += score); + PlayerStats_GameReport_Event_Player(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score); + s.(scores(scorefield)) += score; + MUTATOR_CALLHOOK(AddedPlayerScore, scorefield, score, player); + return s.(scores(scorefield)); +} + +float PlayerScore_Set(entity player, PlayerScoreField scorefield, float score) +{ + if(!scores_initialized) return 0; // FIXME remove this when everything uses this system + entity s = CS(player).scorekeeper; + if(!s) + { + if(game_stopped) + return 0; + LOG_WARN("Setting score of unknown player!"); + return 0; + } + + float oldscore = s.(scores(scorefield)); + if(oldscore == score) + return oldscore; + + if(scores_label(scorefield) != "") + s.SendFlags |= (2 ** (scorefield.m_id % 16)); + s.(scores(scorefield)) = score; + return s.(scores(scorefield)); } float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score) @@ -364,14 +402,13 @@ float PlayerScore_Compare(entity t1, entity t2, float strict) }); if (result.x == 0 && strict) - result.x = etof(t1.owner) - etof(t2.owner); + result.x = t1.owner.playerid - t2.owner.playerid; return result.x; } -void WinningConditionHelper() +void WinningConditionHelper(entity this) { - SELFPARAM(); float c; string s; float fullstatus; @@ -390,10 +427,10 @@ void WinningConditionHelper() s = GetGametype(); s = strcat(s, ":", autocvar_g_xonoticversion); s = strcat(s, ":P", ftos(cvar_purechanges_count)); - s = strcat(s, ":S", ftos(nJoinAllowed(self, world))); + s = strcat(s, ":S", ftos(nJoinAllowed(this, NULL))); s = strcat(s, ":F", ftos(serverflags)); s = strcat(s, ":M", modname); - s = strcat(s, "::", GetPlayerScoreString(world, (fullstatus ? 1 : 2))); + s = strcat(s, "::", GetPlayerScoreString(NULL, (fullstatus ? 1 : 2))); if(teamscores_entities_count) { @@ -406,8 +443,8 @@ void WinningConditionHelper() WinningConditionHelper_winnerteam = -1; WinningConditionHelper_secondteam = -1; - winnerscorekeeper = world; - secondscorekeeper = world; + winnerscorekeeper = NULL; + secondscorekeeper = NULL; for(t = 0; t < 16; ++t) { sk = teamscorekeepers[t]; @@ -439,17 +476,17 @@ void WinningConditionHelper() WinningConditionHelper_lowerisbetter = (teamscores_flags_primary & SFL_LOWER_IS_BETTER); WinningConditionHelper_zeroisworst = (teamscores_flags_primary & SFL_ZERO_IS_WORST); - WinningConditionHelper_winner = world; // not supported in teamplay - WinningConditionHelper_second = world; // not supported in teamplay + WinningConditionHelper_winner = NULL; // not supported in teamplay + WinningConditionHelper_second = NULL; // not supported in teamplay } else { - WinningConditionHelper_winner = world; - WinningConditionHelper_second = world; - winnerscorekeeper = world; - secondscorekeeper = world; - FOREACH_CLIENT(IS_PLAYER(it), LAMBDA( - sk = it.scorekeeper; + WinningConditionHelper_winner = NULL; + WinningConditionHelper_second = NULL; + winnerscorekeeper = NULL; + secondscorekeeper = NULL; + FOREACH_CLIENT(IS_PLAYER(it), { + sk = CS(it).scorekeeper; c = PlayerScore_Compare(winnerscorekeeper, sk, 1); if(c < 0) { @@ -467,11 +504,11 @@ void WinningConditionHelper() secondscorekeeper = sk; } } - )); + }); WinningConditionHelper_equality = (PlayerScore_Compare(winnerscorekeeper, secondscorekeeper, 0) == 0); if(WinningConditionHelper_equality) - WinningConditionHelper_winner = WinningConditionHelper_second = world; + WinningConditionHelper_winner = WinningConditionHelper_second = NULL; WinningConditionHelper_topscore = winnerscorekeeper.scores_primary; WinningConditionHelper_secondscore = secondscorekeeper.scores_primary; @@ -505,35 +542,27 @@ void WinningConditionHelper() } } - if(worldstatus) - strunzone(worldstatus); - worldstatus = strzone(s); + strcpy(worldstatus, s); - FOREACH_CLIENT(true, LAMBDA( + FOREACH_CLIENT(true, { string s = ""; if(fullstatus) { s = GetPlayerScoreString(it, 1); s = strcat(s, IS_REAL_CLIENT(it) ? ":human" : ":bot"); - ret_string = string_null; - if(!IS_PLAYER(it) && !MUTATOR_CALLHOOK(GetPlayerStatus, it, s)) + if(!IS_PLAYER(it) && !MUTATOR_CALLHOOK(GetPlayerStatus, it)) s = strcat(s, ":spectator"); - if (ret_string) s = strcat(s, ret_string); } else { - ret_string = string_null; - if (IS_PLAYER(it) || MUTATOR_CALLHOOK(GetPlayerStatus, it, s)) + if (IS_PLAYER(it) || MUTATOR_CALLHOOK(GetPlayerStatus, it)) s = GetPlayerScoreString(it, 2); else s = "-666"; - if (ret_string) s = strcat(s, ret_string); } - if(it.clientstatus) - strunzone(it.clientstatus); - it.clientstatus = strzone(s); - )); + strcpy(it.clientstatus, s); + }); } string GetScoreLogLabel(string label, float fl) @@ -587,7 +616,7 @@ string GetPlayerScoreString(entity pl, float shortString) }); out = substring(out, 0, strlen(out) - 1); } - else if((sk = pl.scorekeeper)) + else if((sk = CS(pl).scorekeeper)) { FOREACH(Scores, true, { if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY) @@ -682,7 +711,7 @@ float PlayerTeamScore_Compare(entity p1, entity p2, float teams, float strict) return 0; } - return PlayerScore_Compare(p1.scorekeeper, p2.scorekeeper, strict); + return PlayerScore_Compare(CS(p1).scorekeeper, CS(p2).scorekeeper, strict); } entity PlayerScore_Sort(.float field, float teams, float strict, float nospectators) @@ -690,11 +719,11 @@ entity PlayerScore_Sort(.float field, float teams, float strict, float nospectat entity p, plist, pprev, pbest, pbestprev, pfirst, plast; float i, j; - plist = world; + plist = NULL; - FOREACH_CLIENT(true, LAMBDA(it.(field) = 0)); + FOREACH_CLIENT(true, { it.(field) = 0; }); - FOREACH_CLIENT(it.scorekeeper, + FOREACH_CLIENT(CS(it).scorekeeper, { if(nospectators) if(it.frags == FRAGS_SPECTATOR) @@ -705,12 +734,12 @@ entity PlayerScore_Sort(.float field, float teams, float strict, float nospectat }); // Now plist points to the whole list. - pfirst = plast = world; + pfirst = plast = NULL; i = j = 0; while(plist) { - pprev = pbestprev = world; + pprev = pbestprev = NULL; pbest = plist; for(p = plist; (pprev = p), (p = p.chain); ) { @@ -722,11 +751,11 @@ entity PlayerScore_Sort(.float field, float teams, float strict, float nospectat } // remove pbest out of the chain - if(pbestprev == world) + if(pbestprev == NULL) plist = pbest.chain; else pbestprev.chain = pbest.chain; - pbest.chain = world; + pbest.chain = NULL; ++i; if(!plast || PlayerTeamScore_Compare(plast, pbest, teams, 0)) @@ -751,7 +780,7 @@ float TeamScore_GetCompareValue(float t) if(t <= 0 || t >= 16) { - if(gameover) + if(game_stopped) return 0; error("Reading score of invalid team!"); } @@ -826,9 +855,9 @@ void Score_NicePrint_Player(entity to, entity p, float w) float fl, sc; s = " "; - sk = p.scorekeeper; + sk = CS(p).scorekeeper; - s = strcat(s, p.netname); + s = strcat(s, playername(p, false)); for (;;) { i = strlennocol(s) - NAMEWIDTH; @@ -860,7 +889,7 @@ void Score_NicePrint_Spectators(entity to) void Score_NicePrint_Spectator(entity to, entity p) { - print_to(to, strcat(" ", p.netname)); + print_to(to, strcat(" ", playername(p, false))); } .float score_dummyfield; @@ -892,22 +921,22 @@ void Score_NicePrint(entity to) } t = 0; - FOREACH_CLIENT(!IS_PLAYER(it), LAMBDA( + FOREACH_CLIENT(!IS_PLAYER(it), { if (!t) Score_NicePrint_Spectators(to); Score_NicePrint_Spectator(to, it); t = 1; - )); + }); } void PlayerScore_PlayerStats(entity p) { - entity s = p.scorekeeper; + entity s = CS(p).scorekeeper; FOREACH(Scores, true, { - if(s.(scores(it)) != 0) - if(scores_label(it) != "") - PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_SCOREBOARD, scores_label(it)), s.(scores(it))); - }); + if(s.(scores(it)) != 0 && scores_label(it) != "") + PlayerStats_GameReport_Event_Player(s.owner, + strcat(PLAYERSTATS_SCOREBOARD, scores_label(it)), s.(scores(it))); + }); } void PlayerScore_TeamStats() @@ -920,9 +949,9 @@ void PlayerScore_TeamStats() if(!sk) continue; for(i = 0; i < MAX_TEAMSCORE; ++i) - if(sk.(teamscores(i)) != 0) - if(teamscores_label(i) != "") - // the +1 is important here! - PS_GR_T_ADDVAL(t+1, strcat(PLAYERSTATS_SCOREBOARD, teamscores_label(i)), sk.(teamscores(i))); + if(sk.(teamscores(i)) != 0 && teamscores_label(i) != "") + // the +1 is important here! + PlayerStats_GameReport_Event_Team(t+1, + strcat(PLAYERSTATS_SCOREBOARD, teamscores_label(i)), sk.(teamscores(i))); } }