From 3c505e2676c459c1e0dcea5a1ae5072f43c8ac0b Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 3 Jun 2023 14:11:14 +0100 Subject: [PATCH] K_UpdateGPRank - The previous location for updating grandprixinfo.rank.position and grandprixinfo.rank.skin was too early. - K_GetPodiumPosition checks player->score - Y_StartIntermission calls Y_CalculateMatchData - Y_CalculateMatchData checks K_CalculateGPGrade... which uses invalid position info to determine grade! - Y_CalculateMatchData updates player score - To this end, rearrange Y_CalculateMatchData to accomodate. - Calls K_UpdateGPRank. - Then, calls K_CalculateGPGrade. - Also called after G_UpdateVisited if no intermission occours, for general consistency. - In addition, adjust so earlier players have port priority for skin saved to gamedata. --- src/g_game.c | 17 ++---------- src/k_rank.c | 34 ++++++++++++++++++++++++ src/k_rank.h | 15 +++++++++++ src/y_inter.c | 73 +++++++++++++++++++++++++++------------------------ 4 files changed, 89 insertions(+), 50 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index a74eed966..f8d08183f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4464,15 +4464,11 @@ static void G_DoCompleted(void) G_SetGamestate(GS_NULL); wipegamestate = GS_NULL; - grandprixinfo.rank.prisons += numtargets; - grandprixinfo.rank.position = MAXPLAYERS; - grandprixinfo.rank.skin = MAXSKINS; - for (i = 0; i < MAXPLAYERS; i++) { if (playeringame[i]) { - // SRB2Kart: exitlevel shouldn't get you the points + // Exitlevel shouldn't get you the points if (!players[i].exiting && !(players[i].pflags & PF_NOCONTEST)) { clientPowerAdd[i] = 0; @@ -4493,16 +4489,6 @@ static void G_DoCompleted(void) } G_PlayerFinishLevel(i); // take away cards and stuff - - if (players[i].bot == false) - { - UINT8 podiumposition = K_GetPodiumPosition(&players[i]); - if (podiumposition <= grandprixinfo.rank.position) - { - grandprixinfo.rank.position = podiumposition; - grandprixinfo.rank.skin = players[i].skin; - } - } } } @@ -4525,6 +4511,7 @@ static void G_DoCompleted(void) || (intertype == int_none)) { G_UpdateVisited(); + K_UpdateGPRank(); G_AfterIntermission(); } else diff --git a/src/k_rank.c b/src/k_rank.c index 1420cc7b3..dd05cc11f 100644 --- a/src/k_rank.c +++ b/src/k_rank.c @@ -18,6 +18,8 @@ #include "g_game.h" #include "k_bot.h" #include "k_kart.h" +#include "k_battle.h" +#include "k_podium.h" #include "m_random.h" #include "r_things.h" #include "fastcmp.h" @@ -342,6 +344,38 @@ void K_InitGrandPrixRank(gpRank_t *rankData) } } +/*-------------------------------------------------- + void K_UpdateGPRank(void) + + See header file for description. +--------------------------------------------------*/ +void K_UpdateGPRank(void) +{ + if (grandprixinfo.gp != true) + return; + + UINT8 i; + + grandprixinfo.rank.prisons += numtargets; + grandprixinfo.rank.position = MAXPLAYERS; + grandprixinfo.rank.skin = MAXSKINS; + + for (i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] + || players[i].spectator == true + || players[i].bot == true) + continue; + + UINT8 podiumposition = K_GetPodiumPosition(&players[i]); + if (podiumposition >= grandprixinfo.rank.position) // port priority + continue; + + grandprixinfo.rank.position = podiumposition; + grandprixinfo.rank.skin = players[i].skin; + } +} + /*-------------------------------------------------- gp_rank_e K_CalculateGPGrade(gpRank_t *rankData) diff --git a/src/k_rank.h b/src/k_rank.h index fd3e86f97..701c01b7c 100644 --- a/src/k_rank.h +++ b/src/k_rank.h @@ -66,6 +66,21 @@ struct gpRank_t void K_InitGrandPrixRank(gpRank_t *rankData); +/*-------------------------------------------------- + void K_UpdateGPRank(void) + + Updates the best ranking across all human + players. + + Input Arguments:- + N/A + + Return:- + N/A +--------------------------------------------------*/ +void K_UpdateGPRank(void); + + /*-------------------------------------------------- gp_rank_e K_CalculateGPGrade(gpRank_t *rankData); diff --git a/src/y_inter.c b/src/y_inter.c index 70ae5e7fb..be02b4ee4 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -151,41 +151,6 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) { getmainplayer = true; - { - // See also G_GetNextMap, M_DrawPause - data.showrank = false; - if (grandprixinfo.gp == true - && netgame == false // TODO netgame Special Mode support - && grandprixinfo.gamespeed >= KARTSPEED_NORMAL - && roundqueue.size > 1 - && roundqueue.entries[roundqueue.size - 1].rankrestricted == true - ) - { - if (roundqueue.position == roundqueue.size-1) - { - // On A rank pace? Then you get a chance for S rank! - gp_rank_e rankforline = K_CalculateGPGrade(&grandprixinfo.rank); - - data.showrank = (rankforline >= GRADE_A); - - data.linemeter = - (min(rankforline, GRADE_A) - * (2 * TICRATE) - ) / GRADE_A; - - // A little extra time to take it all in - timer += TICRATE; - } - - if (gamedata->everseenspecial == true - || roundqueue.position == roundqueue.size) - { - // Additional cases in which it should always be shown. - data.showrank = true; - } - } - } - data.encore = encoremode; memset(data.jitter, 0, sizeof (data.jitter)); @@ -302,6 +267,44 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) if (getmainplayer == true) { + // Okay, player scores have been set now - we can calculate GP-relevant material. + { + K_UpdateGPRank(); + + // See also G_GetNextMap, M_DrawPause + data.showrank = false; + if (grandprixinfo.gp == true + && netgame == false // TODO netgame Special Mode support + && grandprixinfo.gamespeed >= KARTSPEED_NORMAL + && roundqueue.size > 1 + && roundqueue.entries[roundqueue.size - 1].rankrestricted == true + ) + { + if (roundqueue.position == roundqueue.size-1) + { + // On A rank pace? Then you get a chance for S rank! + gp_rank_e rankforline = K_CalculateGPGrade(&grandprixinfo.rank); + + data.showrank = (rankforline >= GRADE_A); + + data.linemeter = + (min(rankforline, GRADE_A) + * (2 * TICRATE) + ) / GRADE_A; + + // A little extra time to take it all in + timer += TICRATE; + } + + if (gamedata->everseenspecial == true + || roundqueue.position == roundqueue.size) + { + // Additional cases in which it should always be shown. + data.showrank = true; + } + } + } + i = MAXPLAYERS; for (j = 0; j < data.numplayers; j++)