Merge branch 'retune-weak-bots' into 'master'

Foes

Closes #1582

See merge request kart-krew-dev/ring-racers-internal!2713
This commit is contained in:
Oni VelocitOni 2025-08-06 23:59:01 +00:00
commit ad9501203f
11 changed files with 223 additions and 115 deletions

View file

@ -418,6 +418,7 @@ struct botvars_t
UINT8 difficulty; // Bot's difficulty setting UINT8 difficulty; // Bot's difficulty setting
INT16 diffincrease; // In GP: bot difficulty will increase this much next round INT16 diffincrease; // In GP: bot difficulty will increase this much next round
boolean rival; // If true, they're the GP rival boolean rival; // If true, they're the GP rival
boolean foe; // If true, in contention for top X
// All entries above persist between rounds and must be recorded in demos // All entries above persist between rounds and must be recorded in demos

View file

@ -321,6 +321,7 @@ void G_ReadDemoExtraData(void)
players[p].botvars.difficulty = READUINT8(demobuf.p); players[p].botvars.difficulty = READUINT8(demobuf.p);
players[p].botvars.diffincrease = READINT16(demobuf.p); // needed to avoid having to duplicate logic players[p].botvars.diffincrease = READINT16(demobuf.p); // needed to avoid having to duplicate logic
players[p].botvars.rival = (boolean)READUINT8(demobuf.p); players[p].botvars.rival = (boolean)READUINT8(demobuf.p);
players[p].botvars.foe = (boolean)READUINT8(demobuf.p);
} }
} }
if (extradata & DXD_PLAYSTATE) if (extradata & DXD_PLAYSTATE)
@ -497,6 +498,7 @@ void G_WriteDemoExtraData(void)
WRITEUINT8(demobuf.p, players[i].botvars.difficulty); WRITEUINT8(demobuf.p, players[i].botvars.difficulty);
WRITEINT16(demobuf.p, players[i].botvars.diffincrease); // needed to avoid having to duplicate logic WRITEINT16(demobuf.p, players[i].botvars.diffincrease); // needed to avoid having to duplicate logic
WRITEUINT8(demobuf.p, (UINT8)players[i].botvars.rival); WRITEUINT8(demobuf.p, (UINT8)players[i].botvars.rival);
WRITEUINT8(demobuf.p, (UINT8)players[i].botvars.foe);
} }
} }
if (demo_extradata[i] & DXD_PLAYSTATE) if (demo_extradata[i] & DXD_PLAYSTATE)
@ -2111,6 +2113,7 @@ void G_BeginRecording(void)
WRITEUINT8(demobuf.p, player->botvars.difficulty); WRITEUINT8(demobuf.p, player->botvars.difficulty);
WRITEINT16(demobuf.p, player->botvars.diffincrease); // needed to avoid having to duplicate logic WRITEINT16(demobuf.p, player->botvars.diffincrease); // needed to avoid having to duplicate logic
WRITEUINT8(demobuf.p, (UINT8)player->botvars.rival); WRITEUINT8(demobuf.p, (UINT8)player->botvars.rival);
WRITEUINT8(demobuf.p, (UINT8)player->botvars.foe);
} }
// Name // Name
@ -3222,6 +3225,7 @@ void G_DoPlayDemoEx(const char *defdemoname, lumpnum_t deflumpnum)
players[p].botvars.difficulty = READUINT8(demobuf.p); players[p].botvars.difficulty = READUINT8(demobuf.p);
players[p].botvars.diffincrease = READINT16(demobuf.p); // needed to avoid having to duplicate logic players[p].botvars.diffincrease = READINT16(demobuf.p); // needed to avoid having to duplicate logic
players[p].botvars.rival = (boolean)READUINT8(demobuf.p); players[p].botvars.rival = (boolean)READUINT8(demobuf.p);
players[p].botvars.foe = (boolean)READUINT8(demobuf.p);
} }
K_UpdateShrinkCheat(&players[p]); K_UpdateShrinkCheat(&players[p]);

View file

@ -2271,6 +2271,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
INT16 botdiffincrease; INT16 botdiffincrease;
boolean botrival; boolean botrival;
boolean botfoe;
boolean cangrabitems; boolean cangrabitems;
@ -2381,6 +2382,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
botdiffincrease = players[player].botvars.diffincrease; botdiffincrease = players[player].botvars.diffincrease;
botrival = players[player].botvars.rival; botrival = players[player].botvars.rival;
botfoe = players[player].botvars.foe;
totalring = players[player].totalring; totalring = players[player].totalring;
xtralife = players[player].xtralife; xtralife = players[player].xtralife;
@ -2641,6 +2643,7 @@ void G_PlayerReborn(INT32 player, boolean betweenmaps)
p->spheres = spheres; p->spheres = spheres;
p->botvars.diffincrease = botdiffincrease; p->botvars.diffincrease = botdiffincrease;
p->botvars.rival = botrival; p->botvars.rival = botrival;
p->botvars.foe = botfoe;
p->xtralife = xtralife; p->xtralife = xtralife;
// SRB2kart // SRB2kart

View file

@ -408,6 +408,8 @@ void K_UpdateMatchRaceBots(void)
clear_bots(wantedbots); clear_bots(wantedbots);
} }
K_AssignFoes();
// We should have enough bots now :) // We should have enough bots now :)
#ifdef HAVE_DISCORDRPC #ifdef HAVE_DISCORDRPC
@ -615,7 +617,7 @@ fixed_t K_BotMapModifier(void)
--------------------------------------------------*/ --------------------------------------------------*/
static UINT32 K_BotRubberbandDistance(const player_t *player) static UINT32 K_BotRubberbandDistance(const player_t *player)
{ {
const UINT32 spacing = FixedDiv(640 * mapobjectscale, K_GetKartGameSpeedScalar(gamespeed)) / FRACUNIT; UINT32 spacing = FixedDiv(640 * mapobjectscale, K_GetKartGameSpeedScalar(gamespeed)) / FRACUNIT;
const UINT8 portpriority = player - players; const UINT8 portpriority = player - players;
UINT8 pos = 1; UINT8 pos = 1;
UINT8 i; UINT8 i;
@ -626,6 +628,11 @@ static UINT32 K_BotRubberbandDistance(const player_t *player)
return 0; return 0;
} }
/*
if (player->botvars.foe)
spacing /= 2;
*/
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{ {
if (i == portpriority) if (i == portpriority)
@ -649,6 +656,11 @@ static UINT32 K_BotRubberbandDistance(const player_t *player)
continue; continue;
} }
if (player->botvars.foe && !players[i].botvars.foe)
{
continue;
}
// First check difficulty levels, then score, then settle it with port priority! // First check difficulty levels, then score, then settle it with port priority!
if (player->botvars.difficulty < players[i].botvars.difficulty) if (player->botvars.difficulty < players[i].botvars.difficulty)
{ {
@ -694,6 +706,8 @@ fixed_t K_BotRubberband(const player_t *player)
{ {
UINT8 levelreduce = std::min<UINT8>(3, player->botvars.difficulty/4); // How much to drop the "effective level" of bots that are consistently behind UINT8 levelreduce = std::min<UINT8>(3, player->botvars.difficulty/4); // How much to drop the "effective level" of bots that are consistently behind
expreduce = Easing_Linear((K_EffectiveGradingFactor(player) - MINGRADINGFACTOR) * 2, levelreduce*FRACUNIT, 0); expreduce = Easing_Linear((K_EffectiveGradingFactor(player) - MINGRADINGFACTOR) * 2, levelreduce*FRACUNIT, 0);
if (player->botvars.foe)
expreduce /= 2;
} }
fixed_t difficultyEase = (((player->botvars.difficulty - 1) * FRACUNIT) - expreduce) / (MAXBOTDIFFICULTY - 1); fixed_t difficultyEase = (((player->botvars.difficulty - 1) * FRACUNIT) - expreduce) / (MAXBOTDIFFICULTY - 1);
@ -805,7 +819,13 @@ fixed_t K_BotRubberband(const player_t *player)
scaled_dist = FixedDiv(scaled_dist, mapobjectscale); scaled_dist = FixedDiv(scaled_dist, mapobjectscale);
} }
constexpr UINT32 END_DIST = 2048 * 14; UINT32 END_DIST = 2048 * 14;
if (K_EffectiveGradingFactor(player) <= FRACUNIT)
{
END_DIST = Easing_Linear((K_EffectiveGradingFactor(player) - MINGRADINGFACTOR) * 2, END_DIST * 2, END_DIST);
}
if (scaled_dist < END_DIST) if (scaled_dist < END_DIST)
{ {
// At the end of tracks, start slowing down. // At the end of tracks, start slowing down.

View file

@ -299,7 +299,7 @@ static boolean K_RivalBotAggression(const player_t *bot, const player_t *target)
return false; return false;
} }
if (bot->botvars.rival == false && !cv_levelskull.value) if (!(bot->botvars.rival || bot->botvars.foe) && !cv_levelskull.value)
{ {
// Not the rival, we aren't self-aware. // Not the rival, we aren't self-aware.
return false; return false;

View file

@ -98,6 +98,113 @@ static UINT8 K_GetOffsetStartingDifficulty(const UINT8 startingdifficulty, UINT8
return startingdifficulty - offset; return startingdifficulty - offset;
} }
/*--------------------------------------------------
static INT16 K_RivalScore(player_t *bot)
Creates a "rival score" for a bot, used to determine which bot is the
most deserving of the rival status.
Input Arguments:-
bot - Player to check.
Return:-
"Rival score" value.
--------------------------------------------------*/
static INT16 K_RivalScore(player_t *bot)
{
const UINT16 difficulty = bot->botvars.difficulty;
const UINT16 score = bot->score;
SINT8 roundnum = 1, roundsleft = 1;
UINT16 lowestscore = UINT16_MAX;
UINT8 lowestdifficulty = MAXBOTDIFFICULTY;
UINT8 i;
if (grandprixinfo.cup != NULL && roundqueue.size > 0)
{
roundnum = roundqueue.roundnum;
roundsleft = grandprixinfo.cup->numlevels - roundnum;
}
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
{
continue;
}
if (players[i].score < lowestscore)
{
lowestscore = players[i].score;
}
if (players[i].bot == true && players[i].botvars.difficulty < lowestdifficulty)
{
lowestdifficulty = players[i].botvars.difficulty;
}
}
// In the early game, difficulty is more important.
// This will try to influence the higher difficulty bots to get rival more often & get even more points.
// However, when we're running low on matches left, we need to focus more on raw score!
return ((difficulty - lowestdifficulty) * roundsleft) + ((score - lowestscore) * roundnum);
}
static boolean CompareRivals(player_t *a, player_t *b)
{
if (a == NULL)
return false;
if (b == NULL)
return true;
if (K_RivalScore(a) != K_RivalScore(b))
{
// Rival Score is HIGH when bots are strong. Sort them first!
return (K_RivalScore(a) > K_RivalScore(b));
}
// Fuck it
return a > b;
}
void K_AssignFoes(void)
{
std::vector<player_t *> bots;
boolean addedplayer = false;
for (UINT8 i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] == false)
continue;
player_t *player = &players[i];
if (!player->spectator && player->bot)
{
addedplayer = true;
bots.push_back(player);
player->botvars.foe = false;
}
}
// Why the fuck is this blowing up sometimes
if (!addedplayer)
return;
std::stable_sort(bots.begin(), bots.end(), CompareRivals);
UINT8 i = 0;
for (auto &bot : bots)
{
if (bot != NULL)
bot->botvars.foe = true;
i++;
if (i > 2)
break;
}
}
/*-------------------------------------------------- /*--------------------------------------------------
void K_InitGrandPrixBots(void) void K_InitGrandPrixBots(void)
@ -254,6 +361,8 @@ void K_InitGrandPrixBots(void)
{ {
break; break;
} }
if (i <= 2)
players[newplayernum-1].botvars.foe = true;
} }
} }
@ -289,64 +398,13 @@ void K_LoadGrandPrixSaveGame(void)
K_SetBot(i, savedata.bots[i].skin, savedata.bots[i].difficulty, BOT_STYLE_NORMAL); K_SetBot(i, savedata.bots[i].skin, savedata.bots[i].difficulty, BOT_STYLE_NORMAL);
players[i].botvars.rival = savedata.bots[i].rival; players[i].botvars.rival = savedata.bots[i].rival;
players[i].botvars.foe = savedata.bots[i].foe;
players[i].score = savedata.bots[i].score; players[i].score = savedata.bots[i].score;
players[i].spectator = K_BotDefaultSpectator(); players[i].spectator = K_BotDefaultSpectator();
} }
} }
/*--------------------------------------------------
static INT16 K_RivalScore(player_t *bot)
Creates a "rival score" for a bot, used to determine which bot is the
most deserving of the rival status.
Input Arguments:-
bot - Player to check.
Return:-
"Rival score" value.
--------------------------------------------------*/
static INT16 K_RivalScore(player_t *bot)
{
const UINT16 difficulty = bot->botvars.difficulty;
const UINT16 score = bot->score;
SINT8 roundnum = 1, roundsleft = 1;
UINT16 lowestscore = UINT16_MAX;
UINT8 lowestdifficulty = MAXBOTDIFFICULTY;
UINT8 i;
if (grandprixinfo.cup != NULL && roundqueue.size > 0)
{
roundnum = roundqueue.roundnum;
roundsleft = grandprixinfo.cup->numlevels - roundnum;
}
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || players[i].spectator)
{
continue;
}
if (players[i].score < lowestscore)
{
lowestscore = players[i].score;
}
if (players[i].bot == true && players[i].botvars.difficulty < lowestdifficulty)
{
lowestdifficulty = players[i].botvars.difficulty;
}
}
// In the early game, difficulty is more important.
// This will try to influence the higher difficulty bots to get rival more often & get even more points.
// However, when we're running low on matches left, we need to focus more on raw score!
return ((difficulty - lowestdifficulty) * roundsleft) + ((score - lowestscore) * roundnum);
}
/*-------------------------------------------------- /*--------------------------------------------------
void K_UpdateGrandPrixBots(void) void K_UpdateGrandPrixBots(void)
@ -379,6 +437,8 @@ void K_UpdateGrandPrixBots(void)
return; return;
} }
K_AssignFoes();
// Find the rival. // Find the rival.
for (i = 0; i < MAXPLAYERS; i++) for (i = 0; i < MAXPLAYERS; i++)
{ {
@ -689,8 +749,8 @@ static boolean CompareJoiners(player_t *a, player_t *b)
return (a->spectatewait < b->spectatewait); return (a->spectatewait < b->spectatewait);
} }
// They are equals, so just randomize // Fuck it
return (P_Random(PR_BOTS) & 1); return a > b;
} }
static boolean CompareReplacements(player_t *a, player_t *b) static boolean CompareReplacements(player_t *a, player_t *b)
@ -707,8 +767,8 @@ static boolean CompareReplacements(player_t *a, player_t *b)
return (a->position < b->position); return (a->position < b->position);
} }
// They are equals, so just randomize // Fuck it
return (P_Random(PR_BOTS) & 1); return a > b;
} }
/*-------------------------------------------------- /*--------------------------------------------------

View file

@ -200,6 +200,8 @@ boolean K_CanChangeRules(boolean allowdemos);
boolean K_BotDefaultSpectator(void); boolean K_BotDefaultSpectator(void);
void K_AssignFoes(void);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"

View file

@ -5346,8 +5346,10 @@ static void K_DrawCPUTagForPlayer(fixed_t x, fixed_t y, player_t *p, UINT32 flag
K_DrawNameTagItemSpy(barx, bary, p, flags); K_DrawNameTagItemSpy(barx, bary, p, flags);
} }
UINT8 *foecol = R_GetTranslationColormap(TC_RAINBOW, static_cast<skincolornum_t>(SKINCOLOR_RED), GTC_CACHE);
UINT8 blink = ((leveltime / 7) & 1); UINT8 blink = ((leveltime / 7) & 1);
V_DrawFixedPatch(x, y, FRACUNIT, flags, kp_cpu[blink], NULL); V_DrawFixedPatch(x, y, FRACUNIT, flags, kp_cpu[blink], (p->botvars.foe) ? foecol : NULL);
} }
static void K_DrawNameTagForPlayer(fixed_t x, fixed_t y, player_t *p, UINT32 flags) static void K_DrawNameTagForPlayer(fixed_t x, fixed_t y, player_t *p, UINT32 flags)
@ -7314,7 +7316,7 @@ static void K_DrawBotDebugger(void)
V_DrawSmallString(8, 14, 0, va("Difficulty: %d / %d", bot->botvars.difficulty, MAXBOTDIFFICULTY)); V_DrawSmallString(8, 14, 0, va("Difficulty: %d / %d", bot->botvars.difficulty, MAXBOTDIFFICULTY));
V_DrawSmallString(8, 18, 0, va("Difficulty increase: %d", bot->botvars.diffincrease)); V_DrawSmallString(8, 18, 0, va("Difficulty increase: %d", bot->botvars.diffincrease));
V_DrawSmallString(8, 22, 0, va("Rival: %d", (UINT8)(bot->botvars.rival == true))); V_DrawSmallString(8, 22, 0, va("Rival / Foe: %d / %d", (UINT8)(bot->botvars.rival == true), (UINT8)(bot->botvars.foe == true)));
V_DrawSmallString(8, 26, 0, va("Rubberbanding: %.02f", FIXED_TO_FLOAT(bot->botvars.rubberband) * 100.0f)); V_DrawSmallString(8, 26, 0, va("Rubberbanding: %.02f", FIXED_TO_FLOAT(bot->botvars.rubberband) * 100.0f));
V_DrawSmallString(8, 32, 0, va("Item delay: %d", bot->botvars.itemdelay)); V_DrawSmallString(8, 32, 0, va("Item delay: %d", bot->botvars.itemdelay));

View file

@ -1624,6 +1624,8 @@ static boolean K_TryDraft(player_t *player, mobj_t *dest, fixed_t minDist, fixed
// Double speed for the rival! // Double speed for the rival!
if (player->botvars.rival || cv_levelskull.value) if (player->botvars.rival || cv_levelskull.value)
player->draftpower += add; player->draftpower += add;
else if (player->botvars.foe)
player->draftpower += add/2;
else if (dest->player->bot) // Reduce bot gluts. else if (dest->player->bot) // Reduce bot gluts.
player->draftpower -= 3*add/4; player->draftpower -= 3*add/4;
} }
@ -3557,6 +3559,10 @@ static fixed_t K_RingDurationBoost(const player_t *player)
// x2.0 for Rival // x2.0 for Rival
ret *= 2; ret *= 2;
} }
else if (player->botvars.foe)
{
ret = 3 * ret / 2;
}
} }
return ret; return ret;
@ -3979,6 +3985,11 @@ fixed_t K_GetKartSpeed(const player_t *player, boolean doboostpower, boolean dor
// +10% top speed for the rival // +10% top speed for the rival
finalspeed = FixedMul(finalspeed, 11*FRACUNIT/10); finalspeed = FixedMul(finalspeed, 11*FRACUNIT/10);
} }
else if (player->bot && player->botvars.foe)
{
// +5% for foes
finalspeed = FixedMul(finalspeed, 21*FRACUNIT/20);
}
} }
} }

View file

@ -138,6 +138,7 @@ static inline void P_ArchivePlayer(savebuffer_t *save)
WRITEUINT8(save->p, players[i].botvars.difficulty); WRITEUINT8(save->p, players[i].botvars.difficulty);
WRITEUINT8(save->p, (UINT8)players[i].botvars.rival); WRITEUINT8(save->p, (UINT8)players[i].botvars.rival);
WRITEUINT8(save->p, (UINT8)players[i].botvars.foe);
WRITEUINT32(save->p, players[i].score); WRITEUINT32(save->p, players[i].score);
} }
@ -195,6 +196,7 @@ static boolean P_UnArchivePlayer(savebuffer_t *save)
savedata.bots[pid].difficulty = READUINT8(save->p); savedata.bots[pid].difficulty = READUINT8(save->p);
savedata.bots[pid].rival = (boolean)READUINT8(save->p); savedata.bots[pid].rival = (boolean)READUINT8(save->p);
savedata.bots[pid].foe = (boolean)READUINT8(save->p);
savedata.bots[pid].score = READUINT32(save->p); savedata.bots[pid].score = READUINT32(save->p);
} }
@ -765,6 +767,7 @@ static void P_NetArchivePlayers(savebuffer_t *save)
WRITEUINT8(save->p, players[i].botvars.difficulty); WRITEUINT8(save->p, players[i].botvars.difficulty);
WRITEUINT8(save->p, players[i].botvars.diffincrease); WRITEUINT8(save->p, players[i].botvars.diffincrease);
WRITEUINT8(save->p, players[i].botvars.rival); WRITEUINT8(save->p, players[i].botvars.rival);
WRITEUINT8(save->p, players[i].botvars.foe);
WRITEFIXED(save->p, players[i].botvars.rubberband); WRITEFIXED(save->p, players[i].botvars.rubberband);
WRITEUINT8(save->p, players[i].botvars.bumpslow); WRITEUINT8(save->p, players[i].botvars.bumpslow);
WRITEUINT32(save->p, players[i].botvars.itemdelay); WRITEUINT32(save->p, players[i].botvars.itemdelay);
@ -1430,6 +1433,7 @@ static void P_NetUnArchivePlayers(savebuffer_t *save)
players[i].botvars.difficulty = READUINT8(save->p); players[i].botvars.difficulty = READUINT8(save->p);
players[i].botvars.diffincrease = READUINT8(save->p); players[i].botvars.diffincrease = READUINT8(save->p);
players[i].botvars.rival = (boolean)READUINT8(save->p); players[i].botvars.rival = (boolean)READUINT8(save->p);
players[i].botvars.foe = (boolean)READUINT8(save->p);
players[i].botvars.rubberband = READFIXED(save->p); players[i].botvars.rubberband = READFIXED(save->p);
players[i].botvars.bumpslow = READUINT8(save->p); players[i].botvars.bumpslow = READUINT8(save->p);
players[i].botvars.itemdelay = READUINT32(save->p); players[i].botvars.itemdelay = READUINT32(save->p);

View file

@ -46,6 +46,7 @@ struct savedata_bot_s
UINT8 skin; UINT8 skin;
UINT8 difficulty; UINT8 difficulty;
boolean rival; boolean rival;
boolean foe;
UINT32 score; UINT32 score;
}; };