From 6a9c123da9e4144831054a27aaf5a90e108b9529 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 18 Jul 2017 09:35:38 +1000 Subject: [PATCH] Port scorekeeper to ClientState --- qcsrc/common/state.qc | 2 +- qcsrc/server/client.qh | 1 + qcsrc/server/scores.qc | 28 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/qcsrc/common/state.qc b/qcsrc/common/state.qc index 9774bd5b9..cbf9eff72 100644 --- a/qcsrc/common/state.qc +++ b/qcsrc/common/state.qc @@ -70,6 +70,7 @@ void PlayerScore_Detach(entity this); void ClientState_detach(entity this) { accuracy_free(this); // TODO: needs to be before CS() is deleted! + PlayerScore_Detach(this); // what ^they^ said delete(CS(this)); this._cs = NULL; @@ -82,5 +83,4 @@ void ClientState_detach(entity this) playerdemo_shutdown(this); entcs_detach(this); ClientData_Detach(this); - PlayerScore_Detach(this); } diff --git a/qcsrc/server/client.qh b/qcsrc/server/client.qh index d24bc4aad..097ba382b 100644 --- a/qcsrc/server/client.qh +++ b/qcsrc/server/client.qh @@ -103,6 +103,7 @@ CLASS(Client, Object) ATTRIB(Client, model_randomizer, float, this.model_randomizer); ATTRIB(Client, accuracy, entity, this.accuracy); ATTRIB(Client, hasweapon_complain_spam, float, this.hasweapon_complain_spam); + ATTRIB(Client, scorekeeper, entity, this.scorekeeper); METHOD(Client, m_unwind, bool(Client this)); diff --git a/qcsrc/server/scores.qc b/qcsrc/server/scores.qc index 6bfb09cc9..042d450ec 100644 --- a/qcsrc/server/scores.qc +++ b/qcsrc/server/scores.qc @@ -262,7 +262,7 @@ 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) != "") @@ -279,7 +279,7 @@ 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) @@ -306,20 +306,20 @@ 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"); - delete(player.scorekeeper); - player.scorekeeper = NULL; + delete(CS(player).scorekeeper); + CS(player).scorekeeper = NULL; } float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score) @@ -332,7 +332,7 @@ float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score) 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(game_stopped) @@ -455,7 +455,7 @@ void WinningConditionHelper(entity this) winnerscorekeeper = NULL; secondscorekeeper = NULL; FOREACH_CLIENT(IS_PLAYER(it), LAMBDA( - sk = it.scorekeeper; + sk = CS(it).scorekeeper; c = PlayerScore_Compare(winnerscorekeeper, sk, 1); if(c < 0) { @@ -589,7 +589,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) @@ -684,7 +684,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) @@ -696,7 +696,7 @@ entity PlayerScore_Sort(.float field, float teams, float strict, float nospectat FOREACH_CLIENT(true, LAMBDA(it.(field) = 0)); - FOREACH_CLIENT(it.scorekeeper, + FOREACH_CLIENT(CS(it).scorekeeper, { if(nospectators) if(it.frags == FRAGS_SPECTATOR) @@ -828,7 +828,7 @@ void Score_NicePrint_Player(entity to, entity p, float w) float fl, sc; s = " "; - sk = p.scorekeeper; + sk = CS(p).scorekeeper; s = strcat(s, playername(p, false)); for (;;) @@ -904,7 +904,7 @@ void Score_NicePrint(entity to) 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) != "") -- 2.39.2