From b875623be5fe36022c6bfc8078eceb5ad4f1d0bb Mon Sep 17 00:00:00 2001 From: NepDisk Date: Wed, 26 Feb 2025 20:32:43 -0500 Subject: [PATCH] Fix bot skin randomization code Best of both worlds. If theres more then ingamecap worth of skins (or 8 in GP), duplicate skins will be disabled --- src/k_bot.cpp | 15 +++++++----- src/k_grandprix.c | 60 ++++++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/src/k_bot.cpp b/src/k_bot.cpp index 236d5cfa3..3298a3ee5 100644 --- a/src/k_bot.cpp +++ b/src/k_bot.cpp @@ -217,14 +217,14 @@ void K_UpdateMatchRaceBots(void) else { difficulty = cv_kartbot.value; - /*if (netgame) - { - pmax = std::min(pmax, static_cast(cv_maxconnections.value)); - }*/ - if (cv_maxplayers.value > 0) + if (netgame) { pmax = std::min(pmax, static_cast(cv_maxplayers.value)); } + if (cv_maxplayers.value > 0) + { + pmax = std::min(pmax, static_cast(cv_ingamecap.value)); + } } for (i = 0; i < MAXPLAYERS; i++) @@ -322,7 +322,10 @@ void K_UpdateMatchRaceBots(void) { UINT8 index = P_RandomKey(usableskins); skinnum = grabskins[index]; - grabskins[index] = grabskins[--usableskins]; + if (usableskins > cv_ingamecap.value) + { + grabskins[index] = grabskins[--usableskins]; + } } if (!K_AddBot(skinnum, difficulty, BOT_STYLE_NORMAL, &newplayernum)) diff --git a/src/k_grandprix.c b/src/k_grandprix.c index 361778e62..88368463f 100644 --- a/src/k_grandprix.c +++ b/src/k_grandprix.c @@ -102,7 +102,7 @@ INT16 K_CalculateGPRankPoints(UINT8 position, UINT8 numplayers) --------------------------------------------------*/ UINT8 K_BotDefaultSkin(void) { - const char *defaultbotskinname = "eggman"; + const char *defaultbotskinname = "tails"; INT32 defaultbotskin = R_SkinAvailable(defaultbotskinname); if (defaultbotskin == -1) @@ -274,7 +274,10 @@ void K_InitGrandPrixBots(void) { UINT8 index = P_RandomKey(usableskins); skinnum = grabskins[index]; - grabskins[index] = grabskins[--usableskins]; + if (usableskins > K_GetGPPlayerCount(1)) + { + grabskins[index] = grabskins[--usableskins]; + } } botskinlist[botskinlistpos++] = skinnum; @@ -545,13 +548,13 @@ void K_RetireBots(void) const UINT8 defaultbotskin = K_BotDefaultSkin(); SINT8 newDifficulty; - UINT8 usableskins; + UINT8 usableskins, skincount = numskins; UINT8 grabskins[MAXSKINS+1]; UINT8 i; if (grandprixinfo.gp == true - && ((grandprixinfo.roundnum >= grandprixinfo.cup->numlevels) + && (((grandprixinfo.cup != NULL) && (grandprixinfo.roundnum >= grandprixinfo.cup->numlevels)) || grandprixinfo.eventmode != GPEVENT_NONE)) { // No replacement. @@ -559,7 +562,7 @@ void K_RetireBots(void) } // Init usable bot skins list - for (usableskins = 0; usableskins < numskins; usableskins++) + for (usableskins = 0; usableskins < skincount; usableskins++) { grabskins[usableskins] = usableskins; } @@ -579,22 +582,29 @@ void K_RetireBots(void) // Rearrange usable bot skins list to prevent gaps for randomised selection for (i = 0; i < usableskins; i++) { - if (!(grabskins[i] == MAXSKINS /*|| K_SkinLocked(grabskins[i])*/)) + if (!(grabskins[i] == MAXSKINS || !R_SkinUsable(-1, grabskins[i]))) continue; - while (usableskins > i && (grabskins[usableskins] == MAXSKINS /*|| K_SkinLocked(grabskins[i])*/)) + while (usableskins > i && (grabskins[usableskins] == MAXSKINS || !R_SkinUsable(-1, grabskins[usableskins]))) usableskins--; grabskins[i] = grabskins[usableskins]; grabskins[usableskins] = MAXSKINS; } - if (!grandprixinfo.gp) // Sure, let's let this happen all the time :) + if (grandprixinfo.gp) // Sure, let's let this happen all the time :) { - newDifficulty = cv_kartbot.value; + if (grandprixinfo.masterbots == true) + { + newDifficulty = MAXBOTDIFFICULTY; + } + else + { + const UINT8 startingdifficulty = K_BotStartingDifficulty(grandprixinfo.gamespeed); + newDifficulty = startingdifficulty - 4; + } } else { - const UINT8 startingdifficulty = K_BotStartingDifficulty(grandprixinfo.gamespeed); - newDifficulty = startingdifficulty - 4 + grandprixinfo.roundnum; + newDifficulty = cv_kartbot.value; } if (newDifficulty > MAXBOTDIFFICULTY) @@ -606,6 +616,25 @@ void K_RetireBots(void) newDifficulty = 1; } + for (i = 0; i < MAXPLAYERS; i++) + { + player_t *bot = NULL; + + if (!playeringame[i] || !players[i].bot || players[i].spectator) + { + continue; + } + + bot = &players[i]; + + if (bot->pflags & PF_NOCONTEST) + { + // HACK!!!!! two days to end of cleanup period :) + // we do this so that any bot that's been removed doesn't count for K_SetNameForBot conflicts + player_names[i][0] = '0'; + } + } + for (i = 0; i < MAXPLAYERS; i++) { player_t *bot = NULL; @@ -625,15 +654,18 @@ void K_RetireBots(void) { UINT8 index = P_RandomKey(usableskins); skinnum = grabskins[index]; - grabskins[index] = grabskins[--usableskins]; + if (usableskins > K_GetGPPlayerCount(1)) + { + grabskins[index] = grabskins[--usableskins]; + } } bot->botvars.difficulty = newDifficulty; bot->botvars.diffincrease = 0; - SetPlayerSkinByNum(bot - players, skinnum); + SetPlayerSkinByNum(i, skinnum); bot->skincolor = skins[skinnum].prefcolor; - sprintf(player_names[bot - players], "%s", skins[skinnum].realname); + K_SetNameForBot(i, skins[skinnum].realname); bot->score = 0; bot->pflags &= ~PF_NOCONTEST;