diff --git a/src/k_grandprix.c b/src/k_grandprix.c index 52c82d7a3..6b19b8f06 100644 --- a/src/k_grandprix.c +++ b/src/k_grandprix.c @@ -469,8 +469,22 @@ static UINT8 K_BotExpectedStanding(player_t *bot) --------------------------------------------------*/ void K_IncreaseBotDifficulty(player_t *bot) { - UINT8 expectedstanding; - INT16 standingdiff; + UINT8 playerCount = 0; + UINT8 wonCount = 0; + + UINT8 humanThatBeatUs = 0; + INT16 beatenDelta = 0; + + UINT8 winnerHuman = UINT8_MAX; + INT16 winnerDelta = 0; + + UINT8 statusQuo = 1; + INT16 disruptDelta = 0; + + INT16 increase = 1; + size_t i = SIZE_MAX; + + bot->botvars.diffincrease = 0; if (bot->botvars.difficulty >= MAXBOTDIFFICULTY) { @@ -478,33 +492,65 @@ void K_IncreaseBotDifficulty(player_t *bot) return; } - // Increment bot difficulty based on what position you were meant to come in! - expectedstanding = K_BotExpectedStanding(bot); - standingdiff = expectedstanding - bot->position; + // Increment bot difficulty based on + // how much they were beaten by a player! - if (standingdiff >= -2) + // Find the worst-placing player that still beat us. + for (i = 0; i < MAXPLAYERS; i++) { - UINT8 increase; + player_t *other = NULL; - if (standingdiff > 5) + if (playeringame[i] == false) { - increase = 3; - } - else if (standingdiff > 2) - { - increase = 2; - } - else - { - increase = 1; + continue; } - bot->botvars.diffincrease = increase; + other = &players[i]; + if (other->spectator == true) + { + continue; + } + + playerCount++; + if (other->bot == true) + { + continue; + } + + if (other->position <= bot->position && other->position > humanThatBeatUs) + { + humanThatBeatUs = other->position; + } + + if (other->position < winnerHuman) + { + winnerHuman = other->position; + } } - else + + wonCount = playerCount / 2; + if (playerCount & 1) { - bot->botvars.diffincrease = 0; + // Round up + wonCount++; } + + statusQuo = K_BotExpectedStanding(bot); + + // How many levels they gain depends on how hard they beat us, + // and how much the status quo was disturbed. + beatenDelta = bot->position - humanThatBeatUs; + winnerDelta = wonCount - winnerHuman; + disruptDelta = abs(statusQuo - bot->position); + + increase = (beatenDelta + winnerDelta + disruptDelta - 2) / 3; + if (increase <= 0) + { + // No increase... + return; + } + + bot->botvars.diffincrease = increase; } /*--------------------------------------------------