From ff7bb5cd2b63c1af24fce94e61dfe0563ff22308 Mon Sep 17 00:00:00 2001 From: toaster Date: Fri, 11 Oct 2024 13:26:45 +0100 Subject: [PATCH] Rework `showscores` command Prints a full, ordered table of results, basically equivalent to intermission. Much closer to the kind of logging one would want for tournament play, rather than the SRB2 leftover this command was holding previously. --- src/d_netcmd.c | 84 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 8 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 950f95fdf..f6bd4db4d 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -7051,22 +7051,90 @@ void DummyConsvar_OnChange(void) static void Command_ShowScores_f(void) { - UINT8 i; - if (!(netgame || multiplayer)) { - CONS_Printf(M_GetText("This only works in a netgame.\n")); + CONS_Printf("This only works with multiple players.\n"); return; } + if (K_UsingPowerLevels() != PWRLV_DISABLED) + { + CONS_Printf("PWR is currently active - no scores to show!\n"); + return; + } + + UINT8 i, j, numplayers = 0; + UINT8 playerlist[MAXPLAYERS]; + UINT8 pos[MAXPLAYERS]; + UINT16 completed = 0; + + memset(playerlist, 0, sizeof(playerlist)); + memset(pos, 0, sizeof(pos)); + for (i = 0; i < MAXPLAYERS; i++) { - if (playeringame[i]) - // FIXME: %lu? what's wrong with %u? ~Callum (produces warnings...) - CONS_Printf(M_GetText("%s's score is %u\n"), player_names[i], players[i].score); - } - CONS_Printf(M_GetText("The pointlimit is %d\n"), g_pointlimit); + if (playeringame[i] && !players[i].spectator) + { + numplayers++; + continue; + } + completed |= (1 << i); + } + + if (!numplayers) + { + CONS_Printf("No players are currently in-game.\n"); + return; + } + + // This is largely based off of Y_CalculateMatchData. + + for (j = 0; j < numplayers; j++) + { + UINT8 workp = UINT8_MAX; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (completed & (1 << i)) + continue; + if (workp != UINT8_MAX && players[workp].score >= players[i].score) + continue; + workp = i; + } + + completed |= (1 << workp); + + playerlist[j] = workp; + + if (j && players[workp].score == players[playerlist[j-1]].score) + { + pos[j] = pos[j-1]; + } + else + { + pos[j] = j+1; + } + } + + if (roundqueue.size && roundqueue.position) + { + CONS_Printf( + "Rankings %s Round %u:\n", + (gamestate == GS_LEVEL) ? "before" : "as of", + roundqueue.roundnum + ); + } + else + { + CONS_Printf("Total Rankings:\n"); + } + + for (i = 0; i < numplayers; i++) + { + j = playerlist[i]; + CONS_Printf(" %2u - %*s : %9d\n", pos[i], MAXPLAYERNAME-1, player_names[j], players[j].score); // 9 taken from MAXSCORE + } } static void Command_ShowTime_f(void)