Skip to content

Commit 53b9c1e

Browse files
committed
BSPC: merged parts of wop botlib
1 parent b8d5635 commit 53b9c1e

21 files changed

+311
-287
lines changed

deps/botlib/be_aas_bspq3.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size) {
260260
return qfalse;
261261
for (epair = bspworld.entities[ent].epairs; epair; epair = epair->next) {
262262
if (!strcmp(epair->key, key)) {
263-
strncpy(value, epair->value, size - 1);
264-
value[size - 1] = '\0';
263+
Q_strncpyz(value, epair->value, size);
265264
return qtrue;
266265
} // end if
267266
} // end for

deps/botlib/be_aas_cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ int AAS_CheckAreaForPossiblePortals(int areanum) {
775775
//
776776
Com_Memset(numareafrontfaces, 0, sizeof(numareafrontfaces));
777777
Com_Memset(numareabackfaces, 0, sizeof(numareabackfaces));
778-
numareas = numfrontfaces = numbackfaces = 0;
778+
numfrontfaces = numbackfaces = 0;
779779
numfrontareas = numbackareas = 0;
780780
frontplanenum = backplanenum = -1;
781781
// add any adjacent areas with less presence types

deps/botlib/be_aas_debug.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,4 +762,5 @@ void AAS_FloodAreas(vec3_t origin) {
762762
areanum = AAS_PointAreaNum(origin);
763763
cluster = AAS_AreaCluster(areanum);
764764
AAS_FloodAreas_r(areanum, cluster, done);
765+
FreeMemory(done);
765766
}

deps/botlib/be_aas_entity.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ int AAS_NearestEntity(vec3_t origin, int modelindex) {
353353
if (ent->i.modelindex != modelindex)
354354
continue;
355355
VectorSubtract(ent->i.origin, origin, dir);
356-
if (abs(dir[0]) < 40) {
357-
if (abs(dir[1]) < 40) {
356+
if (fabsf(dir[0]) < 40) {
357+
if (fabsf(dir[1]) < 40) {
358358
dist = VectorLength(dir);
359359
if (dist < bestdist) {
360360
bestdist = dist;

deps/botlib/be_aas_main.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void QDECL AAS_Error(char *fmt, ...) {
5959
va_list arglist;
6060

6161
va_start(arglist, fmt);
62-
vsprintf(str, fmt, arglist);
62+
Q_vsnprintf(str, sizeof(str), fmt, arglist);
6363
va_end(arglist);
6464
botimport.Print(PRT_FATAL, str);
6565
} // end of the function AAS_Error
@@ -231,7 +231,7 @@ int AAS_StartFrame(float time) {
231231
//
232232
aasworld.frameroutingupdates = 0;
233233
//
234-
if (bot_developer) {
234+
if (botDeveloper) {
235235
if (LibVarGetValue("showcacheupdates")) {
236236
AAS_RoutingInfo();
237237
LibVarSet("showcacheupdates", "0");
@@ -286,10 +286,9 @@ void AAS_ProjectPointOntoVector(vec3_t point, vec3_t vStart, vec3_t vEnd, vec3_t
286286
//===========================================================================
287287
int AAS_LoadFiles(const char *mapname) {
288288
int errnum;
289-
char aasfile[MAX_PATH];
290-
// char bspfile[MAX_PATH];
289+
char aasfile[MAX_QPATH];
291290

292-
strcpy(aasworld.mapname, mapname);
291+
Q_strncpyz(aasworld.mapname, mapname, sizeof(aasworld.mapname));
293292
// NOTE: first reset the entity links into the AAS areas and BSP leaves
294293
// the AAS link heap and BSP link heap are reset after respectively the
295294
// AAS file and BSP file are loaded
@@ -304,7 +303,7 @@ int AAS_LoadFiles(const char *mapname) {
304303
return errnum;
305304

306305
botimport.Print(PRT_MESSAGE, "loaded %s\n", aasfile);
307-
strncpy(aasworld.filename, aasfile, MAX_PATH);
306+
Q_strncpyz(aasworld.filename, aasfile, sizeof(aasworld.filename));
308307
return BLERR_NOERROR;
309308
} // end of the function AAS_LoadFiles
310309
//===========================================================================

deps/botlib/be_aas_move.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int AAS_AgainstLadder(vec3_t origin) {
166166
// get the plane the face is in
167167
plane = &aasworld.planes[face->planenum ^ side];
168168
// if the origin is pretty close to the plane
169-
if (fabs(DotProduct(plane->normal, origin) - plane->dist) < 3.0f) {
169+
if (fabsf(DotProduct(plane->normal, origin) - plane->dist) < 3) {
170170
if (AAS_PointInsideFace(abs(facenum), origin, 0.1f))
171171
return qtrue;
172172
} // end if
@@ -420,13 +420,15 @@ void AAS_ApplyFriction(vec3_t vel, float friction, float stopspeed, float framet
420420
vel[1] *= newspeed;
421421
} // end if
422422
} // end of the function AAS_ApplyFriction
423+
423424
//===========================================================================
424425
//
425426
// Parameter: -
426427
// Returns: -
427428
// Changes Globals: -
428429
//===========================================================================
429-
int AAS_ClipToBBox(aas_trace_t *trace, vec3_t start, vec3_t end, int presencetype, vec3_t mins, vec3_t maxs) {
430+
static qboolean AAS_ClipToBBox(aas_trace_t *trace, const vec3_t start, const vec3_t end, int presencetype,
431+
const vec3_t mins, const vec3_t maxs) {
430432
int i, j, side;
431433
float front, back, frac, planedist;
432434
vec3_t bboxmins, bboxmaxs, absmins, absmaxs, dir, mid;
@@ -520,6 +522,7 @@ int AAS_ClientMovementPrediction(aas_clientmove_t *move, int entnum, const vec3_
520522
float phys_maxstep, phys_maxsteepness, phys_jumpvel, friction;
521523
float gravity, delta, maxvel, wishspeed, accelerate;
522524
// float velchange, newvel;
525+
// int ax;
523526
int n, i, j, pc, step, swimming, crouch, event, jump_frame, areanum;
524527
int areas[20], numareas;
525528
vec3_t points[20];
@@ -574,6 +577,7 @@ int AAS_ClientMovementPrediction(aas_clientmove_t *move, int entnum, const vec3_
574577
crouch = qfalse;
575578
// apply command movement
576579
if (n < cmdframes) {
580+
// ax = 0;
577581
maxvel = phys_maxwalkvelocity;
578582
accelerate = phys_airaccelerate;
579583
VectorCopy(cmdmove, wishdir);
@@ -597,10 +601,12 @@ int AAS_ClientMovementPrediction(aas_clientmove_t *move, int entnum, const vec3_
597601
else {
598602
accelerate = phys_walkaccelerate;
599603
} // end else
600-
} // end if
604+
// ax = 2;
605+
} // end if
601606
if (swimming) {
602607
maxvel = phys_maxswimvelocity;
603608
accelerate = phys_swimaccelerate;
609+
// ax = 3;
604610
} // end if
605611
else {
606612
wishdir[2] = 0;
@@ -612,6 +618,19 @@ int AAS_ClientMovementPrediction(aas_clientmove_t *move, int entnum, const vec3_
612618
VectorScale(frame_test_vel, 1 / frametime, frame_test_vel);
613619
AAS_Accelerate(frame_test_vel, frametime, wishdir, wishspeed, accelerate);
614620
VectorScale(frame_test_vel, frametime, frame_test_vel);
621+
/*
622+
for (i = 0; i < ax; i++)
623+
{
624+
velchange = (cmdmove[i] * frametime) - frame_test_vel[i];
625+
if (velchange > phys_maxacceleration) velchange = phys_maxacceleration;
626+
else if (velchange < -phys_maxacceleration) velchange = -phys_maxacceleration;
627+
newvel = frame_test_vel[i] + velchange;
628+
//
629+
if (frame_test_vel[i] <= maxvel && newvel > maxvel) frame_test_vel[i] = maxvel;
630+
else if (frame_test_vel[i] >= -maxvel && newvel < -maxvel) frame_test_vel[i] = -maxvel;
631+
else frame_test_vel[i] = newvel;
632+
} //end for
633+
*/
615634
} // end if
616635
if (crouch) {
617636
presencetype = PRESENCE_CROUCH;
@@ -938,7 +957,8 @@ int AAS_ClientMovementPrediction(aas_clientmove_t *move, int entnum, const vec3_
938957
int AAS_PredictClientMovement(struct aas_clientmove_s *move, int entnum, vec3_t origin, int presencetype, int onground,
939958
vec3_t velocity, vec3_t cmdmove, int cmdframes, int maxframes, float frametime,
940959
int stopevent, int stopareanum, int visualize) {
941-
vec3_t mins, maxs;
960+
const vec3_t mins = {-4, -4, -4};
961+
const vec3_t maxs = {4, 4, 4};
942962
return AAS_ClientMovementPrediction(move, entnum, origin, presencetype, onground, velocity, cmdmove, cmdframes,
943963
maxframes, frametime, stopevent, stopareanum, mins, maxs, visualize, 0); // cyr
944964
} // end of the function AAS_PredictClientMovement

deps/botlib/be_aas_reach.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,12 +1033,13 @@ static int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, in
10331033
int water_bestarea2groundedgenum, water_foundreach;
10341034
int side1, area1swim, faceside1, groundface1num;
10351035
float dist, dist1, dist2, diff, ortdot;
1036+
// float invgravitydot;
10361037
float x1, x2, x3, x4, y1, y2, y3, y4, tmp, y;
10371038
float length, ground_bestlength, water_bestlength, ground_bestdist, water_bestdist;
10381039
vec3_t v1, v2, v3, v4, tmpv, p1area1, p1area2, p2area1, p2area2;
10391040
vec3_t normal, ort, edgevec, start, end, dir;
1040-
vec3_t ground_beststart, ground_bestend, ground_bestnormal;
1041-
vec3_t water_beststart, water_bestend, water_bestnormal;
1041+
vec3_t ground_beststart = {0, 0, 0}, ground_bestend = {0, 0, 0}, ground_bestnormal = {0, 0, 0};
1042+
vec3_t water_beststart = {0, 0, 0}, water_bestend = {0, 0, 0}, water_bestnormal = {0, 0, 0};
10421043
vec3_t invgravity = {0, 0, 1};
10431044
vec3_t testpoint;
10441045
aas_plane_t *plane;
@@ -1143,6 +1144,7 @@ static int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, in
11431144
// edges if they overlap in the direction orthogonal to
11441145
// the gravity direction
11451146
CrossProduct(invgravity, normal, ort);
1147+
// invgravitydot = DotProduct(invgravity, invgravity);
11461148
ortdot = DotProduct(ort, ort);
11471149
// projection into the step plane
11481150
// NOTE: since gravity is vertical this is just the z coordinate
@@ -1506,7 +1508,7 @@ static int AAS_Reachability_Step_Barrier_WaterJump_WalkOffLedge(int area1num, in
15061508
trace.endpos[2] += 1;
15071509
if (AAS_PointAreaNum(trace.endpos) == area2num) {
15081510
// if not going through a cluster portal
1509-
numareas = AAS_TraceAreas(start, end, areas, NULL, sizeof(areas) / sizeof(int));
1511+
numareas = AAS_TraceAreas(start, end, areas, NULL, ARRAY_LEN(areas));
15101512
for (i = 0; i < numareas; i++)
15111513
if (AAS_AreaClusterPortal(areas[i]))
15121514
break;
@@ -2032,7 +2034,7 @@ static int AAS_Reachability_Jump(int area1num, int area2num) {
20322034
int stopevent, areas[10], numareas;
20332035
float phys_jumpvel, maxjumpdistance, maxjumpheight, height, bestdist, speed;
20342036
vec_t *v1, *v2, *v3, *v4;
2035-
vec3_t beststart, beststart2, bestend, bestend2;
2037+
vec3_t beststart = {0}, beststart2 = {0}, bestend = {0}, bestend2 = {0};
20362038
vec3_t teststart, testend, dir, velocity, cmdmove, up = {0, 0, 1}, sidewards;
20372039
aas_area_t *area1, *area2;
20382040
aas_face_t *face1, *face2;
@@ -2220,7 +2222,7 @@ static int AAS_Reachability_Jump(int area1num, int area2num) {
22202222
// because the predicted jump could have rushed through the area
22212223
VectorMA(move.endpos, -64, dir, teststart);
22222224
teststart[2] += 1;
2223-
numareas = AAS_TraceAreas(move.endpos, teststart, areas, NULL, sizeof(areas) / sizeof(int));
2225+
numareas = AAS_TraceAreas(move.endpos, teststart, areas, NULL, ARRAY_LEN(areas));
22242226
for (j = 0; j < numareas; j++) {
22252227
if (areas[j] == area2num)
22262228
break;
@@ -2281,16 +2283,16 @@ static int AAS_Reachability_Jump(int area1num, int area2num) {
22812283
// Returns: -
22822284
// Changes Globals: -
22832285
//===========================================================================
2284-
int AAS_Reachability_Ladder(int area1num, int area2num) {
2285-
int i, j, k, l, edge1num, edge2num, sharededgenum, lowestedgenum;
2286-
int face1num, face2num, ladderface1num, ladderface2num;
2286+
static int AAS_Reachability_Ladder(int area1num, int area2num) {
2287+
int i, j, k, l, edge1num, edge2num, sharededgenum = 0, lowestedgenum = 0;
2288+
int face1num, face2num, ladderface1num = 0, ladderface2num = 0;
22872289
int ladderface1vertical, ladderface2vertical, firstv;
2288-
float face1area, face2area, bestface1area, bestface2area;
2290+
float face1area, face2area, bestface1area = -9999, bestface2area = -9999;
22892291
float phys_jumpvel, maxjumpheight;
22902292
vec3_t area1point, area2point, v1, v2, up = {0, 0, 1};
2291-
vec3_t mid, lowestpoint, start, end, sharededgevec, dir;
2293+
vec3_t mid, lowestpoint = {0, 0}, start, end, sharededgevec, dir;
22922294
aas_area_t *area1, *area2;
2293-
aas_face_t *face1, *face2, *ladderface1, *ladderface2;
2295+
aas_face_t *face1, *face2, *ladderface1 = NULL, *ladderface2 = NULL;
22942296
aas_plane_t *plane1, *plane2;
22952297
aas_edge_t *sharededge, *edge1;
22962298
aas_lreachability_t *lreach;
@@ -2305,16 +2307,7 @@ int AAS_Reachability_Ladder(int area1num, int area2num) {
23052307

23062308
area1 = &aasworld.areas[area1num];
23072309
area2 = &aasworld.areas[area2num];
2308-
//
2309-
ladderface1 = NULL;
2310-
ladderface2 = NULL;
2311-
ladderface1num = 0; // make compiler happy
2312-
ladderface2num = 0; // make compiler happy
2313-
bestface1area = -9999;
2314-
bestface2area = -9999;
2315-
sharededgenum = 0; // make compiler happy
2316-
lowestedgenum = 0; // make compiler happy
2317-
//
2310+
23182311
for (i = 0; i < area1->numfaces; i++) {
23192312
face1num = aasworld.faceindex[area1->firstface + i];
23202313
face1 = &aasworld.faces[abs(face1num)];
@@ -2378,18 +2371,18 @@ int AAS_Reachability_Ladder(int area1num, int area2num) {
23782371
VectorMA(area1point, -32, dir, area1point);
23792372
VectorMA(area2point, 32, dir, area2point);
23802373
//
2381-
ladderface1vertical = fabs(DotProduct(plane1->normal, up)) < 0.1f;
2382-
ladderface2vertical = fabs(DotProduct(plane2->normal, up)) < 0.1f;
2374+
ladderface1vertical = fabsf(DotProduct(plane1->normal, up)) < 0.1;
2375+
ladderface2vertical = fabsf(DotProduct(plane2->normal, up)) < 0.1;
23832376
// there's only reachability between vertical ladder faces
23842377
if (!ladderface1vertical && !ladderface2vertical)
23852378
return qfalse;
23862379
// if both vertical ladder faces
23872380
if (ladderface1vertical &&
23882381
ladderface2vertical
23892382
// and the ladder faces do not make a sharp corner
2390-
&& DotProduct(plane1->normal, plane2->normal) > 0.7f
2383+
&& DotProduct(plane1->normal, plane2->normal) > 0.7
23912384
// and the shared edge is not too vertical
2392-
&& fabs(DotProduct(sharededgevec, up)) < 0.7f) {
2385+
&& fabsf(DotProduct(sharededgevec, up)) < 0.7) {
23932386
// create a new reachability link
23942387
lreach = AAS_AllocReachability();
23952388
if (!lreach)
@@ -2510,7 +2503,7 @@ int AAS_Reachability_Ladder(int area1num, int area2num) {
25102503
//
25112504
if (face2->faceflags & FACE_LADDER) {
25122505
plane2 = &aasworld.planes[face2->planenum];
2513-
if (fabs(DotProduct(plane2->normal, up)) < 0.1f)
2506+
if (fabsf(DotProduct(plane2->normal, up)) < 0.1)
25142507
break;
25152508
} // end if
25162509
} // end for
@@ -3115,7 +3108,7 @@ static aas_lreachability_t *AAS_FindFaceReachabilities(vec3_t *facepoints, int n
31153108
int facenum, edgenum, bestfacenum;
31163109
float *v1, *v2, *v3, *v4;
31173110
float bestdist, speed, hordist, dist;
3118-
vec3_t beststart, beststart2, bestend, bestend2, tmp, hordir, testpoint;
3111+
vec3_t beststart = {0}, beststart2 = {0}, bestend = {0}, bestend2 = {0}, tmp, hordir, testpoint;
31193112
aas_lreachability_t *lreach, *lreachabilities;
31203113
aas_area_t *area;
31213114
aas_face_t *face;
@@ -3462,6 +3455,7 @@ static void AAS_Reachability_JumpPad(void) {
34623455
// int modelnum, ent2;
34633456
// float dist, time, height, gravity, forward;
34643457
float speed, zvel;
3458+
// float hordist;
34653459
aas_face_t *face2;
34663460
aas_area_t *area2;
34673461
aas_lreachability_t *lreach;
@@ -3685,6 +3679,8 @@ static void AAS_Reachability_JumpPad(void) {
36853679
// direction towards the face center
36863680
VectorSubtract(facecenter, areastart, dir);
36873681
dir[2] = 0;
3682+
// hordist = VectorNormalize(dir);
3683+
// if (hordist < 1.6 * facecenter[2] - areastart[2])
36883684
{
36893685
// get command movement
36903686
VectorScale(dir, speed, cmdmove);
@@ -3696,7 +3692,8 @@ static void AAS_Reachability_JumpPad(void) {
36963692
area2num, visualize);
36973693
// if prediction time wasn't enough to fully predict the movement
36983694
// don't enter slime or lava and don't fall from too high
3699-
if (move.frames < 30 && !(move.stopevent & (SE_ENTERSLIME | SE_ENTERLAVA)) &&
3695+
if (move.frames < 30 &&
3696+
!(move.stopevent & (SE_ENTERSLIME | SE_ENTERLAVA)) &&
37003697
(move.stopevent & (SE_HITGROUNDAREA | SE_TOUCHJUMPPAD | SE_TOUCHTELEPORTER))) {
37013698
// never go back to the same jumppad
37023699
for (link = areas; link; link = link->next_area) {
@@ -3755,7 +3752,7 @@ static int AAS_Reachability_Grapple(int area1num, int area2num) {
37553752
aas_face_t *face2;
37563753
aas_area_t *area1, *area2;
37573754
aas_lreachability_t *lreach;
3758-
vec3_t areastart, facecenter, start, end, dir, down = {0, 0, -1};
3755+
vec3_t areastart = {0, 0, 0}, facecenter, start, end, dir, down = {0, 0, -1};
37593756
vec_t *v;
37603757

37613758
// only grapple when on the ground or swimming
@@ -3970,6 +3967,7 @@ static void AAS_SetWeaponJumpAreaFlags(void) {
39703967
int AAS_Reachability_WeaponJump(int area1num, int area2num) {
39713968
int face2num, i, n, ret, visualize;
39723969
float speed, zvel;
3970+
// float hordist;
39733971
aas_face_t *face2;
39743972
aas_area_t *area1, *area2;
39753973
aas_lreachability_t *lreach;
@@ -4035,6 +4033,8 @@ int AAS_Reachability_WeaponJump(int area1num, int area2num) {
40354033
// direction towards the face center
40364034
VectorSubtract(facecenter, areastart, dir);
40374035
dir[2] = 0;
4036+
// hordist = VectorNormalize(dir);
4037+
// if (hordist < 1.6 * (facecenter[2] - areastart[2]))
40384038
{
40394039
// get command movement
40404040
VectorScale(dir, speed, cmdmove);
@@ -4218,7 +4218,7 @@ static void AAS_Reachability_WalkOffLedge(int areanum) {
42184218
break;
42194219
} // end if
42204220
// if not going through a cluster portal
4221-
numareas = AAS_TraceAreas(mid, testend, areas, NULL, sizeof(areas) / sizeof(int));
4221+
numareas = AAS_TraceAreas(mid, testend, areas, NULL, ARRAY_LEN(areas));
42224222
for (p = 0; p < numareas; p++)
42234223
if (AAS_AreaClusterPortal(areas[p]))
42244224
break;
@@ -4603,7 +4603,7 @@ void AAS_StoreReachability(void) {
46034603
if (aasworld.reachability)
46044604
FreeMemory(aasworld.reachability);
46054605
aasworld.reachability =
4606-
(aas_reachability_t *)GetClearedMemory((numlreachabilities + 10) * sizeof(aas_reachability_t)); // cyr
4606+
(aas_reachability_t *)GetClearedMemory((numlreachabilities + 10) * sizeof(aas_reachability_t));
46074607
aasworld.reachabilitysize = 1;
46084608
for (i = 0; i < aasworld.numareas; i++) {
46094609
areasettings = &aasworld.areasettings[i];

0 commit comments

Comments
 (0)