From af3499c0248a3b18f30e7326952352ed8b7b2be1 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 31 Mar 2022 18:21:03 -0400 Subject: [PATCH] Make bots RETIRE when they NO CONTEST They get replaced with another bot when they NO CONTEST, swapping their skin and resetting their difficulty & points. --- src/k_grandprix.c | 122 ++++++++++++++++++++++++++++++++++++++++++---- src/k_grandprix.h | 26 ++++++++++ src/y_inter.c | 51 ++++++++++++------- 3 files changed, 173 insertions(+), 26 deletions(-) diff --git a/src/k_grandprix.c b/src/k_grandprix.c index c07bf2a81..be29dbad3 100644 --- a/src/k_grandprix.c +++ b/src/k_grandprix.c @@ -95,6 +95,25 @@ INT16 K_CalculateGPRankPoints(UINT8 position, UINT8 numplayers) return points; } +/*-------------------------------------------------- + SINT8 K_BotDefaultSkin(void) + + See header file for description. +--------------------------------------------------*/ +SINT8 K_BotDefaultSkin(void) +{ + const char *defaultbotskinname = "eggrobo"; + SINT8 defaultbotskin = R_SkinAvailable(defaultbotskinname); + + if (defaultbotskin == -1) + { + // This shouldn't happen, but just in case + defaultbotskin = 0; + } + + return defaultbotskin; +} + /*-------------------------------------------------- void K_InitGrandPrixBots(void) @@ -102,8 +121,7 @@ INT16 K_CalculateGPRankPoints(UINT8 position, UINT8 numplayers) --------------------------------------------------*/ void K_InitGrandPrixBots(void) { - const char *defaultbotskinname = "eggrobo"; - SINT8 defaultbotskin = R_SkinAvailable(defaultbotskinname); + const SINT8 defaultbotskin = K_BotDefaultSkin(); const UINT8 startingdifficulty = K_BotStartingDifficulty(grandprixinfo.gamespeed); UINT8 difficultylevels[MAXPLAYERS]; @@ -121,12 +139,6 @@ void K_InitGrandPrixBots(void) UINT8 newplayernum = 0; UINT8 i, j; - if (defaultbotskin == -1) - { - // This shouldn't happen, but just in case - defaultbotskin = 0; - } - memset(competitors, MAXPLAYERS, sizeof (competitors)); memset(botskinlist, defaultbotskin, sizeof (botskinlist)); @@ -144,7 +156,7 @@ void K_InitGrandPrixBots(void) } #if MAXPLAYERS != 16 - I_Error("GP bot difficulty levels need rebalacned for the new player count!\n"); + I_Error("GP bot difficulty levels need rebalanced for the new player count!\n"); #endif if (grandprixinfo.masterbots) @@ -500,6 +512,98 @@ void K_IncreaseBotDifficulty(player_t *bot) } } +/*-------------------------------------------------- + void K_ReplaceBot(player_t *bot) + + See header file for description. +--------------------------------------------------*/ +void K_ReplaceBot(player_t *bot) +{ + const SINT8 defaultbotskin = K_BotDefaultSkin(); + SINT8 newDifficulty; + + boolean skinusable[MAXSKINS]; + UINT8 skinnum; + UINT8 loops = 0; + + UINT8 i; + + // init usable bot skins list + for (i = 0; i < MAXSKINS; i++) + { + if (i < numskins) + { + skinusable[i] = true; + } + else + { + skinusable[i] = false; + } + } + + for (i = 0; i < MAXPLAYERS; i++) + { + if (playeringame[i] && !players[i].spectator) + { + skinusable[players[i].skin] = false; + } + } + + skinnum = P_RandomKey(numskins); + + while (!skinusable[skinnum]) + { + if (loops >= numskins) + { + // no more skins + break; + } + + skinnum++; + + if (skinnum >= numskins) + { + skinnum = 0; + } + + loops++; + } + + if (loops >= numskins) + { + // Use default skin + skinnum = defaultbotskin; + } + + if (!grandprixinfo.gp) // Sure, let's let this happen all the time :) + { + newDifficulty = cv_kartbot.value; + } + else + { + const UINT8 startingdifficulty = K_BotStartingDifficulty(grandprixinfo.gamespeed); + newDifficulty = startingdifficulty - 3 + (grandprixinfo.roundnum - 1); + } + + if (newDifficulty > MAXBOTDIFFICULTY) + { + newDifficulty = MAXBOTDIFFICULTY; + } + else if (newDifficulty < 1) + { + newDifficulty = 1; + } + + bot->botvars.difficulty = newDifficulty; + bot->botvars.diffincrease = 0; + + SetPlayerSkinByNum(bot - players, skinnum); + bot->skincolor = skins[skinnum].prefcolor; + sprintf(player_names[bot - players], "%s", skins[skinnum].realname); + + bot->score = 0; +} + /*-------------------------------------------------- void K_FakeBotResults(player_t *bot) diff --git a/src/k_grandprix.h b/src/k_grandprix.h index 9f27b485b..f951860d8 100644 --- a/src/k_grandprix.h +++ b/src/k_grandprix.h @@ -62,6 +62,16 @@ UINT8 K_BotStartingDifficulty(SINT8 value); INT16 K_CalculateGPRankPoints(UINT8 position, UINT8 numplayers); +/*-------------------------------------------------- + SINT8 K_BotDefaultSkin(void); + + Returns the skin number of the skin the game + uses as a fallback option. +--------------------------------------------------*/ + +SINT8 K_BotDefaultSkin(void); + + /*-------------------------------------------------- void K_InitGrandPrixBots(void); @@ -95,6 +105,22 @@ void K_UpdateGrandPrixBots(void); void K_IncreaseBotDifficulty(player_t *bot); +/*-------------------------------------------------- + void K_ReplaceBot(player_t *bot); + + "Replaces" a bot, by refreshing their difficulty + and changing their skin. + + Input Arguments:- + bot - Player to do this for. + + Return:- + None +--------------------------------------------------*/ + +void K_ReplaceBot(player_t *bot); + + /*-------------------------------------------------- void K_FakeBotResults(player_t *bot); diff --git a/src/y_inter.c b/src/y_inter.c index a1a414d19..69cbf2660 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -316,25 +316,27 @@ static void Y_CalculateMatchData(UINT8 rankingsmode, void (*comparison)(INT32)) data.pos[data.numplayers] = data.numplayers+1; } - if ((powertype == PWRLV_DISABLED) - && (!rankingsmode) - && !(players[i].pflags & PF_NOCONTEST) - && (data.pos[data.numplayers] < (numplayersingame + numgriefers))) + if (!rankingsmode) { - // Online rank is handled further below in this file. - data.increase[i] = K_CalculateGPRankPoints(data.pos[data.numplayers], numplayersingame + numgriefers); - players[i].score += data.increase[i]; - } + if ((powertype == PWRLV_DISABLED) + && !(players[i].pflags & PF_NOCONTEST) + && (data.pos[data.numplayers] < (numplayersingame + numgriefers))) + { + // Online rank is handled further below in this file. + data.increase[i] = K_CalculateGPRankPoints(data.pos[data.numplayers], numplayersingame + numgriefers); + players[i].score += data.increase[i]; + } - if (demo.recording && !rankingsmode) - { - G_WriteStanding( - data.pos[data.numplayers], - data.name[data.numplayers], - *data.character[data.numplayers], - *data.color[data.numplayers], - data.val[data.numplayers] - ); + if (demo.recording) + { + G_WriteStanding( + data.pos[data.numplayers], + data.name[data.numplayers], + *data.character[data.numplayers], + *data.color[data.numplayers], + data.val[data.numplayers] + ); + } } data.numplayers++; @@ -582,6 +584,12 @@ void Y_IntermissionDrawer(void) V_DrawScaledPatch(x+16, y-4, 0, W_CachePatchName(va("K_CHILI%d", cursorframe+1), PU_CACHE)); } + if (!data.rankingsmode && (players[data.num[i]].pflags & PF_NOCONTEST) && players[data.num[i]].bot) + { + // RETIRED!! + V_DrawScaledPatch(x+12, y-7, 0, W_CachePatchName("K_NOBLNS", PU_CACHE)); + } + STRBUFCPY(strtime, data.name[i]); y2 = y; @@ -803,6 +811,15 @@ void Y_Ticker(void) { if (!data.rankingsmode && sorttic != -1 && (intertic >= sorttic + 8)) { + UINT8 i; + for (i = 0; i < MAXPLAYERS; i++) + { + if ((players[i].pflags & PF_NOCONTEST) && players[i].bot) + { + K_ReplaceBot(&players[i]); + } + } + Y_CalculateMatchData(1, Y_CompareRank); }