Skip to content

Commit b541fb1

Browse files
committed
BSPC: merged parts with wop botlib
1 parent 7c90101 commit b541fb1

File tree

7 files changed

+53
-34
lines changed

7 files changed

+53
-34
lines changed

deps/botlib/be_aas_move.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ int AAS_ClipToBBox(aas_trace_t *trace, vec3_t start, vec3_t end, int presencetyp
509509
// Returns: aas_clientmove_t
510510
// Changes Globals: -
511511
//===========================================================================
512-
int AAS_ClientMovementPrediction(struct aas_clientmove_s *move, int entnum, vec3_t origin, int presencetype,
513-
int onground, vec3_t velocity, vec3_t cmdmove, int cmdframes, int maxframes,
514-
float frametime, int stopevent, int stopareanum, vec3_t mins, vec3_t maxs,
515-
int visualize, int jumper) {
512+
int AAS_ClientMovementPrediction(aas_clientmove_t *move, int entnum, const vec3_t origin, int presencetype,
513+
int onground, const vec3_t velocity, const vec3_t cmdmove, int cmdframes,
514+
int maxframes, float frametime, int stopevent, int stopareanum,
515+
const vec3_t mins, const vec3_t maxs, int visualize, int jumper) {
516516
float phys_friction, phys_stopspeed, phys_gravity, phys_waterfriction;
517517
float phys_watergravity;
518518
float phys_walkaccelerate, phys_airaccelerate, phys_swimaccelerate;

deps/botlib/be_aas_move.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ int AAS_ClientMovementHitBBox(struct aas_clientmove_s *move, int entnum, vec3_t
4242
vec3_t velocity, vec3_t cmdmove, int cmdframes, int maxframes, float frametime,
4343
vec3_t mins, vec3_t maxs, int visualize);
4444
// cyr{
45-
int AAS_ClientMovementPrediction(struct aas_clientmove_s *move, int entnum, vec3_t origin, int presencetype,
46-
int onground, vec3_t velocity, vec3_t cmdmove, int cmdframes, int maxframes,
47-
float frametime, int stopevent, int stopareanum, vec3_t mins, vec3_t maxs,
48-
int visualize, int jumper);
45+
int AAS_ClientMovementPrediction(aas_clientmove_t *move, int entnum, const vec3_t origin, int presencetype,
46+
int onground, const vec3_t velocity, const vec3_t cmdmove, int cmdframes,
47+
int maxframes, float frametime, int stopevent, int stopareanum,
48+
const vec3_t mins, const vec3_t maxs, int visualize, int jumper);
4949
// cyr}
5050
// returns true if on the ground at the given origin
5151
int AAS_OnGround(vec3_t origin, int presencetype, int passent);

deps/botlib/be_aas_reach.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,8 +3200,11 @@ static aas_lreachability_t *AAS_FindFaceReachabilities(vec3_t *facepoints, int n
32003200
VectorCopy(bestend, testpoint);
32013201
else
32023202
VectorCopy(beststart, testpoint);
3203-
testpoint[2] = 0;
3204-
testpoint[2] = (bestfaceplane->dist - DotProduct(bestfaceplane->normal, testpoint)) / bestfaceplane->normal[2];
3203+
if (bestfaceplane != NULL)
3204+
testpoint[2] =
3205+
(bestfaceplane->dist - DotProduct(bestfaceplane->normal, testpoint)) / bestfaceplane->normal[2];
3206+
else
3207+
testpoint[2] = 0;
32053208
//
32063209
if (!AAS_PointInsideFace(bestfacenum, testpoint, 0.1f)) {
32073210
// if the faces are not overlapping then only go down
@@ -3918,6 +3921,10 @@ static void AAS_SetWeaponJumpAreaFlags(void) {
39183921
!strcmp(classname, "weapon_rocketlauncher") || !strcmp(classname, "weapon_lightning") ||
39193922
!strcmp(classname, "weapon_plasmagun") || !strcmp(classname, "weapon_railgun") ||
39203923
!strcmp(classname, "weapon_bfg") || !strcmp(classname, "item_quad") || !strcmp(classname, "item_regen") ||
3924+
!strcmp(classname, "item_invulnerability") || !strcmp(classname, "item_armor_padshield") || !strcmp(classname, "weapon_balloony") ||
3925+
!strcmp(classname, "weapon_betty") || !strcmp(classname, "weapon_boaster") ||
3926+
!strcmp(classname, "weapon_bubbleg") || !strcmp(classname, "weapon_splasher") ||
3927+
!strcmp(classname, "weapon_imperius") || !strcmp(classname, "item_padpower") || !strcmp(classname, "item_revival") ||
39213928
!strcmp(classname, "item_invulnerability")) {
39223929
if (AAS_VectorForBSPEpairKey(ent, "origin", origin)) {
39233930
spawnflags = 0;

deps/botlib/be_ai_chat.c

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -629,22 +629,25 @@ bot_synonymlist_t *BotLoadSynonyms(const char *filename) {
629629
numsynonyms = 0;
630630
lastsynonym = NULL;
631631
while (1) {
632+
size_t len;
632633
if (!PC_ExpectTokenString(source, "(") || !PC_ExpectTokenType(source, TT_STRING, 0, &token)) {
633634
FreeSource(source);
634635
return NULL;
635636
} // end if
636637
StripDoubleQuotes(token.string);
637-
if (strlen(token.string) <= 0) {
638-
SourceError(source, "empty string", token.string);
638+
len = (int)strlen(token.string);
639+
if (len == 0) {
640+
SourceError(source, "empty string");
639641
FreeSource(source);
640642
return NULL;
641643
} // end if
642-
size += sizeof(bot_synonym_t) + strlen(token.string) + 1;
643-
if (pass) {
644+
len = PAD(len + 1, sizeof(long));
645+
size += sizeof(bot_synonym_t) + len;
646+
if (pass && ptr) {
644647
synonym = (bot_synonym_t *)ptr;
645648
ptr += sizeof(bot_synonym_t);
646649
synonym->string = ptr;
647-
ptr += strlen(token.string) + 1;
650+
ptr += len;
648651
strcpy(synonym->string, token.string);
649652
//
650653
if (lastsynonym)
@@ -917,17 +920,20 @@ bot_randomlist_t *BotLoadRandomStrings(const char *filename) {
917920
lastrandom = NULL; // last
918921
//
919922
while (PC_ReadToken(source, &token)) {
923+
size_t len;
920924
if (token.type != TT_NAME) {
921925
SourceError(source, "unknown random %s", token.string);
922926
FreeSource(source);
923927
return NULL;
924928
} // end if
925-
size += sizeof(bot_randomlist_t) + strlen(token.string) + 1;
926-
if (pass) {
929+
len = strlen(token.string) + 1;
930+
len = PAD(len, sizeof(long));
931+
size += sizeof(bot_randomlist_t) + len;
932+
if (pass && ptr) {
927933
random = (bot_randomlist_t *)ptr;
928934
ptr += sizeof(bot_randomlist_t);
929935
random->string = ptr;
930-
ptr += strlen(token.string) + 1;
936+
ptr += len;
931937
strcpy(random->string, token.string);
932938
random->firstrandomstring = NULL;
933939
random->numstrings = 0;
@@ -947,12 +953,14 @@ bot_randomlist_t *BotLoadRandomStrings(const char *filename) {
947953
FreeSource(source);
948954
return NULL;
949955
} // end if
950-
size += sizeof(bot_randomstring_t) + strlen(chatmessagestring) + 1;
951-
if (pass) {
956+
len = strlen(chatmessagestring) + 1;
957+
len = PAD(len, sizeof(long));
958+
size += sizeof(bot_randomstring_t) + len;
959+
if (pass && ptr) {
952960
randomstring = (bot_randomstring_t *)ptr;
953961
ptr += sizeof(bot_randomstring_t);
954962
randomstring->string = ptr;
955-
ptr += strlen(chatmessagestring) + 1;
963+
ptr += len;
956964
strcpy(randomstring->string, chatmessagestring);
957965
//
958966
random->numstrings++;
@@ -1950,11 +1958,14 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname) {
19501958
size += sizeof(bot_chattype_t);
19511959
// read the chat messages
19521960
while (!PC_CheckTokenString(source, "}")) {
1961+
size_t len;
19531962
if (!BotLoadChatMessage(source, chatmessagestring)) {
19541963
FreeSource(source);
19551964
return NULL;
19561965
} // end if
1957-
if (pass) {
1966+
len = strlen(chatmessagestring) + 1;
1967+
len = PAD(len, sizeof(long));
1968+
if (pass && ptr) {
19581969
chatmessage = (bot_chatmessage_t *)ptr;
19591970
chatmessage->time = -2 * CHATMESSAGE_RECENTTIME;
19601971
// put the chat message in the list
@@ -1964,11 +1975,11 @@ bot_chat_t *BotLoadInitialChat(char *chatfile, char *chatname) {
19641975
ptr += sizeof(bot_chatmessage_t);
19651976
chatmessage->chatmessage = ptr;
19661977
strcpy(chatmessage->chatmessage, chatmessagestring);
1967-
ptr += strlen(chatmessagestring) + 1;
1978+
ptr += len;
19681979
// the number of chat messages increased
19691980
chattype->numchatmessages++;
19701981
} // end if
1971-
size += sizeof(bot_chatmessage_t) + strlen(chatmessagestring) + 1;
1982+
size += sizeof(bot_chatmessage_t) + len;
19721983
} // end if
19731984
} // end while
19741985
} // end if

deps/botlib/be_ai_move.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,6 @@ void BotMoveToGoal(bot_moveresult_t *result, int movestate, bot_goal_t *goal, in
34213421
ms->lastreachnum = lastreachnum;
34223422
ms->lastareanum = areas[i];
34233423
// botimport.Print(PRT_MESSAGE, "found jumppad reachability hard!!\n");
3424-
break;
34253424
} // end if
34263425
} // end for
34273426
if (lastreachnum)
@@ -3558,7 +3557,7 @@ void BotResetLastAvoidReach(int movestate) {
35583557
} // end for
35593558
if (latesttime) {
35603559
ms->avoidreachtimes[latest] = 0;
3561-
if (ms->avoidreachtries[i] > 0)
3560+
if (ms->avoidreachtries[latest] > 0)
35623561
ms->avoidreachtries[latest]--;
35633562
} // end if
35643563
} // end of the function BotResetLastAvoidReach

deps/botlib/l_libvar.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ float LibVarStringValue(const char *string) {
7676
libvar_t *LibVarAlloc(const char *var_name) {
7777
libvar_t *v;
7878

79-
v = (libvar_t *)GetMemory(sizeof(libvar_t) + strlen(var_name) + 1);
79+
v = (libvar_t *)GetMemory(sizeof(libvar_t));
8080
Com_Memset(v, 0, sizeof(libvar_t));
81-
v->name = (char *)v + sizeof(libvar_t);
81+
v->name = (char *)GetMemory(strlen(var_name) + 1);
8282
strcpy(v->name, var_name);
8383
// add the variable in the list
8484
v->next = libvarlist;
@@ -94,6 +94,7 @@ libvar_t *LibVarAlloc(const char *var_name) {
9494
void LibVarDeAlloc(libvar_t *v) {
9595
if (v->string)
9696
FreeMemory(v->string);
97+
FreeMemory(v->name);
9798
FreeMemory(v);
9899
} // end of the function LibVarDeAlloc
99100
//===========================================================================

deps/botlib/l_precomp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ static void PC_FreeDefine(define_t *define) {
624624
PC_FreeToken(t);
625625
} // end for
626626
// free the define
627+
FreeMemory(define->name);
627628
FreeMemory(define);
628629
} // end of the function PC_FreeDefine
629630
//============================================================================
@@ -646,9 +647,9 @@ void PC_AddBuiltinDefines(source_t *source) {
646647
{NULL, 0}};
647648

648649
for (i = 0; builtin[i].string; i++) {
649-
define = (define_t *)GetMemory(sizeof(define_t) + strlen(builtin[i].string) + 1);
650+
define = (define_t *)GetMemory(sizeof(define_t));
650651
Com_Memset(define, 0, sizeof(define_t));
651-
define->name = (char *)define + sizeof(define_t);
652+
define->name = (char *)GetMemory(strlen(builtin[i].string) + 1);
652653
strcpy(define->name, builtin[i].string);
653654
define->flags |= DEFINE_FIXED;
654655
define->builtin = builtin[i].builtin;
@@ -1130,9 +1131,9 @@ static int PC_Directive_define(source_t *source) {
11301131
#endif // DEFINEHASHING
11311132
} // end if
11321133
// allocate define
1133-
define = (define_t *)GetMemory(sizeof(define_t) + strlen(token.string) + 1);
1134+
define = (define_t *)GetMemory(sizeof(define_t));
11341135
Com_Memset(define, 0, sizeof(define_t));
1135-
define->name = (char *)define + sizeof(define_t);
1136+
define->name = (char *)GetMemory(strlen(token.string) + 1);
11361137
strcpy(define->name, token.string);
11371138
// add the define to the source
11381139
#if DEFINEHASHING
@@ -1353,9 +1354,9 @@ define_t *PC_CopyDefine(source_t *source, define_t *define) {
13531354
define_t *newdefine;
13541355
token_t *token, *newtoken, *lasttoken;
13551356

1356-
newdefine = (define_t *)GetMemory(sizeof(define_t) + strlen(define->name) + 1);
1357+
newdefine = (define_t *)GetMemory(sizeof(define_t));
13571358
// copy the define name
1358-
newdefine->name = (char *)newdefine + sizeof(define_t);
1359+
newdefine->name = (char *)GetMemory(strlen(define->name) + 1);
13591360
strcpy(newdefine->name, define->name);
13601361
newdefine->flags = define->flags;
13611362
newdefine->builtin = define->builtin;

0 commit comments

Comments
 (0)