K_SetNameForBot

Func specifically for setting name for CPU players.
Lets anything go in offline mode, as per previous behaviour.
In online mode, attempts to append a slot-specific char before running EnsurePlayerNameIsGood (which removes characters at the end if a pre-existing match is found).
This commit is contained in:
toaster 2024-03-18 19:23:55 +00:00
parent 1ef3063772
commit a4cec98c26
3 changed files with 93 additions and 3 deletions

View file

@ -46,6 +46,59 @@
extern "C" consvar_t cv_forcebots;
/*--------------------------------------------------
void K_SetNameForBot(UINT8 playerNum, UINT8 skinnum)
See header file for description.
--------------------------------------------------*/
void K_SetNameForBot(UINT8 newplayernum, const char *realname)
{
UINT8 ix = MAXPLAYERS;
// These names are generally sourced from skins.
I_Assert(MAXPLAYERNAME >= SKINNAMESIZE+2);
if (netgame == true)
{
// Check if a player is currently using the name, case-insensitively.
// We only do this if online, because it doesn't matter if there are multiple Eggrobo *off*line.
// See also EnsurePlayerNameIsGood
for (ix = 0; ix < MAXPLAYERS; ix++)
{
if (ix == newplayernum)
continue;
if (playeringame[ix] == false)
continue;
if (strcasecmp(realname, player_names[ix]) != 0)
continue;
break;
}
}
if (ix == MAXPLAYERS)
{
// No conflict detected!
sprintf(player_names[newplayernum], "%s", realname);
return;
}
// Ok, now we append on the end for duplicates...
char namebuffer[MAXPLAYERNAME+1];
sprintf(namebuffer, "%s %c", realname, 'A'+newplayernum);
// ...and use the actual function, to handle more devious duplication.
if (!EnsurePlayerNameIsGood(namebuffer, newplayernum))
{
// we can't bail from adding the bot...
// this hopefully uncontroversial pick is all we CAN do
sprintf(namebuffer, "Bot %u", newplayernum+1);
}
// And finally write.
sprintf(player_names[newplayernum], "%s", namebuffer);
}
/*--------------------------------------------------
void K_SetBot(UINT8 playerNum, UINT8 skinnum, UINT8 difficulty, botStyle_e style)
@ -117,7 +170,7 @@ void K_SetBot(UINT8 newplayernum, UINT8 skinnum, UINT8 difficulty, botStyle_e st
}
}
players[newplayernum].skincolor = color;
sprintf(player_names[newplayernum], "%s", realname);
K_SetNameForBot(newplayernum, realname);
SetPlayerSkinByNum(newplayernum, skinnum);

View file

@ -197,6 +197,24 @@ boolean K_AddBot(UINT8 skin, UINT8 difficulty, botStyle_e style, UINT8 *p);
// NOT AVAILABLE FOR LUA
/*--------------------------------------------------
void K_SetNameForBot(UINT8 newplayernum, const char *realname)
Sets a bot's name.
by K_AddBot, and indirectly by K_AddBotFromServer by sending
a packet.
Input Arguments:-
newplayernum - Player slot number to set name for.
realname - Proposed name for bot.
Return:-
None
--------------------------------------------------*/
void K_SetNameForBot(UINT8 newplayernum, const char *realname);
/*--------------------------------------------------
void K_SetBot(UINT8 newplayernum, UINT8 skinnum, UINT8 difficulty, botStyle_e style);

View file

@ -745,6 +745,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;
@ -772,9 +791,9 @@ void K_RetireBots(void)
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;