| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include "../qcommon/q_shared.h" |
| 33 |
#include "l_memory.h" |
| 34 |
#include "l_libvar.h" |
| 35 |
#include "l_utils.h" |
| 36 |
#include "l_script.h" |
| 37 |
#include "l_precomp.h" |
| 38 |
#include "l_struct.h" |
| 39 |
#include "aasfile.h" |
| 40 |
#include "botlib.h" |
| 41 |
#include "be_aas.h" |
| 42 |
#include "be_aas_funcs.h" |
| 43 |
#include "be_interface.h" |
| 44 |
|
| 45 |
#include "be_ea.h" |
| 46 |
#include "be_ai_goal.h" |
| 47 |
#include "be_ai_move.h" |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
typedef struct bot_movestate_s |
| 58 |
{ |
| 59 |
|
| 60 |
vec3_t origin; |
| 61 |
vec3_t velocity; |
| 62 |
vec3_t viewoffset; |
| 63 |
int entitynum; |
| 64 |
int client; |
| 65 |
float thinktime; |
| 66 |
int presencetype; |
| 67 |
vec3_t viewangles; |
| 68 |
|
| 69 |
int areanum; |
| 70 |
int lastareanum; |
| 71 |
int lastgoalareanum; |
| 72 |
int lastreachnum; |
| 73 |
vec3_t lastorigin; |
| 74 |
int reachareanum; |
| 75 |
int moveflags; |
| 76 |
int jumpreach; |
| 77 |
float grapplevisible_time; |
| 78 |
float lastgrappledist; |
| 79 |
float reachability_time; |
| 80 |
int avoidreach[MAX_AVOIDREACH]; |
| 81 |
float avoidreachtimes[MAX_AVOIDREACH]; |
| 82 |
int avoidreachtries[MAX_AVOIDREACH]; |
| 83 |
|
| 84 |
bot_avoidspot_t avoidspots[MAX_AVOIDSPOTS]; |
| 85 |
int numavoidspots; |
| 86 |
} bot_movestate_t; |
| 87 |
|
| 88 |
|
| 89 |
#define AVOIDREACH |
| 90 |
#define AVOIDREACH_TIME 6 //avoid links for 6 seconds after use |
| 91 |
#define AVOIDREACH_TRIES 4 |
| 92 |
|
| 93 |
#define PREDICTIONTIME_JUMP 3 //in seconds |
| 94 |
#define PREDICTIONTIME_MOVE 2 //in seconds |
| 95 |
|
| 96 |
#define WEAPONINDEX_ROCKET_LAUNCHER 5 |
| 97 |
#define WEAPONINDEX_BFG 9 |
| 98 |
|
| 99 |
#define MODELTYPE_FUNC_PLAT 1 |
| 100 |
#define MODELTYPE_FUNC_BOB 2 |
| 101 |
#define MODELTYPE_FUNC_DOOR 3 |
| 102 |
#define MODELTYPE_FUNC_STATIC 4 |
| 103 |
|
| 104 |
libvar_t *sv_maxstep; |
| 105 |
libvar_t *sv_maxbarrier; |
| 106 |
libvar_t *sv_gravity; |
| 107 |
libvar_t *weapindex_rocketlauncher; |
| 108 |
libvar_t *weapindex_bfg10k; |
| 109 |
libvar_t *weapindex_grapple; |
| 110 |
libvar_t *entitytypemissile; |
| 111 |
libvar_t *offhandgrapple; |
| 112 |
libvar_t *cmd_grappleoff; |
| 113 |
libvar_t *cmd_grappleon; |
| 114 |
|
| 115 |
int modeltypes[MAX_MODELS]; |
| 116 |
|
| 117 |
bot_movestate_t *botmovestates[MAX_CLIENTS+1]; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
int BotAllocMoveState(void) |
| 126 |
{ |
| 127 |
int i; |
| 128 |
|
| 129 |
for (i = 1; i <= MAX_CLIENTS; i++) |
| 130 |
{ |
| 131 |
if (!botmovestates[i]) |
| 132 |
{ |
| 133 |
botmovestates[i] = GetClearedMemory(sizeof(bot_movestate_t)); |
| 134 |
return i; |
| 135 |
} |
| 136 |
} |
| 137 |
return 0; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
void BotFreeMoveState(int handle) |
| 146 |
{ |
| 147 |
if (handle <= 0 || handle > MAX_CLIENTS) |
| 148 |
{ |
| 149 |
botimport.Print(PRT_FATAL, "move state handle %d out of range\n", handle); |
| 150 |
return; |
| 151 |
} |
| 152 |
if (!botmovestates[handle]) |
| 153 |
{ |
| 154 |
botimport.Print(PRT_FATAL, "invalid move state %d\n", handle); |
| 155 |
return; |
| 156 |
} |
| 157 |
FreeMemory(botmovestates[handle]); |
| 158 |
botmovestates[handle] = NULL; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
bot_movestate_t *BotMoveStateFromHandle(int handle) |
| 167 |
{ |
| 168 |
if (handle <= 0 || handle > MAX_CLIENTS) |
| 169 |
{ |
| 170 |
botimport.Print(PRT_FATAL, "move state handle %d out of range\n", handle); |
| 171 |
return NULL; |
| 172 |
} |
| 173 |
if (!botmovestates[handle]) |
| 174 |
{ |
| 175 |
botimport.Print(PRT_FATAL, "invalid move state %d\n", handle); |
| 176 |
return NULL; |
| 177 |
} |
| 178 |
return botmovestates[handle]; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
void BotInitMoveState(int handle, bot_initmove_t *initmove) |
| 187 |
{ |
| 188 |
bot_movestate_t *ms; |
| 189 |
|
| 190 |
ms = BotMoveStateFromHandle(handle); |
| 191 |
if (!ms) return; |
| 192 |
VectorCopy(initmove->origin, ms->origin); |
| 193 |
VectorCopy(initmove->velocity, ms->velocity); |
| 194 |
VectorCopy(initmove->viewoffset, ms->viewoffset); |
| 195 |
ms->entitynum = initmove->entitynum; |
| 196 |
ms->client = initmove->client; |
| 197 |
ms->thinktime = initmove->thinktime; |
| 198 |
ms->presencetype = initmove->presencetype; |
| 199 |
VectorCopy(initmove->viewangles, ms->viewangles); |
| 200 |
|
| 201 |
ms->moveflags &= ~MFL_ONGROUND; |
| 202 |
if (initmove->or_moveflags & MFL_ONGROUND) ms->moveflags |= MFL_ONGROUND; |
| 203 |
ms->moveflags &= ~MFL_TELEPORTED; |
| 204 |
if (initmove->or_moveflags & MFL_TELEPORTED) ms->moveflags |= MFL_TELEPORTED; |
| 205 |
ms->moveflags &= ~MFL_WATERJUMP; |
| 206 |
if (initmove->or_moveflags & MFL_WATERJUMP) ms->moveflags |= MFL_WATERJUMP; |
| 207 |
ms->moveflags &= ~MFL_WALK; |
| 208 |
if (initmove->or_moveflags & MFL_WALK) ms->moveflags |= MFL_WALK; |
| 209 |
ms->moveflags &= ~MFL_GRAPPLEPULL; |
| 210 |
if (initmove->or_moveflags & MFL_GRAPPLEPULL) ms->moveflags |= MFL_GRAPPLEPULL; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
float AngleDiff(float ang1, float ang2) |
| 219 |
{ |
| 220 |
float diff; |
| 221 |
|
| 222 |
diff = ang1 - ang2; |
| 223 |
if (ang1 > ang2) |
| 224 |
{ |
| 225 |
if (diff > 180.0) diff -= 360.0; |
| 226 |
} |
| 227 |
else |
| 228 |
{ |
| 229 |
if (diff < -180.0) diff += 360.0; |
| 230 |
} |
| 231 |
return diff; |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
int BotFuzzyPointReachabilityArea(vec3_t origin) |
| 240 |
{ |
| 241 |
int firstareanum, j, x, y, z; |
| 242 |
int areas[10], numareas, areanum, bestareanum; |
| 243 |
float dist, bestdist; |
| 244 |
vec3_t points[10], v, end; |
| 245 |
|
| 246 |
firstareanum = 0; |
| 247 |
areanum = AAS_PointAreaNum(origin); |
| 248 |
if (areanum) |
| 249 |
{ |
| 250 |
firstareanum = areanum; |
| 251 |
if (AAS_AreaReachability(areanum)) return areanum; |
| 252 |
} |
| 253 |
VectorCopy(origin, end); |
| 254 |
end[2] += 4; |
| 255 |
numareas = AAS_TraceAreas(origin, end, areas, points, 10); |
| 256 |
for (j = 0; j < numareas; j++) |
| 257 |
{ |
| 258 |
if (AAS_AreaReachability(areas[j])) return areas[j]; |
| 259 |
} |
| 260 |
bestdist = 999999; |
| 261 |
bestareanum = 0; |
| 262 |
for (z = 1; z >= -1; z -= 1) |
| 263 |
{ |
| 264 |
for (x = 1; x >= -1; x -= 1) |
| 265 |
{ |
| 266 |
for (y = 1; y >= -1; y -= 1) |
| 267 |
{ |
| 268 |
VectorCopy(origin, end); |
| 269 |
end[0] += x * 8; |
| 270 |
end[1] += y * 8; |
| 271 |
end[2] += z * 12; |
| 272 |
numareas = AAS_TraceAreas(origin, end, areas, points, 10); |
| 273 |
for (j = 0; j < numareas; j++) |
| 274 |
{ |
| 275 |
if (AAS_AreaReachability(areas[j])) |
| 276 |
{ |
| 277 |
VectorSubtract(points[j], origin, v); |
| 278 |
dist = VectorLength(v); |
| 279 |
if (dist < bestdist) |
| 280 |
{ |
| 281 |
bestareanum = areas[j]; |
| 282 |
bestdist = dist; |
| 283 |
} |
| 284 |
} |
| 285 |
if (!firstareanum) firstareanum = areas[j]; |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
if (bestareanum) return bestareanum; |
| 290 |
} |
| 291 |
return firstareanum; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
int BotReachabilityArea(vec3_t origin, int client) |
| 300 |
{ |
| 301 |
int modelnum, modeltype, reachnum, areanum; |
| 302 |
aas_reachability_t reach; |
| 303 |
vec3_t org, end, mins, maxs, up = {0, 0, 1}; |
| 304 |
bsp_trace_t bsptrace; |
| 305 |
aas_trace_t trace; |
| 306 |
|
| 307 |
|
| 308 |
AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, mins, maxs); |
| 309 |
VectorMA(origin, -3, up, end); |
| 310 |
bsptrace = AAS_Trace(origin, mins, maxs, end, client, CONTENTS_SOLID|CONTENTS_PLAYERCLIP); |
| 311 |
if (!bsptrace.startsolid && bsptrace.fraction < 1 && bsptrace.ent != ENTITYNUM_NONE) |
| 312 |
{ |
| 313 |
|
| 314 |
if (bsptrace.ent == ENTITYNUM_WORLD) |
| 315 |
{ |
| 316 |
return BotFuzzyPointReachabilityArea(origin); |
| 317 |
} |
| 318 |
|
| 319 |
modelnum = AAS_EntityModelindex(bsptrace.ent); |
| 320 |
modeltype = modeltypes[modelnum]; |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
if (modeltype == MODELTYPE_FUNC_PLAT || modeltype == MODELTYPE_FUNC_BOB) |
| 325 |
{ |
| 326 |
reachnum = AAS_NextModelReachability(0, modelnum); |
| 327 |
if (reachnum) |
| 328 |
{ |
| 329 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 330 |
return reach.areanum; |
| 331 |
} |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
if (AAS_Swimming(origin)) |
| 336 |
{ |
| 337 |
return BotFuzzyPointReachabilityArea(origin); |
| 338 |
} |
| 339 |
|
| 340 |
areanum = BotFuzzyPointReachabilityArea(origin); |
| 341 |
|
| 342 |
if (areanum && AAS_AreaReachability(areanum)) return areanum; |
| 343 |
|
| 344 |
VectorCopy(origin, org); |
| 345 |
VectorCopy(org, end); |
| 346 |
end[2] -= 800; |
| 347 |
trace = AAS_TraceClientBBox(org, end, PRESENCE_CROUCH, -1); |
| 348 |
if (!trace.startsolid) |
| 349 |
{ |
| 350 |
VectorCopy(trace.endpos, org); |
| 351 |
} |
| 352 |
|
| 353 |
return BotFuzzyPointReachabilityArea(org); |
| 354 |
} |
| 355 |
|
| 356 |
return BotFuzzyPointReachabilityArea(origin); |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
int BotOnMover(vec3_t origin, int entnum, aas_reachability_t *reach) |
| 441 |
{ |
| 442 |
int i, modelnum; |
| 443 |
vec3_t mins, maxs, modelorigin, org, end; |
| 444 |
vec3_t angles = {0, 0, 0}; |
| 445 |
vec3_t boxmins = {-16, -16, -8}, boxmaxs = {16, 16, 8}; |
| 446 |
bsp_trace_t trace; |
| 447 |
|
| 448 |
modelnum = reach->facenum & 0x0000FFFF; |
| 449 |
|
| 450 |
AAS_BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, NULL); |
| 451 |
|
| 452 |
if (!AAS_OriginOfMoverWithModelNum(modelnum, modelorigin)) |
| 453 |
{ |
| 454 |
botimport.Print(PRT_MESSAGE, "no entity with model %d\n", modelnum); |
| 455 |
return qfalse; |
| 456 |
} |
| 457 |
|
| 458 |
for (i = 0; i < 2; i++) |
| 459 |
{ |
| 460 |
if (origin[i] > modelorigin[i] + maxs[i] + 16) return qfalse; |
| 461 |
if (origin[i] < modelorigin[i] + mins[i] - 16) return qfalse; |
| 462 |
} |
| 463 |
|
| 464 |
VectorCopy(origin, org); |
| 465 |
org[2] += 24; |
| 466 |
VectorCopy(origin, end); |
| 467 |
end[2] -= 48; |
| 468 |
|
| 469 |
trace = AAS_Trace(org, boxmins, boxmaxs, end, entnum, CONTENTS_SOLID|CONTENTS_PLAYERCLIP); |
| 470 |
if (!trace.startsolid && !trace.allsolid) |
| 471 |
{ |
| 472 |
|
| 473 |
if (trace.ent != ENTITYNUM_NONE && AAS_EntityModelNum(trace.ent) == modelnum) |
| 474 |
{ |
| 475 |
return qtrue; |
| 476 |
} |
| 477 |
} |
| 478 |
return qfalse; |
| 479 |
} |
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
int MoverDown(aas_reachability_t *reach) |
| 487 |
{ |
| 488 |
int modelnum; |
| 489 |
vec3_t mins, maxs, origin; |
| 490 |
vec3_t angles = {0, 0, 0}; |
| 491 |
|
| 492 |
modelnum = reach->facenum & 0x0000FFFF; |
| 493 |
|
| 494 |
AAS_BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, origin); |
| 495 |
|
| 496 |
if (!AAS_OriginOfMoverWithModelNum(modelnum, origin)) |
| 497 |
{ |
| 498 |
botimport.Print(PRT_MESSAGE, "no entity with model %d\n", modelnum); |
| 499 |
return qfalse; |
| 500 |
} |
| 501 |
|
| 502 |
if (origin[2] + maxs[2] < reach->start[2]) return qtrue; |
| 503 |
return qfalse; |
| 504 |
} |
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
void BotSetBrushModelTypes(void) |
| 512 |
{ |
| 513 |
int ent, modelnum; |
| 514 |
char classname[MAX_EPAIRKEY], model[MAX_EPAIRKEY]; |
| 515 |
|
| 516 |
Com_Memset(modeltypes, 0, MAX_MODELS * sizeof(int)); |
| 517 |
|
| 518 |
for (ent = AAS_NextBSPEntity(0); ent; ent = AAS_NextBSPEntity(ent)) |
| 519 |
{ |
| 520 |
if (!AAS_ValueForBSPEpairKey(ent, "classname", classname, MAX_EPAIRKEY)) continue; |
| 521 |
if (!AAS_ValueForBSPEpairKey(ent, "model", model, MAX_EPAIRKEY)) continue; |
| 522 |
if (model[0]) modelnum = atoi(model+1); |
| 523 |
else modelnum = 0; |
| 524 |
|
| 525 |
if (modelnum < 0 || modelnum >= MAX_MODELS) |
| 526 |
{ |
| 527 |
botimport.Print(PRT_MESSAGE, "entity %s model number out of range\n", classname); |
| 528 |
continue; |
| 529 |
} |
| 530 |
|
| 531 |
if (!Q_stricmp(classname, "func_bobbing")) |
| 532 |
modeltypes[modelnum] = MODELTYPE_FUNC_BOB; |
| 533 |
else if (!Q_stricmp(classname, "func_plat")) |
| 534 |
modeltypes[modelnum] = MODELTYPE_FUNC_PLAT; |
| 535 |
else if (!Q_stricmp(classname, "func_door")) |
| 536 |
modeltypes[modelnum] = MODELTYPE_FUNC_DOOR; |
| 537 |
else if (!Q_stricmp(classname, "func_static")) |
| 538 |
modeltypes[modelnum] = MODELTYPE_FUNC_STATIC; |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
int BotOnTopOfEntity(bot_movestate_t *ms) |
| 548 |
{ |
| 549 |
vec3_t mins, maxs, end, up = {0, 0, 1}; |
| 550 |
bsp_trace_t trace; |
| 551 |
|
| 552 |
AAS_PresenceTypeBoundingBox(ms->presencetype, mins, maxs); |
| 553 |
VectorMA(ms->origin, -3, up, end); |
| 554 |
trace = AAS_Trace(ms->origin, mins, maxs, end, ms->entitynum, CONTENTS_SOLID|CONTENTS_PLAYERCLIP); |
| 555 |
if (!trace.startsolid && (trace.ent != ENTITYNUM_WORLD && trace.ent != ENTITYNUM_NONE) ) |
| 556 |
{ |
| 557 |
return trace.ent; |
| 558 |
} |
| 559 |
return -1; |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
int BotValidTravel(vec3_t origin, aas_reachability_t *reach, int travelflags) |
| 568 |
{ |
| 569 |
|
| 570 |
if (AAS_TravelFlagForType(reach->traveltype) & ~travelflags) return qfalse; |
| 571 |
|
| 572 |
if (AAS_AreaContentsTravelFlags(reach->areanum) & ~travelflags) return qfalse; |
| 573 |
return qtrue; |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
void BotAddToAvoidReach(bot_movestate_t *ms, int number, float avoidtime) |
| 582 |
{ |
| 583 |
int i; |
| 584 |
|
| 585 |
for (i = 0; i < MAX_AVOIDREACH; i++) |
| 586 |
{ |
| 587 |
if (ms->avoidreach[i] == number) |
| 588 |
{ |
| 589 |
if (ms->avoidreachtimes[i] > AAS_Time()) ms->avoidreachtries[i]++; |
| 590 |
else ms->avoidreachtries[i] = 1; |
| 591 |
ms->avoidreachtimes[i] = AAS_Time() + avoidtime; |
| 592 |
return; |
| 593 |
} |
| 594 |
} |
| 595 |
|
| 596 |
for (i = 0; i < MAX_AVOIDREACH; i++) |
| 597 |
{ |
| 598 |
if (ms->avoidreachtimes[i] < AAS_Time()) |
| 599 |
{ |
| 600 |
ms->avoidreach[i] = number; |
| 601 |
ms->avoidreachtimes[i] = AAS_Time() + avoidtime; |
| 602 |
ms->avoidreachtries[i] = 1; |
| 603 |
return; |
| 604 |
} |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
float DistanceFromLineSquared(vec3_t p, vec3_t lp1, vec3_t lp2) |
| 614 |
{ |
| 615 |
vec3_t proj, dir; |
| 616 |
int j; |
| 617 |
|
| 618 |
AAS_ProjectPointOntoVector(p, lp1, lp2, proj); |
| 619 |
for (j = 0; j < 3; j++) |
| 620 |
if ((proj[j] > lp1[j] && proj[j] > lp2[j]) || |
| 621 |
(proj[j] < lp1[j] && proj[j] < lp2[j])) |
| 622 |
break; |
| 623 |
if (j < 3) { |
| 624 |
if (fabs(proj[j] - lp1[j]) < fabs(proj[j] - lp2[j])) |
| 625 |
VectorSubtract(p, lp1, dir); |
| 626 |
else |
| 627 |
VectorSubtract(p, lp2, dir); |
| 628 |
return VectorLengthSquared(dir); |
| 629 |
} |
| 630 |
VectorSubtract(p, proj, dir); |
| 631 |
return VectorLengthSquared(dir); |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
float VectorDistanceSquared(vec3_t p1, vec3_t p2) |
| 640 |
{ |
| 641 |
vec3_t dir; |
| 642 |
VectorSubtract(p2, p1, dir); |
| 643 |
return VectorLengthSquared(dir); |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
int BotAvoidSpots(vec3_t origin, aas_reachability_t *reach, bot_avoidspot_t *avoidspots, int numavoidspots) |
| 652 |
{ |
| 653 |
int checkbetween, i, type; |
| 654 |
float squareddist, squaredradius; |
| 655 |
|
| 656 |
switch(reach->traveltype & TRAVELTYPE_MASK) |
| 657 |
{ |
| 658 |
case TRAVEL_WALK: checkbetween = qtrue; break; |
| 659 |
case TRAVEL_CROUCH: checkbetween = qtrue; break; |
| 660 |
case TRAVEL_BARRIERJUMP: checkbetween = qtrue; break; |
| 661 |
case TRAVEL_LADDER: checkbetween = qtrue; break; |
| 662 |
case TRAVEL_WALKOFFLEDGE: checkbetween = qfalse; break; |
| 663 |
case TRAVEL_JUMP: checkbetween = qfalse; break; |
| 664 |
case TRAVEL_SWIM: checkbetween = qtrue; break; |
| 665 |
case TRAVEL_WATERJUMP: checkbetween = qtrue; break; |
| 666 |
case TRAVEL_TELEPORT: checkbetween = qfalse; break; |
| 667 |
case TRAVEL_ELEVATOR: checkbetween = qfalse; break; |
| 668 |
case TRAVEL_GRAPPLEHOOK: checkbetween = qfalse; break; |
| 669 |
case TRAVEL_ROCKETJUMP: checkbetween = qfalse; break; |
| 670 |
case TRAVEL_BFGJUMP: checkbetween = qfalse; break; |
| 671 |
case TRAVEL_JUMPPAD: checkbetween = qfalse; break; |
| 672 |
case TRAVEL_FUNCBOB: checkbetween = qfalse; break; |
| 673 |
default: checkbetween = qtrue; break; |
| 674 |
} |
| 675 |
|
| 676 |
type = AVOID_CLEAR; |
| 677 |
for (i = 0; i < numavoidspots; i++) |
| 678 |
{ |
| 679 |
squaredradius = Square(avoidspots[i].radius); |
| 680 |
squareddist = DistanceFromLineSquared(avoidspots[i].origin, origin, reach->start); |
| 681 |
|
| 682 |
if (squareddist < squaredradius && |
| 683 |
VectorDistanceSquared(avoidspots[i].origin, origin) > squareddist) |
| 684 |
{ |
| 685 |
type = avoidspots[i].type; |
| 686 |
} |
| 687 |
else if (checkbetween) { |
| 688 |
squareddist = DistanceFromLineSquared(avoidspots[i].origin, reach->start, reach->end); |
| 689 |
|
| 690 |
if (squareddist < squaredradius && |
| 691 |
VectorDistanceSquared(avoidspots[i].origin, reach->start) > squareddist) |
| 692 |
{ |
| 693 |
type = avoidspots[i].type; |
| 694 |
} |
| 695 |
} |
| 696 |
else |
| 697 |
{ |
| 698 |
VectorDistanceSquared(avoidspots[i].origin, reach->end); |
| 699 |
|
| 700 |
if (squareddist < squaredradius && |
| 701 |
VectorDistanceSquared(avoidspots[i].origin, reach->start) > squareddist) |
| 702 |
{ |
| 703 |
type = avoidspots[i].type; |
| 704 |
} |
| 705 |
} |
| 706 |
if (type == AVOID_ALWAYS) |
| 707 |
return type; |
| 708 |
} |
| 709 |
return type; |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
void BotAddAvoidSpot(int movestate, vec3_t origin, float radius, int type) |
| 718 |
{ |
| 719 |
bot_movestate_t *ms; |
| 720 |
|
| 721 |
ms = BotMoveStateFromHandle(movestate); |
| 722 |
if (!ms) return; |
| 723 |
if (type == AVOID_CLEAR) |
| 724 |
{ |
| 725 |
ms->numavoidspots = 0; |
| 726 |
return; |
| 727 |
} |
| 728 |
|
| 729 |
if (ms->numavoidspots >= MAX_AVOIDSPOTS) |
| 730 |
return; |
| 731 |
VectorCopy(origin, ms->avoidspots[ms->numavoidspots].origin); |
| 732 |
ms->avoidspots[ms->numavoidspots].radius = radius; |
| 733 |
ms->avoidspots[ms->numavoidspots].type = type; |
| 734 |
ms->numavoidspots++; |
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
int BotGetReachabilityToGoal(vec3_t origin, int areanum, |
| 743 |
int lastgoalareanum, int lastareanum, |
| 744 |
int *avoidreach, float *avoidreachtimes, int *avoidreachtries, |
| 745 |
bot_goal_t *goal, int travelflags, |
| 746 |
struct bot_avoidspot_s *avoidspots, int numavoidspots, int *flags) |
| 747 |
{ |
| 748 |
int i, t, besttime, bestreachnum, reachnum; |
| 749 |
aas_reachability_t reach; |
| 750 |
|
| 751 |
|
| 752 |
if (!areanum) return 0; |
| 753 |
|
| 754 |
if (AAS_AreaDoNotEnter(areanum) || AAS_AreaDoNotEnter(goal->areanum)) |
| 755 |
{ |
| 756 |
travelflags |= TFL_DONOTENTER; |
| 757 |
} |
| 758 |
|
| 759 |
besttime = 0; |
| 760 |
bestreachnum = 0; |
| 761 |
|
| 762 |
for (reachnum = AAS_NextAreaReachability(areanum, 0); reachnum; |
| 763 |
reachnum = AAS_NextAreaReachability(areanum, reachnum)) |
| 764 |
{ |
| 765 |
#ifdef AVOIDREACH |
| 766 |
|
| 767 |
for (i = 0; i < MAX_AVOIDREACH; i++) |
| 768 |
{ |
| 769 |
if (avoidreach[i] == reachnum && avoidreachtimes[i] >= AAS_Time()) break; |
| 770 |
} |
| 771 |
if (i != MAX_AVOIDREACH && avoidreachtries[i] > AVOIDREACH_TRIES) |
| 772 |
{ |
| 773 |
#ifdef DEBUG |
| 774 |
if (botDeveloper) |
| 775 |
{ |
| 776 |
botimport.Print(PRT_MESSAGE, "avoiding reachability %d\n", avoidreach[i]); |
| 777 |
} |
| 778 |
#endif |
| 779 |
continue; |
| 780 |
} |
| 781 |
#endif |
| 782 |
|
| 783 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 784 |
|
| 785 |
|
| 786 |
if (lastgoalareanum == goal->areanum && reach.areanum == lastareanum) continue; |
| 787 |
|
| 788 |
|
| 789 |
if (!BotValidTravel(origin, &reach, travelflags)) continue; |
| 790 |
|
| 791 |
t = AAS_AreaTravelTimeToGoalArea(reach.areanum, reach.end, goal->areanum, travelflags); |
| 792 |
|
| 793 |
if (!t) continue; |
| 794 |
|
| 795 |
if (BotAvoidSpots(origin, &reach, avoidspots, numavoidspots)) { |
| 796 |
if (flags) { |
| 797 |
*flags |= MOVERESULT_BLOCKEDBYAVOIDSPOT; |
| 798 |
} |
| 799 |
continue; |
| 800 |
} |
| 801 |
|
| 802 |
t += reach.traveltime; |
| 803 |
|
| 804 |
if (!besttime || t < besttime) |
| 805 |
{ |
| 806 |
besttime = t; |
| 807 |
bestreachnum = reachnum; |
| 808 |
} |
| 809 |
} |
| 810 |
|
| 811 |
return bestreachnum; |
| 812 |
} |
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
int BotAddToTarget(vec3_t start, vec3_t end, float maxdist, float *dist, vec3_t target) |
| 820 |
{ |
| 821 |
vec3_t dir; |
| 822 |
float curdist; |
| 823 |
|
| 824 |
VectorSubtract(end, start, dir); |
| 825 |
curdist = VectorNormalize(dir); |
| 826 |
if (*dist + curdist < maxdist) |
| 827 |
{ |
| 828 |
VectorCopy(end, target); |
| 829 |
*dist += curdist; |
| 830 |
return qfalse; |
| 831 |
} |
| 832 |
else |
| 833 |
{ |
| 834 |
VectorMA(start, maxdist - *dist, dir, target); |
| 835 |
*dist = maxdist; |
| 836 |
return qtrue; |
| 837 |
} |
| 838 |
} |
| 839 |
|
| 840 |
int BotMovementViewTarget(int movestate, bot_goal_t *goal, int travelflags, float lookahead, vec3_t target) |
| 841 |
{ |
| 842 |
aas_reachability_t reach; |
| 843 |
int reachnum, lastareanum; |
| 844 |
bot_movestate_t *ms; |
| 845 |
vec3_t end; |
| 846 |
float dist; |
| 847 |
|
| 848 |
ms = BotMoveStateFromHandle(movestate); |
| 849 |
if (!ms) return qfalse; |
| 850 |
|
| 851 |
if (!ms->lastreachnum || !goal) return qfalse; |
| 852 |
|
| 853 |
reachnum = ms->lastreachnum; |
| 854 |
VectorCopy(ms->origin, end); |
| 855 |
lastareanum = ms->lastareanum; |
| 856 |
dist = 0; |
| 857 |
while(reachnum && dist < lookahead) |
| 858 |
{ |
| 859 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 860 |
if (BotAddToTarget(end, reach.start, lookahead, &dist, target)) return qtrue; |
| 861 |
|
| 862 |
if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_TELEPORT) return qtrue; |
| 863 |
|
| 864 |
if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_ROCKETJUMP) return qtrue; |
| 865 |
if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_BFGJUMP) return qtrue; |
| 866 |
|
| 867 |
if ((reach.traveltype & TRAVELTYPE_MASK) != TRAVEL_JUMPPAD && |
| 868 |
(reach.traveltype & TRAVELTYPE_MASK) != TRAVEL_ELEVATOR && |
| 869 |
(reach.traveltype & TRAVELTYPE_MASK) != TRAVEL_FUNCBOB) |
| 870 |
{ |
| 871 |
if (BotAddToTarget(reach.start, reach.end, lookahead, &dist, target)) return qtrue; |
| 872 |
} |
| 873 |
reachnum = BotGetReachabilityToGoal(reach.end, reach.areanum, |
| 874 |
ms->lastgoalareanum, lastareanum, |
| 875 |
ms->avoidreach, ms->avoidreachtimes, ms->avoidreachtries, |
| 876 |
goal, travelflags, NULL, 0, NULL); |
| 877 |
VectorCopy(reach.end, end); |
| 878 |
lastareanum = reach.areanum; |
| 879 |
if (lastareanum == goal->areanum) |
| 880 |
{ |
| 881 |
BotAddToTarget(reach.end, goal->origin, lookahead, &dist, target); |
| 882 |
return qtrue; |
| 883 |
} |
| 884 |
} |
| 885 |
|
| 886 |
return qfalse; |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
int BotVisible(int ent, vec3_t eye, vec3_t target) |
| 895 |
{ |
| 896 |
bsp_trace_t trace; |
| 897 |
|
| 898 |
trace = AAS_Trace(eye, NULL, NULL, target, ent, CONTENTS_SOLID|CONTENTS_PLAYERCLIP); |
| 899 |
if (trace.fraction >= 1) return qtrue; |
| 900 |
return qfalse; |
| 901 |
} |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
int BotPredictVisiblePosition(vec3_t origin, int areanum, bot_goal_t *goal, int travelflags, vec3_t target) |
| 909 |
{ |
| 910 |
aas_reachability_t reach; |
| 911 |
int reachnum, lastgoalareanum, lastareanum, i; |
| 912 |
int avoidreach[MAX_AVOIDREACH]; |
| 913 |
float avoidreachtimes[MAX_AVOIDREACH]; |
| 914 |
int avoidreachtries[MAX_AVOIDREACH]; |
| 915 |
vec3_t end; |
| 916 |
|
| 917 |
|
| 918 |
if (!goal) return qfalse; |
| 919 |
|
| 920 |
if (!areanum) return qfalse; |
| 921 |
|
| 922 |
if (!goal->areanum) return qfalse; |
| 923 |
|
| 924 |
Com_Memset(avoidreach, 0, MAX_AVOIDREACH * sizeof(int)); |
| 925 |
lastgoalareanum = goal->areanum; |
| 926 |
lastareanum = areanum; |
| 927 |
VectorCopy(origin, end); |
| 928 |
|
| 929 |
for (i = 0; i < 20 && (areanum != goal->areanum); i++) |
| 930 |
{ |
| 931 |
|
| 932 |
reachnum = BotGetReachabilityToGoal(end, areanum, |
| 933 |
lastgoalareanum, lastareanum, |
| 934 |
avoidreach, avoidreachtimes, avoidreachtries, |
| 935 |
goal, travelflags, NULL, 0, NULL); |
| 936 |
if (!reachnum) return qfalse; |
| 937 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 938 |
|
| 939 |
if (BotVisible(goal->entitynum, goal->origin, reach.start)) |
| 940 |
{ |
| 941 |
VectorCopy(reach.start, target); |
| 942 |
return qtrue; |
| 943 |
} |
| 944 |
|
| 945 |
if (BotVisible(goal->entitynum, goal->origin, reach.end)) |
| 946 |
{ |
| 947 |
VectorCopy(reach.end, target); |
| 948 |
return qtrue; |
| 949 |
} |
| 950 |
|
| 951 |
if (reach.areanum == goal->areanum) |
| 952 |
{ |
| 953 |
VectorCopy(reach.end, target); |
| 954 |
return qtrue; |
| 955 |
} |
| 956 |
|
| 957 |
lastareanum = areanum; |
| 958 |
areanum = reach.areanum; |
| 959 |
VectorCopy(reach.end, end); |
| 960 |
|
| 961 |
} |
| 962 |
|
| 963 |
return qfalse; |
| 964 |
} |
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
void MoverBottomCenter(aas_reachability_t *reach, vec3_t bottomcenter) |
| 972 |
{ |
| 973 |
int modelnum; |
| 974 |
vec3_t mins, maxs, origin, mids; |
| 975 |
vec3_t angles = {0, 0, 0}; |
| 976 |
|
| 977 |
modelnum = reach->facenum & 0x0000FFFF; |
| 978 |
|
| 979 |
AAS_BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, origin); |
| 980 |
|
| 981 |
if (!AAS_OriginOfMoverWithModelNum(modelnum, origin)) |
| 982 |
{ |
| 983 |
botimport.Print(PRT_MESSAGE, "no entity with model %d\n", modelnum); |
| 984 |
} |
| 985 |
|
| 986 |
VectorAdd(mins, maxs, mids); |
| 987 |
VectorMA(origin, 0.5, mids, bottomcenter); |
| 988 |
bottomcenter[2] = reach->start[2]; |
| 989 |
} |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
float BotGapDistance(vec3_t origin, vec3_t hordir, int entnum) |
| 997 |
{ |
| 998 |
int dist; |
| 999 |
float startz; |
| 1000 |
vec3_t start, end; |
| 1001 |
aas_trace_t trace; |
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
{ |
| 1007 |
VectorCopy(origin, start); |
| 1008 |
VectorCopy(origin, end); |
| 1009 |
end[2] -= 60; |
| 1010 |
trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, entnum); |
| 1011 |
if (trace.fraction >= 1) return 1; |
| 1012 |
startz = trace.endpos[2] + 1; |
| 1013 |
} |
| 1014 |
|
| 1015 |
for (dist = 8; dist <= 100; dist += 8) |
| 1016 |
{ |
| 1017 |
VectorMA(origin, dist, hordir, start); |
| 1018 |
start[2] = startz + 24; |
| 1019 |
VectorCopy(start, end); |
| 1020 |
end[2] -= 48 + sv_maxbarrier->value; |
| 1021 |
trace = AAS_TraceClientBBox(start, end, PRESENCE_CROUCH, entnum); |
| 1022 |
|
| 1023 |
if (!trace.startsolid) |
| 1024 |
{ |
| 1025 |
|
| 1026 |
if (trace.endpos[2] < startz - sv_maxstep->value - 8) |
| 1027 |
{ |
| 1028 |
VectorCopy(trace.endpos, end); |
| 1029 |
end[2] -= 20; |
| 1030 |
if (AAS_PointContents(end) & CONTENTS_WATER) break; |
| 1031 |
|
| 1032 |
|
| 1033 |
return dist; |
| 1034 |
} |
| 1035 |
startz = trace.endpos[2]; |
| 1036 |
} |
| 1037 |
} |
| 1038 |
return 0; |
| 1039 |
} |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
int BotCheckBarrierJump(bot_movestate_t *ms, vec3_t dir, float speed) |
| 1047 |
{ |
| 1048 |
vec3_t start, hordir, end; |
| 1049 |
aas_trace_t trace; |
| 1050 |
|
| 1051 |
VectorCopy(ms->origin, end); |
| 1052 |
end[2] += sv_maxbarrier->value; |
| 1053 |
|
| 1054 |
trace = AAS_TraceClientBBox(ms->origin, end, PRESENCE_NORMAL, ms->entitynum); |
| 1055 |
|
| 1056 |
if (trace.startsolid) return qfalse; |
| 1057 |
|
| 1058 |
if (trace.endpos[2] - ms->origin[2] < sv_maxstep->value) return qfalse; |
| 1059 |
|
| 1060 |
hordir[0] = dir[0]; |
| 1061 |
hordir[1] = dir[1]; |
| 1062 |
hordir[2] = 0; |
| 1063 |
VectorNormalize(hordir); |
| 1064 |
VectorMA(ms->origin, ms->thinktime * speed * 0.5, hordir, end); |
| 1065 |
VectorCopy(trace.endpos, start); |
| 1066 |
end[2] = trace.endpos[2]; |
| 1067 |
|
| 1068 |
trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, ms->entitynum); |
| 1069 |
|
| 1070 |
if (trace.startsolid) return qfalse; |
| 1071 |
|
| 1072 |
VectorCopy(trace.endpos, start); |
| 1073 |
VectorCopy(trace.endpos, end); |
| 1074 |
end[2] = ms->origin[2]; |
| 1075 |
|
| 1076 |
trace = AAS_TraceClientBBox(start, end, PRESENCE_NORMAL, ms->entitynum); |
| 1077 |
|
| 1078 |
if (trace.startsolid) return qfalse; |
| 1079 |
|
| 1080 |
if (trace.fraction >= 1.0) return qfalse; |
| 1081 |
|
| 1082 |
if (trace.endpos[2] - ms->origin[2] < sv_maxstep->value) return qfalse; |
| 1083 |
|
| 1084 |
EA_Jump(ms->client); |
| 1085 |
EA_Move(ms->client, hordir, speed); |
| 1086 |
ms->moveflags |= MFL_BARRIERJUMP; |
| 1087 |
|
| 1088 |
return qtrue; |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
int BotSwimInDirection(bot_movestate_t *ms, vec3_t dir, float speed, int type) |
| 1097 |
{ |
| 1098 |
vec3_t normdir; |
| 1099 |
|
| 1100 |
VectorCopy(dir, normdir); |
| 1101 |
VectorNormalize(normdir); |
| 1102 |
EA_Move(ms->client, normdir, speed); |
| 1103 |
return qtrue; |
| 1104 |
} |
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
int BotWalkInDirection(bot_movestate_t *ms, vec3_t dir, float speed, int type) |
| 1112 |
{ |
| 1113 |
vec3_t hordir, cmdmove, velocity, tmpdir, origin; |
| 1114 |
int presencetype, maxframes, cmdframes, stopevent; |
| 1115 |
aas_clientmove_t move; |
| 1116 |
float dist; |
| 1117 |
|
| 1118 |
if (AAS_OnGround(ms->origin, ms->presencetype, ms->entitynum)) ms->moveflags |= MFL_ONGROUND; |
| 1119 |
|
| 1120 |
if (ms->moveflags & MFL_ONGROUND) |
| 1121 |
{ |
| 1122 |
|
| 1123 |
if (BotCheckBarrierJump(ms, dir, speed)) return qtrue; |
| 1124 |
|
| 1125 |
ms->moveflags &= ~MFL_BARRIERJUMP; |
| 1126 |
|
| 1127 |
if ((type & MOVE_CROUCH) && !(type & MOVE_JUMP)) presencetype = PRESENCE_CROUCH; |
| 1128 |
else presencetype = PRESENCE_NORMAL; |
| 1129 |
|
| 1130 |
hordir[0] = dir[0]; |
| 1131 |
hordir[1] = dir[1]; |
| 1132 |
hordir[2] = 0; |
| 1133 |
VectorNormalize(hordir); |
| 1134 |
|
| 1135 |
if (!(type & MOVE_JUMP)) |
| 1136 |
{ |
| 1137 |
|
| 1138 |
if (BotGapDistance(ms->origin, hordir, ms->entitynum) > 0) type |= MOVE_JUMP; |
| 1139 |
} |
| 1140 |
|
| 1141 |
VectorScale(hordir, speed, cmdmove); |
| 1142 |
VectorCopy(ms->velocity, velocity); |
| 1143 |
|
| 1144 |
if (type & MOVE_JUMP) |
| 1145 |
{ |
| 1146 |
|
| 1147 |
cmdmove[2] = 400; |
| 1148 |
maxframes = PREDICTIONTIME_JUMP / 0.1; |
| 1149 |
cmdframes = 1; |
| 1150 |
stopevent = SE_HITGROUND|SE_HITGROUNDDAMAGE| |
| 1151 |
SE_ENTERWATER|SE_ENTERSLIME|SE_ENTERLAVA; |
| 1152 |
} |
| 1153 |
else |
| 1154 |
{ |
| 1155 |
maxframes = 2; |
| 1156 |
cmdframes = 2; |
| 1157 |
stopevent = SE_HITGROUNDDAMAGE| |
| 1158 |
SE_ENTERWATER|SE_ENTERSLIME|SE_ENTERLAVA; |
| 1159 |
} |
| 1160 |
|
| 1161 |
|
| 1162 |
VectorCopy(ms->origin, origin); |
| 1163 |
origin[2] += 0.5; |
| 1164 |
AAS_PredictClientMovement(&move, ms->entitynum, origin, presencetype, qtrue, |
| 1165 |
velocity, cmdmove, cmdframes, maxframes, 0.1f, |
| 1166 |
stopevent, 0, qfalse); |
| 1167 |
|
| 1168 |
if (move.frames >= maxframes && (type & MOVE_JUMP)) |
| 1169 |
{ |
| 1170 |
|
| 1171 |
return qfalse; |
| 1172 |
} |
| 1173 |
|
| 1174 |
if (move.stopevent & (SE_ENTERSLIME|SE_ENTERLAVA|SE_HITGROUNDDAMAGE)) |
| 1175 |
{ |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
return qfalse; |
| 1181 |
} |
| 1182 |
|
| 1183 |
if (move.stopevent & SE_HITGROUND) |
| 1184 |
{ |
| 1185 |
|
| 1186 |
VectorNormalize2(move.velocity, tmpdir); |
| 1187 |
dist = BotGapDistance(move.endpos, tmpdir, ms->entitynum); |
| 1188 |
if (dist > 0) return qfalse; |
| 1189 |
|
| 1190 |
dist = BotGapDistance(move.endpos, hordir, ms->entitynum); |
| 1191 |
if (dist > 0) return qfalse; |
| 1192 |
} |
| 1193 |
|
| 1194 |
tmpdir[0] = move.endpos[0] - ms->origin[0]; |
| 1195 |
tmpdir[1] = move.endpos[1] - ms->origin[1]; |
| 1196 |
tmpdir[2] = 0; |
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
if (VectorLength(tmpdir) < speed * ms->thinktime * 0.5) return qfalse; |
| 1201 |
|
| 1202 |
if (type & MOVE_JUMP) EA_Jump(ms->client); |
| 1203 |
if (type & MOVE_CROUCH) EA_Crouch(ms->client); |
| 1204 |
EA_Move(ms->client, hordir, speed); |
| 1205 |
|
| 1206 |
return qtrue; |
| 1207 |
} |
| 1208 |
else |
| 1209 |
{ |
| 1210 |
if (ms->moveflags & MFL_BARRIERJUMP) |
| 1211 |
{ |
| 1212 |
|
| 1213 |
if (ms->velocity[2] < 50) |
| 1214 |
{ |
| 1215 |
EA_Move(ms->client, dir, speed); |
| 1216 |
} |
| 1217 |
} |
| 1218 |
|
| 1219 |
return qtrue; |
| 1220 |
} |
| 1221 |
} |
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
int BotMoveInDirection(int movestate, vec3_t dir, float speed, int type) |
| 1229 |
{ |
| 1230 |
bot_movestate_t *ms; |
| 1231 |
|
| 1232 |
ms = BotMoveStateFromHandle(movestate); |
| 1233 |
if (!ms) return qfalse; |
| 1234 |
|
| 1235 |
if (AAS_Swimming(ms->origin)) |
| 1236 |
{ |
| 1237 |
return BotSwimInDirection(ms, dir, speed, type); |
| 1238 |
} |
| 1239 |
else |
| 1240 |
{ |
| 1241 |
return BotWalkInDirection(ms, dir, speed, type); |
| 1242 |
} |
| 1243 |
} |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
int Intersection(vec2_t p1, vec2_t p2, vec2_t p3, vec2_t p4, vec2_t out) |
| 1251 |
{ |
| 1252 |
float x1, dx1, dy1, x2, dx2, dy2, d; |
| 1253 |
|
| 1254 |
dx1 = p2[0] - p1[0]; |
| 1255 |
dy1 = p2[1] - p1[1]; |
| 1256 |
dx2 = p4[0] - p3[0]; |
| 1257 |
dy2 = p4[1] - p3[1]; |
| 1258 |
|
| 1259 |
d = dy1 * dx2 - dx1 * dy2; |
| 1260 |
if (d != 0) |
| 1261 |
{ |
| 1262 |
x1 = p1[1] * dx1 - p1[0] * dy1; |
| 1263 |
x2 = p3[1] * dx2 - p3[0] * dy2; |
| 1264 |
out[0] = (int) ((dx1 * x2 - dx2 * x1) / d); |
| 1265 |
out[1] = (int) ((dy1 * x2 - dy2 * x1) / d); |
| 1266 |
return qtrue; |
| 1267 |
} |
| 1268 |
else |
| 1269 |
{ |
| 1270 |
return qfalse; |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
void BotCheckBlocked(bot_movestate_t *ms, vec3_t dir, int checkbottom, bot_moveresult_t *result) |
| 1280 |
{ |
| 1281 |
vec3_t mins, maxs, end, up = {0, 0, 1}; |
| 1282 |
bsp_trace_t trace; |
| 1283 |
|
| 1284 |
|
| 1285 |
AAS_PresenceTypeBoundingBox(ms->presencetype, mins, maxs); |
| 1286 |
|
| 1287 |
if (fabs(DotProduct(dir, up)) < 0.7) |
| 1288 |
{ |
| 1289 |
mins[2] += sv_maxstep->value; |
| 1290 |
maxs[2] -= 10; |
| 1291 |
} |
| 1292 |
VectorMA(ms->origin, 3, dir, end); |
| 1293 |
trace = AAS_Trace(ms->origin, mins, maxs, end, ms->entitynum, CONTENTS_SOLID|CONTENTS_PLAYERCLIP|CONTENTS_BODY); |
| 1294 |
|
| 1295 |
if (!trace.startsolid && (trace.ent != ENTITYNUM_WORLD && trace.ent != ENTITYNUM_NONE) ) |
| 1296 |
{ |
| 1297 |
result->blocked = qtrue; |
| 1298 |
result->blockentity = trace.ent; |
| 1299 |
#ifdef DEBUG |
| 1300 |
|
| 1301 |
#endif |
| 1302 |
} |
| 1303 |
|
| 1304 |
else if (checkbottom && !AAS_AreaReachability(ms->areanum)) |
| 1305 |
{ |
| 1306 |
|
| 1307 |
AAS_PresenceTypeBoundingBox(ms->presencetype, mins, maxs); |
| 1308 |
VectorMA(ms->origin, -3, up, end); |
| 1309 |
trace = AAS_Trace(ms->origin, mins, maxs, end, ms->entitynum, CONTENTS_SOLID|CONTENTS_PLAYERCLIP); |
| 1310 |
if (!trace.startsolid && (trace.ent != ENTITYNUM_WORLD && trace.ent != ENTITYNUM_NONE) ) |
| 1311 |
{ |
| 1312 |
result->blocked = qtrue; |
| 1313 |
result->blockentity = trace.ent; |
| 1314 |
result->flags |= MOVERESULT_ONTOPOFOBSTACLE; |
| 1315 |
#ifdef DEBUG |
| 1316 |
|
| 1317 |
#endif |
| 1318 |
} |
| 1319 |
} |
| 1320 |
} |
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
bot_moveresult_t BotTravel_Walk(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1328 |
{ |
| 1329 |
float dist, speed; |
| 1330 |
vec3_t hordir; |
| 1331 |
bot_moveresult_t_cleared( result ); |
| 1332 |
|
| 1333 |
|
| 1334 |
hordir[0] = reach->start[0] - ms->origin[0]; |
| 1335 |
hordir[1] = reach->start[1] - ms->origin[1]; |
| 1336 |
hordir[2] = 0; |
| 1337 |
dist = VectorNormalize(hordir); |
| 1338 |
|
| 1339 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 1340 |
|
| 1341 |
if (dist < 10) |
| 1342 |
{ |
| 1343 |
|
| 1344 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 1345 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 1346 |
hordir[2] = 0; |
| 1347 |
dist = VectorNormalize(hordir); |
| 1348 |
} |
| 1349 |
|
| 1350 |
if (!(AAS_AreaPresenceType(reach->areanum) & PRESENCE_NORMAL)) |
| 1351 |
{ |
| 1352 |
|
| 1353 |
if (dist < 20) EA_Crouch(ms->client); |
| 1354 |
} |
| 1355 |
|
| 1356 |
dist = BotGapDistance(ms->origin, hordir, ms->entitynum); |
| 1357 |
|
| 1358 |
if (ms->moveflags & MFL_WALK) |
| 1359 |
{ |
| 1360 |
if (dist > 0) speed = 200 - (180 - 1 * dist); |
| 1361 |
else speed = 200; |
| 1362 |
EA_Walk(ms->client); |
| 1363 |
} |
| 1364 |
else |
| 1365 |
{ |
| 1366 |
if (dist > 0) speed = 400 - (360 - 2 * dist); |
| 1367 |
else speed = 400; |
| 1368 |
} |
| 1369 |
|
| 1370 |
EA_Move(ms->client, hordir, speed); |
| 1371 |
VectorCopy(hordir, result.movedir); |
| 1372 |
|
| 1373 |
return result; |
| 1374 |
} |
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
bot_moveresult_t BotFinishTravel_Walk(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1382 |
{ |
| 1383 |
vec3_t hordir; |
| 1384 |
float dist, speed; |
| 1385 |
bot_moveresult_t_cleared( result ); |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 1399 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 1400 |
hordir[2] = 0; |
| 1401 |
dist = VectorNormalize(hordir); |
| 1402 |
|
| 1403 |
if (dist > 100) dist = 100; |
| 1404 |
speed = 400 - (400 - 3 * dist); |
| 1405 |
|
| 1406 |
EA_Move(ms->client, hordir, speed); |
| 1407 |
VectorCopy(hordir, result.movedir); |
| 1408 |
|
| 1409 |
return result; |
| 1410 |
} |
| 1411 |
|
| 1412 |
|
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
bot_moveresult_t BotTravel_Crouch(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1418 |
{ |
| 1419 |
float speed; |
| 1420 |
vec3_t hordir; |
| 1421 |
bot_moveresult_t_cleared( result ); |
| 1422 |
|
| 1423 |
|
| 1424 |
speed = 400; |
| 1425 |
|
| 1426 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 1427 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 1428 |
hordir[2] = 0; |
| 1429 |
VectorNormalize(hordir); |
| 1430 |
|
| 1431 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 1432 |
|
| 1433 |
EA_Crouch(ms->client); |
| 1434 |
EA_Move(ms->client, hordir, speed); |
| 1435 |
|
| 1436 |
VectorCopy(hordir, result.movedir); |
| 1437 |
|
| 1438 |
return result; |
| 1439 |
} |
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
bot_moveresult_t BotTravel_BarrierJump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1447 |
{ |
| 1448 |
float dist, speed; |
| 1449 |
vec3_t hordir; |
| 1450 |
bot_moveresult_t_cleared( result ); |
| 1451 |
|
| 1452 |
|
| 1453 |
hordir[0] = reach->start[0] - ms->origin[0]; |
| 1454 |
hordir[1] = reach->start[1] - ms->origin[1]; |
| 1455 |
hordir[2] = 0; |
| 1456 |
dist = VectorNormalize(hordir); |
| 1457 |
|
| 1458 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 1459 |
|
| 1460 |
if (dist < 9) |
| 1461 |
{ |
| 1462 |
EA_Jump(ms->client); |
| 1463 |
} |
| 1464 |
else |
| 1465 |
{ |
| 1466 |
if (dist > 60) dist = 60; |
| 1467 |
speed = 360 - (360 - 6 * dist); |
| 1468 |
EA_Move(ms->client, hordir, speed); |
| 1469 |
} |
| 1470 |
VectorCopy(hordir, result.movedir); |
| 1471 |
|
| 1472 |
return result; |
| 1473 |
} |
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
bot_moveresult_t BotFinishTravel_BarrierJump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1481 |
{ |
| 1482 |
vec3_t hordir; |
| 1483 |
bot_moveresult_t_cleared( result ); |
| 1484 |
|
| 1485 |
|
| 1486 |
if (ms->velocity[2] < 250) |
| 1487 |
{ |
| 1488 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 1489 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 1490 |
hordir[2] = 0; |
| 1491 |
|
| 1492 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 1493 |
|
| 1494 |
EA_Move(ms->client, hordir, 400); |
| 1495 |
VectorCopy(hordir, result.movedir); |
| 1496 |
} |
| 1497 |
|
| 1498 |
return result; |
| 1499 |
} |
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
bot_moveresult_t BotTravel_Swim(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1507 |
{ |
| 1508 |
vec3_t dir; |
| 1509 |
bot_moveresult_t_cleared( result ); |
| 1510 |
|
| 1511 |
|
| 1512 |
VectorSubtract(reach->start, ms->origin, dir); |
| 1513 |
VectorNormalize(dir); |
| 1514 |
|
| 1515 |
BotCheckBlocked(ms, dir, qtrue, &result); |
| 1516 |
|
| 1517 |
EA_Move(ms->client, dir, 400); |
| 1518 |
|
| 1519 |
VectorCopy(dir, result.movedir); |
| 1520 |
Vector2Angles(dir, result.ideal_viewangles); |
| 1521 |
result.flags |= MOVERESULT_SWIMVIEW; |
| 1522 |
|
| 1523 |
return result; |
| 1524 |
} |
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
bot_moveresult_t BotTravel_WaterJump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1532 |
{ |
| 1533 |
vec3_t dir, hordir; |
| 1534 |
float dist; |
| 1535 |
bot_moveresult_t_cleared( result ); |
| 1536 |
|
| 1537 |
|
| 1538 |
VectorSubtract(reach->end, ms->origin, dir); |
| 1539 |
VectorCopy(dir, hordir); |
| 1540 |
hordir[2] = 0; |
| 1541 |
dir[2] += 15 + crandom() * 40; |
| 1542 |
|
| 1543 |
VectorNormalize(dir); |
| 1544 |
dist = VectorNormalize(hordir); |
| 1545 |
|
| 1546 |
|
| 1547 |
EA_MoveForward(ms->client); |
| 1548 |
|
| 1549 |
if (dist < 40) EA_MoveUp(ms->client); |
| 1550 |
|
| 1551 |
Vector2Angles(dir, result.ideal_viewangles); |
| 1552 |
result.flags |= MOVERESULT_MOVEMENTVIEW; |
| 1553 |
|
| 1554 |
VectorCopy(dir, result.movedir); |
| 1555 |
|
| 1556 |
return result; |
| 1557 |
} |
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
bot_moveresult_t BotFinishTravel_WaterJump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1565 |
{ |
| 1566 |
vec3_t dir, pnt; |
| 1567 |
bot_moveresult_t_cleared( result ); |
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
if (ms->moveflags & MFL_WATERJUMP) return result; |
| 1572 |
|
| 1573 |
|
| 1574 |
VectorCopy(ms->origin, pnt); |
| 1575 |
pnt[2] -= 32; |
| 1576 |
if (!(AAS_PointContents(pnt) & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER))) return result; |
| 1577 |
|
| 1578 |
VectorSubtract(reach->end, ms->origin, dir); |
| 1579 |
dir[0] += crandom() * 10; |
| 1580 |
dir[1] += crandom() * 10; |
| 1581 |
dir[2] += 70 + crandom() * 10; |
| 1582 |
|
| 1583 |
EA_Move(ms->client, dir, 400); |
| 1584 |
|
| 1585 |
Vector2Angles(dir, result.ideal_viewangles); |
| 1586 |
result.flags |= MOVERESULT_MOVEMENTVIEW; |
| 1587 |
|
| 1588 |
VectorCopy(dir, result.movedir); |
| 1589 |
|
| 1590 |
return result; |
| 1591 |
} |
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
bot_moveresult_t BotTravel_WalkOffLedge(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1599 |
{ |
| 1600 |
vec3_t hordir, dir; |
| 1601 |
float dist, speed, reachhordist; |
| 1602 |
bot_moveresult_t_cleared( result ); |
| 1603 |
|
| 1604 |
|
| 1605 |
VectorSubtract(reach->start, ms->origin, dir); |
| 1606 |
VectorNormalize(dir); |
| 1607 |
BotCheckBlocked(ms, dir, qtrue, &result); |
| 1608 |
|
| 1609 |
VectorSubtract(reach->end, reach->start, dir); |
| 1610 |
dir[2] = 0; |
| 1611 |
reachhordist = VectorLength(dir); |
| 1612 |
|
| 1613 |
hordir[0] = reach->start[0] - ms->origin[0]; |
| 1614 |
hordir[1] = reach->start[1] - ms->origin[1]; |
| 1615 |
hordir[2] = 0; |
| 1616 |
dist = VectorNormalize(hordir); |
| 1617 |
|
| 1618 |
if (dist < 48) |
| 1619 |
{ |
| 1620 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 1621 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 1622 |
hordir[2] = 0; |
| 1623 |
VectorNormalize(hordir); |
| 1624 |
|
| 1625 |
if (reachhordist < 20) |
| 1626 |
{ |
| 1627 |
speed = 100; |
| 1628 |
} |
| 1629 |
else if (!AAS_HorizontalVelocityForJump(0, reach->start, reach->end, &speed)) |
| 1630 |
{ |
| 1631 |
speed = 400; |
| 1632 |
} |
| 1633 |
} |
| 1634 |
else |
| 1635 |
{ |
| 1636 |
if (reachhordist < 20) |
| 1637 |
{ |
| 1638 |
if (dist > 64) dist = 64; |
| 1639 |
speed = 400 - (256 - 4 * dist); |
| 1640 |
} |
| 1641 |
else |
| 1642 |
{ |
| 1643 |
speed = 400; |
| 1644 |
} |
| 1645 |
} |
| 1646 |
|
| 1647 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 1648 |
|
| 1649 |
EA_Move(ms->client, hordir, speed); |
| 1650 |
VectorCopy(hordir, result.movedir); |
| 1651 |
|
| 1652 |
return result; |
| 1653 |
} |
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
int BotAirControl(vec3_t origin, vec3_t velocity, vec3_t goal, vec3_t dir, float *speed) |
| 1661 |
{ |
| 1662 |
vec3_t org, vel; |
| 1663 |
float dist; |
| 1664 |
int i; |
| 1665 |
|
| 1666 |
VectorCopy(origin, org); |
| 1667 |
VectorScale(velocity, 0.1, vel); |
| 1668 |
for (i = 0; i < 50; i++) |
| 1669 |
{ |
| 1670 |
vel[2] -= sv_gravity->value * 0.01; |
| 1671 |
|
| 1672 |
if (vel[2] < 0 && org[2] + vel[2] < goal[2]) |
| 1673 |
{ |
| 1674 |
VectorScale(vel, (goal[2] - org[2]) / vel[2], vel); |
| 1675 |
VectorAdd(org, vel, org); |
| 1676 |
VectorSubtract(goal, org, dir); |
| 1677 |
dist = VectorNormalize(dir); |
| 1678 |
if (dist > 32) dist = 32; |
| 1679 |
*speed = 400 - (400 - 13 * dist); |
| 1680 |
return qtrue; |
| 1681 |
} |
| 1682 |
else |
| 1683 |
{ |
| 1684 |
VectorAdd(org, vel, org); |
| 1685 |
} |
| 1686 |
} |
| 1687 |
VectorSet(dir, 0, 0, 0); |
| 1688 |
*speed = 400; |
| 1689 |
return qfalse; |
| 1690 |
} |
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
bot_moveresult_t BotFinishTravel_WalkOffLedge(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1698 |
{ |
| 1699 |
vec3_t dir, hordir, end, v; |
| 1700 |
float dist, speed; |
| 1701 |
bot_moveresult_t_cleared( result ); |
| 1702 |
|
| 1703 |
|
| 1704 |
VectorSubtract(reach->end, ms->origin, dir); |
| 1705 |
BotCheckBlocked(ms, dir, qtrue, &result); |
| 1706 |
|
| 1707 |
VectorSubtract(reach->end, ms->origin, v); |
| 1708 |
v[2] = 0; |
| 1709 |
dist = VectorNormalize(v); |
| 1710 |
if (dist > 16) VectorMA(reach->end, 16, v, end); |
| 1711 |
else VectorCopy(reach->end, end); |
| 1712 |
|
| 1713 |
if (!BotAirControl(ms->origin, ms->velocity, end, hordir, &speed)) |
| 1714 |
{ |
| 1715 |
|
| 1716 |
VectorCopy(dir, hordir); |
| 1717 |
hordir[2] = 0; |
| 1718 |
|
| 1719 |
speed = 400; |
| 1720 |
} |
| 1721 |
|
| 1722 |
EA_Move(ms->client, hordir, speed); |
| 1723 |
VectorCopy(hordir, result.movedir); |
| 1724 |
|
| 1725 |
return result; |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
|
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
bot_moveresult_t BotTravel_Jump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1855 |
{ |
| 1856 |
vec3_t hordir, dir1, dir2, start, end, runstart; |
| 1857 |
|
| 1858 |
int gapdist; |
| 1859 |
float dist1, dist2, speed; |
| 1860 |
bot_moveresult_t_cleared( result ); |
| 1861 |
|
| 1862 |
|
| 1863 |
AAS_JumpReachRunStart(reach, runstart); |
| 1864 |
|
| 1865 |
hordir[0] = runstart[0] - reach->start[0]; |
| 1866 |
hordir[1] = runstart[1] - reach->start[1]; |
| 1867 |
hordir[2] = 0; |
| 1868 |
VectorNormalize(hordir); |
| 1869 |
|
| 1870 |
VectorCopy(reach->start, start); |
| 1871 |
start[2] += 1; |
| 1872 |
VectorMA(reach->start, 80, hordir, runstart); |
| 1873 |
|
| 1874 |
for (gapdist = 0; gapdist < 80; gapdist += 10) |
| 1875 |
{ |
| 1876 |
VectorMA(start, gapdist+10, hordir, end); |
| 1877 |
end[2] += 1; |
| 1878 |
if (AAS_PointAreaNum(end) != ms->reachareanum) break; |
| 1879 |
} |
| 1880 |
if (gapdist < 80) VectorMA(reach->start, gapdist, hordir, runstart); |
| 1881 |
|
| 1882 |
VectorSubtract(ms->origin, reach->start, dir1); |
| 1883 |
dir1[2] = 0; |
| 1884 |
dist1 = VectorNormalize(dir1); |
| 1885 |
VectorSubtract(ms->origin, runstart, dir2); |
| 1886 |
dir2[2] = 0; |
| 1887 |
dist2 = VectorNormalize(dir2); |
| 1888 |
|
| 1889 |
if (DotProduct(dir1, dir2) < -0.8 || dist2 < 5) |
| 1890 |
{ |
| 1891 |
|
| 1892 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 1893 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 1894 |
hordir[2] = 0; |
| 1895 |
VectorNormalize(hordir); |
| 1896 |
|
| 1897 |
if (dist1 < 24) EA_Jump(ms->client); |
| 1898 |
else if (dist1 < 32) EA_DelayedJump(ms->client); |
| 1899 |
EA_Move(ms->client, hordir, 600); |
| 1900 |
|
| 1901 |
ms->jumpreach = ms->lastreachnum; |
| 1902 |
} |
| 1903 |
else |
| 1904 |
{ |
| 1905 |
|
| 1906 |
hordir[0] = runstart[0] - ms->origin[0]; |
| 1907 |
hordir[1] = runstart[1] - ms->origin[1]; |
| 1908 |
hordir[2] = 0; |
| 1909 |
VectorNormalize(hordir); |
| 1910 |
|
| 1911 |
if (dist2 > 80) dist2 = 80; |
| 1912 |
speed = 400 - (400 - 5 * dist2); |
| 1913 |
EA_Move(ms->client, hordir, speed); |
| 1914 |
} |
| 1915 |
VectorCopy(hordir, result.movedir); |
| 1916 |
|
| 1917 |
return result; |
| 1918 |
} |
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
bot_moveresult_t BotFinishTravel_Jump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1926 |
{ |
| 1927 |
vec3_t hordir, hordir2; |
| 1928 |
float speed, dist; |
| 1929 |
bot_moveresult_t_cleared( result ); |
| 1930 |
|
| 1931 |
|
| 1932 |
if (!ms->jumpreach) return result; |
| 1933 |
|
| 1934 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 1935 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 1936 |
hordir[2] = 0; |
| 1937 |
dist = VectorNormalize(hordir); |
| 1938 |
|
| 1939 |
hordir2[0] = reach->end[0] - reach->start[0]; |
| 1940 |
hordir2[1] = reach->end[1] - reach->start[1]; |
| 1941 |
hordir2[2] = 0; |
| 1942 |
VectorNormalize(hordir2); |
| 1943 |
|
| 1944 |
if (DotProduct(hordir, hordir2) < -0.5 && dist < 24) return result; |
| 1945 |
|
| 1946 |
speed = 800; |
| 1947 |
|
| 1948 |
EA_Move(ms->client, hordir, speed); |
| 1949 |
VectorCopy(hordir, result.movedir); |
| 1950 |
|
| 1951 |
return result; |
| 1952 |
} |
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
bot_moveresult_t BotTravel_Ladder(bot_movestate_t *ms, aas_reachability_t *reach) |
| 1960 |
{ |
| 1961 |
|
| 1962 |
vec3_t dir, viewdir; |
| 1963 |
vec3_t origin = {0, 0, 0}; |
| 1964 |
|
| 1965 |
bot_moveresult_t_cleared( result ); |
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
{ |
| 1972 |
|
| 1973 |
VectorSubtract(reach->end, ms->origin, dir); |
| 1974 |
VectorNormalize(dir); |
| 1975 |
|
| 1976 |
viewdir[0] = dir[0]; |
| 1977 |
viewdir[1] = dir[1]; |
| 1978 |
viewdir[2] = 3 * dir[2]; |
| 1979 |
Vector2Angles(viewdir, result.ideal_viewangles); |
| 1980 |
|
| 1981 |
EA_Move(ms->client, origin, 0); |
| 1982 |
EA_MoveForward(ms->client); |
| 1983 |
|
| 1984 |
result.flags |= MOVERESULT_MOVEMENTVIEW; |
| 1985 |
} |
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
VectorCopy(dir, result.movedir); |
| 2005 |
|
| 2006 |
return result; |
| 2007 |
} |
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
bot_moveresult_t BotTravel_Teleport(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2015 |
{ |
| 2016 |
vec3_t hordir; |
| 2017 |
float dist; |
| 2018 |
bot_moveresult_t_cleared( result ); |
| 2019 |
|
| 2020 |
|
| 2021 |
if (ms->moveflags & MFL_TELEPORTED) return result; |
| 2022 |
|
| 2023 |
|
| 2024 |
VectorSubtract(reach->start, ms->origin, hordir); |
| 2025 |
if (!(ms->moveflags & MFL_SWIMMING)) hordir[2] = 0; |
| 2026 |
dist = VectorNormalize(hordir); |
| 2027 |
|
| 2028 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 2029 |
|
| 2030 |
if (dist < 30) EA_Move(ms->client, hordir, 200); |
| 2031 |
else EA_Move(ms->client, hordir, 400); |
| 2032 |
|
| 2033 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2034 |
|
| 2035 |
VectorCopy(hordir, result.movedir); |
| 2036 |
return result; |
| 2037 |
} |
| 2038 |
|
| 2039 |
|
| 2040 |
|
| 2041 |
|
| 2042 |
|
| 2043 |
|
| 2044 |
bot_moveresult_t BotTravel_Elevator(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2045 |
{ |
| 2046 |
vec3_t dir, dir1, dir2, hordir, bottomcenter; |
| 2047 |
float dist, dist1, dist2, speed; |
| 2048 |
bot_moveresult_t_cleared( result ); |
| 2049 |
|
| 2050 |
|
| 2051 |
if (BotOnMover(ms->origin, ms->entitynum, reach)) |
| 2052 |
{ |
| 2053 |
#ifdef DEBUG_ELEVATOR |
| 2054 |
botimport.Print(PRT_MESSAGE, "bot on elevator\n"); |
| 2055 |
#endif |
| 2056 |
|
| 2057 |
if (fabsf(ms->origin[2] - reach->end[2]) < sv_maxbarrier->value) |
| 2058 |
{ |
| 2059 |
#ifdef DEBUG_ELEVATOR |
| 2060 |
botimport.Print(PRT_MESSAGE, "bot moving to end\n"); |
| 2061 |
#endif |
| 2062 |
|
| 2063 |
VectorSubtract(reach->end, ms->origin, hordir); |
| 2064 |
hordir[2] = 0; |
| 2065 |
VectorNormalize(hordir); |
| 2066 |
if (!BotCheckBarrierJump(ms, hordir, 100)) |
| 2067 |
{ |
| 2068 |
EA_Move(ms->client, hordir, 400); |
| 2069 |
} |
| 2070 |
VectorCopy(hordir, result.movedir); |
| 2071 |
} |
| 2072 |
|
| 2073 |
else |
| 2074 |
{ |
| 2075 |
MoverBottomCenter(reach, bottomcenter); |
| 2076 |
VectorSubtract(bottomcenter, ms->origin, hordir); |
| 2077 |
hordir[2] = 0; |
| 2078 |
dist = VectorNormalize(hordir); |
| 2079 |
|
| 2080 |
if (dist > 10) |
| 2081 |
{ |
| 2082 |
#ifdef DEBUG_ELEVATOR |
| 2083 |
botimport.Print(PRT_MESSAGE, "bot moving to center\n"); |
| 2084 |
#endif |
| 2085 |
|
| 2086 |
if (dist > 100) dist = 100; |
| 2087 |
speed = 400 - (400 - 4 * dist); |
| 2088 |
|
| 2089 |
EA_Move(ms->client, hordir, speed); |
| 2090 |
VectorCopy(hordir, result.movedir); |
| 2091 |
} |
| 2092 |
} |
| 2093 |
} |
| 2094 |
else |
| 2095 |
{ |
| 2096 |
#ifdef DEBUG_ELEVATOR |
| 2097 |
botimport.Print(PRT_MESSAGE, "bot not on elevator\n"); |
| 2098 |
#endif |
| 2099 |
|
| 2100 |
VectorSubtract(reach->end, ms->origin, dir); |
| 2101 |
dist = VectorLength(dir); |
| 2102 |
if (dist < 64) |
| 2103 |
{ |
| 2104 |
if (dist > 60) dist = 60; |
| 2105 |
speed = 360 - (360 - 6 * dist); |
| 2106 |
|
| 2107 |
if ((ms->moveflags & MFL_SWIMMING) || !BotCheckBarrierJump(ms, dir, 50)) |
| 2108 |
{ |
| 2109 |
if (speed > 5) EA_Move(ms->client, dir, speed); |
| 2110 |
} |
| 2111 |
VectorCopy(dir, result.movedir); |
| 2112 |
|
| 2113 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2114 |
|
| 2115 |
ms->reachability_time = 0; |
| 2116 |
return result; |
| 2117 |
} |
| 2118 |
|
| 2119 |
VectorSubtract(reach->start, ms->origin, dir1); |
| 2120 |
if (!(ms->moveflags & MFL_SWIMMING)) dir1[2] = 0; |
| 2121 |
dist1 = VectorNormalize(dir1); |
| 2122 |
|
| 2123 |
if (!MoverDown(reach)) |
| 2124 |
{ |
| 2125 |
#ifdef DEBUG_ELEVATOR |
| 2126 |
botimport.Print(PRT_MESSAGE, "elevator not down\n"); |
| 2127 |
#endif |
| 2128 |
dist = dist1; |
| 2129 |
VectorCopy(dir1, dir); |
| 2130 |
|
| 2131 |
BotCheckBlocked(ms, dir, qfalse, &result); |
| 2132 |
|
| 2133 |
if (dist > 60) dist = 60; |
| 2134 |
speed = 360 - (360 - 6 * dist); |
| 2135 |
|
| 2136 |
if (!(ms->moveflags & MFL_SWIMMING) && !BotCheckBarrierJump(ms, dir, 50)) |
| 2137 |
{ |
| 2138 |
if (speed > 5) EA_Move(ms->client, dir, speed); |
| 2139 |
} |
| 2140 |
VectorCopy(dir, result.movedir); |
| 2141 |
|
| 2142 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2143 |
|
| 2144 |
result.type = RESULTTYPE_ELEVATORUP; |
| 2145 |
result.flags |= MOVERESULT_WAITING; |
| 2146 |
return result; |
| 2147 |
} |
| 2148 |
|
| 2149 |
MoverBottomCenter(reach, bottomcenter); |
| 2150 |
VectorSubtract(bottomcenter, ms->origin, dir2); |
| 2151 |
if (!(ms->moveflags & MFL_SWIMMING)) dir2[2] = 0; |
| 2152 |
dist2 = VectorNormalize(dir2); |
| 2153 |
|
| 2154 |
|
| 2155 |
|
| 2156 |
if (dist1 < 20 || dist2 < dist1 || DotProduct(dir1, dir2) < 0) |
| 2157 |
{ |
| 2158 |
#ifdef DEBUG_ELEVATOR |
| 2159 |
botimport.Print(PRT_MESSAGE, "bot moving to center\n"); |
| 2160 |
#endif |
| 2161 |
dist = dist2; |
| 2162 |
VectorCopy(dir2, dir); |
| 2163 |
} |
| 2164 |
else |
| 2165 |
{ |
| 2166 |
#ifdef DEBUG_ELEVATOR |
| 2167 |
botimport.Print(PRT_MESSAGE, "bot moving to start\n"); |
| 2168 |
#endif |
| 2169 |
dist = dist1; |
| 2170 |
VectorCopy(dir1, dir); |
| 2171 |
} |
| 2172 |
|
| 2173 |
BotCheckBlocked(ms, dir, qfalse, &result); |
| 2174 |
|
| 2175 |
if (dist > 60) dist = 60; |
| 2176 |
speed = 400 - (400 - 6 * dist); |
| 2177 |
|
| 2178 |
if (!(ms->moveflags & MFL_SWIMMING) && !BotCheckBarrierJump(ms, dir, 50)) |
| 2179 |
{ |
| 2180 |
EA_Move(ms->client, dir, speed); |
| 2181 |
} |
| 2182 |
VectorCopy(dir, result.movedir); |
| 2183 |
|
| 2184 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2185 |
} |
| 2186 |
return result; |
| 2187 |
} |
| 2188 |
|
| 2189 |
|
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
|
| 2194 |
bot_moveresult_t BotFinishTravel_Elevator(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2195 |
{ |
| 2196 |
vec3_t bottomcenter, bottomdir, topdir; |
| 2197 |
bot_moveresult_t_cleared( result ); |
| 2198 |
|
| 2199 |
|
| 2200 |
MoverBottomCenter(reach, bottomcenter); |
| 2201 |
VectorSubtract(bottomcenter, ms->origin, bottomdir); |
| 2202 |
|
| 2203 |
VectorSubtract(reach->end, ms->origin, topdir); |
| 2204 |
|
| 2205 |
if (fabs(bottomdir[2]) < fabs(topdir[2])) |
| 2206 |
{ |
| 2207 |
VectorNormalize(bottomdir); |
| 2208 |
EA_Move(ms->client, bottomdir, 300); |
| 2209 |
} |
| 2210 |
else |
| 2211 |
{ |
| 2212 |
VectorNormalize(topdir); |
| 2213 |
EA_Move(ms->client, topdir, 300); |
| 2214 |
} |
| 2215 |
return result; |
| 2216 |
} |
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
void BotFuncBobStartEnd(aas_reachability_t *reach, vec3_t start, vec3_t end, vec3_t origin) |
| 2224 |
{ |
| 2225 |
int spawnflags, modelnum; |
| 2226 |
vec3_t mins, maxs, mid, angles = {0, 0, 0}; |
| 2227 |
int num0, num1; |
| 2228 |
|
| 2229 |
modelnum = reach->facenum & 0x0000FFFF; |
| 2230 |
if (!AAS_OriginOfMoverWithModelNum(modelnum, origin)) |
| 2231 |
{ |
| 2232 |
botimport.Print(PRT_MESSAGE, "BotFuncBobStartEnd: no entity with model %d\n", modelnum); |
| 2233 |
VectorSet(start, 0, 0, 0); |
| 2234 |
VectorSet(end, 0, 0, 0); |
| 2235 |
return; |
| 2236 |
} |
| 2237 |
AAS_BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, NULL); |
| 2238 |
VectorAdd(mins, maxs, mid); |
| 2239 |
VectorScale(mid, 0.5, mid); |
| 2240 |
VectorCopy(mid, start); |
| 2241 |
VectorCopy(mid, end); |
| 2242 |
spawnflags = reach->facenum >> 16; |
| 2243 |
num0 = reach->edgenum >> 16; |
| 2244 |
if (num0 > 0x00007FFF) num0 |= 0xFFFF0000; |
| 2245 |
num1 = reach->edgenum & 0x0000FFFF; |
| 2246 |
if (num1 > 0x00007FFF) num1 |= 0xFFFF0000; |
| 2247 |
if (spawnflags & 1) |
| 2248 |
{ |
| 2249 |
start[0] = num0; |
| 2250 |
end[0] = num1; |
| 2251 |
|
| 2252 |
origin[0] += mid[0]; |
| 2253 |
origin[1] = mid[1]; |
| 2254 |
origin[2] = mid[2]; |
| 2255 |
} |
| 2256 |
else if (spawnflags & 2) |
| 2257 |
{ |
| 2258 |
start[1] = num0; |
| 2259 |
end[1] = num1; |
| 2260 |
|
| 2261 |
origin[0] = mid[0]; |
| 2262 |
origin[1] += mid[1]; |
| 2263 |
origin[2] = mid[2]; |
| 2264 |
} |
| 2265 |
else |
| 2266 |
{ |
| 2267 |
start[2] = num0; |
| 2268 |
end[2] = num1; |
| 2269 |
|
| 2270 |
origin[0] = mid[0]; |
| 2271 |
origin[1] = mid[1]; |
| 2272 |
origin[2] += mid[2]; |
| 2273 |
} |
| 2274 |
} |
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
bot_moveresult_t BotTravel_FuncBobbing(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2282 |
{ |
| 2283 |
vec3_t dir, dir1, dir2, hordir, bottomcenter, bob_start, bob_end, bob_origin; |
| 2284 |
float dist, dist1, dist2, speed; |
| 2285 |
bot_moveresult_t_cleared( result ); |
| 2286 |
|
| 2287 |
|
| 2288 |
BotFuncBobStartEnd(reach, bob_start, bob_end, bob_origin); |
| 2289 |
|
| 2290 |
if (BotOnMover(ms->origin, ms->entitynum, reach)) |
| 2291 |
{ |
| 2292 |
#ifdef DEBUG_FUNCBOB |
| 2293 |
botimport.Print(PRT_MESSAGE, "bot on func_bobbing\n"); |
| 2294 |
#endif |
| 2295 |
|
| 2296 |
VectorSubtract(bob_origin, bob_end, dir); |
| 2297 |
if (VectorLength(dir) < 24) |
| 2298 |
{ |
| 2299 |
#ifdef DEBUG_FUNCBOB |
| 2300 |
botimport.Print(PRT_MESSAGE, "bot moving to reachability end\n"); |
| 2301 |
#endif |
| 2302 |
|
| 2303 |
VectorSubtract(reach->end, ms->origin, hordir); |
| 2304 |
hordir[2] = 0; |
| 2305 |
VectorNormalize(hordir); |
| 2306 |
if (!BotCheckBarrierJump(ms, hordir, 100)) |
| 2307 |
{ |
| 2308 |
EA_Move(ms->client, hordir, 400); |
| 2309 |
} |
| 2310 |
VectorCopy(hordir, result.movedir); |
| 2311 |
} |
| 2312 |
|
| 2313 |
else |
| 2314 |
{ |
| 2315 |
MoverBottomCenter(reach, bottomcenter); |
| 2316 |
VectorSubtract(bottomcenter, ms->origin, hordir); |
| 2317 |
hordir[2] = 0; |
| 2318 |
dist = VectorNormalize(hordir); |
| 2319 |
|
| 2320 |
if (dist > 10) |
| 2321 |
{ |
| 2322 |
#ifdef DEBUG_FUNCBOB |
| 2323 |
botimport.Print(PRT_MESSAGE, "bot moving to func_bobbing center\n"); |
| 2324 |
#endif |
| 2325 |
|
| 2326 |
if (dist > 100) dist = 100; |
| 2327 |
speed = 400 - (400 - 4 * dist); |
| 2328 |
|
| 2329 |
EA_Move(ms->client, hordir, speed); |
| 2330 |
VectorCopy(hordir, result.movedir); |
| 2331 |
} |
| 2332 |
} |
| 2333 |
} |
| 2334 |
else |
| 2335 |
{ |
| 2336 |
#ifdef DEBUG_FUNCBOB |
| 2337 |
botimport.Print(PRT_MESSAGE, "bot not ontop of func_bobbing\n"); |
| 2338 |
#endif |
| 2339 |
|
| 2340 |
VectorSubtract(reach->end, ms->origin, dir); |
| 2341 |
dist = VectorLength(dir); |
| 2342 |
if (dist < 64) |
| 2343 |
{ |
| 2344 |
#ifdef DEBUG_FUNCBOB |
| 2345 |
botimport.Print(PRT_MESSAGE, "bot moving to end\n"); |
| 2346 |
#endif |
| 2347 |
if (dist > 60) dist = 60; |
| 2348 |
speed = 360 - (360 - 6 * dist); |
| 2349 |
|
| 2350 |
if ((ms->moveflags & MFL_SWIMMING) || !BotCheckBarrierJump(ms, dir, 50)) |
| 2351 |
{ |
| 2352 |
if (speed > 5) EA_Move(ms->client, dir, speed); |
| 2353 |
} |
| 2354 |
VectorCopy(dir, result.movedir); |
| 2355 |
|
| 2356 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2357 |
|
| 2358 |
ms->reachability_time = 0; |
| 2359 |
return result; |
| 2360 |
} |
| 2361 |
|
| 2362 |
VectorSubtract(reach->start, ms->origin, dir1); |
| 2363 |
if (!(ms->moveflags & MFL_SWIMMING)) dir1[2] = 0; |
| 2364 |
dist1 = VectorNormalize(dir1); |
| 2365 |
|
| 2366 |
VectorSubtract(bob_origin, bob_start, dir); |
| 2367 |
if (VectorLength(dir) > 16) |
| 2368 |
{ |
| 2369 |
#ifdef DEBUG_FUNCBOB |
| 2370 |
botimport.Print(PRT_MESSAGE, "func_bobbing not at start\n"); |
| 2371 |
#endif |
| 2372 |
dist = dist1; |
| 2373 |
VectorCopy(dir1, dir); |
| 2374 |
|
| 2375 |
BotCheckBlocked(ms, dir, qfalse, &result); |
| 2376 |
|
| 2377 |
if (dist > 60) dist = 60; |
| 2378 |
speed = 360 - (360 - 6 * dist); |
| 2379 |
|
| 2380 |
if (!(ms->moveflags & MFL_SWIMMING) && !BotCheckBarrierJump(ms, dir, 50)) |
| 2381 |
{ |
| 2382 |
if (speed > 5) EA_Move(ms->client, dir, speed); |
| 2383 |
} |
| 2384 |
VectorCopy(dir, result.movedir); |
| 2385 |
|
| 2386 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2387 |
|
| 2388 |
result.type = RESULTTYPE_WAITFORFUNCBOBBING; |
| 2389 |
result.flags |= MOVERESULT_WAITING; |
| 2390 |
return result; |
| 2391 |
} |
| 2392 |
|
| 2393 |
MoverBottomCenter(reach, bottomcenter); |
| 2394 |
VectorSubtract(bottomcenter, ms->origin, dir2); |
| 2395 |
if (!(ms->moveflags & MFL_SWIMMING)) dir2[2] = 0; |
| 2396 |
dist2 = VectorNormalize(dir2); |
| 2397 |
|
| 2398 |
|
| 2399 |
|
| 2400 |
if (dist1 < 20 || dist2 < dist1 || DotProduct(dir1, dir2) < 0) |
| 2401 |
{ |
| 2402 |
#ifdef DEBUG_FUNCBOB |
| 2403 |
botimport.Print(PRT_MESSAGE, "bot moving to func_bobbing center\n"); |
| 2404 |
#endif |
| 2405 |
dist = dist2; |
| 2406 |
VectorCopy(dir2, dir); |
| 2407 |
} |
| 2408 |
else |
| 2409 |
{ |
| 2410 |
#ifdef DEBUG_FUNCBOB |
| 2411 |
botimport.Print(PRT_MESSAGE, "bot moving to reachability start\n"); |
| 2412 |
#endif |
| 2413 |
dist = dist1; |
| 2414 |
VectorCopy(dir1, dir); |
| 2415 |
} |
| 2416 |
|
| 2417 |
BotCheckBlocked(ms, dir, qfalse, &result); |
| 2418 |
|
| 2419 |
if (dist > 60) dist = 60; |
| 2420 |
speed = 400 - (400 - 6 * dist); |
| 2421 |
|
| 2422 |
if (!(ms->moveflags & MFL_SWIMMING) && !BotCheckBarrierJump(ms, dir, 50)) |
| 2423 |
{ |
| 2424 |
EA_Move(ms->client, dir, speed); |
| 2425 |
} |
| 2426 |
VectorCopy(dir, result.movedir); |
| 2427 |
|
| 2428 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2429 |
} |
| 2430 |
return result; |
| 2431 |
} |
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
bot_moveresult_t BotFinishTravel_FuncBobbing(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2439 |
{ |
| 2440 |
vec3_t bob_origin, bob_start, bob_end, dir, hordir, bottomcenter; |
| 2441 |
bot_moveresult_t_cleared( result ); |
| 2442 |
float dist, speed; |
| 2443 |
|
| 2444 |
|
| 2445 |
BotFuncBobStartEnd(reach, bob_start, bob_end, bob_origin); |
| 2446 |
|
| 2447 |
VectorSubtract(bob_origin, bob_end, dir); |
| 2448 |
dist = VectorLength(dir); |
| 2449 |
|
| 2450 |
if (dist < 16) |
| 2451 |
{ |
| 2452 |
VectorSubtract(reach->end, ms->origin, hordir); |
| 2453 |
if (!(ms->moveflags & MFL_SWIMMING)) hordir[2] = 0; |
| 2454 |
dist = VectorNormalize(hordir); |
| 2455 |
|
| 2456 |
if (dist > 60) dist = 60; |
| 2457 |
speed = 360 - (360 - 6 * dist); |
| 2458 |
|
| 2459 |
if (speed > 5) EA_Move(ms->client, dir, speed); |
| 2460 |
VectorCopy(dir, result.movedir); |
| 2461 |
|
| 2462 |
if (ms->moveflags & MFL_SWIMMING) result.flags |= MOVERESULT_SWIMVIEW; |
| 2463 |
} |
| 2464 |
else |
| 2465 |
{ |
| 2466 |
MoverBottomCenter(reach, bottomcenter); |
| 2467 |
VectorSubtract(bottomcenter, ms->origin, hordir); |
| 2468 |
if (!(ms->moveflags & MFL_SWIMMING)) hordir[2] = 0; |
| 2469 |
dist = VectorNormalize(hordir); |
| 2470 |
|
| 2471 |
if (dist > 5) |
| 2472 |
{ |
| 2473 |
|
| 2474 |
if (dist > 100) dist = 100; |
| 2475 |
speed = 400 - (400 - 4 * dist); |
| 2476 |
|
| 2477 |
EA_Move(ms->client, hordir, speed); |
| 2478 |
VectorCopy(hordir, result.movedir); |
| 2479 |
} |
| 2480 |
} |
| 2481 |
return result; |
| 2482 |
} |
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
int GrappleState(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2493 |
{ |
| 2494 |
int i; |
| 2495 |
aas_entityinfo_t entinfo; |
| 2496 |
|
| 2497 |
|
| 2498 |
if (ms->moveflags & MFL_GRAPPLEPULL) |
| 2499 |
return 2; |
| 2500 |
|
| 2501 |
|
| 2502 |
for (i = AAS_NextEntity(0); i; i = AAS_NextEntity(i)) |
| 2503 |
{ |
| 2504 |
if (AAS_EntityType(i) == (int) entitytypemissile->value) |
| 2505 |
{ |
| 2506 |
AAS_EntityInfo(i, &entinfo); |
| 2507 |
if (entinfo.weapon == (int) weapindex_grapple->value) |
| 2508 |
{ |
| 2509 |
return 1; |
| 2510 |
} |
| 2511 |
} |
| 2512 |
} |
| 2513 |
|
| 2514 |
return 0; |
| 2515 |
} |
| 2516 |
|
| 2517 |
|
| 2518 |
|
| 2519 |
|
| 2520 |
|
| 2521 |
|
| 2522 |
void BotResetGrapple(bot_movestate_t *ms) |
| 2523 |
{ |
| 2524 |
aas_reachability_t reach; |
| 2525 |
|
| 2526 |
AAS_ReachabilityFromNum(ms->lastreachnum, &reach); |
| 2527 |
|
| 2528 |
if ((reach.traveltype & TRAVELTYPE_MASK) != TRAVEL_GRAPPLEHOOK) |
| 2529 |
{ |
| 2530 |
if ((ms->moveflags & MFL_ACTIVEGRAPPLE) || ms->grapplevisible_time) |
| 2531 |
{ |
| 2532 |
if (offhandgrapple->value) |
| 2533 |
EA_Command(ms->client, cmd_grappleoff->string); |
| 2534 |
ms->moveflags &= ~MFL_ACTIVEGRAPPLE; |
| 2535 |
ms->grapplevisible_time = 0; |
| 2536 |
#ifdef DEBUG_GRAPPLE |
| 2537 |
botimport.Print(PRT_MESSAGE, "reset grapple\n"); |
| 2538 |
#endif |
| 2539 |
} |
| 2540 |
} |
| 2541 |
} |
| 2542 |
|
| 2543 |
|
| 2544 |
|
| 2545 |
|
| 2546 |
|
| 2547 |
|
| 2548 |
bot_moveresult_t BotTravel_Grapple(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2549 |
{ |
| 2550 |
bot_moveresult_t_cleared( result ); |
| 2551 |
float dist, speed; |
| 2552 |
vec3_t dir, viewdir, org; |
| 2553 |
int state, areanum; |
| 2554 |
bsp_trace_t trace; |
| 2555 |
|
| 2556 |
#ifdef DEBUG_GRAPPLE |
| 2557 |
static int debugline; |
| 2558 |
if (!debugline) debugline = botimport.DebugLineCreate(); |
| 2559 |
botimport.DebugLineShow(debugline, reach->start, reach->end, LINECOLOR_BLUE); |
| 2560 |
#endif |
| 2561 |
|
| 2562 |
|
| 2563 |
if (ms->moveflags & MFL_GRAPPLERESET) |
| 2564 |
{ |
| 2565 |
if (offhandgrapple->value) |
| 2566 |
EA_Command(ms->client, cmd_grappleoff->string); |
| 2567 |
ms->moveflags &= ~MFL_ACTIVEGRAPPLE; |
| 2568 |
return result; |
| 2569 |
} |
| 2570 |
|
| 2571 |
if (!(int) offhandgrapple->value) |
| 2572 |
{ |
| 2573 |
result.weapon = weapindex_grapple->value; |
| 2574 |
result.flags |= MOVERESULT_MOVEMENTWEAPON; |
| 2575 |
} |
| 2576 |
|
| 2577 |
if (ms->moveflags & MFL_ACTIVEGRAPPLE) |
| 2578 |
{ |
| 2579 |
#ifdef DEBUG_GRAPPLE |
| 2580 |
botimport.Print(PRT_MESSAGE, "BotTravel_Grapple: active grapple\n"); |
| 2581 |
#endif |
| 2582 |
|
| 2583 |
state = GrappleState(ms, reach); |
| 2584 |
|
| 2585 |
VectorSubtract(reach->end, ms->origin, dir); |
| 2586 |
dir[2] = 0; |
| 2587 |
dist = VectorLength(dir); |
| 2588 |
|
| 2589 |
|
| 2590 |
if (state && dist < 48) |
| 2591 |
{ |
| 2592 |
if (ms->lastgrappledist - dist < 1) |
| 2593 |
{ |
| 2594 |
#ifdef DEBUG_GRAPPLE |
| 2595 |
botimport.Print(PRT_ERROR, "grapple normal end\n"); |
| 2596 |
#endif |
| 2597 |
if (offhandgrapple->value) |
| 2598 |
EA_Command(ms->client, cmd_grappleoff->string); |
| 2599 |
ms->moveflags &= ~MFL_ACTIVEGRAPPLE; |
| 2600 |
ms->moveflags |= MFL_GRAPPLERESET; |
| 2601 |
ms->reachability_time = 0; |
| 2602 |
return result; |
| 2603 |
} |
| 2604 |
} |
| 2605 |
|
| 2606 |
|
| 2607 |
else if (!state || (state == 2 && dist > ms->lastgrappledist - 2)) |
| 2608 |
{ |
| 2609 |
if (ms->grapplevisible_time < AAS_Time() - 0.4) |
| 2610 |
{ |
| 2611 |
#ifdef DEBUG_GRAPPLE |
| 2612 |
botimport.Print(PRT_ERROR, "grapple not visible\n"); |
| 2613 |
#endif |
| 2614 |
if (offhandgrapple->value) |
| 2615 |
EA_Command(ms->client, cmd_grappleoff->string); |
| 2616 |
ms->moveflags &= ~MFL_ACTIVEGRAPPLE; |
| 2617 |
ms->moveflags |= MFL_GRAPPLERESET; |
| 2618 |
ms->reachability_time = 0; |
| 2619 |
return result; |
| 2620 |
} |
| 2621 |
} |
| 2622 |
else |
| 2623 |
{ |
| 2624 |
ms->grapplevisible_time = AAS_Time(); |
| 2625 |
} |
| 2626 |
|
| 2627 |
if (!(int) offhandgrapple->value) |
| 2628 |
{ |
| 2629 |
EA_Attack(ms->client); |
| 2630 |
} |
| 2631 |
|
| 2632 |
ms->lastgrappledist = dist; |
| 2633 |
} |
| 2634 |
else |
| 2635 |
{ |
| 2636 |
#ifdef DEBUG_GRAPPLE |
| 2637 |
botimport.Print(PRT_MESSAGE, "BotTravel_Grapple: inactive grapple\n"); |
| 2638 |
#endif |
| 2639 |
|
| 2640 |
ms->grapplevisible_time = AAS_Time(); |
| 2641 |
|
| 2642 |
VectorSubtract(reach->start, ms->origin, dir); |
| 2643 |
if (!(ms->moveflags & MFL_SWIMMING)) dir[2] = 0; |
| 2644 |
VectorAdd(ms->origin, ms->viewoffset, org); |
| 2645 |
VectorSubtract(reach->end, org, viewdir); |
| 2646 |
|
| 2647 |
dist = VectorNormalize(dir); |
| 2648 |
Vector2Angles(viewdir, result.ideal_viewangles); |
| 2649 |
result.flags |= MOVERESULT_MOVEMENTVIEW; |
| 2650 |
|
| 2651 |
if (dist < 5 && |
| 2652 |
fabs(AngleDiff(result.ideal_viewangles[0], ms->viewangles[0])) < 2 && |
| 2653 |
fabs(AngleDiff(result.ideal_viewangles[1], ms->viewangles[1])) < 2) |
| 2654 |
{ |
| 2655 |
#ifdef DEBUG_GRAPPLE |
| 2656 |
botimport.Print(PRT_MESSAGE, "BotTravel_Grapple: activating grapple\n"); |
| 2657 |
#endif |
| 2658 |
|
| 2659 |
VectorAdd(ms->origin, ms->viewoffset, org); |
| 2660 |
trace = AAS_Trace(org, NULL, NULL, reach->end, ms->entitynum, CONTENTS_SOLID); |
| 2661 |
VectorSubtract(reach->end, trace.endpos, dir); |
| 2662 |
if (VectorLength(dir) > 16) |
| 2663 |
{ |
| 2664 |
result.failure = qtrue; |
| 2665 |
return result; |
| 2666 |
} |
| 2667 |
|
| 2668 |
if (offhandgrapple->value) |
| 2669 |
{ |
| 2670 |
EA_Command(ms->client, cmd_grappleon->string); |
| 2671 |
} |
| 2672 |
else |
| 2673 |
{ |
| 2674 |
EA_Attack(ms->client); |
| 2675 |
} |
| 2676 |
ms->moveflags |= MFL_ACTIVEGRAPPLE; |
| 2677 |
ms->lastgrappledist = 999999; |
| 2678 |
} |
| 2679 |
else |
| 2680 |
{ |
| 2681 |
if (dist < 70) speed = 300 - (300 - 4 * dist); |
| 2682 |
else speed = 400; |
| 2683 |
|
| 2684 |
BotCheckBlocked(ms, dir, qtrue, &result); |
| 2685 |
|
| 2686 |
EA_Move(ms->client, dir, speed); |
| 2687 |
VectorCopy(dir, result.movedir); |
| 2688 |
} |
| 2689 |
|
| 2690 |
areanum = AAS_PointAreaNum(ms->origin); |
| 2691 |
if (areanum && areanum != ms->reachareanum) ms->reachability_time = 0; |
| 2692 |
} |
| 2693 |
return result; |
| 2694 |
} |
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
bot_moveresult_t BotTravel_RocketJump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2702 |
{ |
| 2703 |
vec3_t hordir; |
| 2704 |
float dist, speed; |
| 2705 |
bot_moveresult_t_cleared( result ); |
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
hordir[0] = reach->start[0] - ms->origin[0]; |
| 2710 |
hordir[1] = reach->start[1] - ms->origin[1]; |
| 2711 |
hordir[2] = 0; |
| 2712 |
|
| 2713 |
dist = VectorNormalize(hordir); |
| 2714 |
|
| 2715 |
Vector2Angles(hordir, result.ideal_viewangles); |
| 2716 |
|
| 2717 |
result.ideal_viewangles[PITCH] = 90; |
| 2718 |
|
| 2719 |
if (dist < 5 && |
| 2720 |
fabs(AngleDiff(result.ideal_viewangles[0], ms->viewangles[0])) < 5 && |
| 2721 |
fabs(AngleDiff(result.ideal_viewangles[1], ms->viewangles[1])) < 5) |
| 2722 |
{ |
| 2723 |
|
| 2724 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 2725 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 2726 |
hordir[2] = 0; |
| 2727 |
VectorNormalize(hordir); |
| 2728 |
|
| 2729 |
EA_Jump(ms->client); |
| 2730 |
EA_Attack(ms->client); |
| 2731 |
EA_Move(ms->client, hordir, 800); |
| 2732 |
|
| 2733 |
ms->jumpreach = ms->lastreachnum; |
| 2734 |
} |
| 2735 |
else |
| 2736 |
{ |
| 2737 |
if (dist > 80) dist = 80; |
| 2738 |
speed = 400 - (400 - 5 * dist); |
| 2739 |
EA_Move(ms->client, hordir, speed); |
| 2740 |
} |
| 2741 |
|
| 2742 |
Vector2Angles(hordir, result.ideal_viewangles); |
| 2743 |
|
| 2744 |
result.ideal_viewangles[PITCH] = 90; |
| 2745 |
|
| 2746 |
EA_View(ms->client, result.ideal_viewangles); |
| 2747 |
|
| 2748 |
result.flags |= MOVERESULT_MOVEMENTVIEWSET; |
| 2749 |
|
| 2750 |
EA_SelectWeapon(ms->client, (int) weapindex_rocketlauncher->value); |
| 2751 |
|
| 2752 |
result.weapon = (int) weapindex_rocketlauncher->value; |
| 2753 |
result.flags |= MOVERESULT_MOVEMENTWEAPON; |
| 2754 |
|
| 2755 |
VectorCopy(hordir, result.movedir); |
| 2756 |
|
| 2757 |
return result; |
| 2758 |
} |
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
bot_moveresult_t BotTravel_BFGJump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2766 |
{ |
| 2767 |
vec3_t hordir; |
| 2768 |
float dist, speed; |
| 2769 |
bot_moveresult_t_cleared( result ); |
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
hordir[0] = reach->start[0] - ms->origin[0]; |
| 2774 |
hordir[1] = reach->start[1] - ms->origin[1]; |
| 2775 |
hordir[2] = 0; |
| 2776 |
|
| 2777 |
dist = VectorNormalize(hordir); |
| 2778 |
|
| 2779 |
if (dist < 5 && |
| 2780 |
fabs(AngleDiff(result.ideal_viewangles[0], ms->viewangles[0])) < 5 && |
| 2781 |
fabs(AngleDiff(result.ideal_viewangles[1], ms->viewangles[1])) < 5) |
| 2782 |
{ |
| 2783 |
|
| 2784 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 2785 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 2786 |
hordir[2] = 0; |
| 2787 |
VectorNormalize(hordir); |
| 2788 |
|
| 2789 |
EA_Jump(ms->client); |
| 2790 |
EA_Attack(ms->client); |
| 2791 |
EA_Move(ms->client, hordir, 800); |
| 2792 |
|
| 2793 |
ms->jumpreach = ms->lastreachnum; |
| 2794 |
} |
| 2795 |
else |
| 2796 |
{ |
| 2797 |
if (dist > 80) dist = 80; |
| 2798 |
speed = 400 - (400 - 5 * dist); |
| 2799 |
EA_Move(ms->client, hordir, speed); |
| 2800 |
} |
| 2801 |
|
| 2802 |
Vector2Angles(hordir, result.ideal_viewangles); |
| 2803 |
|
| 2804 |
result.ideal_viewangles[PITCH] = 90; |
| 2805 |
|
| 2806 |
EA_View(ms->client, result.ideal_viewangles); |
| 2807 |
|
| 2808 |
result.flags |= MOVERESULT_MOVEMENTVIEWSET; |
| 2809 |
|
| 2810 |
EA_SelectWeapon(ms->client, (int) weapindex_bfg10k->value); |
| 2811 |
|
| 2812 |
result.weapon = (int) weapindex_bfg10k->value; |
| 2813 |
result.flags |= MOVERESULT_MOVEMENTWEAPON; |
| 2814 |
|
| 2815 |
VectorCopy(hordir, result.movedir); |
| 2816 |
|
| 2817 |
return result; |
| 2818 |
} |
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
|
| 2825 |
bot_moveresult_t BotFinishTravel_WeaponJump(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2826 |
{ |
| 2827 |
vec3_t hordir; |
| 2828 |
float speed; |
| 2829 |
bot_moveresult_t_cleared( result ); |
| 2830 |
|
| 2831 |
|
| 2832 |
if (!ms->jumpreach) return result; |
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
if (!BotAirControl(ms->origin, ms->velocity, reach->end, hordir, &speed)) |
| 2845 |
{ |
| 2846 |
|
| 2847 |
VectorSubtract(reach->end, ms->origin, hordir); |
| 2848 |
hordir[2] = 0; |
| 2849 |
VectorNormalize(hordir); |
| 2850 |
speed = 400; |
| 2851 |
} |
| 2852 |
|
| 2853 |
EA_Move(ms->client, hordir, speed); |
| 2854 |
VectorCopy(hordir, result.movedir); |
| 2855 |
|
| 2856 |
return result; |
| 2857 |
} |
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
bot_moveresult_t BotTravel_JumpPad(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2865 |
{ |
| 2866 |
vec3_t hordir; |
| 2867 |
bot_moveresult_t_cleared( result ); |
| 2868 |
|
| 2869 |
|
| 2870 |
hordir[0] = reach->start[0] - ms->origin[0]; |
| 2871 |
hordir[1] = reach->start[1] - ms->origin[1]; |
| 2872 |
hordir[2] = 0; |
| 2873 |
|
| 2874 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 2875 |
|
| 2876 |
EA_Move(ms->client, hordir, 400); |
| 2877 |
VectorCopy(hordir, result.movedir); |
| 2878 |
|
| 2879 |
return result; |
| 2880 |
} |
| 2881 |
|
| 2882 |
|
| 2883 |
|
| 2884 |
|
| 2885 |
|
| 2886 |
|
| 2887 |
bot_moveresult_t BotFinishTravel_JumpPad(bot_movestate_t *ms, aas_reachability_t *reach) |
| 2888 |
{ |
| 2889 |
float speed; |
| 2890 |
vec3_t hordir; |
| 2891 |
bot_moveresult_t_cleared( result ); |
| 2892 |
|
| 2893 |
if (!BotAirControl(ms->origin, ms->velocity, reach->end, hordir, &speed)) |
| 2894 |
{ |
| 2895 |
hordir[0] = reach->end[0] - ms->origin[0]; |
| 2896 |
hordir[1] = reach->end[1] - ms->origin[1]; |
| 2897 |
hordir[2] = 0; |
| 2898 |
VectorNormalize(hordir); |
| 2899 |
speed = 400; |
| 2900 |
} |
| 2901 |
BotCheckBlocked(ms, hordir, qtrue, &result); |
| 2902 |
|
| 2903 |
EA_Move(ms->client, hordir, speed); |
| 2904 |
VectorCopy(hordir, result.movedir); |
| 2905 |
|
| 2906 |
return result; |
| 2907 |
} |
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
int BotReachabilityTime(aas_reachability_t *reach) |
| 2916 |
{ |
| 2917 |
switch(reach->traveltype & TRAVELTYPE_MASK) |
| 2918 |
{ |
| 2919 |
case TRAVEL_WALK: return 5; |
| 2920 |
case TRAVEL_CROUCH: return 5; |
| 2921 |
case TRAVEL_BARRIERJUMP: return 5; |
| 2922 |
case TRAVEL_LADDER: return 6; |
| 2923 |
case TRAVEL_WALKOFFLEDGE: return 5; |
| 2924 |
case TRAVEL_JUMP: return 5; |
| 2925 |
case TRAVEL_SWIM: return 5; |
| 2926 |
case TRAVEL_WATERJUMP: return 5; |
| 2927 |
case TRAVEL_TELEPORT: return 5; |
| 2928 |
case TRAVEL_ELEVATOR: return 10; |
| 2929 |
case TRAVEL_GRAPPLEHOOK: return 8; |
| 2930 |
case TRAVEL_ROCKETJUMP: return 6; |
| 2931 |
case TRAVEL_BFGJUMP: return 6; |
| 2932 |
case TRAVEL_JUMPPAD: return 10; |
| 2933 |
case TRAVEL_FUNCBOB: return 10; |
| 2934 |
default: |
| 2935 |
{ |
| 2936 |
botimport.Print(PRT_ERROR, "travel type %d not implemented yet\n", reach->traveltype); |
| 2937 |
return 8; |
| 2938 |
} |
| 2939 |
} |
| 2940 |
} |
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
|
| 2946 |
|
| 2947 |
bot_moveresult_t BotMoveInGoalArea(bot_movestate_t *ms, bot_goal_t *goal) |
| 2948 |
{ |
| 2949 |
bot_moveresult_t_cleared( result ); |
| 2950 |
vec3_t dir; |
| 2951 |
float dist, speed; |
| 2952 |
|
| 2953 |
#ifdef DEBUG |
| 2954 |
|
| 2955 |
|
| 2956 |
|
| 2957 |
#endif |
| 2958 |
|
| 2959 |
dir[0] = goal->origin[0] - ms->origin[0]; |
| 2960 |
dir[1] = goal->origin[1] - ms->origin[1]; |
| 2961 |
if (ms->moveflags & MFL_SWIMMING) |
| 2962 |
{ |
| 2963 |
dir[2] = goal->origin[2] - ms->origin[2]; |
| 2964 |
result.traveltype = TRAVEL_SWIM; |
| 2965 |
} |
| 2966 |
else |
| 2967 |
{ |
| 2968 |
dir[2] = 0; |
| 2969 |
result.traveltype = TRAVEL_WALK; |
| 2970 |
} |
| 2971 |
|
| 2972 |
dist = VectorNormalize(dir); |
| 2973 |
if (dist > 100) dist = 100; |
| 2974 |
speed = 400 - (400 - 4 * dist); |
| 2975 |
if (speed < 10) speed = 0; |
| 2976 |
|
| 2977 |
BotCheckBlocked(ms, dir, qtrue, &result); |
| 2978 |
|
| 2979 |
EA_Move(ms->client, dir, speed); |
| 2980 |
VectorCopy(dir, result.movedir); |
| 2981 |
|
| 2982 |
if (ms->moveflags & MFL_SWIMMING) |
| 2983 |
{ |
| 2984 |
Vector2Angles(dir, result.ideal_viewangles); |
| 2985 |
result.flags |= MOVERESULT_SWIMVIEW; |
| 2986 |
} |
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
ms->lastreachnum = 0; |
| 2991 |
ms->lastareanum = 0; |
| 2992 |
ms->lastgoalareanum = goal->areanum; |
| 2993 |
VectorCopy(ms->origin, ms->lastorigin); |
| 2994 |
|
| 2995 |
return result; |
| 2996 |
} |
| 2997 |
|
| 2998 |
|
| 2999 |
|
| 3000 |
|
| 3001 |
|
| 3002 |
|
| 3003 |
void BotMoveToGoal(bot_moveresult_t *result, int movestate, bot_goal_t *goal, int travelflags) |
| 3004 |
{ |
| 3005 |
int reachnum, lastreachnum, foundjumppad, ent, resultflags; |
| 3006 |
aas_reachability_t reach, lastreach; |
| 3007 |
bot_movestate_t *ms; |
| 3008 |
|
| 3009 |
|
| 3010 |
|
| 3011 |
|
| 3012 |
result->failure = qfalse; |
| 3013 |
result->type = 0; |
| 3014 |
result->blocked = qfalse; |
| 3015 |
result->blockentity = 0; |
| 3016 |
result->traveltype = 0; |
| 3017 |
result->flags = 0; |
| 3018 |
|
| 3019 |
|
| 3020 |
ms = BotMoveStateFromHandle(movestate); |
| 3021 |
if (!ms) return; |
| 3022 |
|
| 3023 |
|
| 3024 |
BotResetGrapple(ms); |
| 3025 |
|
| 3026 |
if (!goal) |
| 3027 |
{ |
| 3028 |
#ifdef DEBUG |
| 3029 |
botimport.Print(PRT_MESSAGE, "client %d: movetogoal -> no goal\n", ms->client); |
| 3030 |
#endif |
| 3031 |
result->failure = qtrue; |
| 3032 |
return; |
| 3033 |
} |
| 3034 |
|
| 3035 |
|
| 3036 |
ms->moveflags &= ~(MFL_SWIMMING|MFL_AGAINSTLADDER); |
| 3037 |
|
| 3038 |
|
| 3039 |
if (AAS_OnGround(ms->origin, ms->presencetype, ms->entitynum)) ms->moveflags |= MFL_ONGROUND; |
| 3040 |
|
| 3041 |
if (ms->moveflags & MFL_ONGROUND) |
| 3042 |
{ |
| 3043 |
int modeltype, modelnum; |
| 3044 |
|
| 3045 |
ent = BotOnTopOfEntity(ms); |
| 3046 |
|
| 3047 |
if (ent != -1) |
| 3048 |
{ |
| 3049 |
modelnum = AAS_EntityModelindex(ent); |
| 3050 |
if (modelnum >= 0 && modelnum < MAX_MODELS) |
| 3051 |
{ |
| 3052 |
modeltype = modeltypes[modelnum]; |
| 3053 |
|
| 3054 |
if (modeltype == MODELTYPE_FUNC_PLAT) |
| 3055 |
{ |
| 3056 |
AAS_ReachabilityFromNum(ms->lastreachnum, &reach); |
| 3057 |
|
| 3058 |
if ((reach.traveltype & TRAVELTYPE_MASK) != TRAVEL_ELEVATOR || |
| 3059 |
|
| 3060 |
(reach.facenum & 0x0000FFFF) != modelnum) |
| 3061 |
{ |
| 3062 |
reachnum = AAS_NextModelReachability(0, modelnum); |
| 3063 |
if (reachnum) |
| 3064 |
{ |
| 3065 |
|
| 3066 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 3067 |
ms->lastreachnum = reachnum; |
| 3068 |
ms->reachability_time = AAS_Time() + BotReachabilityTime(&reach); |
| 3069 |
} |
| 3070 |
else |
| 3071 |
{ |
| 3072 |
if (botDeveloper) |
| 3073 |
{ |
| 3074 |
botimport.Print(PRT_MESSAGE, "client %d: on func_plat without reachability\n", ms->client); |
| 3075 |
} |
| 3076 |
result->blocked = qtrue; |
| 3077 |
result->blockentity = ent; |
| 3078 |
result->flags |= MOVERESULT_ONTOPOFOBSTACLE; |
| 3079 |
return; |
| 3080 |
} |
| 3081 |
} |
| 3082 |
result->flags |= MOVERESULT_ONTOPOF_ELEVATOR; |
| 3083 |
} |
| 3084 |
else if (modeltype == MODELTYPE_FUNC_BOB) |
| 3085 |
{ |
| 3086 |
AAS_ReachabilityFromNum(ms->lastreachnum, &reach); |
| 3087 |
|
| 3088 |
if ((reach.traveltype & TRAVELTYPE_MASK) != TRAVEL_FUNCBOB || |
| 3089 |
|
| 3090 |
(reach.facenum & 0x0000FFFF) != modelnum) |
| 3091 |
{ |
| 3092 |
reachnum = AAS_NextModelReachability(0, modelnum); |
| 3093 |
if (reachnum) |
| 3094 |
{ |
| 3095 |
|
| 3096 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 3097 |
ms->lastreachnum = reachnum; |
| 3098 |
ms->reachability_time = AAS_Time() + BotReachabilityTime(&reach); |
| 3099 |
} |
| 3100 |
else |
| 3101 |
{ |
| 3102 |
if (botDeveloper) |
| 3103 |
{ |
| 3104 |
botimport.Print(PRT_MESSAGE, "client %d: on func_bobbing without reachability\n", ms->client); |
| 3105 |
} |
| 3106 |
result->blocked = qtrue; |
| 3107 |
result->blockentity = ent; |
| 3108 |
result->flags |= MOVERESULT_ONTOPOFOBSTACLE; |
| 3109 |
return; |
| 3110 |
} |
| 3111 |
} |
| 3112 |
result->flags |= MOVERESULT_ONTOPOF_FUNCBOB; |
| 3113 |
} |
| 3114 |
else if (modeltype == MODELTYPE_FUNC_STATIC || modeltype == MODELTYPE_FUNC_DOOR) |
| 3115 |
{ |
| 3116 |
|
| 3117 |
ms->areanum = BotFuzzyPointReachabilityArea(ms->origin); |
| 3118 |
|
| 3119 |
if (!AAS_AreaReachability(ms->areanum)) |
| 3120 |
{ |
| 3121 |
result->blocked = qtrue; |
| 3122 |
result->blockentity = ent; |
| 3123 |
result->flags |= MOVERESULT_ONTOPOFOBSTACLE; |
| 3124 |
return; |
| 3125 |
} |
| 3126 |
} |
| 3127 |
else |
| 3128 |
{ |
| 3129 |
result->blocked = qtrue; |
| 3130 |
result->blockentity = ent; |
| 3131 |
result->flags |= MOVERESULT_ONTOPOFOBSTACLE; |
| 3132 |
return; |
| 3133 |
} |
| 3134 |
} |
| 3135 |
} |
| 3136 |
} |
| 3137 |
|
| 3138 |
if (AAS_Swimming(ms->origin)) ms->moveflags |= MFL_SWIMMING; |
| 3139 |
|
| 3140 |
if (AAS_AgainstLadder(ms->origin)) ms->moveflags |= MFL_AGAINSTLADDER; |
| 3141 |
|
| 3142 |
if (ms->moveflags & (MFL_ONGROUND|MFL_SWIMMING|MFL_AGAINSTLADDER)) |
| 3143 |
{ |
| 3144 |
|
| 3145 |
|
| 3146 |
AAS_ReachabilityFromNum(ms->lastreachnum, &lastreach); |
| 3147 |
|
| 3148 |
|
| 3149 |
ms->areanum = BotFuzzyPointReachabilityArea(ms->origin); |
| 3150 |
|
| 3151 |
if ( !ms->areanum ) |
| 3152 |
{ |
| 3153 |
result->failure = qtrue; |
| 3154 |
result->blocked = qtrue; |
| 3155 |
result->blockentity = 0; |
| 3156 |
result->type = RESULTTYPE_INSOLIDAREA; |
| 3157 |
return; |
| 3158 |
} |
| 3159 |
|
| 3160 |
if (ms->areanum == goal->areanum) |
| 3161 |
{ |
| 3162 |
*result = BotMoveInGoalArea(ms, goal); |
| 3163 |
return; |
| 3164 |
} |
| 3165 |
|
| 3166 |
reachnum = ms->lastreachnum; |
| 3167 |
|
| 3168 |
if (reachnum) |
| 3169 |
{ |
| 3170 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 3171 |
|
| 3172 |
if (!(AAS_TravelFlagForType(reach.traveltype) & travelflags)) |
| 3173 |
{ |
| 3174 |
reachnum = 0; |
| 3175 |
} |
| 3176 |
|
| 3177 |
else if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_GRAPPLEHOOK) |
| 3178 |
{ |
| 3179 |
if (ms->reachability_time < AAS_Time() || |
| 3180 |
(ms->moveflags & MFL_GRAPPLERESET)) |
| 3181 |
{ |
| 3182 |
reachnum = 0; |
| 3183 |
} |
| 3184 |
} |
| 3185 |
|
| 3186 |
else if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_ELEVATOR || |
| 3187 |
(reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_FUNCBOB) |
| 3188 |
{ |
| 3189 |
if ((result->flags & MOVERESULT_ONTOPOF_ELEVATOR) || |
| 3190 |
(result->flags & MOVERESULT_ONTOPOF_FUNCBOB)) |
| 3191 |
{ |
| 3192 |
ms->reachability_time = AAS_Time() + 5; |
| 3193 |
} |
| 3194 |
|
| 3195 |
if (ms->areanum == reach.areanum || |
| 3196 |
ms->reachability_time < AAS_Time()) |
| 3197 |
{ |
| 3198 |
reachnum = 0; |
| 3199 |
} |
| 3200 |
} |
| 3201 |
else |
| 3202 |
{ |
| 3203 |
#ifdef DEBUG |
| 3204 |
if (botDeveloper) |
| 3205 |
{ |
| 3206 |
if (ms->reachability_time < AAS_Time()) |
| 3207 |
{ |
| 3208 |
botimport.Print(PRT_MESSAGE, "client %d: reachability timeout in ", ms->client); |
| 3209 |
AAS_PrintTravelType(reach.traveltype & TRAVELTYPE_MASK); |
| 3210 |
botimport.Print(PRT_MESSAGE, "\n"); |
| 3211 |
} |
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
} |
| 3218 |
#endif |
| 3219 |
|
| 3220 |
|
| 3221 |
if (ms->lastgoalareanum != goal->areanum || |
| 3222 |
ms->reachability_time < AAS_Time() || |
| 3223 |
ms->lastareanum != ms->areanum) |
| 3224 |
{ |
| 3225 |
reachnum = 0; |
| 3226 |
|
| 3227 |
} |
| 3228 |
} |
| 3229 |
} |
| 3230 |
resultflags = 0; |
| 3231 |
|
| 3232 |
if (!reachnum) |
| 3233 |
{ |
| 3234 |
|
| 3235 |
if (!AAS_AreaReachability(ms->areanum)) |
| 3236 |
{ |
| 3237 |
#ifdef DEBUG |
| 3238 |
if (botDeveloper) |
| 3239 |
{ |
| 3240 |
botimport.Print(PRT_MESSAGE, "area %d no reachability\n", ms->areanum); |
| 3241 |
} |
| 3242 |
#endif |
| 3243 |
} |
| 3244 |
|
| 3245 |
reachnum = BotGetReachabilityToGoal(ms->origin, ms->areanum, |
| 3246 |
ms->lastgoalareanum, ms->lastareanum, |
| 3247 |
ms->avoidreach, ms->avoidreachtimes, ms->avoidreachtries, |
| 3248 |
goal, travelflags, |
| 3249 |
ms->avoidspots, ms->numavoidspots, &resultflags); |
| 3250 |
|
| 3251 |
ms->reachareanum = ms->areanum; |
| 3252 |
|
| 3253 |
ms->jumpreach = 0; |
| 3254 |
ms->moveflags &= ~MFL_GRAPPLERESET; |
| 3255 |
|
| 3256 |
if (reachnum) |
| 3257 |
{ |
| 3258 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 3259 |
|
| 3260 |
ms->reachability_time = AAS_Time() + BotReachabilityTime(&reach); |
| 3261 |
|
| 3262 |
#ifdef AVOIDREACH |
| 3263 |
|
| 3264 |
BotAddToAvoidReach(ms, reachnum, AVOIDREACH_TIME); |
| 3265 |
#endif |
| 3266 |
} |
| 3267 |
#ifdef DEBUG |
| 3268 |
|
| 3269 |
else if (botDeveloper) |
| 3270 |
{ |
| 3271 |
botimport.Print(PRT_MESSAGE, "goal not reachable\n"); |
| 3272 |
Com_Memset(&reach, 0, sizeof(aas_reachability_t)); |
| 3273 |
} |
| 3274 |
if (botDeveloper) |
| 3275 |
{ |
| 3276 |
|
| 3277 |
if (ms->lastgoalareanum == goal->areanum) |
| 3278 |
{ |
| 3279 |
if (ms->lastareanum == reach.areanum) |
| 3280 |
{ |
| 3281 |
botimport.Print(PRT_MESSAGE, "same goal, going back to previous area\n"); |
| 3282 |
} |
| 3283 |
} |
| 3284 |
} |
| 3285 |
#endif |
| 3286 |
} |
| 3287 |
|
| 3288 |
ms->lastreachnum = reachnum; |
| 3289 |
ms->lastgoalareanum = goal->areanum; |
| 3290 |
ms->lastareanum = ms->areanum; |
| 3291 |
|
| 3292 |
if (reachnum) |
| 3293 |
{ |
| 3294 |
|
| 3295 |
AAS_ReachabilityFromNum(reachnum, &reach); |
| 3296 |
result->traveltype = reach.traveltype; |
| 3297 |
|
| 3298 |
#ifdef DEBUG_AI_MOVE |
| 3299 |
AAS_ClearShownDebugLines(); |
| 3300 |
AAS_PrintTravelType(reach.traveltype & TRAVELTYPE_MASK); |
| 3301 |
AAS_ShowReachability(&reach); |
| 3302 |
#endif |
| 3303 |
|
| 3304 |
#ifdef DEBUG |
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
#endif |
| 3309 |
switch(reach.traveltype & TRAVELTYPE_MASK) |
| 3310 |
{ |
| 3311 |
case TRAVEL_WALK: *result = BotTravel_Walk(ms, &reach); break; |
| 3312 |
case TRAVEL_CROUCH: *result = BotTravel_Crouch(ms, &reach); break; |
| 3313 |
case TRAVEL_BARRIERJUMP: *result = BotTravel_BarrierJump(ms, &reach); break; |
| 3314 |
case TRAVEL_LADDER: *result = BotTravel_Ladder(ms, &reach); break; |
| 3315 |
case TRAVEL_WALKOFFLEDGE: *result = BotTravel_WalkOffLedge(ms, &reach); break; |
| 3316 |
case TRAVEL_JUMP: *result = BotTravel_Jump(ms, &reach); break; |
| 3317 |
case TRAVEL_SWIM: *result = BotTravel_Swim(ms, &reach); break; |
| 3318 |
case TRAVEL_WATERJUMP: *result = BotTravel_WaterJump(ms, &reach); break; |
| 3319 |
case TRAVEL_TELEPORT: *result = BotTravel_Teleport(ms, &reach); break; |
| 3320 |
case TRAVEL_ELEVATOR: *result = BotTravel_Elevator(ms, &reach); break; |
| 3321 |
case TRAVEL_GRAPPLEHOOK: *result = BotTravel_Grapple(ms, &reach); break; |
| 3322 |
case TRAVEL_ROCKETJUMP: *result = BotTravel_RocketJump(ms, &reach); break; |
| 3323 |
case TRAVEL_BFGJUMP: *result = BotTravel_BFGJump(ms, &reach); break; |
| 3324 |
case TRAVEL_JUMPPAD: *result = BotTravel_JumpPad(ms, &reach); break; |
| 3325 |
case TRAVEL_FUNCBOB: *result = BotTravel_FuncBobbing(ms, &reach); break; |
| 3326 |
default: |
| 3327 |
{ |
| 3328 |
botimport.Print(PRT_FATAL, "travel type %d not implemented yet\n", (reach.traveltype & TRAVELTYPE_MASK)); |
| 3329 |
break; |
| 3330 |
} |
| 3331 |
} |
| 3332 |
result->traveltype = reach.traveltype; |
| 3333 |
result->flags |= resultflags; |
| 3334 |
} |
| 3335 |
else |
| 3336 |
{ |
| 3337 |
result->failure = qtrue; |
| 3338 |
result->flags |= resultflags; |
| 3339 |
Com_Memset(&reach, 0, sizeof(aas_reachability_t)); |
| 3340 |
} |
| 3341 |
#ifdef DEBUG |
| 3342 |
if (botDeveloper) |
| 3343 |
{ |
| 3344 |
if (result->failure) |
| 3345 |
{ |
| 3346 |
botimport.Print(PRT_MESSAGE, "client %d: movement failure in ", ms->client); |
| 3347 |
AAS_PrintTravelType(reach.traveltype & TRAVELTYPE_MASK); |
| 3348 |
botimport.Print(PRT_MESSAGE, "\n"); |
| 3349 |
} |
| 3350 |
} |
| 3351 |
#endif |
| 3352 |
} |
| 3353 |
else |
| 3354 |
{ |
| 3355 |
int i, numareas, areas[16]; |
| 3356 |
vec3_t end; |
| 3357 |
|
| 3358 |
|
| 3359 |
foundjumppad = qfalse; |
| 3360 |
VectorMA(ms->origin, -2 * ms->thinktime, ms->velocity, end); |
| 3361 |
numareas = AAS_TraceAreas(ms->origin, end, areas, NULL, 16); |
| 3362 |
for (i = numareas-1; i >= 0; i--) |
| 3363 |
{ |
| 3364 |
if (AAS_AreaJumpPad(areas[i])) |
| 3365 |
{ |
| 3366 |
|
| 3367 |
foundjumppad = qtrue; |
| 3368 |
lastreachnum = BotGetReachabilityToGoal(end, areas[i], |
| 3369 |
ms->lastgoalareanum, ms->lastareanum, |
| 3370 |
ms->avoidreach, ms->avoidreachtimes, ms->avoidreachtries, |
| 3371 |
goal, TFL_JUMPPAD, ms->avoidspots, ms->numavoidspots, NULL); |
| 3372 |
if (lastreachnum) |
| 3373 |
{ |
| 3374 |
ms->lastreachnum = lastreachnum; |
| 3375 |
ms->lastareanum = areas[i]; |
| 3376 |
|
| 3377 |
break; |
| 3378 |
} |
| 3379 |
else |
| 3380 |
{ |
| 3381 |
for (lastreachnum = AAS_NextAreaReachability(areas[i], 0); lastreachnum; |
| 3382 |
lastreachnum = AAS_NextAreaReachability(areas[i], lastreachnum)) |
| 3383 |
{ |
| 3384 |
|
| 3385 |
AAS_ReachabilityFromNum(lastreachnum, &reach); |
| 3386 |
if ((reach.traveltype & TRAVELTYPE_MASK) == TRAVEL_JUMPPAD) |
| 3387 |
{ |
| 3388 |
ms->lastreachnum = lastreachnum; |
| 3389 |
ms->lastareanum = areas[i]; |
| 3390 |
|
| 3391 |
} |
| 3392 |
} |
| 3393 |
if (lastreachnum) break; |
| 3394 |
} |
| 3395 |
} |
| 3396 |
} |
| 3397 |
if (botDeveloper) |
| 3398 |
{ |
| 3399 |
|
| 3400 |
if (foundjumppad && !ms->lastreachnum) |
| 3401 |
{ |
| 3402 |
botimport.Print(PRT_MESSAGE, "client %d didn't find jumppad reachability\n", ms->client); |
| 3403 |
} |
| 3404 |
} |
| 3405 |
|
| 3406 |
if (ms->lastreachnum) |
| 3407 |
{ |
| 3408 |
|
| 3409 |
AAS_ReachabilityFromNum(ms->lastreachnum, &reach); |
| 3410 |
result->traveltype = reach.traveltype; |
| 3411 |
#ifdef DEBUG |
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
#endif |
| 3416 |
|
| 3417 |
switch(reach.traveltype & TRAVELTYPE_MASK) |
| 3418 |
{ |
| 3419 |
case TRAVEL_WALK: *result = BotTravel_Walk(ms, &reach); break; |
| 3420 |
case TRAVEL_CROUCH: break; |
| 3421 |
case TRAVEL_BARRIERJUMP: *result = BotFinishTravel_BarrierJump(ms, &reach); break; |
| 3422 |
case TRAVEL_LADDER: *result = BotTravel_Ladder(ms, &reach); break; |
| 3423 |
case TRAVEL_WALKOFFLEDGE: *result = BotFinishTravel_WalkOffLedge(ms, &reach); break; |
| 3424 |
case TRAVEL_JUMP: *result = BotFinishTravel_Jump(ms, &reach); break; |
| 3425 |
case TRAVEL_SWIM: *result = BotTravel_Swim(ms, &reach); break; |
| 3426 |
case TRAVEL_WATERJUMP: *result = BotFinishTravel_WaterJump(ms, &reach); break; |
| 3427 |
case TRAVEL_TELEPORT: break; |
| 3428 |
case TRAVEL_ELEVATOR: *result = BotFinishTravel_Elevator(ms, &reach); break; |
| 3429 |
case TRAVEL_GRAPPLEHOOK: *result = BotTravel_Grapple(ms, &reach); break; |
| 3430 |
case TRAVEL_ROCKETJUMP: |
| 3431 |
case TRAVEL_BFGJUMP: *result = BotFinishTravel_WeaponJump(ms, &reach); break; |
| 3432 |
case TRAVEL_JUMPPAD: *result = BotFinishTravel_JumpPad(ms, &reach); break; |
| 3433 |
case TRAVEL_FUNCBOB: *result = BotFinishTravel_FuncBobbing(ms, &reach); break; |
| 3434 |
default: |
| 3435 |
{ |
| 3436 |
botimport.Print(PRT_FATAL, "(last) travel type %d not implemented yet\n", (reach.traveltype & TRAVELTYPE_MASK)); |
| 3437 |
break; |
| 3438 |
} |
| 3439 |
} |
| 3440 |
result->traveltype = reach.traveltype; |
| 3441 |
#ifdef DEBUG |
| 3442 |
if (botDeveloper) |
| 3443 |
{ |
| 3444 |
if (result->failure) |
| 3445 |
{ |
| 3446 |
botimport.Print(PRT_MESSAGE, "client %d: movement failure in finish ", ms->client); |
| 3447 |
AAS_PrintTravelType(reach.traveltype & TRAVELTYPE_MASK); |
| 3448 |
botimport.Print(PRT_MESSAGE, "\n"); |
| 3449 |
} |
| 3450 |
} |
| 3451 |
#endif |
| 3452 |
} |
| 3453 |
} |
| 3454 |
|
| 3455 |
if (result->blocked) ms->reachability_time -= 10 * ms->thinktime; |
| 3456 |
|
| 3457 |
VectorCopy(ms->origin, ms->lastorigin); |
| 3458 |
} |
| 3459 |
|
| 3460 |
|
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
void BotResetAvoidReach(int movestate) |
| 3466 |
{ |
| 3467 |
bot_movestate_t *ms; |
| 3468 |
|
| 3469 |
ms = BotMoveStateFromHandle(movestate); |
| 3470 |
if (!ms) return; |
| 3471 |
Com_Memset(ms->avoidreach, 0, MAX_AVOIDREACH * sizeof(int)); |
| 3472 |
Com_Memset(ms->avoidreachtimes, 0, MAX_AVOIDREACH * sizeof(float)); |
| 3473 |
Com_Memset(ms->avoidreachtries, 0, MAX_AVOIDREACH * sizeof(int)); |
| 3474 |
} |
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
void BotResetLastAvoidReach(int movestate) |
| 3482 |
{ |
| 3483 |
int i, latest; |
| 3484 |
float latesttime; |
| 3485 |
bot_movestate_t *ms; |
| 3486 |
|
| 3487 |
ms = BotMoveStateFromHandle(movestate); |
| 3488 |
if (!ms) return; |
| 3489 |
latesttime = 0; |
| 3490 |
latest = 0; |
| 3491 |
for (i = 0; i < MAX_AVOIDREACH; i++) |
| 3492 |
{ |
| 3493 |
if (ms->avoidreachtimes[i] > latesttime) |
| 3494 |
{ |
| 3495 |
latesttime = ms->avoidreachtimes[i]; |
| 3496 |
latest = i; |
| 3497 |
} |
| 3498 |
} |
| 3499 |
if (latesttime) |
| 3500 |
{ |
| 3501 |
ms->avoidreachtimes[latest] = 0; |
| 3502 |
if (ms->avoidreachtries[latest] > 0) ms->avoidreachtries[latest]--; |
| 3503 |
} |
| 3504 |
} |
| 3505 |
|
| 3506 |
|
| 3507 |
|
| 3508 |
|
| 3509 |
|
| 3510 |
|
| 3511 |
void BotResetMoveState(int movestate) |
| 3512 |
{ |
| 3513 |
bot_movestate_t *ms; |
| 3514 |
|
| 3515 |
ms = BotMoveStateFromHandle(movestate); |
| 3516 |
if (!ms) return; |
| 3517 |
Com_Memset(ms, 0, sizeof(bot_movestate_t)); |
| 3518 |
} |
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
int BotSetupMoveAI(void) |
| 3526 |
{ |
| 3527 |
BotSetBrushModelTypes(); |
| 3528 |
sv_maxstep = LibVar("sv_step", "18"); |
| 3529 |
sv_maxbarrier = LibVar("sv_maxbarrier", "32"); |
| 3530 |
sv_gravity = LibVar("sv_gravity", "800"); |
| 3531 |
weapindex_rocketlauncher = LibVar("weapindex_rocketlauncher", "5"); |
| 3532 |
weapindex_bfg10k = LibVar("weapindex_bfg10k", "9"); |
| 3533 |
weapindex_grapple = LibVar("weapindex_grapple", "10"); |
| 3534 |
entitytypemissile = LibVar("entitytypemissile", "3"); |
| 3535 |
offhandgrapple = LibVar("offhandgrapple", "0"); |
| 3536 |
cmd_grappleon = LibVar("cmd_grappleon", "grappleon"); |
| 3537 |
cmd_grappleoff = LibVar("cmd_grappleoff", "grappleoff"); |
| 3538 |
return BLERR_NOERROR; |
| 3539 |
} |
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
void BotShutdownMoveAI(void) |
| 3547 |
{ |
| 3548 |
int i; |
| 3549 |
|
| 3550 |
for (i = 1; i <= MAX_CLIENTS; i++) |
| 3551 |
{ |
| 3552 |
if (botmovestates[i]) |
| 3553 |
{ |
| 3554 |
FreeMemory(botmovestates[i]); |
| 3555 |
botmovestates[i] = NULL; |
| 3556 |
} |
| 3557 |
} |
| 3558 |
} |
| 3559 |
|
| 3560 |
|