Skip to content

Commit fb40f60

Browse files
authored
Merge pull request #178 from tcsabina/Issue_165
Fixed the score calculation for XonXonX modes.
2 parents d1f79a4 + cc60ee9 commit fb40f60

File tree

6 files changed

+291
-28
lines changed

6 files changed

+291
-28
lines changed

include/g_local.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ char* OnOff(float f);
343343

344344
int get_scores1();
345345
int get_scores2();
346+
int get_scores3();
346347
gedict_t* get_ed_scores1();
347348
gedict_t* get_ed_scores2();
348349

@@ -653,6 +654,7 @@ typedef struct usermode_s
653654

654655
extern usermode um_list[];
655656
extern int um_cnt; // count of entrys in 'um_list'
657+
extern int current_umode; // current UserMode
656658

657659
// for user call this like UserMode( 1 )
658660
// for server call like UserMode( -1 )

src/client.c

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3036,7 +3036,9 @@ void Print_Wp_Stats()
30363036

30373037
G_centerprint(self, "%s", buf);
30383038
}
3039-
3039+
/*
3040+
* Function is called when a player or spectator enables continuous score display with +scores console command.
3041+
* */
30403042
void Print_Scores()
30413043
{
30423044
char buf[1024] =
@@ -3191,8 +3193,41 @@ void Print_Scores()
31913193
}
31923194
else
31933195
{
3194-
strlcat(buf, last_va = va(" \364:%d \345:%d \x90%d\x91", ts, es, ts - es),
3195-
sizeof(buf));
3196+
if ((current_umode < 11) || (current_umode > 13))
3197+
{
3198+
strlcat(buf, last_va = va(" \364:%d \345:%d \x90%d\x91", ts, es, ts - es),
3199+
sizeof(buf));
3200+
}
3201+
else
3202+
{
3203+
// if the current UserMode is 2on2on2, 3on3on3, 4on4on4, we have 3 teams
3204+
int s1 = get_scores1();
3205+
int s2 = get_scores2();
3206+
int s3 = get_scores3();
3207+
char *t1 = cvar_string("_k_team1");
3208+
char *t2 = cvar_string("_k_team2");
3209+
char *t3 = cvar_string("_k_team3");
3210+
char *t = getteam(e);
3211+
3212+
if (streq(t1, t))
3213+
{
3214+
// the tracked player is in Team 1
3215+
strlcat(buf, last_va = va(" \364:%d \345:%d \x90%d\x91 \345:%d \x90%d\x91",
3216+
s1, s2, s1 - s2 , s3, s1 - s3), sizeof(buf));
3217+
}
3218+
else if (streq(t2, t))
3219+
{
3220+
// the tracked player is in Team 2
3221+
strlcat(buf, last_va = va(" \364:%d \345:%d \x90%d\x91 \345:%d \x90%d\x91",
3222+
s2, s1, s2 - s1 , s3, s2 - s3), sizeof(buf));
3223+
}
3224+
else if (streq(t3, t))
3225+
{
3226+
// the tracked player is in Team 3
3227+
strlcat(buf, last_va = va(" \364:%d \345:%d \x90%d\x91 \345:%d \x90%d\x91",
3228+
s3, s1, s3 - s1 , s2, s3 - s2), sizeof(buf));
3229+
}
3230+
}
31963231
}
31973232
}
31983233

src/commands.c

Lines changed: 115 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,13 +3272,78 @@ void PrintScores()
32723272
{
32733273
int s1 = get_scores1();
32743274
int s2 = get_scores2();
3275+
int s3;
32753276
char *t1 = cvar_string("_k_team1");
32763277
char *t2 = cvar_string("_k_team2");
3278+
char *t3;
32773279

3278-
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s2 ? t1 : t2),
3280+
if ((current_umode < 11) || (current_umode > 13))
3281+
{
3282+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s2 ? t1 : t2),
32793283
dig3(s1 > s2 ? s1 : s2));
3280-
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s2 ? t2 : t1),
3284+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s2 ? t2 : t1),
32813285
dig3(s1 > s2 ? s2 : s1));
3286+
}
3287+
else
3288+
{
3289+
// if the current UserMode is 2on2on2, 3on3on3, 4on4on4, we have 3 teams
3290+
s3 = get_scores3();
3291+
t3 = cvar_string("_k_team3");
3292+
3293+
if ((s1 > s2) && (s1 > s3))
3294+
{
3295+
// Team 1 is leading
3296+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t1, dig3(s1));
3297+
// Team 2 and 3
3298+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s2 > s3 ? t2 : t3),
3299+
dig3(s2 > s3 ? s2 : s3));
3300+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s2 > s3 ? t3 : t2),
3301+
dig3(s2 > s3 ? s3 : s2));
3302+
}
3303+
else if ((s2 > s1) && (s2 > s3))
3304+
{
3305+
// Team 2 is leading
3306+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t2, dig3(s2));
3307+
// Team 1 and 3
3308+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s3 ? t1 : t3),
3309+
dig3(s1 > s3 ? s1 : s3));
3310+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s3 ? t3 : t1),
3311+
dig3(s1 > s3 ? s3 : s1));
3312+
3313+
}
3314+
else if ((s3 > s1) && (s3 > s2))
3315+
{
3316+
// Team 3 is leading
3317+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t3, dig3(s3));
3318+
// Team 1 and 2
3319+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s2 ? t1 : t2),
3320+
dig3(s1 > s2 ? s1 : s2));
3321+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), (s1 > s2 ? t2 : t1),
3322+
dig3(s1 > s2 ? s2 : s1));
3323+
}
3324+
else if (s1 == s3)
3325+
{
3326+
// Team 1 and Team 3 have equal scores
3327+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t1, dig3(s1));
3328+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t3, dig3(s3));
3329+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t2, dig3(s2));
3330+
3331+
}
3332+
else if (s2 == s3)
3333+
{
3334+
// Team 2 and Team 3 have equal scores
3335+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t2, dig3(s2));
3336+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t3, dig3(s3));
3337+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t1, dig3(s1));
3338+
}
3339+
else
3340+
{
3341+
// Team 1 and Team 2 have equal scores, but this is the 'catch all' case also
3342+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t1, dig3(s1));
3343+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t2, dig3(s2));
3344+
G_sprint(self, 2, "%s \220%s\221 = %s\n", redtext("Team"), t3, dig3(s3));
3345+
}
3346+
}
32823347
}
32833348
}
32843349
}
@@ -4205,6 +4270,7 @@ usermode um_list[] =
42054270
};
42064271

42074272
int um_cnt = sizeof(um_list) / sizeof(um_list[0]);
4273+
int current_umode;
42084274

42094275
// return -1 if not found
42104276
int um_idx_byname(char *name)
@@ -4270,6 +4336,8 @@ void UserMode(float umode)
42704336

42714337
int k_free_mode = (k_matchLess ? 5 : cvar("k_free_mode"));
42724338

4339+
current_umode = 0;
4340+
42734341
if (umode < 0)
42744342
{
42754343
sv_invoked = true;
@@ -4481,6 +4549,7 @@ void UserMode(float umode)
44814549
}
44824550

44834551
cvar_fset("_k_last_xonx", umode + 1); // save last XonX command
4552+
current_umode = umode+1;
44844553
}
44854554

44864555
void execute_rules_reset(void)
@@ -6224,16 +6293,27 @@ char* lastscores2str(lsType_t lst)
62246293

62256294
void lastscore_add()
62266295
{
6227-
gedict_t *p, *ed1 = get_ed_scores1(), *ed2 = get_ed_scores2();
6296+
gedict_t *p;
6297+
gedict_t *ed1 = get_ed_scores1();
6298+
gedict_t *ed2 = get_ed_scores2();
62286299
int from;
6229-
int i, s1 = 0, s2 = 0;
6300+
int i;
6301+
int s1 = 0;
6302+
int s2 = 0;
6303+
int s3 = 0;
62306304
int k_ls = bound(0, cvar("__k_ls"), MAX_LASTSCORES - 1);
6231-
char *e1, *e2, t1[128] =
6232-
{ 0 }, t2[128] =
6233-
{ 0 }, *name, date[64], *extra;
6305+
char *e1;
6306+
char *e2;
6307+
char *e3;
6308+
char t1[128] = { 0 };
6309+
char t2[128] = { 0 };
6310+
char t3[128] = { 0 };
6311+
char *name;
6312+
char date[64];
6313+
char *extra;
62346314
lsType_t lst = lsUnknown;
62356315

6236-
e1 = e2 = extra = "";
6316+
e1 = e2 = e3 = extra = "";
62376317

62386318
if ((isRA() || isFFA()) && ed1 && ed2)
62396319
{ // not the best way since get_ed_scores do not serve ghosts, so...
@@ -6311,6 +6391,21 @@ void lastscore_add()
63116391
strlcat(t2, va(" %s", name), sizeof(t2));
63126392
}
63136393
}
6394+
6395+
if ((current_umode >= 11) && (current_umode <= 13))
6396+
{
6397+
e3 = cvar_string("_k_team3");
6398+
s3 = get_scores3();
6399+
6400+
// players from third team
6401+
for (t3[0] = from = 0, p = world; (p = find_plrghst(p, &from));)
6402+
{
6403+
if (streq(getteam(p), e3) && !strnull(name = getname(p)))
6404+
{
6405+
strlcat(t3, va(" %s", name), sizeof(t3));
6406+
}
6407+
}
6408+
}
63146409
}
63156410

63166411
if (strnull(e1) || strnull(e2))
@@ -6338,8 +6433,18 @@ void lastscore_add()
63386433
cvar_set(va("__k_ls_e2_%d", k_ls), e2);
63396434
cvar_set(va("__k_ls_t1_%d", k_ls), t1);
63406435
cvar_set(va("__k_ls_t2_%d", k_ls), t2);
6341-
cvar_set(va("__k_ls_s_%d", k_ls),
6342-
va("%3d:%-3d \x8D %-8.8s %13.13s%s", s1, s2, g_globalvars.mapname, date, extra));
6436+
if ((current_umode < 10) || (current_umode > 13))
6437+
{
6438+
cvar_set(va("__k_ls_s_%d", k_ls),
6439+
va("%3d:%-3d \x8D %-8.8s %13.13s%s", s1, s2, g_globalvars.mapname, date, extra));
6440+
}
6441+
else
6442+
{
6443+
cvar_set(va("__k_ls_e3_%d", k_ls), e3);
6444+
cvar_set(va("__k_ls_t3_%d", k_ls), t3);
6445+
cvar_set(va("__k_ls_s_%d", k_ls),
6446+
va("%3d:%-3d:%-3d \x8D %-8.8s %13.13s%s", s1, s2, s3, g_globalvars.mapname, date, extra));
6447+
}
63436448

63446449
cvar_fset("__k_ls", ++k_ls % MAX_LASTSCORES);
63456450

src/g_utils.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,7 @@ char* OnOff(float f)
18431843
// for team games
18441844
int k_scores1 = 0;
18451845
int k_scores2 = 0;
1846+
int k_scores3 = 0;
18461847

18471848
// for ffa and duel
18481849
gedict_t *ed_scores1 = NULL;
@@ -1852,7 +1853,10 @@ void ReScores()
18521853
{
18531854
gedict_t *p;
18541855
int from;
1855-
char *team1, *team2;
1856+
char *team1;
1857+
char *team2;
1858+
char *team3;
1859+
char *team;
18561860

18571861
// DO this by checking if k_nochange is 0.
18581862
// which is set in ClientObituary in client.c
@@ -1867,23 +1871,34 @@ void ReScores()
18671871

18681872
k_scores1 = 0;
18691873
k_scores2 = 0;
1874+
k_scores3 = 0;
18701875

18711876
if (k_showscores)
18721877
{
18731878
team1 = cvar_string("_k_team1");
1879+
team2 = cvar_string("_k_team2");
1880+
team3 = cvar_string("_k_team3");
18741881

18751882
for (from = 0, p = world; (p = find_plrghst(p, &from));)
18761883
{
1877-
team2 = getteam(p);
1884+
team = getteam(p);
18781885

1879-
if (streq(team1, team2))
1886+
if (streq(team1, team))
18801887
{
18811888
k_scores1 += p->s.v.frags;
18821889
}
1883-
else
1890+
else if (streq(team2, team))
18841891
{
18851892
k_scores2 += p->s.v.frags;
18861893
}
1894+
else if (streq(team3, team))
1895+
{
1896+
k_scores3 += p->s.v.frags;
1897+
}
1898+
else
1899+
{
1900+
1901+
}
18871902
}
18881903
}
18891904

@@ -1937,6 +1952,13 @@ int get_scores2()
19371952
return k_scores2;
19381953
}
19391954

1955+
int get_scores3()
1956+
{
1957+
ReScores();
1958+
1959+
return k_scores3;
1960+
}
1961+
19401962
gedict_t* get_ed_scores1()
19411963
{
19421964
ReScores();

0 commit comments

Comments
 (0)