float complain_weapon_type;
float complain_weapon_time;
-int ps_primary, ps_secondary;
+PlayerScoreField ps_primary, ps_secondary;
int ts_primary, ts_secondary;
Weapon last_switchweapon;
{
entity sk;
sk = playerslots[player_localnum];
- if(sk.(scores[ps_primary]) >= 666)
+ if(sk.(scores(ps_primary)) >= 666)
s = _("^1Match has already begun");
- else if(sk.(scores[ps_primary]) > 0)
+ else if(sk.(scores(ps_primary)) > 0)
s = _("^1You have no more lives left");
else
s = sprintf(_("^1Press ^3%s^1 to join"), getcommandkey("jump", "+jump"));
entity me;
me = playerslots[player_localnum];
float score;
- score = me.(scores[ps_primary]);
+ score = me.(scores(ps_primary));
- if(!(scores_flags[ps_primary] & SFL_TIME) || teamplay) // race/cts record display on HUD
+ if(!(scores_flags(ps_primary) & SFL_TIME) || teamplay) // race/cts record display on HUD
return; // no records in the actual race
// clientside personal record
continue;
if (tm.team == myteam)
drawfill(pos + eX * score_size * i, eX * score_size + eY * fontsize.y, '1 1 1', highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
- drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores[ts_primary])), eX * score_size + eY * fontsize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
+ drawstring_aspect(pos + eX * score_size * i, ftos(tm.(teamscores(ts_primary))), eX * score_size + eY * fontsize.y, Team_ColorRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
++i;
}
first_pl = 1;
score_color = Team_ColorRGB(pl.team) * 0.8;
s = textShortenToWidth(entcs_GetName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
- drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores[ps_primary])), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
+ drawstring(pos + eX * (name_size + spacing_size), ftos(pl.(scores(ps_primary))), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
pos.y += fontsize.y;
++i;
}
me = playerslots[current_player];
- if((scores_flags[ps_primary] & SFL_TIME) && !teamplay) { // race/cts record display on HUD
+ if((scores_flags(ps_primary) & SFL_TIME) && !teamplay) { // race/cts record display on HUD
string timer, distrtimer;
pl = players.sort_next;
if(pl == me)
pl = pl.sort_next;
- if(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)
- if(pl.scores[ps_primary] == 0)
+ if(scores_flags(ps_primary) & SFL_ZERO_IS_WORST)
+ if(pl.scores(ps_primary) == 0)
pl = world;
- score = me.(scores[ps_primary]);
+ score = me.(scores(ps_primary));
timer = TIME_ENCODED_TOSTRING(score);
draw_beginBoldFont();
- if (pl && ((!(scores_flags[ps_primary] & SFL_ZERO_IS_WORST)) || score)) {
+ if (pl && ((!(scores_flags(ps_primary) & SFL_ZERO_IS_WORST)) || score)) {
// distribution display
- distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
+ distribution = me.(scores(ps_primary)) - pl.(scores(ps_primary));
distrtimer = ftos_decimals(fabs(distribution/pow(10, TIME_DECIMALS)), TIME_DECIMALS);
if(autocvar__hud_configure)
distribution = 42;
else if(pl)
- distribution = me.(scores[ps_primary]) - pl.(scores[ps_primary]);
+ distribution = me.(scores(ps_primary)) - pl.(scores(ps_primary));
else
distribution = 0;
- score = me.(scores[ps_primary]);
+ score = me.(scores(ps_primary));
if(autocvar__hud_configure)
score = 123;
continue;
if(!tm.team && teamplay)
continue;
- score = tm.(teamscores[ts_primary]);
+ score = tm.(teamscores(ts_primary));
if(autocvar__hud_configure)
score = 123;
if(this.owner) {
SetTeam(this.owner, -1);
this.owner.gotscores = 0;
- for(int i = 0; i < MAX_SCORE; ++i) {
- this.owner.(scores[i]) = 0; // clear all scores
- }
+ FOREACH(Scores, true, {
+ this.owner.(scores(it)) = 0; // clear all scores
+ });
}
}
NET_HANDLE(ENT_CLIENT_SCORES, bool isnew)
{
make_pure(this);
- int i, n;
- bool isNew;
entity o;
// damnit -.- don't want to go change every single .sv_entnum in hud.qc AGAIN
// (no I've never heard of M-x replace-string, sed, or anything like that)
- isNew = !this.owner; // workaround for DP bug
- n = ReadByte()-1;
+ bool isNew = !this.owner; // workaround for DP bug
+ int n = ReadByte()-1;
#ifdef DP_CSQC_ENTITY_REMOVE_IS_B0RKED
if(!isNew && n != this.sv_entnum)
//playerchecker will do this for us later, if it has not already done so
int sf, lf;
-#if MAX_SCORE <= 8
- sf = ReadByte();
- lf = ReadByte();
-#else
sf = ReadShort();
lf = ReadShort();
-#endif
- int p;
- for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
- if(sf & p)
+ FOREACH(Scores, true, {
+ int p = 1 << (i % 16);
+ if (sf & p)
{
- if(lf & p)
- o.(scores[i]) = ReadInt24_t();
+ if (lf & p)
+ o.(scores(it)) = ReadInt24_t();
else
- o.(scores[i]) = ReadChar();
+ o.(scores(it)) = ReadChar();
}
+ });
return = true;
if(sf & p)
{
if(lf & p)
- o.(teamscores[i]) = ReadInt24_t();
+ o.(teamscores(i)) = ReadInt24_t();
else
- o.(teamscores[i]) = ReadChar();
+ o.(teamscores(i)) = ReadChar();
}
return = true;
make_pure(this);
gametype = ReadInt24_t();
HUD_ModIcons_SetFunc();
- for (int i = 0; i < MAX_SCORE; ++i)
- {
- if (scores_label[i]) strunzone(scores_label[i]);
- scores_label[i] = strzone(ReadString());
- scores_flags[i] = ReadByte();
- }
+ FOREACH(Scores, true, {
+ if (scores_label(it)) strunzone(scores_label(it));
+ scores_label(it) = strzone(ReadString());
+ scores_flags(it) = ReadByte();
+ });
for (int i = 0; i < MAX_TEAMSCORE; ++i)
{
- if (teamscores_label[i]) strunzone(teamscores_label[i]);
- teamscores_label[i] = strzone(ReadString());
- teamscores_flags[i] = ReadByte();
+ if (teamscores_label(i)) strunzone(teamscores_label(i));
+ teamscores_label(i) = strzone(ReadString());
+ teamscores_flags(i) = ReadByte();
}
return = true;
HUD_InitScores();
// --------------------------------------------------------------------------
// Scoreboard stuff
-const int MAX_HUD_FIELDS = 16;
+const int MAX_HUD_FIELDS = 64;
-const int SP_END = -1;
-
-const int SP_PING = -2;
-const int SP_NAME = -3;
-const int SP_KDRATIO = -4;
-const int SP_CLRATIO = -5;
-const int SP_PL = -6;
-const int SP_FRAGS = -7;
-const int SP_SUM = -8;
-
-const int SP_SEPARATOR = -100;
-
-float hud_field[MAX_HUD_FIELDS + 1];
+PlayerScoreField hud_field[MAX_HUD_FIELDS + 1];
float hud_size[MAX_HUD_FIELDS + 1];
string hud_title[MAX_HUD_FIELDS + 1];
int hud_num_fields;
-string scores_label[MAX_SCORE];
-int scores_flags[MAX_SCORE];
-string teamscores_label[MAX_SCORE];
-int teamscores_flags[MAX_SCORE];
-.int scores[MAX_SCORE];
-.float teamscores[MAX_TEAMSCORE];
-
-#define IS_INCREASING(x) ( (x)&SFL_LOWER_IS_BETTER )
-#define IS_DECREASING(x) ( !((x)&SFL_LOWER_IS_BETTER) )
-
-
vector hud_fontsize;
float RANKINGS_RECEIVED_CNT;
{
int i, f;
- ps_primary = ps_secondary = ts_primary = ts_secondary = -1;
- for(i = 0; i < MAX_SCORE; ++i)
- {
- f = (scores_flags[i] & SFL_SORT_PRIO_MASK);
+ ps_primary = ps_secondary = NULL;
+ ts_primary = ts_secondary = -1;
+ FOREACH(Scores, true, {
+ f = (scores_flags(it) & SFL_SORT_PRIO_MASK);
if(f == SFL_SORT_PRIO_PRIMARY)
- ps_primary = i;
+ ps_primary = it;
if(f == SFL_SORT_PRIO_SECONDARY)
- ps_secondary = i;
- }
- if(ps_secondary == -1)
+ ps_secondary = it;
+ });
+ if(ps_secondary == NULL)
ps_secondary = ps_primary;
for(i = 0; i < MAX_TEAMSCORE; ++i)
{
- f = (teamscores_flags[i] & SFL_SORT_PRIO_MASK);
+ f = (teamscores_flags(i) & SFL_SORT_PRIO_MASK);
if(f == SFL_SORT_PRIO_PRIMARY)
ts_primary = i;
if(f == SFL_SORT_PRIO_SECONDARY)
return false;
}
- r = HUD_CompareScore(left.scores[ps_primary], right.scores[ps_primary], scores_flags[ps_primary]);
+ r = HUD_CompareScore(left.scores(ps_primary), right.scores(ps_primary), scores_flags(ps_primary));
if (r >= 0)
return r;
- r = HUD_CompareScore(left.scores[ps_secondary], right.scores[ps_secondary], scores_flags[ps_secondary]);
+ r = HUD_CompareScore(left.scores(ps_secondary), right.scores(ps_secondary), scores_flags(ps_secondary));
if (r >= 0)
return r;
- int i;
- for(i = 0; i < MAX_SCORE; ++i)
- {
- r = HUD_CompareScore(left.scores[i], right.scores[i], scores_flags[i]);
- if (r >= 0)
- return r;
- }
+ FOREACH(Scores, true, {
+ r = HUD_CompareScore(left.scores(it), right.scores(it), scores_flags(it));
+ if (r >= 0) return r;
+ });
if (left.sv_entnum < right.sv_entnum)
return true;
if(right.team == NUM_SPECTATOR)
return 0;
- r = HUD_CompareScore(left.teamscores[ts_primary], right.teamscores[ts_primary], teamscores_flags[ts_primary]);
+ r = HUD_CompareScore(left.teamscores(ts_primary), right.teamscores(ts_primary), teamscores_flags(ts_primary));
if (r >= 0)
return r;
- r = HUD_CompareScore(left.teamscores[ts_secondary], right.teamscores[ts_secondary], teamscores_flags[ts_secondary]);
+ r = HUD_CompareScore(left.teamscores(ts_secondary), right.teamscores(ts_secondary), teamscores_flags(ts_secondary));
if (r >= 0)
return r;
- for(i = 0; i < MAX_SCORE; ++i)
+ for(i = 0; i < MAX_TEAMSCORE; ++i)
{
- r = HUD_CompareScore(left.teamscores[i], right.teamscores[i], teamscores_flags[i]);
+ r = HUD_CompareScore(left.teamscores(i), right.teamscores(i), teamscores_flags(i));
if (r >= 0)
return r;
}
void Cmd_HUD_SetFields(int argc)
{
TC(int, argc);
- int i, j, slash;
+ int i, slash;
string str, pattern;
float have_name = 0, have_primary = 0, have_secondary = 0, have_separator = 0;
float missing;
// set up a temporary scoreboard layout
// no layout can be properly set up until score_info data haven't been received
argc = tokenizebyseparator("0 1 ping pl name | score", " ");
- ps_primary = 0;
- scores_label[ps_primary] = strzone("score");
- scores_flags[ps_primary] = SFL_ALLOW_HIDE;
+ ps_primary = SP_SCORE;
+ scores_label(ps_primary) = strzone("score");
+ scores_flags(ps_primary) = SFL_ALLOW_HIDE;
}
// TODO: re enable with gametype dependant cvars?
{
string s;
s = "ping pl name |";
- for(i = 0; i < MAX_SCORE; ++i)
- {
- if(i != ps_primary)
- if(i != ps_secondary)
- if(scores_label[i] != "")
- s = strcat(s, " ", scores_label[i]);
- }
+ FOREACH(Scores, true, {
+ if(it != ps_primary)
+ if(it != ps_secondary)
+ if(scores_label(it) != "")
+ s = strcat(s, " ", scores_label(it));
+ });
if(ps_secondary != ps_primary)
- s = strcat(s, " ", scores_label[ps_secondary]);
- s = strcat(s, " ", scores_label[ps_primary]);
+ s = strcat(s, " ", scores_label(ps_secondary));
+ s = strcat(s, " ", scores_label(ps_primary));
argc = tokenizebyseparator(strcat("0 1 ", s), " ");
}
}
hud_size[hud_num_fields] = stringwidth(hud_title[hud_num_fields], false, hud_fontsize);
str = strtolower(str);
+ PlayerScoreField j;
switch(str)
{
case "ping": hud_field[hud_num_fields] = SP_PING; break;
case "dmgtaken": hud_field[hud_num_fields] = SP_DMGTAKEN; break;
default:
{
- for(j = 0; j < MAX_SCORE; ++j)
- if(str == strtolower(scores_label[j]))
+ FOREACH(Scores, true, {
+ if (str == strtolower(scores_label(it))) {
+ j = it;
goto found; // sorry, but otherwise fteqcc -O3 miscompiles this and warns about "unreachable code"
+ }
+ });
LABEL(notfound)
if(str == "frags")
break;
}
- if(scores_flags[ps_primary] & SFL_ALLOW_HIDE)
+ if(scores_flags(ps_primary) & SFL_ALLOW_HIDE)
have_primary = 1;
- if(scores_flags[ps_secondary] & SFL_ALLOW_HIDE)
+ if(scores_flags(ps_secondary) & SFL_ALLOW_HIDE)
have_secondary = 1;
if(ps_primary == ps_secondary)
have_secondary = 1;
if(!have_secondary)
{
strunzone(hud_title[hud_num_fields]);
- hud_title[hud_num_fields] = strzone(TranslateScoresLabel(scores_label[ps_secondary]));
+ hud_title[hud_num_fields] = strzone(TranslateScoresLabel(scores_label(ps_secondary)));
hud_size[hud_num_fields] = stringwidth(hud_title[hud_num_fields], false, hud_fontsize);
hud_field[hud_num_fields] = ps_secondary;
++hud_num_fields;
- LOG_INFOF("fixed missing field '%s'\n", scores_label[ps_secondary]);
+ LOG_INFOF("fixed missing field '%s'\n", scores_label(ps_secondary));
}
if(!have_primary)
{
strunzone(hud_title[hud_num_fields]);
- hud_title[hud_num_fields] = strzone(TranslateScoresLabel(scores_label[ps_primary]));
+ hud_title[hud_num_fields] = strzone(TranslateScoresLabel(scores_label(ps_primary)));
hud_size[hud_num_fields] = stringwidth(hud_title[hud_num_fields], false, hud_fontsize);
hud_field[hud_num_fields] = ps_primary;
++hud_num_fields;
- LOG_INFOF("fixed missing field '%s'\n", scores_label[ps_primary]);
+ LOG_INFOF("fixed missing field '%s'\n", scores_label(ps_primary));
}
}
float hud_field_icon0_alpha;
float hud_field_icon1_alpha;
float hud_field_icon2_alpha;
-string HUD_GetField(entity pl, int field)
+string HUD_GetField(entity pl, PlayerScoreField field)
{
- TC(int, field);
float tmp, num, denom;
int f;
string str;
return entcs_GetName(pl.sv_entnum);
case SP_FRAGS:
- f = pl.(scores[SP_KILLS]);
- f -= pl.(scores[SP_SUICIDES]);
+ f = pl.(scores(SP_KILLS));
+ f -= pl.(scores(SP_SUICIDES));
return ftos(f);
case SP_KDRATIO:
- num = pl.(scores[SP_KILLS]);
- denom = pl.(scores[SP_DEATHS]);
+ num = pl.(scores(SP_KILLS));
+ denom = pl.(scores(SP_DEATHS));
if(denom == 0) {
hud_field_rgb = '0 1 0';
return str;
case SP_SUM:
- f = pl.(scores[SP_KILLS]);
- f -= pl.(scores[SP_DEATHS]);
+ f = pl.(scores(SP_KILLS));
+ f -= pl.(scores(SP_DEATHS));
if(f > 0) {
hud_field_rgb = '0 1 0';
return ftos(f);
case SP_DMG:
- num = pl.(scores[SP_DMG]);
+ num = pl.(scores(SP_DMG));
denom = 1000;
str = sprintf("%.1f k", num/denom);
return str;
case SP_DMGTAKEN:
- num = pl.(scores[SP_DMGTAKEN]);
+ num = pl.(scores(SP_DMGTAKEN));
denom = 1000;
str = sprintf("%.1f k", num/denom);
return str;
default:
- tmp = pl.(scores[field]);
- f = scores_flags[field];
+ tmp = pl.(scores(field));
+ f = scores_flags(field);
if(field == ps_primary)
hud_field_rgb = '1 1 0';
else if(field == ps_secondary)
string HUD_FixScoreboardColumnWidth(int i, string str)
{
TC(int, i);
- float field, f;
+ float f;
vector sz;
- field = hud_field[i];
+ PlayerScoreField field = hud_field[i];
hud_fixscoreboardcolumnwidth_iconlen = 0;
void HUD_PrintScoreboardItem(vector pos, vector item_size, entity pl, bool is_self, int pl_number)
{
TC(bool, is_self); TC(int, pl_number);
- vector tmp, rgb;
- rgb = Team_ColorRGB(pl.team);
+ vector tmp;
+ vector rgb = Team_ColorRGB(pl.team);
string str;
- int field;
- float is_spec;
- is_spec = (entcs_GetTeam(pl.sv_entnum) == NUM_SPECTATOR);
+ bool is_spec = (entcs_GetTeam(pl.sv_entnum) == NUM_SPECTATOR);
if((rgb == '1 1 1') && (!is_spec)) {
rgb.x = autocvar_scoreboard_color_bg_r + 0.5;
tmp.y = 0;
tmp.z = 0;
int i;
+ PlayerScoreField field;
for(i = 0; i < hud_num_fields; ++i)
{
field = hud_field[i];
draw_beginBoldFont();
rgb = Team_ColorRGB(tm.team);
- str = ftos(tm.(teamscores[ts_primary]));
+ str = ftos(tm.(teamscores(ts_primary)));
drawstring(pos + team_score_baseoffset - eX * stringwidth(str, false, hud_fontsize * 1.5), str, hud_fontsize * 1.5, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
if(ts_primary != ts_secondary)
{
- str = ftos(tm.(teamscores[ts_secondary]));
+ str = ftos(tm.(teamscores(ts_secondary)));
drawstring(pos + team_score_baseoffset - eX * stringwidth(str, false, hud_fontsize) + eY * hud_fontsize.y * 1.5, str, hud_fontsize, rgb, scoreboard_alpha_fg, DRAWFLAG_NORMAL);
}
draw_endBoldFont();
str = strcat(str, _(" or"));
if(teamplay)
{
- str = strcat(str, sprintf(_(" until ^3%s %s^7"), ScoreString(teamscores_flags[ts_primary], fl),
- (teamscores_label[ts_primary] == "score") ? CTX(_("SCO^points")) :
- (teamscores_label[ts_primary] == "fastest") ? CTX(_("SCO^is beaten")) :
- TranslateScoresLabel(teamscores_label[ts_primary])));
+ str = strcat(str, sprintf(_(" until ^3%s %s^7"), ScoreString(teamscores_flags(ts_primary), fl),
+ (teamscores_label(ts_primary) == "score") ? CTX(_("SCO^points")) :
+ (teamscores_label(ts_primary) == "fastest") ? CTX(_("SCO^is beaten")) :
+ TranslateScoresLabel(teamscores_label(ts_primary))));
}
else
{
- str = strcat(str, sprintf(_(" until ^3%s %s^7"), ScoreString(scores_flags[ps_primary], fl),
- (scores_label[ps_primary] == "score") ? CTX(_("SCO^points")) :
- (scores_label[ps_primary] == "fastest") ? CTX(_("SCO^is beaten")) :
- TranslateScoresLabel(scores_label[ps_primary])));
+ str = strcat(str, sprintf(_(" until ^3%s %s^7"), ScoreString(scores_flags(ps_primary), fl),
+ (scores_label(ps_primary) == "score") ? CTX(_("SCO^points")) :
+ (scores_label(ps_primary) == "fastest") ? CTX(_("SCO^is beaten")) :
+ TranslateScoresLabel(scores_label(ps_primary))));
}
}
if(ll > 0)
str = strcat(str, _(" or"));
if(teamplay)
{
- str = strcat(str, sprintf(_(" until a lead of ^3%s %s^7"), ScoreString(teamscores_flags[ts_primary], ll),
- (teamscores_label[ts_primary] == "score") ? CTX(_("SCO^points")) :
- (teamscores_label[ts_primary] == "fastest") ? CTX(_("SCO^is beaten")) :
- TranslateScoresLabel(teamscores_label[ts_primary])));
+ str = strcat(str, sprintf(_(" until a lead of ^3%s %s^7"), ScoreString(teamscores_flags(ts_primary), ll),
+ (teamscores_label(ts_primary) == "score") ? CTX(_("SCO^points")) :
+ (teamscores_label(ts_primary) == "fastest") ? CTX(_("SCO^is beaten")) :
+ TranslateScoresLabel(teamscores_label(ts_primary))));
}
else
{
- str = strcat(str, sprintf(_(" until a lead of ^3%s %s^7"), ScoreString(scores_flags[ps_primary], ll),
- (scores_label[ps_primary] == "score") ? CTX(_("SCO^points")) :
- (scores_label[ps_primary] == "fastest") ? CTX(_("SCO^is beaten")) :
- TranslateScoresLabel(scores_label[ps_primary])));
+ str = strcat(str, sprintf(_(" until a lead of ^3%s %s^7"), ScoreString(scores_flags(ps_primary), ll),
+ (scores_label(ps_primary) == "score") ? CTX(_("SCO^points")) :
+ (scores_label(ps_primary) == "fastest") ? CTX(_("SCO^is beaten")) :
+ TranslateScoresLabel(scores_label(ps_primary))));
}
}
}
const int SFL_SORT_PRIO_PRIMARY = 8;
const int SFL_SORT_PRIO_MASK = 12;
-/**
+/*
* Score indices
*/
-#define MAX_SCORE 12
+
+#ifndef MENUQC
+
+#define IS_INCREASING(x) ( (x) & SFL_LOWER_IS_BETTER )
+#define IS_DECREASING(x) ( !((x) & SFL_LOWER_IS_BETTER) )
+
+
+#define MAX_SCORE 64
+
+#define REGISTER_SP(id) REGISTER(Scores, SP, id, m_id, new_pure(PlayerScoreField))
+REGISTRY(Scores, MAX_SCORE);
+#define Scores_from(i) _Scores_from(i, NULL)
+REGISTER_REGISTRY(Scores)
+REGISTRY_SORT(Scores);
+REGISTRY_CHECK(Scores);
+STATIC_INIT(Scores_renumber) { FOREACH(Scores, true, it.m_id = i); }
+
+USING(PlayerScoreField, entity);
+.int _scores[MAX_SCORE];
+.string m_name;
+.int m_flags;
+
+#define scores(this) _scores[(this).m_id]
+#define scores_label(this) ((this).m_name)
+#define scores_flags(this) ((this).m_flags)
+
+REGISTER_SP(END);
+
+REGISTER_SP(PING);
+REGISTER_SP(NAME);
+REGISTER_SP(KDRATIO);
+REGISTER_SP(CLRATIO);
+REGISTER_SP(PL);
+REGISTER_SP(SUM);
+
+REGISTER_SP(SEPARATOR);
+
+REGISTER_SP(SCORE);
+
+REGISTER_SP(DMG);
+REGISTER_SP(DMGTAKEN);
+
+REGISTER_SP(KILLS);
+REGISTER_SP(DEATHS);
+REGISTER_SP(SUICIDES);
+REGISTER_SP(FRAGS);
+
+REGISTER_SP(RACE_TIME);
+REGISTER_SP(RACE_LAPS);
+REGISTER_SP(RACE_FASTEST);
+
+REGISTER_SP(CTS_TIME);
+REGISTER_SP(CTS_LAPS);
+REGISTER_SP(CTS_FASTEST);
+
+REGISTER_SP(ASSAULT_OBJECTIVES);
+
+REGISTER_SP(CTF_PICKUPS);
+REGISTER_SP(CTF_FCKILLS);
+REGISTER_SP(CTF_RETURNS);
+REGISTER_SP(CTF_CAPS);
+REGISTER_SP(CTF_CAPTIME);
+REGISTER_SP(CTF_DROPS);
+
+REGISTER_SP(DOM_TAKES);
+REGISTER_SP(DOM_TICKS);
+
+REGISTER_SP(FREEZETAG_REVIVALS);
+
+REGISTER_SP(KEEPAWAY_PICKUPS);
+REGISTER_SP(KEEPAWAY_BCTIME);
+REGISTER_SP(KEEPAWAY_CARRIERKILLS);
+
+REGISTER_SP(KH_PICKUPS);
+REGISTER_SP(KH_CAPS);
+REGISTER_SP(KH_KCKILLS);
+REGISTER_SP(KH_PUSHES);
+REGISTER_SP(KH_DESTROYS);
+REGISTER_SP(KH_LOSSES);
+
+REGISTER_SP(LMS_RANK);
+REGISTER_SP(LMS_LIVES);
+
+REGISTER_SP(NEXBALL_GOALS);
+REGISTER_SP(NEXBALL_FAULTS);
+
+REGISTER_SP(ONS_TAKES);
+REGISTER_SP(ONS_CAPS);
+
#define MAX_TEAMSCORE 2
+USING(ScoreTeam, string);
+.int _teamscores[MAX_TEAMSCORE];
+#define teamscores(i) _teamscores[i]
+string _teamscores_label[MAX_TEAMSCORE];
+#define teamscores_label(i) _teamscores_label[i]
+int _teamscores_flags[MAX_TEAMSCORE];
+#define teamscores_flags(i) _teamscores_flags[i]
+
+#endif
const int ST_SCORE = 0;
-const int SP_KILLS = 0;
-const int SP_DEATHS = 1;
-const int SP_SUICIDES = 2;
-const int SP_SCORE = 3;
-const int SP_DMG = 10;
-const int SP_DMGTAKEN = 11;
+
// game mode specific indices are not in common/, but in server/scores_rules.qc!
// WEAPONTODO: move this into separate/new projectile handling code // this sets sounds and other properties of the projectiles in csqc
}
const float ST_NEXBALL_GOALS = 1;
-const float SP_NEXBALL_GOALS = 4;
-const float SP_NEXBALL_FAULTS = 5;
void nb_ScoreRules(float teams)
{
ScoreRules_basics(teams, 0, 0, true);
ScoreInfo_SetLabel_TeamScore( ST_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
- ScoreInfo_SetLabel_PlayerScore( SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
+ ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_GOALS, "goals", SFL_SORT_PRIO_PRIMARY);
ScoreInfo_SetLabel_PlayerScore(SP_NEXBALL_FAULTS, "faults", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER);
ScoreRules_basics_end();
}
// score rule declarations
const int ST_ONS_CAPS = 1;
-const int SP_ONS_CAPS = 4;
-const int SP_ONS_TAKES = 6;
#endif
#endif
CheckAllowedTeams(world);
ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
- ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
+ ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
ScoreRules_basics_end();
}
float currentbots;
float bots_would_leave;
-void UpdateFrags(entity player, float f);
+void UpdateFrags(entity player, int f);
.float totalfrags;
float team1_score, team2_score, team3_score, team4_score;
#include "../lib/csqcmodel/sv_model.qh"
#include "../lib/warpzone/common.qh"
-void UpdateFrags(entity player, float f)
+void UpdateFrags(entity player, int f)
{
PlayerTeamScore_AddScore(player, f);
}
float IsFlying(entity a);
-void UpdateFrags(entity player, float f);
+void UpdateFrags(entity player, int f);
// NOTE: f=0 means still count as a (positive) kill, but count no frags for it
void W_SwitchWeapon_Force(Player this, Weapon w);
MUTATOR_HOOKABLE(WantWeapon, EV_WantWeapon);
#define EV_AddPlayerScore(i, o) \
- /**/ i(int, score_field) \
+ /**/ i(entity, score_field) \
/**/ i(float, ret_float) \
/**/ o(float, ret_float) \
/**/
-int score_field;
+PlayerScoreField score_field;
MUTATOR_HOOKABLE(AddPlayerScore, EV_AddPlayerScore);
#define EV_GetPlayerStatus(i, o) \
// scoreboard stuff
const float ST_ASSAULT_OBJECTIVES = 1;
-const float SP_ASSAULT_OBJECTIVES = 4;
// predefined spawnfuncs
void target_objective_decrease_activate();
if(ctf_captureshield_max_ratio <= 0)
return false;
- s = PlayerScore_Add(p, SP_CTF_CAPS, 0);
+ s = PlayerScore_Add(p, SP_CTF_CAPS, 0);
s2 = PlayerScore_Add(p, SP_CTF_PICKUPS, 0);
s3 = PlayerScore_Add(p, SP_CTF_RETURNS, 0);
s4 = PlayerScore_Add(p, SP_CTF_FCKILLS, 0);
FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
if(DIFF_TEAM(it, p))
continue;
- se = PlayerScore_Add(it, SP_CTF_CAPS, 0);
+ se = PlayerScore_Add(it, SP_CTF_CAPS, 0);
se2 = PlayerScore_Add(it, SP_CTF_PICKUPS, 0);
se3 = PlayerScore_Add(it, SP_CTF_RETURNS, 0);
se4 = PlayerScore_Add(it, SP_CTF_FCKILLS, 0);
CheckAllowedTeams(world);
ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
ScoreInfo_SetLabel_TeamScore (ST_CTF_CAPS, "caps", SFL_SORT_PRIO_PRIMARY);
- ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
- ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPTIME, "captime", SFL_LOWER_IS_BETTER | SFL_TIME);
- ScoreInfo_SetLabel_PlayerScore(SP_CTF_PICKUPS, "pickups", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_CTF_FCKILLS, "fckills", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_CTF_RETURNS, "returns", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_CTF_DROPS, "drops", SFL_LOWER_IS_BETTER);
+ ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
+ ScoreInfo_SetLabel_PlayerScore(SP_CTF_CAPTIME, "captime", SFL_LOWER_IS_BETTER | SFL_TIME);
+ ScoreInfo_SetLabel_PlayerScore(SP_CTF_PICKUPS, "pickups", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_CTF_FCKILLS, "fckills", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_CTF_RETURNS, "returns", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_CTF_DROPS, "drops", SFL_LOWER_IS_BETTER);
ScoreRules_basics_end();
}
// score rule declarations
const int ST_CTF_CAPS = 1;
-const int SP_CTF_CAPS = 4;
-const int SP_CTF_CAPTIME = 5;
-const int SP_CTF_PICKUPS = 6;
-const int SP_CTF_DROPS = 7;
-const int SP_CTF_FCKILLS = 8;
-const int SP_CTF_RETURNS = 9;
CLASS(Flag, Pickup)
ATTRIB(Flag, m_mins, vector, PL_MIN_CONST + '0 0 -13')
// scores
const float ST_CTS_LAPS = 1;
-const float SP_CTS_LAPS = 4;
-const float SP_CTS_TIME = 5;
-const float SP_CTS_FASTEST = 6;
#endif
#ifdef IMPLEMENTATION
// score rule declarations
const float ST_DOM_TICKS = 1;
-const float SP_DOM_TICKS = 4;
-const float SP_DOM_TAKES = 5;
const float ST_DOM_CAPS = 1;
-const float SP_DOM_CAPS = 4;
// pps: points per second
.float dom_total_pps = _STAT(DOM_TOTAL_PPS);
int autocvar_g_freezetag_teams_override;
float autocvar_g_freezetag_warmup;
-const float SP_FREEZETAG_REVIVALS = 4;
void freezetag_ScoreRules(float teams)
{
ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
entity ka_ball;
-const float SP_KEEPAWAY_PICKUPS = 4;
-const float SP_KEEPAWAY_CARRIERKILLS = 5;
-const float SP_KEEPAWAY_BCTIME = 6;
-
void(entity this) havocbot_role_ka_carrier;
void(entity this) havocbot_role_ka_collector;
void ka_ScoreRules()
{
ScoreRules_basics(0, SFL_SORT_PRIO_PRIMARY, 0, true); // SFL_SORT_PRIO_PRIMARY
- ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_PICKUPS, "pickups", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY);
+ ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_PICKUPS, "pickups", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_CARRIERKILLS, "bckills", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_KEEPAWAY_BCTIME, "bctime", SFL_SORT_PRIO_SECONDARY);
ScoreRules_basics_end();
}
float kh_key_dropped, kh_key_carried;
const float ST_KH_CAPS = 1;
-const float SP_KH_CAPS = 4;
-const float SP_KH_PUSHES = 5;
-const float SP_KH_DESTROYS = 6;
-const float SP_KH_PICKUPS = 7;
-const float SP_KH_KCKILLS = 8;
-const float SP_KH_LOSSES = 9;
void kh_ScoreRules(float teams)
{
ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true);
ScoreInfo_SetLabel_TeamScore( ST_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
- ScoreInfo_SetLabel_PlayerScore(SP_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
- ScoreInfo_SetLabel_PlayerScore(SP_KH_PUSHES, "pushes", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_KH_DESTROYS, "destroyed", SFL_LOWER_IS_BETTER);
- ScoreInfo_SetLabel_PlayerScore(SP_KH_PICKUPS, "pickups", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_KH_KCKILLS, "kckills", 0);
- ScoreInfo_SetLabel_PlayerScore(SP_KH_LOSSES, "losses", SFL_LOWER_IS_BETTER);
+ ScoreInfo_SetLabel_PlayerScore(SP_KH_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
+ ScoreInfo_SetLabel_PlayerScore(SP_KH_PUSHES, "pushes", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_KH_DESTROYS, "destroyed", SFL_LOWER_IS_BETTER);
+ ScoreInfo_SetLabel_PlayerScore(SP_KH_PICKUPS, "pickups", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_KH_KCKILLS, "kckills", 0);
+ ScoreInfo_SetLabel_PlayerScore(SP_KH_LOSSES, "losses", SFL_LOWER_IS_BETTER);
ScoreRules_basics_end();
}
return 0;
}
-// scoreboard stuff
-const float SP_LMS_LIVES = 4;
-const float SP_LMS_RANK = 5;
-
// lives related defs
float lms_lowest_lives;
float lms_next_place;
ScoreRules_basics(race_teams, 0, 0, false);
if(race_teams)
{
- ScoreInfo_SetLabel_TeamScore( ST_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
+ ScoreInfo_SetLabel_TeamScore( ST_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
ScoreInfo_SetLabel_PlayerScore(SP_RACE_LAPS, "laps", SFL_SORT_PRIO_PRIMARY);
ScoreInfo_SetLabel_PlayerScore(SP_RACE_TIME, "time", SFL_SORT_PRIO_SECONDARY | SFL_LOWER_IS_BETTER | SFL_TIME);
ScoreInfo_SetLabel_PlayerScore(SP_RACE_FASTEST, "fastest", SFL_LOWER_IS_BETTER | SFL_TIME);
// scores
const float ST_RACE_LAPS = 1;
-const float SP_RACE_LAPS = 4;
-const float SP_RACE_TIME = 5;
-const float SP_RACE_FASTEST = 6;
bool g_race_qualifying;
.entity scorekeeper;
entity teamscorekeepers[16];
-string scores_label[MAX_SCORE];
-float scores_flags[MAX_SCORE];
-string teamscores_label[MAX_TEAMSCORE];
-float teamscores_flags[MAX_TEAMSCORE];
float teamscores_entities_count;
var .float scores_primary;
var .float teamscores_primary;
longflags = 0;
for(i = 0, p = 1; i < MAX_TEAMSCORE; ++i, p *= 2)
- if(self.(teamscores[i]) > 127 || self.(teamscores[i]) <= -128)
+ if(self.(teamscores(i)) > 127 || self.(teamscores(i)) <= -128)
longflags |= p;
#if MAX_TEAMSCORE <= 8
if(sendflags & p)
{
if(longflags & p)
- WriteInt24_t(MSG_ENTITY, self.(teamscores[i]));
+ WriteInt24_t(MSG_ENTITY, self.(teamscores(i)));
else
- WriteChar(MSG_ENTITY, self.(teamscores[i]));
+ WriteChar(MSG_ENTITY, self.(teamscores(i)));
}
return true;
error("Adding score to unknown team!");
}
if(score)
- if(teamscores_label[scorefield] != "")
+ if(teamscores_label(scorefield) != "")
s.SendFlags |= pow(2, scorefield);
- return (s.(teamscores[scorefield]) += score);
+ return (s.(teamscores(scorefield)) += score);
}
float TeamScore_Add(entity player, float scorefield, float score)
for(i = 0; i < MAX_TEAMSCORE; ++i)
{
var .float f;
- f = teamscores[i];
- result = ScoreField_Compare(t1, t2, f, teamscores_flags[i], result, strict);
+ f = teamscores(i);
+ result = ScoreField_Compare(t1, t2, f, teamscores_flags(i), result, strict);
}
if (result.x == 0 && strict)
* the scoreinfo entity
*/
-void ScoreInfo_SetLabel_PlayerScore(float i, string label, float scoreflags)
+void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags)
{
- scores_label[i] = label;
- scores_flags[i] = scoreflags;
+ scores_label(i) = label;
+ scores_flags(i) = scoreflags;
if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
{
- scores_primary = scores[i];
+ scores_primary = scores(i);
scores_flags_primary = scoreflags;
}
if(label != "")
void ScoreInfo_SetLabel_TeamScore(float i, string label, float scoreflags)
{
- teamscores_label[i] = label;
- teamscores_flags[i] = scoreflags;
+ teamscores_label(i) = label;
+ teamscores_flags(i) = scoreflags;
if((scoreflags & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
{
- teamscores_primary = teamscores[i];
+ teamscores_primary = teamscores(i);
teamscores_flags_primary = scoreflags;
}
if(label != "")
float i;
WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES_INFO);
WriteInt24_t(MSG_ENTITY, MapInfo_LoadedGametype);
- for(i = 0; i < MAX_SCORE; ++i)
- {
- WriteString(MSG_ENTITY, scores_label[i]);
- WriteByte(MSG_ENTITY, scores_flags[i]);
- }
+ FOREACH(Scores, true, {
+ WriteString(MSG_ENTITY, scores_label(it));
+ WriteByte(MSG_ENTITY, scores_flags(it));
+ });
for(i = 0; i < MAX_TEAMSCORE; ++i)
{
- WriteString(MSG_ENTITY, teamscores_label[i]);
- WriteByte(MSG_ENTITY, teamscores_flags[i]);
+ WriteString(MSG_ENTITY, teamscores_label(i));
+ WriteByte(MSG_ENTITY, teamscores_flags(i));
}
return true;
}
bool PlayerScore_SendEntity(entity this, entity to, float sendflags)
{
- float i, p, longflags;
-
WriteHeader(MSG_ENTITY, ENT_CLIENT_SCORES);
WriteByte(MSG_ENTITY, etof(self.owner));
- longflags = 0;
- for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
- if(self.(scores[i]) > 127 || self.(scores[i]) <= -128)
+ int longflags = 0;
+ FOREACH(Scores, true, {
+ int p = 1 << (i % 16);
+ if (self.(scores(it)) > 127 || self.(scores(it)) <= -128)
longflags |= p;
+ });
-#if MAX_SCORE <= 8
- WriteByte(MSG_ENTITY, sendflags);
- WriteByte(MSG_ENTITY, longflags);
-#else
WriteShort(MSG_ENTITY, sendflags);
WriteShort(MSG_ENTITY, longflags);
-#endif
- for(i = 0, p = 1; i < MAX_SCORE; ++i, p *= 2)
- if(sendflags & p)
+ FOREACH(Scores, true, {
+ int p = 1 << (i % 16);
+ if (sendflags & p)
{
if(longflags & p)
- WriteInt24_t(MSG_ENTITY, self.(scores[i]));
+ WriteInt24_t(MSG_ENTITY, self.(scores(it)));
else
- WriteChar(MSG_ENTITY, self.(scores[i]));
+ WriteChar(MSG_ENTITY, self.(scores(it)));
}
+ });
return true;
}
float PlayerScore_Clear(entity player)
{
entity sk;
- float i;
if(teamscores_entities_count)
return 0;
if(MUTATOR_CALLHOOK(ForbidPlayerScore_Clear)) return 0;
sk = player.scorekeeper;
- for(i = 0; i < MAX_SCORE; ++i)
- {
- if(sk.(scores[i]) != 0)
- if(scores_label[i] != "")
- sk.SendFlags |= pow(2, i);
- sk.(scores[i]) = 0;
- }
+ FOREACH(Scores, true, {
+ if(sk.(scores(it)) != 0)
+ if(scores_label(it) != "")
+ sk.SendFlags |= pow(2, i % 16);
+ sk.(scores(it)) = 0;
+ });
return 1;
}
{
entity sk;
float t;
- FOREACH_CLIENTSLOT(true,
- {
+ FOREACH_CLIENTSLOT(true, {
sk = it.scorekeeper;
- if(!sk)
- continue;
- for(int j = 0; j < MAX_SCORE; ++j)
- {
- if(sk.(scores[j]) != 0)
- if(scores_label[j] != "")
- sk.SendFlags |= pow(2, j);
- sk.(scores[j]) = 0;
- }
+ 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;
+ });
});
for(t = 0; t < 16; ++t)
{
continue;
for(int j = 0; j < MAX_TEAMSCORE; ++j)
{
- if(sk.(teamscores[j]) != 0)
- if(teamscores_label[j] != "")
+ if(sk.(teamscores(j)) != 0)
+ if(teamscores_label(j) != "")
sk.SendFlags |= pow(2, j);
- sk.(teamscores[j]) = 0;
+ sk.(teamscores(j)) = 0;
}
}
}
player.scorekeeper = world;
}
-float PlayerScore_Add(entity player, float scorefield, float score)
+float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score)
{
bool mutator_returnvalue = MUTATOR_CALLHOOK(AddPlayerScore, scorefield, score);
score = ret_float;
return 0;
}
if(score)
- if(scores_label[scorefield] != "")
- s.SendFlags |= pow(2, scorefield);
+ if(scores_label(scorefield) != "")
+ s.SendFlags |= pow(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);
+ PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_TOTAL, scores_label(scorefield)), score);
+ return (s.(scores(scorefield)) += score);
}
-float PlayerTeamScore_Add(entity player, float pscorefield, float tscorefield, float score)
+float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score)
{
float r;
r = PlayerScore_Add(player, pscorefield, score);
if(!t1 || !t2) return (!t2) - !t1;
vector result = '0 0 0';
- float i;
- for(i = 0; i < MAX_SCORE; ++i)
- {
- var .float f;
- f = scores[i];
- result = ScoreField_Compare(t1, t2, f, scores_flags[i], result, strict);
- }
+ FOREACH(Scores, true, {
+ var .float f = scores(it);
+ result = ScoreField_Compare(t1, t2, f, scores_flags(it), result, strict);
+ });
if (result.x == 0 && strict)
result.x = etof(t1.owner) - etof(t2.owner);
{
string out;
entity sk;
- float i, f;
+ float f;
string l;
out = "";
if(!pl)
{
// label
- for(i = 0; i < MAX_SCORE; ++i)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
+ FOREACH(Scores, true, {
+ if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
{
- f = scores_flags[i];
- l = scores_label[i];
+ f = scores_flags(it);
+ l = scores_label(it);
out = strcat(out, GetScoreLogLabel(l, f), ",");
}
+ });
if(shortString < 2)
- for(i = 0; i < MAX_SCORE; ++i)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
+ FOREACH(Scores, true, {
+ if((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
{
- f = scores_flags[i];
- l = scores_label[i];
+ f = scores_flags(it);
+ l = scores_label(it);
out = strcat(out, GetScoreLogLabel(l, f), ",");
}
+ });
if(shortString < 1)
- for(i = 0; i < MAX_SCORE; ++i)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
+ FOREACH(Scores, true, {
+ if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
+ if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
{
- f = scores_flags[i];
- l = scores_label[i];
+ f = scores_flags(it);
+ l = scores_label(it);
out = strcat(out, GetScoreLogLabel(l, f), ",");
}
+ });
out = substring(out, 0, strlen(out) - 1);
}
else if((sk = pl.scorekeeper))
{
- for(i = 0; i < MAX_SCORE; ++i)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
- out = strcat(out, ftos(sk.(scores[i])), ",");
+ FOREACH(Scores, true, {
+ if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
+ out = strcat(out, ftos(sk.(scores(it))), ",");
+ });
if(shortString < 2)
- for(i = 0; i < MAX_SCORE; ++i)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
- out = strcat(out, ftos(sk.(scores[i])), ",");
+ FOREACH(Scores, true, {
+ if ((scores_flags(it) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
+ out = strcat(out, ftos(sk.(scores(it))), ",");
+ });
if(shortString < 1)
- for(i = 0; i < MAX_SCORE; ++i)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
- if((scores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
- out = strcat(out, ftos(sk.(scores[i])), ",");
+ FOREACH(Scores, true, {
+ if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
+ if((scores_flags(it) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
+ out = strcat(out, ftos(sk.(scores(it))), ",");
+ });
out = substring(out, 0, strlen(out) - 1);
}
return out;
{
// label
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
{
- f = teamscores_flags[i];
- l = teamscores_label[i];
+ f = teamscores_flags(i);
+ l = teamscores_label(i);
out = strcat(out, GetScoreLogLabel(l, f), ",");
}
if(shortString < 2)
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
{
- f = teamscores_flags[i];
- l = teamscores_label[i];
+ f = teamscores_flags(i);
+ l = teamscores_label(i);
out = strcat(out, GetScoreLogLabel(l, f), ",");
}
if(shortString < 1)
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
{
- f = teamscores_flags[i];
- l = teamscores_label[i];
+ f = teamscores_flags(i);
+ l = teamscores_label(i);
out = strcat(out, GetScoreLogLabel(l, f), ",");
}
out = substring(out, 0, strlen(out) - 1);
else if((sk = teamscorekeepers[tm - 1]))
{
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
- out = strcat(out, ftos(sk.(teamscores[i])), ",");
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_PRIMARY)
+ out = strcat(out, ftos(sk.(teamscores(i))), ",");
if(shortString < 2)
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
- out = strcat(out, ftos(sk.(teamscores[i])), ",");
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) == SFL_SORT_PRIO_SECONDARY)
+ out = strcat(out, ftos(sk.(teamscores(i))), ",");
if(shortString < 1)
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
- if((teamscores_flags[i] & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
- out = strcat(out, ftos(sk.(teamscores[i])), ",");
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_PRIMARY)
+ if((teamscores_flags(i) & SFL_SORT_PRIO_MASK) != SFL_SORT_PRIO_SECONDARY)
+ out = strcat(out, ftos(sk.(teamscores(i))), ",");
out = substring(out, 0, strlen(out) - 1);
}
return out;
{
s = strcat(s, Team_ColoredFullName(t));
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if(teamscores_label[i] != "")
+ if(teamscores_label(i) != "")
{
- fl = teamscores_flags[i];
- sc = sk.(teamscores[i]);
+ fl = teamscores_flags(i);
+ sc = sk.(teamscores(i));
s = strcat(s, " ", Score_NicePrint_ItemColor(fl), ScoreString(fl, sc));
}
}
s = strcat(s, strpad(max(0, NAMEWIDTH - strlennocol(s)), ""));
- for(i = 0; i < MAX_SCORE; ++i)
- if(scores_label[i] != "")
+ FOREACH(Scores, true, {
+ if(scores_label(it) != "")
{
- fl = scores_flags[i];
- s2 = scores_label[i];
+ fl = scores_flags(it);
+ s2 = scores_label(it);
s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, substring(s2, 0, w)));
}
+ });
print_to(to, s);
}
}
}
- for(i = 0; i < MAX_SCORE; ++i)
- if(scores_label[i] != "")
+ FOREACH(Scores, true, {
+ if(scores_label(it) != "")
{
- fl = scores_flags[i];
- sc = sk.(scores[i]);
+ fl = scores_flags(it);
+ sc = sk.(scores(it));
s = strcat(s, " ", Score_NicePrint_ItemColor(fl), strpad(-w, ScoreString(fl, sc)));
}
+ });
print_to(to, s);
}
void Score_NicePrint(entity to)
{
entity p;
- float i;
float w;
int t = 0;
- for(i = 0; i < MAX_SCORE; ++i)
- if(scores_label[i] != "")
+ FOREACH(Scores, true, {
+ if(scores_label(it) != "")
++t;
+ });
w = bound(6, floor(SCORESWIDTH / t - 1), 9);
p = PlayerScore_Sort(score_dummyfield, 1, 1, 0);
void PlayerScore_PlayerStats(entity p)
{
- entity s;
- float i;
- s = p.scorekeeper;
-
- for(i = 0; i < MAX_SCORE; ++i)
- if(s.(scores[i]) != 0)
- if(scores_label[i] != "")
- PS_GR_P_ADDVAL(s.owner, strcat(PLAYERSTATS_SCOREBOARD, scores_label[i]), s.(scores[i]));
+ entity s = 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)));
+ });
}
void PlayerScore_TeamStats()
if(!sk)
continue;
for(i = 0; i < MAX_TEAMSCORE; ++i)
- if(sk.(teamscores[i]) != 0)
- if(teamscores_label[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]));
+ PS_GR_T_ADDVAL(t+1, strcat(PLAYERSTATS_SCOREBOARD, teamscores_label(i)), sk.(teamscores(i)));
}
}
#include <common/constants.qh>
entity scores_initialized; // non-world when scores labels/rules have been set
-.float scores[MAX_SCORE];
-.float teamscores[MAX_TEAMSCORE];
.float scoreboard_pos;
/**
* Means: FIXME make players unable to join the game when not called ClientConnect yet.
* Returns the new score.
*/
-float PlayerScore_Add(entity player, float scorefield, float score);
+float PlayerScore_Add(entity player, PlayerScoreField scorefield, float score);
/**
* Initialize the score of this player if needed.
* Adds a score to both the player and the team. Returns the team score if
* possible, otherwise the player score.
*/
-float PlayerTeamScore_Add(entity player, float pscorefield, float tscorefield, float score);
+float PlayerTeamScore_Add(entity player, PlayerScoreField pscorefield, float tscorefield, float score);
/**
* Adds to the generic score fields for both the player and the team.
*/
-#define PlayerTeamScore_AddScore(p,s) PlayerTeamScore_Add(p, SP_SCORE, ST_SCORE, s)
+#define PlayerTeamScore_AddScore(p, s) PlayerTeamScore_Add(p, SP_SCORE, ST_SCORE, s)
/**
* Set the label of a team score item, as well as the scoring flags.
/**
* Set the label of a player score item, as well as the scoring flags.
*/
-void ScoreInfo_SetLabel_PlayerScore(float i, string label, float scoreflags);
+void ScoreInfo_SetLabel_PlayerScore(PlayerScoreField i, string label, float scoreflags);
/**
* Initialize the scores info for the given number of teams.
void CheckAllowedTeams (entity for_whom);
-// NOTE: SP_ constants may not be >= MAX_SCORE; ST_constants may not be >= MAX_TEAMSCORE
+// NOTE: ST_constants may not be >= MAX_TEAMSCORE
// scores that should be in all modes:
float ScoreRules_teams;
void ScoreRules_basics(float teams, float sprio, float stprio, float score_enabled)
{
- float i;
- for(i = 0; i < MAX_SCORE; ++i)
- ScoreInfo_SetLabel_PlayerScore(i, "", 0);
- for(i = 0; i < MAX_TEAMSCORE; ++i)
+ FOREACH(Scores, true, {
+ ScoreInfo_SetLabel_PlayerScore(it, "", 0);
+ });
+ for(int i = 0; i < MAX_TEAMSCORE; ++i)
ScoreInfo_SetLabel_TeamScore(i, "", 0);
ScoreRules_teams = teams;