Basic work to restore the wanted system

This commit is contained in:
NepDisk 2024-12-17 10:54:22 -05:00
parent a5b76597eb
commit 8dcaba2d43
8 changed files with 146 additions and 43 deletions

View file

@ -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

View file

@ -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);

View file

@ -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;

View file

@ -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
};
//

View file

@ -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;

View file

@ -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);

View file

@ -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++)
{

View file

@ -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++;
}
}
}
}
}