Prevent duplicate skins, fix bots not being able to be disabled, change default to "off"

This commit is contained in:
Sally Coolatta 2020-05-24 17:12:58 -04:00
parent 5d77807a78
commit 4916516e2e
2 changed files with 81 additions and 30 deletions

View file

@ -393,12 +393,19 @@ static CV_PossibleValue_t kartvoices_cons_t[] = {{0, "Never"}, {1, "Tasteful"},
consvar_t cv_kartvoices = {"kartvoices", "Tasteful", CV_SAVE, kartvoices_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_kartvoices = {"kartvoices", "Tasteful", CV_SAVE, kartvoices_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
static CV_PossibleValue_t kartbot_cons_t[] = { static CV_PossibleValue_t kartbot_cons_t[] = {
{1, "MIN"},
{9, "MAX"},
{0, "Off"}, {0, "Off"},
{1, "Lv.1"},
{2, "Lv.2"},
{3, "Lv.3"},
{4, "Lv.4"},
{5, "Lv.5"},
{6, "Lv.6"},
{7, "Lv.7"},
{8, "Lv.8"},
{9, "Lv.9"},
{0, NULL} {0, NULL}
}; };
consvar_t cv_kartbot = {"kartbot", "5", CV_NETVAR|CV_CHEAT, kartbot_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_kartbot = {"kartbot", "0", CV_NETVAR|CV_CHEAT, kartbot_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_karteliminatelast = {"karteliminatelast", "Yes", CV_NETVAR|CV_CHEAT|CV_CALL|CV_NOSHOWHELP, CV_YesNo, KartEliminateLast_OnChange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_karteliminatelast = {"karteliminatelast", "Yes", CV_NETVAR|CV_CHEAT|CV_CALL|CV_NOSHOWHELP, CV_YesNo, KartEliminateLast_OnChange, 0, NULL, NULL, 0, 0, NULL};

View file

@ -111,6 +111,7 @@ void K_UpdateMatchRaceBots(void)
UINT8 numbots = 0; UINT8 numbots = 0;
UINT8 numwaiting = 0; UINT8 numwaiting = 0;
SINT8 wantedbots = 0; SINT8 wantedbots = 0;
boolean skinusable[MAXSKINS];
UINT8 i; UINT8 i;
if (!server) if (!server)
@ -118,38 +119,57 @@ void K_UpdateMatchRaceBots(void)
return; return;
} }
if (difficulty != 0) // init usable bot skins list
for (i = 0; i < MAXSKINS; i++)
{ {
if (cv_ingamecap.value > 0) if (i < numskins)
{ {
pmax = min(pmax, cv_ingamecap.value); skinusable[i] = true;
} }
else
for (i = 0; i < MAXPLAYERS; i++)
{ {
if (playeringame[i]) skinusable[i] = false;
{ }
if (!players[i].spectator) }
{
if (players[i].bot)
{
numbots++;
// While we're here, we should update bot difficulty to the proper value. if (cv_ingamecap.value > 0)
players[i].botvars.difficulty = difficulty; {
} pmax = min(pmax, cv_ingamecap.value);
else }
{
numplayers++; for (i = 0; i < MAXPLAYERS; i++)
} {
} if (playeringame[i])
else if (players[i].pflags & PF_WANTSTOJOIN) {
if (!players[i].spectator)
{
skinusable[players[i].skin] = false;
if (players[i].bot)
{ {
numwaiting++; numbots++;
// While we're here, we should update bot difficulty to the proper value.
players[i].botvars.difficulty = difficulty;
}
else
{
numplayers++;
} }
} }
else if (players[i].pflags & PF_WANTSTOJOIN)
{
numwaiting++;
}
} }
}
if (difficulty == 0)
{
wantedbots = 0;
}
else
{
wantedbots = pmax - numplayers - numwaiting; wantedbots = pmax - numplayers - numwaiting;
if (wantedbots < 0) if (wantedbots < 0)
@ -157,15 +177,12 @@ void K_UpdateMatchRaceBots(void)
wantedbots = 0; wantedbots = 0;
} }
} }
else
{
wantedbots = 0;
}
if (numbots < wantedbots) if (numbots < wantedbots)
{ {
// We require MORE bots! // We require MORE bots!
UINT8 newplayernum = 0; UINT8 newplayernum = 0;
boolean usedallskins = false;
if (dedicated) if (dedicated)
{ {
@ -174,12 +191,39 @@ void K_UpdateMatchRaceBots(void)
while (numbots < wantedbots) while (numbots < wantedbots)
{ {
if (!K_AddBot(M_RandomKey(numskins), difficulty, &newplayernum)) UINT8 skin = M_RandomKey(numskins);
if (usedallskins == false)
{
UINT8 loops = 0;
while (!skinusable[skin])
{
if (loops >= numskins)
{
// no more skins, stick to our first choice
usedallskins = true;
break;
}
skin++;
if (skin >= numskins)
{
skin = 0;
}
loops++;
}
}
if (!K_AddBot(skin, difficulty, &newplayernum))
{ {
// Not enough player slots to add the bot, break the loop. // Not enough player slots to add the bot, break the loop.
break; break;
} }
skinusable[skin] = false;
numbots++; numbots++;
} }
} }