- use FString to manage strings in bot code.

This commit is contained in:
Christoph Oelckers 2020-04-11 12:11:22 +02:00
parent 6bfdf904b9
commit 5865c4dcca
4 changed files with 23 additions and 44 deletions

View file

@ -847,7 +847,7 @@ void FLevelLocals::CopyPlayer(player_t *dst, player_t *src, const char *name)
if (dst->Bot != nullptr)
{
botinfo_t *thebot = BotInfo.botinfo;
while (thebot && stricmp(name, thebot->name))
while (thebot && thebot->Name.CompareNoCase(name))
{
thebot = thebot->next;
}

View file

@ -186,7 +186,7 @@ void FCajunMaster::ClearPlayer (int i, bool keepTeam)
players[i].mo = nullptr;
}
botinfo_t *bot = botinfo;
while (bot && stricmp (players[i].userinfo.GetName(), bot->name))
while (bot && stricmp (players[i].userinfo.GetName(), bot->Name.GetChars()))
bot = bot->next;
if (bot)
{
@ -237,7 +237,7 @@ CCMD (listbots)
while (thebot)
{
Printf ("%s%s\n", thebot->name, thebot->inuse == BOTINUSE_Yes ? " (active)" : "");
Printf ("%s%s\n", thebot->Name.GetChars(), thebot->inuse == BOTINUSE_Yes ? " (active)" : "");
thebot = thebot->next;
count++;
}

View file

@ -72,8 +72,8 @@ enum
struct botinfo_t
{
botinfo_t *next;
char *name;
char *info;
FString Name;
FString Info;
botskill_t skill;
int inuse;
int lastteam;

View file

@ -237,7 +237,7 @@ bool FCajunMaster::SpawnBot (const char *name, int color)
if (name)
{
// Check if exist or already in the game.
while (thebot && stricmp (name, thebot->name))
while (thebot && thebot->Name.CompareNoCase(name))
{
botshift++;
thebot = thebot->next;
@ -296,16 +296,14 @@ bool FCajunMaster::SpawnBot (const char *name, int color)
Net_WriteByte (botshift);
{
//Set color.
char concat[512];
strcpy (concat, thebot->info);
FString concat = thebot->Info;
if (color == NOCOLOR && bot_next_color < NOCOLOR && bot_next_color >= 0)
{
strcat (concat, colors[bot_next_color]);
concat << colors[bot_next_color];
}
if (TeamLibrary.IsValidTeam (thebot->lastteam))
{ // Keep the bot on the same team when switching levels
mysnprintf (concat + strlen(concat), countof(concat) - strlen(concat),
"\\team\\%d\n", thebot->lastteam);
concat.AppendFormat("\\team\\%d\n", thebot->lastteam);
}
Net_WriteString (concat);
}
@ -453,26 +451,9 @@ void FCajunMaster::RemoveAllBots (FLevelLocals *Level, bool fromlist)
// ??? any other valid userinfo strings can go here
//}
static void appendinfo (char *&front, const char *back)
static void appendinfo (FString &front, const char *back)
{
char *newstr;
if (front)
{
size_t newlen = strlen (front) + strlen (back) + 2;
newstr = new char[newlen];
strcpy (newstr, front);
delete[] front;
}
else
{
size_t newlen = strlen (back) + 2;
newstr = new char[newlen];
newstr[0] = 0;
}
strcat (newstr, "\\");
strcat (newstr, back);
front = newstr;
front << "\\" << back;
}
void FCajunMaster::ForgetBots ()
@ -482,8 +463,6 @@ void FCajunMaster::ForgetBots ()
while (thebot)
{
botinfo_t *next = thebot->next;
delete[] thebot->name;
delete[] thebot->info;
delete thebot;
thebot = next;
}
@ -523,7 +502,7 @@ bool FCajunMaster::LoadBots ()
memset (newinfo, 0, sizeof(*newinfo));
newinfo->info = copystring ("\\autoaim\\0\\movebob\\.25");
newinfo->Info = "\\autoaim\\0\\movebob\\.25";
for (;;)
{
@ -535,9 +514,9 @@ bool FCajunMaster::LoadBots ()
{
case BOTCFG_NAME:
sc.MustGetString ();
appendinfo (newinfo->info, "name");
appendinfo (newinfo->info, sc.String);
newinfo->name = copystring (sc.String);
appendinfo (newinfo->Info, "name");
appendinfo (newinfo->Info, sc.String);
newinfo->Name = sc.String;
break;
case BOTCFG_AIMING:
@ -586,9 +565,9 @@ bool FCajunMaster::LoadBots ()
}
}
}
appendinfo (newinfo->info, "team");
appendinfo (newinfo->Info, "team");
mysnprintf (teamstr, countof(teamstr), "%d", teamnum);
appendinfo (newinfo->info, teamstr);
appendinfo (newinfo->Info, teamstr);
gotteam = true;
break;
}
@ -598,21 +577,21 @@ bool FCajunMaster::LoadBots ()
{
gotclass = true;
}
appendinfo (newinfo->info, sc.String);
appendinfo (newinfo->Info, sc.String);
sc.MustGetString ();
appendinfo (newinfo->info, sc.String);
appendinfo (newinfo->Info, sc.String);
break;
}
}
if (!gotclass)
{ // Bots that don't specify a class get a random one
appendinfo (newinfo->info, "playerclass");
appendinfo (newinfo->info, "random");
appendinfo (newinfo->Info, "playerclass");
appendinfo (newinfo->Info, "random");
}
if (!gotteam)
{ // Same for bot teams
appendinfo (newinfo->info, "team");
appendinfo (newinfo->info, "255");
appendinfo (newinfo->Info, "team");
appendinfo (newinfo->Info, "255");
}
newinfo->next = botinfo;
newinfo->lastteam = TEAM_NONE;