Skip to content
5 changes: 4 additions & 1 deletion codemp/botlib/be_aas_reach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,10 @@ int AAS_Reachability_Jump(int area1num, int area2num)
int stopevent, areas[10], numareas;
float phys_jumpvel, maxjumpdistance, maxjumpheight, height, bestdist, speed;
float *v1, *v2, *v3, *v4;
vec3_t beststart, beststart2, bestend, bestend2;
vec3_t beststart = {};
vec3_t beststart2 = {};
vec3_t bestend = {};
vec3_t bestend2 = {};
vec3_t teststart, testend, dir, velocity, cmdmove, up = {0, 0, 1}, sidewards;
aas_area_t *area1, *area2;
aas_face_t *face1, *face2;
Expand Down
9 changes: 6 additions & 3 deletions codemp/botlib/be_ai_chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ void BotQueueConsoleMessage(int chatstate, int type, char *message)
m->handle = cs->handle;
m->time = AAS_Time();
m->type = type;
strncpy(m->message, message, MAX_MESSAGE_SIZE);
strncpy(m->message, message, MAX_MESSAGE_SIZE - 1);
m->message[MAX_MESSAGE_SIZE - 1] = '\0';
m->next = NULL;
if (cs->lastmessage)
{
Expand Down Expand Up @@ -1462,7 +1463,8 @@ int BotFindMatch(char *str, bot_match_t *match, unsigned long int context)
int i;
bot_matchtemplate_t *ms;

strncpy(match->string, str, MAX_MESSAGE_SIZE);
strncpy(match->string, str, MAX_MESSAGE_SIZE - 1);
match->string[MAX_MESSAGE_SIZE - 1] = '\0';
//remove any trailing enters
while(strlen(match->string) &&
match->string[strlen(match->string)-1] == '\n')
Expand Down Expand Up @@ -2121,7 +2123,8 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname)
if (pass)
{
chattype = (bot_chattype_t *) ptr;
strncpy(chattype->name, token.string, MAX_CHATTYPE_NAME);
strncpy(chattype->name, token.string, MAX_CHATTYPE_NAME - 1);
chattype->name[MAX_CHATTYPE_NAME - 1] = '\0';
chattype->firstchatmessage = NULL;
//add the chat type to the chat
chattype->next = chat->types;
Expand Down
25 changes: 17 additions & 8 deletions codemp/botlib/be_ai_goal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ typedef struct levelitem_s
struct levelitem_s *prev, *next;
} levelitem_t;

#define ITEMINFO_CLASSNAME_SIZE 32

typedef struct iteminfo_s
{
char classname[32]; //classname of the item
char classname[ITEMINFO_CLASSNAME_SIZE]; //classname of the item
char name[MAX_STRINGFIELD]; //name of the item
char model[MAX_STRINGFIELD]; //model of the item
int modelindex; //model index
Expand Down Expand Up @@ -166,6 +168,8 @@ typedef struct itemconfig_s
iteminfo_t *iteminfo;
} itemconfig_t;

#define MAX_GOAL_NAME_LEN 32

//goal state
typedef struct bot_goalstate_s
{
Expand Down Expand Up @@ -287,7 +291,8 @@ itemconfig_t *LoadItemConfig(char *filename)
LibVarSet( "max_iteminfo", "256" );
}

strncpy( path, filename, MAX_PATH );
strncpy( path, filename, MAX_PATH - 1 );
path[MAX_PATH - 1] = '\0';
PC_SetBaseFolder(BOTFILESBASEFOLDER);
source = LoadSourceFile( path );
if( !source ) {
Expand Down Expand Up @@ -321,6 +326,7 @@ itemconfig_t *LoadItemConfig(char *filename)
} //end if
StripDoubleQuotes(token.string);
strncpy(ii->classname, token.string, sizeof(ii->classname)-1);
ii->classname[ITEMINFO_CLASSNAME_SIZE - 1] = '\0';
if (!ReadStructure(source, &iteminfo_struct, (char *) ii))
{
FreeMemory(ic);
Expand Down Expand Up @@ -683,6 +689,7 @@ void BotInitLevelItems(void)
//===========================================================================
void BotGoalName(int number, char *name, int size)
{
const size_t max_len = (size_t)(size - 1);
levelitem_t *li;

if (!itemconfig) return;
Expand All @@ -691,8 +698,10 @@ void BotGoalName(int number, char *name, int size)
{
if (li->number == number)
{
strncpy(name, itemconfig->iteminfo[li->iteminfo].name, size-1);
name[size-1] = '\0';
const size_t len = strlen( itemconfig->iteminfo[li->iteminfo].name );
const size_t count = len < max_len ? len : max_len;
memcpy(name, itemconfig->iteminfo[li->iteminfo].name, count );
name[count] = '\0';
return;
} //end for
} //end for
Expand Down Expand Up @@ -724,15 +733,15 @@ void BotDumpAvoidGoals(int goalstate)
{
int i;
bot_goalstate_t *gs;
char name[32];
char name[MAX_GOAL_NAME_LEN];

gs = BotGoalStateFromHandle(goalstate);
if (!gs) return;
for (i = 0; i < MAX_AVOIDGOALS; i++)
{
if (gs->avoidgoaltimes[i] >= AAS_Time())
{
BotGoalName(gs->avoidgoals[i], name, 32);
BotGoalName(gs->avoidgoals[i], name, MAX_GOAL_NAME_LEN);
Log_Write("avoid goal %s, number %d for %f seconds", name,
gs->avoidgoals[i], gs->avoidgoaltimes[i] - AAS_Time());
} //end if
Expand Down Expand Up @@ -1188,13 +1197,13 @@ void BotDumpGoalStack(int goalstate)
{
int i;
bot_goalstate_t *gs;
char name[32];
char name[MAX_GOAL_NAME_LEN];

gs = BotGoalStateFromHandle(goalstate);
if (!gs) return;
for (i = 1; i <= gs->goalstacktop; i++)
{
BotGoalName(gs->goalstack[i].number, name, 32);
BotGoalName(gs->goalstack[i].number, name, MAX_GOAL_NAME_LEN);
Log_Write("%d: %s", i, name);
} //end for
} //end of the function BotDumpGoalStack
Expand Down
54 changes: 27 additions & 27 deletions codemp/botlib/be_ai_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ bot_moveresult_t BotTravel_Walk(bot_movestate_t *ms, aas_reachability_t *reach)
{
float dist, speed;
vec3_t hordir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//first walk straight to the reachability start
hordir[0] = reach->start[0] - ms->origin[0];
Expand Down Expand Up @@ -1389,7 +1389,7 @@ bot_moveresult_t BotFinishTravel_Walk(bot_movestate_t *ms, aas_reachability_t *r
{
vec3_t hordir;
float dist, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};
//if not on the ground and changed areas... don't walk back!!
//(doesn't seem to help)
/*
Expand Down Expand Up @@ -1425,7 +1425,7 @@ bot_moveresult_t BotTravel_Crouch(bot_movestate_t *ms, aas_reachability_t *reach
{
float speed;
vec3_t hordir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//
speed = 400;
Expand Down Expand Up @@ -1454,7 +1454,7 @@ bot_moveresult_t BotTravel_BarrierJump(bot_movestate_t *ms, aas_reachability_t *
{
float dist, speed;
vec3_t hordir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//walk straight to reachability start
hordir[0] = reach->start[0] - ms->origin[0];
Expand Down Expand Up @@ -1487,7 +1487,7 @@ bot_moveresult_t BotTravel_BarrierJump(bot_movestate_t *ms, aas_reachability_t *
bot_moveresult_t BotFinishTravel_BarrierJump(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t hordir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//if near the top or going down
if (ms->velocity[2] < 250)
Expand All @@ -1513,7 +1513,7 @@ bot_moveresult_t BotFinishTravel_BarrierJump(bot_movestate_t *ms, aas_reachabili
bot_moveresult_t BotTravel_Swim(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t dir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//swim straight to reachability end
VectorSubtract(reach->start, ms->origin, dir);
Expand All @@ -1539,7 +1539,7 @@ bot_moveresult_t BotTravel_WaterJump(bot_movestate_t *ms, aas_reachability_t *re
{
vec3_t dir, hordir;
float dist;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//swim straight to reachability end
VectorSubtract(reach->end, ms->origin, dir);
Expand Down Expand Up @@ -1571,7 +1571,7 @@ bot_moveresult_t BotTravel_WaterJump(bot_movestate_t *ms, aas_reachability_t *re
bot_moveresult_t BotFinishTravel_WaterJump(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t dir, pnt;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//botimport.Print(PRT_MESSAGE, "BotFinishTravel_WaterJump\n");
//if waterjumping there's nothing to do
Expand Down Expand Up @@ -1606,7 +1606,7 @@ bot_moveresult_t BotTravel_WalkOffLedge(bot_movestate_t *ms, aas_reachability_t
{
vec3_t hordir, dir;
float dist, speed, reachhordist;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//check if the bot is blocked by anything
VectorSubtract(reach->start, ms->origin, dir);
Expand Down Expand Up @@ -1705,7 +1705,7 @@ bot_moveresult_t BotFinishTravel_WalkOffLedge(bot_movestate_t *ms, aas_reachabil
{
vec3_t dir, hordir, end, v;
float dist, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//
VectorSubtract(reach->end, ms->origin, dir);
Expand Down Expand Up @@ -1742,7 +1742,7 @@ bot_moveresult_t BotTravel_Jump(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t hordir;
float dist, gapdist, speed, horspeed, sv_jumpvel;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//
sv_jumpvel = botlibglobals.sv_jumpvel->value;
Expand Down Expand Up @@ -1791,7 +1791,7 @@ bot_moveresult_t BotTravel_Jump(bot_movestate_t *ms, aas_reachability_t *reach)
vec3_t hordir, dir1, dir2, mins, maxs, start, end;
int gapdist;
float dist1, dist2, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};
bsp_trace_t trace;

//
Expand Down Expand Up @@ -1864,7 +1864,7 @@ bot_moveresult_t BotTravel_Jump(bot_movestate_t *ms, aas_reachability_t *reach)
// vec3_t runstart, dir1, dir2, hordir;
int gapdist;
float dist1, dist2, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//
AAS_JumpReachRunStart(reach, runstart);
Expand Down Expand Up @@ -1933,7 +1933,7 @@ bot_moveresult_t BotFinishTravel_Jump(bot_movestate_t *ms, aas_reachability_t *r
{
vec3_t hordir, hordir2;
float speed, dist;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//if not jumped yet
if (!ms->jumpreach) return result;
Expand Down Expand Up @@ -1969,7 +1969,7 @@ bot_moveresult_t BotTravel_Ladder(bot_movestate_t *ms, aas_reachability_t *reach
vec3_t dir, viewdir;//, hordir;
vec3_t origin = {0, 0, 0};
// vec3_t up = {0, 0, 1};
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//
// if ((ms->moveflags & MFL_AGAINSTLADDER))
Expand Down Expand Up @@ -2022,7 +2022,7 @@ bot_moveresult_t BotTravel_Teleport(bot_movestate_t *ms, aas_reachability_t *rea
{
vec3_t hordir;
float dist;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//if the bot is being teleported
if (ms->moveflags & MFL_TELEPORTED) return result;
Expand Down Expand Up @@ -2052,7 +2052,7 @@ bot_moveresult_t BotTravel_Elevator(bot_movestate_t *ms, aas_reachability_t *rea
{
vec3_t dir, dir1, dir2, hordir, bottomcenter;
float dist, dist1, dist2, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//if standing on the plat
if (BotOnMover(ms->origin, ms->entitynum, reach))
Expand Down Expand Up @@ -2201,7 +2201,7 @@ bot_moveresult_t BotTravel_Elevator(bot_movestate_t *ms, aas_reachability_t *rea
bot_moveresult_t BotFinishTravel_Elevator(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t bottomcenter, bottomdir, topdir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//
MoverBottomCenter(reach, bottomcenter);
Expand Down Expand Up @@ -2289,7 +2289,7 @@ bot_moveresult_t BotTravel_FuncBobbing(bot_movestate_t *ms, aas_reachability_t *
{
vec3_t dir, dir1, dir2, hordir, bottomcenter, bob_start, bob_end, bob_origin;
float dist, dist1, dist2, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//
BotFuncBobStartEnd(reach, bob_start, bob_end, bob_origin);
Expand Down Expand Up @@ -2445,7 +2445,7 @@ bot_moveresult_t BotTravel_FuncBobbing(bot_movestate_t *ms, aas_reachability_t *
bot_moveresult_t BotFinishTravel_FuncBobbing(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t bob_origin, bob_start, bob_end, dir, hordir, bottomcenter;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};
float dist, speed;

//
Expand Down Expand Up @@ -2554,7 +2554,7 @@ void BotResetGrapple(bot_movestate_t *ms)
//===========================================================================
bot_moveresult_t BotTravel_Grapple(bot_movestate_t *ms, aas_reachability_t *reach)
{
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};
float dist, speed;
vec3_t dir, viewdir, org;
int state, areanum;
Expand Down Expand Up @@ -2709,7 +2709,7 @@ bot_moveresult_t BotTravel_RocketJump(bot_movestate_t *ms, aas_reachability_t *r
{
vec3_t hordir;
float dist, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//botimport.Print(PRT_MESSAGE, "BotTravel_RocketJump: bah\n");
//
Expand Down Expand Up @@ -2773,7 +2773,7 @@ bot_moveresult_t BotTravel_BFGJump(bot_movestate_t *ms, aas_reachability_t *reac
{
vec3_t hordir;
float dist, speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//botimport.Print(PRT_MESSAGE, "BotTravel_BFGJump: bah\n");
//
Expand Down Expand Up @@ -2833,7 +2833,7 @@ bot_moveresult_t BotFinishTravel_WeaponJump(bot_movestate_t *ms, aas_reachabilit
{
vec3_t hordir;
float speed;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//if not jumped yet
if (!ms->jumpreach) return result;
Expand Down Expand Up @@ -2871,7 +2871,7 @@ bot_moveresult_t BotFinishTravel_WeaponJump(bot_movestate_t *ms, aas_reachabilit
bot_moveresult_t BotTravel_JumpPad(bot_movestate_t *ms, aas_reachability_t *reach)
{
vec3_t hordir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

//first walk straight to the reachability start
hordir[0] = reach->start[0] - ms->origin[0];
Expand All @@ -2895,7 +2895,7 @@ bot_moveresult_t BotFinishTravel_JumpPad(bot_movestate_t *ms, aas_reachability_t
{
float speed;
vec3_t hordir;
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};

if (!BotAirControl(ms->origin, ms->velocity, reach->end, hordir, &speed))
{
Expand Down Expand Up @@ -2953,7 +2953,7 @@ int BotReachabilityTime(aas_reachability_t *reach)
//===========================================================================
bot_moveresult_t BotMoveInGoalArea(bot_movestate_t *ms, bot_goal_t *goal)
{
bot_moveresult_t_cleared( result );
auto result = bot_moveresult_t{};
vec3_t dir;
float dist, speed;

Expand Down
1 change: 0 additions & 1 deletion codemp/botlib/be_ai_move.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ typedef struct bot_moveresult_s
vec3_t ideal_viewangles; //ideal viewangles for the movement
} bot_moveresult_t;

#define bot_moveresult_t_cleared(x) bot_moveresult_t (x) = {0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, {0, 0, 0}}

typedef struct bot_avoidspot_s
{
Expand Down
3 changes: 2 additions & 1 deletion codemp/botlib/be_ai_weap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ weaponconfig_t *LoadWeaponConfig(char *filename)
max_projectileinfo = 32;
LibVarSet("max_projectileinfo", "32");
} //end if
strncpy(path, filename, MAX_PATH);
strncpy(path, filename, MAX_PATH - 1);
path[MAX_PATH - 1] = '\0';
PC_SetBaseFolder(BOTFILESBASEFOLDER);
source = LoadSourceFile(path);
if (!source)
Expand Down
Loading