From 8dcaba2d433f7a24407e4e36ee5fe3fec97eb6ff Mon Sep 17 00:00:00 2001 From: NepDisk Date: Tue, 17 Dec 2024 10:54:22 -0500 Subject: [PATCH] Basic work to restore the wanted system --- src/d_clisrv.c | 3 +- src/d_netcmd.c | 3 +- src/d_player.h | 1 + src/g_game.c | 2 +- src/k_battle.c | 137 +++++++++++++++++++++++++++++++++++++++++++++---- src/k_battle.h | 2 +- src/k_hud.c | 5 -- src/k_kart.c | 36 +++++-------- 8 files changed, 146 insertions(+), 43 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 67a719702..a00bd4033 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2555,7 +2555,8 @@ void CL_RemovePlayer(INT32 playernum, kickreason_t reason) } } - K_CalculateBattleWanted(); + if (K_IsPlayerWanted(&players[playernum])) + K_CalculateBattleWanted(); LUA_HookPlayerQuit(&players[playernum], reason); // Lua hook for player quitting diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 45c22139d..41c68fb6a 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3744,7 +3744,8 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum) if (gametyperules & GTR_BUMPERS) // SRB2kart { players[playernum].roundscore = 0; - K_CalculateBattleWanted(); + if (K_IsPlayerWanted(&players[playernum])) + K_CalculateBattleWanted(); } K_PlayerForfeit(playernum, true); diff --git a/src/d_player.h b/src/d_player.h index e178e1b8f..1d3d363cb 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -502,6 +502,7 @@ struct player_t UINT32 roundscore; // battle score this round UINT8 emeralds; UINT8 bumper; + INT32 wanted; INT16 karmadelay; tic_t overtimekarma; // time to live in overtime comeback INT16 spheres; diff --git a/src/g_game.c b/src/g_game.c index 9d0131d68..0f9f23590 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3069,7 +3069,7 @@ UINT32 gametypedefaultrules[NUMGAMETYPES] = // Race GTR_CIRCUIT|GTR_BOTS, // Battle - GTR_BUMPERS|GTR_KARMA|GTR_ITEMARROWS|GTR_ITEMBREAKER|GTR_BATTLESTARTS|GTR_TIMELIMIT + GTR_BUMPERS|GTR_KARMA|GTR_WANTED|GTR_ITEMARROWS|GTR_ITEMBREAKER|GTR_BATTLESTARTS|GTR_TIMELIMIT }; // diff --git a/src/k_battle.c b/src/k_battle.c index d5a5d03d0..d554d0bdf 100644 --- a/src/k_battle.c +++ b/src/k_battle.c @@ -40,17 +40,134 @@ INT32 K_StartingBumperCount(void) boolean K_IsPlayerWanted(player_t *player) { - UINT8 i = 0, nump = 0, numfirst = 0; - for (; i < MAXPLAYERS; i++) + UINT8 i; + + if (!(gametyperules & GTR_WANTED)) + return false; + + for (i = 0; i < 4; i++) { - if (!playeringame[i] || players[i].spectator) - continue; - nump++; - if (players[i].position > 1) - continue; - numfirst++; + if (battlewanted[i] == -1) + break; + if (player == &players[battlewanted[i]]) + return true; + } + return false; +} + +void K_CalculateBattleWanted(void) +{ + UINT8 numingame = 0, numwanted = 0; + SINT8 camppos[MAXPLAYERS]; // who is the biggest camper + UINT8 ties = 0, nextcamppos = 0; + UINT8 i, j; + + if (!(gametyperules & GTR_WANTED)) + { + memset(battlewanted, -1, sizeof (battlewanted)); + return; + } + + wantedcalcdelay = wantedfrequency; + memset(camppos, -1, sizeof (camppos)); // initialize + + for (i = 0; i < MAXPLAYERS; i++) + { + UINT8 position = 1; + + if (!playeringame[i] || players[i].spectator) // Not playing + continue; + + if (players[i].exiting) // We're done, don't calculate. + return; + + if (players[i].bumper <= 0) // Not alive, so don't do anything else + continue; + + numingame++; + + for (j = 0; j < MAXPLAYERS; j++) + { + if (!playeringame[j] || players[j].spectator) + continue; + + if (players[j].bumper <= 0) + continue; + + if (j == i) + continue; + + if (K_NumEmeralds(&players[j]) > K_NumEmeralds(&players[i])) + { + position++; + } + else if (players[j].bumper > players[i].bumper) + { + position++; + } + else if (players[j].roundscore > players[i].roundscore) + { + position++; + } + else if (players[j].wanted > players[i].wanted) + { + position++; + } + } + + position--; // Make zero based + + while (camppos[position] != -1) // Port priority! + position++; + + camppos[position] = i; + } + + if (numingame <= 2) // In 1v1s then there's no need for WANTED. + numwanted = 0; + else + numwanted = min(4, 1 + ((numingame-2) / 4)); + + for (i = 0; i < 4; i++) + { + if (i+1 > numwanted) // Not enough players for this slot to be wanted! + { + battlewanted[i] = -1; + } + else + { + // Do not add *any* more people if there's too many times that are tied with others. + // This could theoretically happen very easily if people don't hit each other for a while after the start of a match. + // (I will be sincerely impressed if more than 2 people tie after people start hitting each other though) + + if (camppos[nextcamppos] == -1 // Out of entries + || ties >= (numwanted-i)) // Already counted ties + { + battlewanted[i] = -1; + continue; + } + + if (ties < (numwanted-i)) + { + ties = 0; // Reset + for (j = 0; j < 2; j++) + { + if (camppos[nextcamppos+(j+1)] == -1) // Nothing beyond, cancel + break; + if (players[camppos[nextcamppos]].wanted == players[camppos[nextcamppos+(j+1)]].wanted) + ties++; + } + } + + if (ties < (numwanted-i)) // Is it still low enough after counting? + { + battlewanted[i] = camppos[nextcamppos]; + nextcamppos++; + } + else + battlewanted[i] = -1; + } } - return ((numfirst < nump) && !player->spectator && (player->position == 1)); } void K_SpawnBattlePoints(player_t *source, player_t *victim, UINT8 amount) @@ -201,8 +318,6 @@ void K_RunPaperItemSpawners(void) { tic_t interval = 8*TICRATE; - const boolean canmakeemeralds = true; //(!(itembreaker || bossinfo.boss)); - thinker_t *th; mobj_t *mo; diff --git a/src/k_battle.h b/src/k_battle.h index b2c8e3df1..b014dd5a4 100644 --- a/src/k_battle.h +++ b/src/k_battle.h @@ -14,7 +14,7 @@ extern UINT8 numtargets; INT32 K_StartingBumperCount(void); boolean K_IsPlayerWanted(player_t *player); -#define K_CalculateBattleWanted() (void)0 // not nulled out so we know where we need to recalculate some other form of battle mode importance +void K_CalculateBattleWanted(void); void K_SpawnBattlePoints(player_t *source, player_t *victim, UINT8 amount); void K_CheckBumpers(void); UINT8 K_NumEmeralds(player_t *player); diff --git a/src/k_hud.c b/src/k_hud.c index c818abd8c..bc2156445 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -2643,11 +2643,6 @@ static void K_drawKartWanted(void) UINT8 *colormap = NULL; INT32 basex = 0, basey = 0; - if (!splitscreen) - return; - - if (stplyr != &players[displayplayers[0]]) - return; for (i = 0; i < 4; i++) { diff --git a/src/k_kart.c b/src/k_kart.c index 07c992140..158664683 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3395,8 +3395,8 @@ void K_HandleBumperChanges(player_t *player, UINT8 prevBumpers) CONS_Printf(M_GetText("%s lost all of their bumpers!\n"), player_names[player-players]); } } - - K_CalculateBattleWanted(); + if (K_IsPlayerWanted(player)) + K_CalculateBattleWanted(); K_CheckBumpers(); } @@ -7886,29 +7886,19 @@ void K_KartUpdatePosition(player_t *player) } else { - UINT8 myEmeralds = K_NumEmeralds(player); - UINT8 yourEmeralds = K_NumEmeralds(&players[i]); - - if (yourEmeralds > myEmeralds) + if (player->exiting) // End of match standings { - // Emeralds matter above all - position++; - } - else if (yourEmeralds == myEmeralds) - { - // Bumpers are a tie breaker - if (players[i].bumper > player->bumper) - { + // Only score matters + if (players[i].roundscore > player->roundscore) + position++; + } + else + { + // I have less points than but the same bumpers as this player OR + // I have less bumpers than this player + if ((players[i].bumper == player->bumper && players[i].roundscore > player->roundscore) + || (players[i].bumper > player->bumper)) position++; - } - else if (players[i].bumper == player->bumper) - { - // Score is the second tier tie breaker - if (players[i].roundscore > player->roundscore) - { - position++; - } - } } } }