| 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 |
|
| 33 |
#include "g_local.h" |
| 34 |
#include "../botlib/botlib.h" |
| 35 |
#include "../botlib/be_aas.h" |
| 36 |
#include "../botlib/be_ea.h" |
| 37 |
#include "../botlib/be_ai_char.h" |
| 38 |
#include "../botlib/be_ai_chat.h" |
| 39 |
#include "../botlib/be_ai_gen.h" |
| 40 |
#include "../botlib/be_ai_goal.h" |
| 41 |
#include "../botlib/be_ai_move.h" |
| 42 |
#include "../botlib/be_ai_weap.h" |
| 43 |
|
| 44 |
#include "ai_main.h" |
| 45 |
#include "ai_dmq3.h" |
| 46 |
#include "ai_chat.h" |
| 47 |
#include "ai_cmd.h" |
| 48 |
#include "ai_dmnet.h" |
| 49 |
#include "ai_team.h" |
| 50 |
|
| 51 |
#include "chars.h" |
| 52 |
#include "inv.h" |
| 53 |
#include "syn.h" |
| 54 |
#include "match.h" |
| 55 |
|
| 56 |
|
| 57 |
#include "../../ui/menudef.h" |
| 58 |
|
| 59 |
|
| 60 |
#define GFL_AIR 128 |
| 61 |
|
| 62 |
int numnodeswitches; |
| 63 |
char nodeswitch[MAX_NODESWITCHES+1][144]; |
| 64 |
|
| 65 |
#define LOOKAHEAD_DISTANCE 300 |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
void BotResetNodeSwitches(void) { |
| 73 |
numnodeswitches = 0; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
void BotDumpNodeSwitches(bot_state_t *bs) { |
| 82 |
int i; |
| 83 |
char netname[MAX_NETNAME]; |
| 84 |
|
| 85 |
ClientName(bs->client, netname, sizeof(netname)); |
| 86 |
BotAI_Print(PRT_MESSAGE, "%s at %1.1f switched more than %d AI nodes\n", netname, FloatTime(), MAX_NODESWITCHES); |
| 87 |
for (i = 0; i < numnodeswitches; i++) { |
| 88 |
BotAI_Print(PRT_MESSAGE, "%s", nodeswitch[i]); |
| 89 |
} |
| 90 |
BotAI_Print(PRT_FATAL, ""); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
void BotRecordNodeSwitch(bot_state_t *bs, char *node, char *str, char *s) { |
| 99 |
char netname[MAX_NETNAME]; |
| 100 |
|
| 101 |
ClientName(bs->client, netname, sizeof(netname)); |
| 102 |
Com_sprintf(nodeswitch[numnodeswitches], 144, "%s at %2.1f entered %s: %s from %s\n", netname, FloatTime(), node, str, s); |
| 103 |
#ifdef DEBUG |
| 104 |
if (0) { |
| 105 |
BotAI_Print(PRT_MESSAGE, "%s", nodeswitch[numnodeswitches]); |
| 106 |
} |
| 107 |
#endif |
| 108 |
numnodeswitches++; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
int BotGetAirGoal(bot_state_t *bs, bot_goal_t *goal) { |
| 117 |
bsp_trace_t bsptrace; |
| 118 |
vec3_t end, mins = {-15, -15, -2}, maxs = {15, 15, 2}; |
| 119 |
int areanum; |
| 120 |
|
| 121 |
|
| 122 |
VectorCopy(bs->origin, end); |
| 123 |
end[2] += 1000; |
| 124 |
BotAI_Trace(&bsptrace, bs->origin, mins, maxs, end, bs->entitynum, CONTENTS_SOLID|CONTENTS_PLAYERCLIP); |
| 125 |
|
| 126 |
VectorCopy(bsptrace.endpos, end); |
| 127 |
BotAI_Trace(&bsptrace, end, mins, maxs, bs->origin, bs->entitynum, CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA); |
| 128 |
|
| 129 |
if (bsptrace.fraction > 0) { |
| 130 |
areanum = BotPointAreaNum(bsptrace.endpos); |
| 131 |
if (areanum) { |
| 132 |
VectorCopy(bsptrace.endpos, goal->origin); |
| 133 |
goal->origin[2] -= 2; |
| 134 |
goal->areanum = areanum; |
| 135 |
goal->mins[0] = -15; |
| 136 |
goal->mins[1] = -15; |
| 137 |
goal->mins[2] = -1; |
| 138 |
goal->maxs[0] = 15; |
| 139 |
goal->maxs[1] = 15; |
| 140 |
goal->maxs[2] = 1; |
| 141 |
goal->flags = GFL_AIR; |
| 142 |
goal->number = 0; |
| 143 |
goal->iteminfo = 0; |
| 144 |
goal->entitynum = 0; |
| 145 |
return qtrue; |
| 146 |
} |
| 147 |
} |
| 148 |
return qfalse; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
int BotGoForAir(bot_state_t *bs, int tfl, bot_goal_t *ltg, float range) { |
| 157 |
bot_goal_t goal; |
| 158 |
|
| 159 |
|
| 160 |
if (bs->lastair_time < FloatTime() - 6) { |
| 161 |
|
| 162 |
#ifdef DEBUG |
| 163 |
|
| 164 |
#endif |
| 165 |
|
| 166 |
if (BotGetAirGoal(bs, &goal)) { |
| 167 |
trap_BotPushGoal(bs->gs, &goal); |
| 168 |
return qtrue; |
| 169 |
} |
| 170 |
else { |
| 171 |
|
| 172 |
while(trap_BotChooseNBGItem(bs->gs, bs->origin, bs->inventory, tfl, ltg, range)) { |
| 173 |
trap_BotGetTopGoal(bs->gs, &goal); |
| 174 |
|
| 175 |
if (!(trap_AAS_PointContents(goal.origin) & (CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA))) { |
| 176 |
return qtrue; |
| 177 |
} |
| 178 |
trap_BotPopGoal(bs->gs); |
| 179 |
} |
| 180 |
trap_BotResetAvoidGoals(bs->gs); |
| 181 |
} |
| 182 |
} |
| 183 |
return qfalse; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
int BotNearbyGoal(bot_state_t *bs, int tfl, bot_goal_t *ltg, float range) { |
| 192 |
int ret; |
| 193 |
|
| 194 |
|
| 195 |
if (BotGoForAir(bs, tfl, ltg, range)) return qtrue; |
| 196 |
|
| 197 |
if (BotCTFCarryingFlag(bs) |
| 198 |
#ifdef MISSIONPACK |
| 199 |
|| Bot1FCTFCarryingFlag(bs) || BotHarvesterCarryingCubes(bs) |
| 200 |
#endif |
| 201 |
) { |
| 202 |
|
| 203 |
if (trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, |
| 204 |
bs->teamgoal.areanum, TFL_DEFAULT) < 300) { |
| 205 |
|
| 206 |
range = 50; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
ret = trap_BotChooseNBGItem(bs->gs, bs->origin, bs->inventory, tfl, ltg, range); |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
return ret; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
int BotReachedGoal(bot_state_t *bs, bot_goal_t *goal) { |
| 230 |
if (goal->flags & GFL_ITEM) { |
| 231 |
|
| 232 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 233 |
if (!(goal->flags & GFL_DROPPED)) { |
| 234 |
trap_BotSetAvoidGoalTime(bs->gs, goal->number, -1); |
| 235 |
} |
| 236 |
return qtrue; |
| 237 |
} |
| 238 |
|
| 239 |
if (trap_BotItemGoalInVisButNotVisible(bs->entitynum, bs->eye, bs->viewangles, goal)) { |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
return qtrue; |
| 252 |
} |
| 253 |
|
| 254 |
if (bs->areanum == goal->areanum) { |
| 255 |
if (bs->origin[0] > goal->origin[0] + goal->mins[0] && bs->origin[0] < goal->origin[0] + goal->maxs[0]) { |
| 256 |
if (bs->origin[1] > goal->origin[1] + goal->mins[1] && bs->origin[1] < goal->origin[1] + goal->maxs[1]) { |
| 257 |
if (!trap_AAS_Swimming(bs->origin)) { |
| 258 |
return qtrue; |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
} |
| 264 |
else if (goal->flags & GFL_AIR) { |
| 265 |
|
| 266 |
if (trap_BotTouchingGoal(bs->origin, goal)) return qtrue; |
| 267 |
|
| 268 |
if (bs->lastair_time > FloatTime() - 1) return qtrue; |
| 269 |
} |
| 270 |
else { |
| 271 |
|
| 272 |
if (trap_BotTouchingGoal(bs->origin, goal)) return qtrue; |
| 273 |
} |
| 274 |
return qfalse; |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
int BotGetItemLongTermGoal(bot_state_t *bs, int tfl, bot_goal_t *goal) { |
| 283 |
|
| 284 |
if (!trap_BotGetTopGoal(bs->gs, goal)) { |
| 285 |
|
| 286 |
bs->ltg_time = 0; |
| 287 |
} |
| 288 |
|
| 289 |
else if (BotReachedGoal(bs, goal)) { |
| 290 |
BotChooseWeapon(bs); |
| 291 |
bs->ltg_time = 0; |
| 292 |
} |
| 293 |
|
| 294 |
if (bs->ltg_time < FloatTime()) { |
| 295 |
|
| 296 |
trap_BotPopGoal(bs->gs); |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
if (trap_BotChooseLTGItem(bs->gs, bs->origin, bs->inventory, tfl)) { |
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
bs->ltg_time = FloatTime() + 20; |
| 309 |
} |
| 310 |
else { |
| 311 |
|
| 312 |
#ifdef DEBUG |
| 313 |
char netname[128]; |
| 314 |
|
| 315 |
BotAI_Print(PRT_MESSAGE, "%s: no valid ltg (probably stuck)\n", ClientName(bs->client, netname, sizeof(netname))); |
| 316 |
#endif |
| 317 |
|
| 318 |
|
| 319 |
trap_BotResetAvoidGoals(bs->gs); |
| 320 |
trap_BotResetAvoidReach(bs->ms); |
| 321 |
} |
| 322 |
|
| 323 |
return trap_BotGetTopGoal(bs->gs, goal); |
| 324 |
} |
| 325 |
return qtrue; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
int BotGetLongTermGoal(bot_state_t *bs, int tfl, int retreat, bot_goal_t *goal) { |
| 337 |
vec3_t target, dir, dir2; |
| 338 |
char netname[MAX_NETNAME]; |
| 339 |
char buf[MAX_MESSAGE_SIZE]; |
| 340 |
int areanum; |
| 341 |
float croucher; |
| 342 |
aas_entityinfo_t entinfo, botinfo; |
| 343 |
bot_waypoint_t *wp; |
| 344 |
|
| 345 |
if (bs->ltgtype == LTG_TEAMHELP && !retreat) { |
| 346 |
|
| 347 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 348 |
BotAI_BotInitialChat(bs, "help_start", EasyClientName(bs->teammate, netname, sizeof(netname)), NULL); |
| 349 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 350 |
BotVoiceChatOnly(bs, bs->decisionmaker, VOICECHAT_YES); |
| 351 |
trap_EA_Action(bs->client, ACTION_AFFIRMATIVE); |
| 352 |
bs->teammessage_time = 0; |
| 353 |
} |
| 354 |
|
| 355 |
if (bs->teamgoal_time < FloatTime()) |
| 356 |
bs->ltgtype = 0; |
| 357 |
|
| 358 |
if (bs->teammatevisible_time < FloatTime() - 10) bs->ltgtype = 0; |
| 359 |
|
| 360 |
BotEntityInfo(bs->teammate, &entinfo); |
| 361 |
|
| 362 |
if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->teammate)) { |
| 363 |
|
| 364 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 365 |
if (VectorLengthSquared(dir) < Square(100)) { |
| 366 |
trap_BotResetAvoidReach(bs->ms); |
| 367 |
return qfalse; |
| 368 |
} |
| 369 |
} |
| 370 |
else { |
| 371 |
|
| 372 |
bs->teammatevisible_time = FloatTime(); |
| 373 |
} |
| 374 |
|
| 375 |
if (entinfo.valid) { |
| 376 |
areanum = BotPointAreaNum(entinfo.origin); |
| 377 |
if (areanum && trap_AAS_AreaReachability(areanum)) { |
| 378 |
|
| 379 |
bs->teamgoal.entitynum = bs->teammate; |
| 380 |
bs->teamgoal.areanum = areanum; |
| 381 |
VectorCopy(entinfo.origin, bs->teamgoal.origin); |
| 382 |
VectorSet(bs->teamgoal.mins, -8, -8, -8); |
| 383 |
VectorSet(bs->teamgoal.maxs, 8, 8, 8); |
| 384 |
} |
| 385 |
} |
| 386 |
memcpy(goal, &bs->teamgoal, sizeof(bot_goal_t)); |
| 387 |
return qtrue; |
| 388 |
} |
| 389 |
|
| 390 |
if (bs->ltgtype == LTG_TEAMACCOMPANY && !retreat) { |
| 391 |
|
| 392 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 393 |
BotAI_BotInitialChat(bs, "accompany_start", EasyClientName(bs->teammate, netname, sizeof(netname)), NULL); |
| 394 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 395 |
BotVoiceChatOnly(bs, bs->decisionmaker, VOICECHAT_YES); |
| 396 |
trap_EA_Action(bs->client, ACTION_AFFIRMATIVE); |
| 397 |
bs->teammessage_time = 0; |
| 398 |
} |
| 399 |
|
| 400 |
if (bs->teamgoal_time < FloatTime()) { |
| 401 |
BotAI_BotInitialChat(bs, "accompany_stop", EasyClientName(bs->teammate, netname, sizeof(netname)), NULL); |
| 402 |
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL); |
| 403 |
bs->ltgtype = 0; |
| 404 |
} |
| 405 |
|
| 406 |
BotEntityInfo(bs->teammate, &entinfo); |
| 407 |
|
| 408 |
if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->teammate)) { |
| 409 |
|
| 410 |
bs->teammatevisible_time = FloatTime(); |
| 411 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 412 |
if (VectorLengthSquared(dir) < Square(bs->formation_dist)) { |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
BotEntityInfo(bs->entitynum, &botinfo); |
| 417 |
|
| 418 |
if (botinfo.origin[2] + botinfo.maxs[2] > entinfo.origin[2] + entinfo.mins[2]) { |
| 419 |
|
| 420 |
if (botinfo.origin[0] + botinfo.maxs[0] > entinfo.origin[0] + entinfo.mins[0] - 4&& |
| 421 |
botinfo.origin[0] + botinfo.mins[0] < entinfo.origin[0] + entinfo.maxs[0] + 4) { |
| 422 |
if (botinfo.origin[1] + botinfo.maxs[1] > entinfo.origin[1] + entinfo.mins[1] - 4 && |
| 423 |
botinfo.origin[1] + botinfo.mins[1] < entinfo.origin[1] + entinfo.maxs[1] + 4) { |
| 424 |
if (botinfo.origin[2] + botinfo.maxs[2] > entinfo.origin[2] + entinfo.mins[2] - 4 && |
| 425 |
botinfo.origin[2] + botinfo.mins[2] < entinfo.origin[2] + entinfo.maxs[2] + 4) { |
| 426 |
|
| 427 |
AngleVectors(entinfo.angles, dir, NULL, NULL); |
| 428 |
dir[2] = 0; |
| 429 |
VectorNormalize(dir); |
| 430 |
|
| 431 |
VectorSubtract(bs->origin, entinfo.origin, dir2); |
| 432 |
VectorNormalize(dir2); |
| 433 |
if (DotProduct(dir, dir2) > 0.7) { |
| 434 |
|
| 435 |
BotSetupForMovement(bs); |
| 436 |
trap_BotMoveInDirection(bs->ms, dir2, 400, MOVE_WALK); |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
if (bs->attackcrouch_time < FloatTime() - 5) { |
| 445 |
croucher = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CROUCHER, 0, 1); |
| 446 |
if (random() < bs->thinktime * croucher) { |
| 447 |
bs->attackcrouch_time = FloatTime() + 5 + croucher * 15; |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
if (trap_AAS_Swimming(bs->origin)) bs->attackcrouch_time = FloatTime() - 1; |
| 452 |
|
| 453 |
if (bs->arrive_time < FloatTime() - 2) { |
| 454 |
|
| 455 |
if (!bs->arrive_time) { |
| 456 |
trap_EA_Gesture(bs->client); |
| 457 |
BotAI_BotInitialChat(bs, "accompany_arrive", EasyClientName(bs->teammate, netname, sizeof(netname)), NULL); |
| 458 |
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL); |
| 459 |
bs->arrive_time = FloatTime(); |
| 460 |
} |
| 461 |
|
| 462 |
else if (bs->attackcrouch_time > FloatTime()) { |
| 463 |
trap_EA_Crouch(bs->client); |
| 464 |
} |
| 465 |
|
| 466 |
else if (random() < bs->thinktime * 0.05) { |
| 467 |
|
| 468 |
trap_EA_Gesture(bs->client); |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
if (bs->arrive_time > FloatTime() - 2) { |
| 473 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 474 |
vectoangles(dir, bs->ideal_viewangles); |
| 475 |
bs->ideal_viewangles[2] *= 0.5; |
| 476 |
} |
| 477 |
|
| 478 |
else if (random() < bs->thinktime * 0.8) { |
| 479 |
BotRoamGoal(bs, target); |
| 480 |
VectorSubtract(target, bs->origin, dir); |
| 481 |
vectoangles(dir, bs->ideal_viewangles); |
| 482 |
bs->ideal_viewangles[2] *= 0.5; |
| 483 |
} |
| 484 |
|
| 485 |
if (BotGoForAir(bs, bs->tfl, &bs->teamgoal, 400)) { |
| 486 |
trap_BotResetLastAvoidReach(bs->ms); |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
bs->nbg_time = FloatTime() + 8; |
| 493 |
AIEnter_Seek_NBG(bs, "BotLongTermGoal: go for air"); |
| 494 |
return qfalse; |
| 495 |
} |
| 496 |
|
| 497 |
trap_BotResetAvoidReach(bs->ms); |
| 498 |
return qfalse; |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
if (entinfo.valid) { |
| 503 |
areanum = BotPointAreaNum(entinfo.origin); |
| 504 |
if (areanum && trap_AAS_AreaReachability(areanum)) { |
| 505 |
|
| 506 |
bs->teamgoal.entitynum = bs->teammate; |
| 507 |
bs->teamgoal.areanum = areanum; |
| 508 |
VectorCopy(entinfo.origin, bs->teamgoal.origin); |
| 509 |
VectorSet(bs->teamgoal.mins, -8, -8, -8); |
| 510 |
VectorSet(bs->teamgoal.maxs, 8, 8, 8); |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
memcpy(goal, &bs->teamgoal, sizeof(bot_goal_t)); |
| 515 |
|
| 516 |
if (bs->teammatevisible_time < FloatTime() - 60) { |
| 517 |
BotAI_BotInitialChat(bs, "accompany_cannotfind", EasyClientName(bs->teammate, netname, sizeof(netname)), NULL); |
| 518 |
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL); |
| 519 |
bs->ltgtype = 0; |
| 520 |
|
| 521 |
bs->teammatevisible_time = FloatTime(); |
| 522 |
} |
| 523 |
return qtrue; |
| 524 |
} |
| 525 |
|
| 526 |
if (bs->ltgtype == LTG_DEFENDKEYAREA) { |
| 527 |
if (trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, |
| 528 |
bs->teamgoal.areanum, TFL_DEFAULT) > bs->defendaway_range) { |
| 529 |
bs->defendaway_time = 0; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
if (bs->ltgtype == LTG_DEFENDKEYAREA && !retreat && |
| 534 |
bs->defendaway_time < FloatTime()) { |
| 535 |
|
| 536 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 537 |
trap_BotGoalName(bs->teamgoal.number, buf, sizeof(buf)); |
| 538 |
BotAI_BotInitialChat(bs, "defend_start", buf, NULL); |
| 539 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 540 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONDEFENSE); |
| 541 |
bs->teammessage_time = 0; |
| 542 |
} |
| 543 |
|
| 544 |
memcpy(goal, &bs->teamgoal, sizeof(bot_goal_t)); |
| 545 |
|
| 546 |
if (bs->teamgoal_time < FloatTime()) { |
| 547 |
trap_BotGoalName(bs->teamgoal.number, buf, sizeof(buf)); |
| 548 |
BotAI_BotInitialChat(bs, "defend_stop", buf, NULL); |
| 549 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 550 |
bs->ltgtype = 0; |
| 551 |
} |
| 552 |
|
| 553 |
VectorSubtract(goal->origin, bs->origin, dir); |
| 554 |
if (VectorLengthSquared(dir) < Square(70)) { |
| 555 |
trap_BotResetAvoidReach(bs->ms); |
| 556 |
bs->defendaway_time = FloatTime() + 3 + 3 * random(); |
| 557 |
if (BotHasPersistantPowerupAndWeapon(bs)) { |
| 558 |
bs->defendaway_range = 100; |
| 559 |
} |
| 560 |
else { |
| 561 |
bs->defendaway_range = 350; |
| 562 |
} |
| 563 |
} |
| 564 |
return qtrue; |
| 565 |
} |
| 566 |
|
| 567 |
if (bs->ltgtype == LTG_KILL && !retreat) { |
| 568 |
|
| 569 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 570 |
EasyClientName(bs->teamgoal.entitynum, buf, sizeof(buf)); |
| 571 |
BotAI_BotInitialChat(bs, "kill_start", buf, NULL); |
| 572 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 573 |
bs->teammessage_time = 0; |
| 574 |
} |
| 575 |
|
| 576 |
if (bs->killedenemy_time > bs->teamgoal_time - TEAM_KILL_SOMEONE && bs->lastkilledplayer == bs->teamgoal.entitynum) { |
| 577 |
EasyClientName(bs->teamgoal.entitynum, buf, sizeof(buf)); |
| 578 |
BotAI_BotInitialChat(bs, "kill_done", buf, NULL); |
| 579 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 580 |
bs->ltgtype = 0; |
| 581 |
} |
| 582 |
|
| 583 |
if (bs->teamgoal_time < FloatTime()) { |
| 584 |
bs->ltgtype = 0; |
| 585 |
} |
| 586 |
|
| 587 |
return BotGetItemLongTermGoal(bs, tfl, goal); |
| 588 |
} |
| 589 |
|
| 590 |
if (bs->ltgtype == LTG_GETITEM && !retreat) { |
| 591 |
|
| 592 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 593 |
trap_BotGoalName(bs->teamgoal.number, buf, sizeof(buf)); |
| 594 |
BotAI_BotInitialChat(bs, "getitem_start", buf, NULL); |
| 595 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 596 |
BotVoiceChatOnly(bs, bs->decisionmaker, VOICECHAT_YES); |
| 597 |
trap_EA_Action(bs->client, ACTION_AFFIRMATIVE); |
| 598 |
bs->teammessage_time = 0; |
| 599 |
} |
| 600 |
|
| 601 |
memcpy(goal, &bs->teamgoal, sizeof(bot_goal_t)); |
| 602 |
|
| 603 |
if (bs->teamgoal_time < FloatTime()) { |
| 604 |
bs->ltgtype = 0; |
| 605 |
} |
| 606 |
|
| 607 |
if (trap_BotItemGoalInVisButNotVisible(bs->entitynum, bs->eye, bs->viewangles, goal)) { |
| 608 |
trap_BotGoalName(bs->teamgoal.number, buf, sizeof(buf)); |
| 609 |
BotAI_BotInitialChat(bs, "getitem_notthere", buf, NULL); |
| 610 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 611 |
bs->ltgtype = 0; |
| 612 |
} |
| 613 |
else if (BotReachedGoal(bs, goal)) { |
| 614 |
trap_BotGoalName(bs->teamgoal.number, buf, sizeof(buf)); |
| 615 |
BotAI_BotInitialChat(bs, "getitem_gotit", buf, NULL); |
| 616 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 617 |
bs->ltgtype = 0; |
| 618 |
} |
| 619 |
return qtrue; |
| 620 |
} |
| 621 |
|
| 622 |
if ((bs->ltgtype == LTG_CAMP || bs->ltgtype == LTG_CAMPORDER) && !retreat) { |
| 623 |
|
| 624 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 625 |
if (bs->ltgtype == LTG_CAMPORDER) { |
| 626 |
BotAI_BotInitialChat(bs, "camp_start", EasyClientName(bs->teammate, netname, sizeof(netname)), NULL); |
| 627 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 628 |
BotVoiceChatOnly(bs, bs->decisionmaker, VOICECHAT_YES); |
| 629 |
trap_EA_Action(bs->client, ACTION_AFFIRMATIVE); |
| 630 |
} |
| 631 |
bs->teammessage_time = 0; |
| 632 |
} |
| 633 |
|
| 634 |
memcpy(goal, &bs->teamgoal, sizeof(bot_goal_t)); |
| 635 |
|
| 636 |
if (bs->teamgoal_time < FloatTime()) { |
| 637 |
if (bs->ltgtype == LTG_CAMPORDER) { |
| 638 |
BotAI_BotInitialChat(bs, "camp_stop", NULL); |
| 639 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 640 |
} |
| 641 |
bs->ltgtype = 0; |
| 642 |
} |
| 643 |
|
| 644 |
VectorSubtract(goal->origin, bs->origin, dir); |
| 645 |
if (VectorLengthSquared(dir) < Square(60)) |
| 646 |
{ |
| 647 |
|
| 648 |
if (!bs->arrive_time) { |
| 649 |
if (bs->ltgtype == LTG_CAMPORDER) { |
| 650 |
BotAI_BotInitialChat(bs, "camp_arrive", EasyClientName(bs->teammate, netname, sizeof(netname)), NULL); |
| 651 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 652 |
BotVoiceChatOnly(bs, bs->decisionmaker, VOICECHAT_INPOSITION); |
| 653 |
} |
| 654 |
bs->arrive_time = FloatTime(); |
| 655 |
} |
| 656 |
|
| 657 |
if (random() < bs->thinktime * 0.8) { |
| 658 |
BotRoamGoal(bs, target); |
| 659 |
VectorSubtract(target, bs->origin, dir); |
| 660 |
vectoangles(dir, bs->ideal_viewangles); |
| 661 |
bs->ideal_viewangles[2] *= 0.5; |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
if (bs->attackcrouch_time < FloatTime() - 5) { |
| 666 |
croucher = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CROUCHER, 0, 1); |
| 667 |
if (random() < bs->thinktime * croucher) { |
| 668 |
bs->attackcrouch_time = FloatTime() + 5 + croucher * 15; |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
if (bs->attackcrouch_time > FloatTime()) { |
| 673 |
trap_EA_Crouch(bs->client); |
| 674 |
} |
| 675 |
|
| 676 |
if (trap_AAS_Swimming(bs->origin)) bs->attackcrouch_time = FloatTime() - 1; |
| 677 |
|
| 678 |
if (trap_PointContents(bs->eye,bs->entitynum) & (CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA)) { |
| 679 |
if (bs->ltgtype == LTG_CAMPORDER) { |
| 680 |
BotAI_BotInitialChat(bs, "camp_stop", NULL); |
| 681 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 682 |
|
| 683 |
if (bs->lastgoal_ltgtype == LTG_CAMPORDER) { |
| 684 |
bs->lastgoal_ltgtype = 0; |
| 685 |
} |
| 686 |
} |
| 687 |
bs->ltgtype = 0; |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
trap_BotResetAvoidReach(bs->ms); |
| 693 |
return qfalse; |
| 694 |
} |
| 695 |
return qtrue; |
| 696 |
} |
| 697 |
|
| 698 |
if (bs->ltgtype == LTG_PATROL && !retreat) { |
| 699 |
|
| 700 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 701 |
strcpy(buf, ""); |
| 702 |
for (wp = bs->patrolpoints; wp; wp = wp->next) { |
| 703 |
strcat(buf, wp->name); |
| 704 |
if (wp->next) strcat(buf, " to "); |
| 705 |
} |
| 706 |
BotAI_BotInitialChat(bs, "patrol_start", buf, NULL); |
| 707 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 708 |
BotVoiceChatOnly(bs, bs->decisionmaker, VOICECHAT_YES); |
| 709 |
trap_EA_Action(bs->client, ACTION_AFFIRMATIVE); |
| 710 |
bs->teammessage_time = 0; |
| 711 |
} |
| 712 |
|
| 713 |
if (!bs->curpatrolpoint) { |
| 714 |
bs->ltgtype = 0; |
| 715 |
return qfalse; |
| 716 |
} |
| 717 |
|
| 718 |
if (trap_BotTouchingGoal(bs->origin, &bs->curpatrolpoint->goal)) { |
| 719 |
if (bs->patrolflags & PATROL_BACK) { |
| 720 |
if (bs->curpatrolpoint->prev) { |
| 721 |
bs->curpatrolpoint = bs->curpatrolpoint->prev; |
| 722 |
} |
| 723 |
else { |
| 724 |
bs->curpatrolpoint = bs->curpatrolpoint->next; |
| 725 |
bs->patrolflags &= ~PATROL_BACK; |
| 726 |
} |
| 727 |
} |
| 728 |
else { |
| 729 |
if (bs->curpatrolpoint->next) { |
| 730 |
bs->curpatrolpoint = bs->curpatrolpoint->next; |
| 731 |
} |
| 732 |
else { |
| 733 |
bs->curpatrolpoint = bs->curpatrolpoint->prev; |
| 734 |
bs->patrolflags |= PATROL_BACK; |
| 735 |
} |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
if (bs->teamgoal_time < FloatTime()) { |
| 740 |
BotAI_BotInitialChat(bs, "patrol_stop", NULL); |
| 741 |
trap_BotEnterChat(bs->cs, bs->decisionmaker, CHAT_TELL); |
| 742 |
bs->ltgtype = 0; |
| 743 |
} |
| 744 |
if (!bs->curpatrolpoint) { |
| 745 |
bs->ltgtype = 0; |
| 746 |
return qfalse; |
| 747 |
} |
| 748 |
memcpy(goal, &bs->curpatrolpoint->goal, sizeof(bot_goal_t)); |
| 749 |
return qtrue; |
| 750 |
} |
| 751 |
#ifdef CTF |
| 752 |
if (gametype == GT_CTF) { |
| 753 |
|
| 754 |
if (bs->ltgtype == LTG_GETFLAG) { |
| 755 |
|
| 756 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 757 |
BotAI_BotInitialChat(bs, "captureflag_start", NULL); |
| 758 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 759 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONGETFLAG); |
| 760 |
bs->teammessage_time = 0; |
| 761 |
} |
| 762 |
|
| 763 |
switch(BotTeam(bs)) { |
| 764 |
case TEAM_RED: memcpy(goal, &ctf_blueflag, sizeof(bot_goal_t)); break; |
| 765 |
case TEAM_BLUE: memcpy(goal, &ctf_redflag, sizeof(bot_goal_t)); break; |
| 766 |
default: bs->ltgtype = 0; return qfalse; |
| 767 |
} |
| 768 |
|
| 769 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 770 |
|
| 771 |
switch(BotTeam(bs)) { |
| 772 |
case TEAM_RED: bs->blueflagstatus = 1; break; |
| 773 |
case TEAM_BLUE: bs->redflagstatus = 1; break; |
| 774 |
} |
| 775 |
bs->ltgtype = 0; |
| 776 |
} |
| 777 |
|
| 778 |
if (bs->teamgoal_time < FloatTime()) { |
| 779 |
bs->ltgtype = 0; |
| 780 |
} |
| 781 |
BotAlternateRoute(bs, goal); |
| 782 |
return qtrue; |
| 783 |
} |
| 784 |
|
| 785 |
if (bs->ltgtype == LTG_RUSHBASE && bs->rushbaseaway_time < FloatTime()) { |
| 786 |
switch(BotTeam(bs)) { |
| 787 |
case TEAM_RED: memcpy(goal, &ctf_redflag, sizeof(bot_goal_t)); break; |
| 788 |
case TEAM_BLUE: memcpy(goal, &ctf_blueflag, sizeof(bot_goal_t)); break; |
| 789 |
default: bs->ltgtype = 0; return qfalse; |
| 790 |
} |
| 791 |
|
| 792 |
if (!BotCTFCarryingFlag(bs)) bs->ltgtype = 0; |
| 793 |
|
| 794 |
if (bs->teamgoal_time < FloatTime()) bs->ltgtype = 0; |
| 795 |
|
| 796 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 797 |
|
| 798 |
|
| 799 |
if (BotCTFCarryingFlag(bs)) { |
| 800 |
trap_BotResetAvoidReach(bs->ms); |
| 801 |
bs->rushbaseaway_time = FloatTime() + 5 + 10 * random(); |
| 802 |
|
| 803 |
} |
| 804 |
else { |
| 805 |
bs->ltgtype = 0; |
| 806 |
} |
| 807 |
} |
| 808 |
BotAlternateRoute(bs, goal); |
| 809 |
return qtrue; |
| 810 |
} |
| 811 |
|
| 812 |
if (bs->ltgtype == LTG_RETURNFLAG) { |
| 813 |
|
| 814 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 815 |
BotAI_BotInitialChat(bs, "returnflag_start", NULL); |
| 816 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 817 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONRETURNFLAG); |
| 818 |
bs->teammessage_time = 0; |
| 819 |
} |
| 820 |
|
| 821 |
switch(BotTeam(bs)) { |
| 822 |
case TEAM_RED: memcpy(goal, &ctf_blueflag, sizeof(bot_goal_t)); break; |
| 823 |
case TEAM_BLUE: memcpy(goal, &ctf_redflag, sizeof(bot_goal_t)); break; |
| 824 |
default: bs->ltgtype = 0; return qfalse; |
| 825 |
} |
| 826 |
|
| 827 |
if (trap_BotTouchingGoal(bs->origin, goal)) bs->ltgtype = 0; |
| 828 |
|
| 829 |
if (bs->teamgoal_time < FloatTime()) { |
| 830 |
bs->ltgtype = 0; |
| 831 |
} |
| 832 |
BotAlternateRoute(bs, goal); |
| 833 |
return qtrue; |
| 834 |
} |
| 835 |
} |
| 836 |
#endif |
| 837 |
#ifdef MISSIONPACK |
| 838 |
else if (gametype == GT_1FCTF) { |
| 839 |
if (bs->ltgtype == LTG_GETFLAG) { |
| 840 |
|
| 841 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 842 |
BotAI_BotInitialChat(bs, "captureflag_start", NULL); |
| 843 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 844 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONGETFLAG); |
| 845 |
bs->teammessage_time = 0; |
| 846 |
} |
| 847 |
memcpy(goal, &ctf_neutralflag, sizeof(bot_goal_t)); |
| 848 |
|
| 849 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 850 |
bs->ltgtype = 0; |
| 851 |
} |
| 852 |
|
| 853 |
if (bs->teamgoal_time < FloatTime()) { |
| 854 |
bs->ltgtype = 0; |
| 855 |
} |
| 856 |
return qtrue; |
| 857 |
} |
| 858 |
|
| 859 |
if (bs->ltgtype == LTG_RUSHBASE) { |
| 860 |
switch(BotTeam(bs)) { |
| 861 |
case TEAM_RED: memcpy(goal, &ctf_blueflag, sizeof(bot_goal_t)); break; |
| 862 |
case TEAM_BLUE: memcpy(goal, &ctf_redflag, sizeof(bot_goal_t)); break; |
| 863 |
default: bs->ltgtype = 0; return qfalse; |
| 864 |
} |
| 865 |
|
| 866 |
if (!Bot1FCTFCarryingFlag(bs)) { |
| 867 |
bs->ltgtype = 0; |
| 868 |
} |
| 869 |
|
| 870 |
if (bs->teamgoal_time < FloatTime()) { |
| 871 |
bs->ltgtype = 0; |
| 872 |
} |
| 873 |
|
| 874 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 875 |
bs->ltgtype = 0; |
| 876 |
} |
| 877 |
BotAlternateRoute(bs, goal); |
| 878 |
return qtrue; |
| 879 |
} |
| 880 |
|
| 881 |
if (bs->ltgtype == LTG_ATTACKENEMYBASE && |
| 882 |
bs->attackaway_time < FloatTime()) { |
| 883 |
|
| 884 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 885 |
BotAI_BotInitialChat(bs, "attackenemybase_start", NULL); |
| 886 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 887 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE); |
| 888 |
bs->teammessage_time = 0; |
| 889 |
} |
| 890 |
switch(BotTeam(bs)) { |
| 891 |
case TEAM_RED: memcpy(goal, &ctf_blueflag, sizeof(bot_goal_t)); break; |
| 892 |
case TEAM_BLUE: memcpy(goal, &ctf_redflag, sizeof(bot_goal_t)); break; |
| 893 |
default: bs->ltgtype = 0; return qfalse; |
| 894 |
} |
| 895 |
|
| 896 |
if (bs->teamgoal_time < FloatTime()) { |
| 897 |
bs->ltgtype = 0; |
| 898 |
} |
| 899 |
|
| 900 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 901 |
bs->attackaway_time = FloatTime() + 2 + 5 * random(); |
| 902 |
} |
| 903 |
return qtrue; |
| 904 |
} |
| 905 |
|
| 906 |
if (bs->ltgtype == LTG_RETURNFLAG) { |
| 907 |
|
| 908 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 909 |
BotAI_BotInitialChat(bs, "returnflag_start", NULL); |
| 910 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 911 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONRETURNFLAG); |
| 912 |
bs->teammessage_time = 0; |
| 913 |
} |
| 914 |
|
| 915 |
if (bs->teamgoal_time < FloatTime()) { |
| 916 |
bs->ltgtype = 0; |
| 917 |
} |
| 918 |
|
| 919 |
return BotGetItemLongTermGoal(bs, tfl, goal); |
| 920 |
} |
| 921 |
} |
| 922 |
else if (gametype == GT_OBELISK) { |
| 923 |
if (bs->ltgtype == LTG_ATTACKENEMYBASE && |
| 924 |
bs->attackaway_time < FloatTime()) { |
| 925 |
|
| 926 |
|
| 927 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 928 |
BotAI_BotInitialChat(bs, "attackenemybase_start", NULL); |
| 929 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 930 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE); |
| 931 |
bs->teammessage_time = 0; |
| 932 |
} |
| 933 |
switch(BotTeam(bs)) { |
| 934 |
case TEAM_RED: memcpy(goal, &blueobelisk, sizeof(bot_goal_t)); break; |
| 935 |
case TEAM_BLUE: memcpy(goal, &redobelisk, sizeof(bot_goal_t)); break; |
| 936 |
default: bs->ltgtype = 0; return qfalse; |
| 937 |
} |
| 938 |
|
| 939 |
if (BotFeelingBad(bs) > 50) { |
| 940 |
return BotGetItemLongTermGoal(bs, tfl, goal); |
| 941 |
} |
| 942 |
|
| 943 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 944 |
bs->attackaway_time = FloatTime() + 3 + 5 * random(); |
| 945 |
} |
| 946 |
|
| 947 |
VectorSubtract(bs->origin, goal->origin, dir); |
| 948 |
if (VectorLengthSquared(dir) < Square(60)) { |
| 949 |
bs->attackaway_time = FloatTime() + 3 + 5 * random(); |
| 950 |
} |
| 951 |
|
| 952 |
if (bs->teamgoal_time < FloatTime()) { |
| 953 |
bs->ltgtype = 0; |
| 954 |
} |
| 955 |
BotAlternateRoute(bs, goal); |
| 956 |
|
| 957 |
return qtrue; |
| 958 |
} |
| 959 |
} |
| 960 |
else if (gametype == GT_HARVESTER) { |
| 961 |
|
| 962 |
if (bs->ltgtype == LTG_RUSHBASE) { |
| 963 |
switch(BotTeam(bs)) { |
| 964 |
case TEAM_RED: memcpy(goal, &blueobelisk, sizeof(bot_goal_t)); break; |
| 965 |
case TEAM_BLUE: memcpy(goal, &redobelisk, sizeof(bot_goal_t)); break; |
| 966 |
default: BotGoHarvest(bs); return qfalse; |
| 967 |
} |
| 968 |
|
| 969 |
if (!BotHarvesterCarryingCubes(bs)) { |
| 970 |
BotGoHarvest(bs); |
| 971 |
return qfalse; |
| 972 |
} |
| 973 |
|
| 974 |
if (bs->teamgoal_time < FloatTime()) { |
| 975 |
BotGoHarvest(bs); |
| 976 |
return qfalse; |
| 977 |
} |
| 978 |
|
| 979 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 980 |
BotGoHarvest(bs); |
| 981 |
return qfalse; |
| 982 |
} |
| 983 |
BotAlternateRoute(bs, goal); |
| 984 |
return qtrue; |
| 985 |
} |
| 986 |
|
| 987 |
if (bs->ltgtype == LTG_ATTACKENEMYBASE && |
| 988 |
bs->attackaway_time < FloatTime()) { |
| 989 |
|
| 990 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 991 |
BotAI_BotInitialChat(bs, "attackenemybase_start", NULL); |
| 992 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 993 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE); |
| 994 |
bs->teammessage_time = 0; |
| 995 |
} |
| 996 |
switch(BotTeam(bs)) { |
| 997 |
case TEAM_RED: memcpy(goal, &blueobelisk, sizeof(bot_goal_t)); break; |
| 998 |
case TEAM_BLUE: memcpy(goal, &redobelisk, sizeof(bot_goal_t)); break; |
| 999 |
default: bs->ltgtype = 0; return qfalse; |
| 1000 |
} |
| 1001 |
|
| 1002 |
if (bs->teamgoal_time < FloatTime()) { |
| 1003 |
bs->ltgtype = 0; |
| 1004 |
} |
| 1005 |
|
| 1006 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 1007 |
bs->attackaway_time = FloatTime() + 2 + 5 * random(); |
| 1008 |
} |
| 1009 |
return qtrue; |
| 1010 |
} |
| 1011 |
|
| 1012 |
if (bs->ltgtype == LTG_HARVEST && |
| 1013 |
bs->harvestaway_time < FloatTime()) { |
| 1014 |
|
| 1015 |
if (bs->teammessage_time && bs->teammessage_time < FloatTime()) { |
| 1016 |
BotAI_BotInitialChat(bs, "harvest_start", NULL); |
| 1017 |
trap_BotEnterChat(bs->cs, 0, CHAT_TEAM); |
| 1018 |
BotVoiceChatOnly(bs, -1, VOICECHAT_ONOFFENSE); |
| 1019 |
bs->teammessage_time = 0; |
| 1020 |
} |
| 1021 |
memcpy(goal, &neutralobelisk, sizeof(bot_goal_t)); |
| 1022 |
|
| 1023 |
if (bs->teamgoal_time < FloatTime()) { |
| 1024 |
bs->ltgtype = 0; |
| 1025 |
} |
| 1026 |
|
| 1027 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 1028 |
bs->harvestaway_time = FloatTime() + 4 + 3 * random(); |
| 1029 |
} |
| 1030 |
return qtrue; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
#endif |
| 1034 |
|
| 1035 |
return BotGetItemLongTermGoal(bs, tfl, goal); |
| 1036 |
} |
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
int BotLongTermGoal(bot_state_t *bs, int tfl, int retreat, bot_goal_t *goal) { |
| 1044 |
aas_entityinfo_t entinfo; |
| 1045 |
char teammate[MAX_MESSAGE_SIZE]; |
| 1046 |
float squaredist; |
| 1047 |
int areanum; |
| 1048 |
vec3_t dir; |
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
if (bs->lead_time > 0 && !retreat) { |
| 1054 |
if (bs->lead_time < FloatTime()) { |
| 1055 |
BotAI_BotInitialChat(bs, "lead_stop", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL); |
| 1056 |
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL); |
| 1057 |
bs->lead_time = 0; |
| 1058 |
return BotGetLongTermGoal(bs, tfl, retreat, goal); |
| 1059 |
} |
| 1060 |
|
| 1061 |
if (bs->leadmessage_time < 0 && -bs->leadmessage_time < FloatTime()) { |
| 1062 |
BotAI_BotInitialChat(bs, "followme", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL); |
| 1063 |
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL); |
| 1064 |
bs->leadmessage_time = FloatTime(); |
| 1065 |
} |
| 1066 |
|
| 1067 |
BotEntityInfo(bs->lead_teammate, &entinfo); |
| 1068 |
|
| 1069 |
if (entinfo.valid) { |
| 1070 |
areanum = BotPointAreaNum(entinfo.origin); |
| 1071 |
if (areanum && trap_AAS_AreaReachability(areanum)) { |
| 1072 |
|
| 1073 |
bs->lead_teamgoal.entitynum = bs->lead_teammate; |
| 1074 |
bs->lead_teamgoal.areanum = areanum; |
| 1075 |
VectorCopy(entinfo.origin, bs->lead_teamgoal.origin); |
| 1076 |
VectorSet(bs->lead_teamgoal.mins, -8, -8, -8); |
| 1077 |
VectorSet(bs->lead_teamgoal.maxs, 8, 8, 8); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
|
| 1081 |
if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->lead_teammate)) { |
| 1082 |
bs->leadvisible_time = FloatTime(); |
| 1083 |
} |
| 1084 |
|
| 1085 |
if (bs->leadvisible_time < FloatTime() - 1) { |
| 1086 |
bs->leadbackup_time = FloatTime() + 2; |
| 1087 |
} |
| 1088 |
|
| 1089 |
VectorSubtract(bs->origin, bs->lead_teamgoal.origin, dir); |
| 1090 |
squaredist = VectorLengthSquared(dir); |
| 1091 |
|
| 1092 |
if (bs->leadbackup_time > FloatTime()) { |
| 1093 |
if (bs->leadmessage_time < FloatTime() - 20) { |
| 1094 |
BotAI_BotInitialChat(bs, "followme", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL); |
| 1095 |
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL); |
| 1096 |
bs->leadmessage_time = FloatTime(); |
| 1097 |
} |
| 1098 |
|
| 1099 |
if (squaredist < Square(100)) { |
| 1100 |
bs->leadbackup_time = 0; |
| 1101 |
} |
| 1102 |
|
| 1103 |
memcpy(goal, &bs->lead_teamgoal, sizeof(bot_goal_t)); |
| 1104 |
return qtrue; |
| 1105 |
} |
| 1106 |
else { |
| 1107 |
|
| 1108 |
if (squaredist > Square(500)) { |
| 1109 |
if (bs->leadmessage_time < FloatTime() - 20) { |
| 1110 |
BotAI_BotInitialChat(bs, "followme", EasyClientName(bs->lead_teammate, teammate, sizeof(teammate)), NULL); |
| 1111 |
trap_BotEnterChat(bs->cs, bs->teammate, CHAT_TELL); |
| 1112 |
bs->leadmessage_time = FloatTime(); |
| 1113 |
} |
| 1114 |
|
| 1115 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 1116 |
vectoangles(dir, bs->ideal_viewangles); |
| 1117 |
bs->ideal_viewangles[2] *= 0.5; |
| 1118 |
|
| 1119 |
return qfalse; |
| 1120 |
} |
| 1121 |
} |
| 1122 |
} |
| 1123 |
return BotGetLongTermGoal(bs, tfl, retreat, goal); |
| 1124 |
} |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
void AIEnter_Intermission(bot_state_t *bs, char *s) { |
| 1132 |
BotRecordNodeSwitch(bs, "intermission", "", s); |
| 1133 |
|
| 1134 |
BotResetState(bs); |
| 1135 |
|
| 1136 |
if (BotChat_EndLevel(bs)) { |
| 1137 |
trap_BotEnterChat(bs->cs, 0, bs->chatto); |
| 1138 |
} |
| 1139 |
bs->ainode = AINode_Intermission; |
| 1140 |
} |
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
int AINode_Intermission(bot_state_t *bs) { |
| 1148 |
|
| 1149 |
if (!BotIntermission(bs)) { |
| 1150 |
if (BotChat_StartLevel(bs)) { |
| 1151 |
bs->stand_time = FloatTime() + BotChatTime(bs); |
| 1152 |
} |
| 1153 |
else { |
| 1154 |
bs->stand_time = FloatTime() + 2; |
| 1155 |
} |
| 1156 |
AIEnter_Stand(bs, "intermission: chat"); |
| 1157 |
} |
| 1158 |
return qtrue; |
| 1159 |
} |
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
void AIEnter_Observer(bot_state_t *bs, char *s) { |
| 1167 |
BotRecordNodeSwitch(bs, "observer", "", s); |
| 1168 |
|
| 1169 |
BotResetState(bs); |
| 1170 |
bs->ainode = AINode_Observer; |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
int AINode_Observer(bot_state_t *bs) { |
| 1179 |
|
| 1180 |
if (!BotIsObserver(bs)) { |
| 1181 |
AIEnter_Stand(bs, "observer: left observer"); |
| 1182 |
} |
| 1183 |
return qtrue; |
| 1184 |
} |
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
void AIEnter_Stand(bot_state_t *bs, char *s) { |
| 1192 |
BotRecordNodeSwitch(bs, "stand", "", s); |
| 1193 |
bs->standfindenemy_time = FloatTime() + 1; |
| 1194 |
bs->ainode = AINode_Stand; |
| 1195 |
} |
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
int AINode_Stand(bot_state_t *bs) { |
| 1203 |
|
| 1204 |
|
| 1205 |
if (bs->lastframe_health > bs->inventory[INVENTORY_HEALTH]) { |
| 1206 |
if (BotChat_HitTalking(bs)) { |
| 1207 |
bs->standfindenemy_time = FloatTime() + BotChatTime(bs) + 0.1; |
| 1208 |
bs->stand_time = FloatTime() + BotChatTime(bs) + 0.1; |
| 1209 |
} |
| 1210 |
} |
| 1211 |
if (bs->standfindenemy_time < FloatTime()) { |
| 1212 |
if (BotFindEnemy(bs, -1)) { |
| 1213 |
AIEnter_Battle_Fight(bs, "stand: found enemy"); |
| 1214 |
return qfalse; |
| 1215 |
} |
| 1216 |
bs->standfindenemy_time = FloatTime() + 1; |
| 1217 |
} |
| 1218 |
|
| 1219 |
trap_EA_Talk(bs->client); |
| 1220 |
|
| 1221 |
if (bs->stand_time < FloatTime()) { |
| 1222 |
trap_BotEnterChat(bs->cs, 0, bs->chatto); |
| 1223 |
AIEnter_Seek_LTG(bs, "stand: time out"); |
| 1224 |
return qfalse; |
| 1225 |
} |
| 1226 |
|
| 1227 |
return qtrue; |
| 1228 |
} |
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
void AIEnter_Respawn(bot_state_t *bs, char *s) { |
| 1236 |
BotRecordNodeSwitch(bs, "respawn", "", s); |
| 1237 |
|
| 1238 |
trap_BotResetMoveState(bs->ms); |
| 1239 |
trap_BotResetGoalState(bs->gs); |
| 1240 |
trap_BotResetAvoidGoals(bs->gs); |
| 1241 |
trap_BotResetAvoidReach(bs->ms); |
| 1242 |
|
| 1243 |
if (BotChat_Death(bs)) { |
| 1244 |
bs->respawn_time = FloatTime() + BotChatTime(bs); |
| 1245 |
bs->respawnchat_time = FloatTime(); |
| 1246 |
} |
| 1247 |
else { |
| 1248 |
bs->respawn_time = FloatTime() + 1 + random(); |
| 1249 |
bs->respawnchat_time = 0; |
| 1250 |
} |
| 1251 |
|
| 1252 |
bs->respawn_wait = qfalse; |
| 1253 |
bs->ainode = AINode_Respawn; |
| 1254 |
} |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
int AINode_Respawn(bot_state_t *bs) { |
| 1262 |
|
| 1263 |
if (bs->respawn_wait) { |
| 1264 |
if (!BotIsDead(bs)) { |
| 1265 |
AIEnter_Seek_LTG(bs, "respawn: respawned"); |
| 1266 |
} |
| 1267 |
else { |
| 1268 |
trap_EA_Respawn(bs->client); |
| 1269 |
} |
| 1270 |
} |
| 1271 |
else if (bs->respawn_time < FloatTime()) { |
| 1272 |
|
| 1273 |
bs->respawn_wait = qtrue; |
| 1274 |
|
| 1275 |
trap_EA_Respawn(bs->client); |
| 1276 |
|
| 1277 |
if (bs->respawnchat_time) { |
| 1278 |
trap_BotEnterChat(bs->cs, 0, bs->chatto); |
| 1279 |
bs->enemy = -1; |
| 1280 |
} |
| 1281 |
} |
| 1282 |
if (bs->respawnchat_time && bs->respawnchat_time < FloatTime() - 0.5) { |
| 1283 |
trap_EA_Talk(bs->client); |
| 1284 |
} |
| 1285 |
|
| 1286 |
return qtrue; |
| 1287 |
} |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
int BotSelectActivateWeapon(bot_state_t *bs) { |
| 1295 |
|
| 1296 |
if (bs->inventory[INVENTORY_MACHINEGUN] > 0 && bs->inventory[INVENTORY_BULLETS] > 0) |
| 1297 |
return WEAPONINDEX_MACHINEGUN; |
| 1298 |
else if (bs->inventory[INVENTORY_SHOTGUN] > 0 && bs->inventory[INVENTORY_SHELLS] > 0) |
| 1299 |
return WEAPONINDEX_SHOTGUN; |
| 1300 |
else if (bs->inventory[INVENTORY_PLASMAGUN] > 0 && bs->inventory[INVENTORY_CELLS] > 0) |
| 1301 |
return WEAPONINDEX_PLASMAGUN; |
| 1302 |
else if (bs->inventory[INVENTORY_LIGHTNING] > 0 && bs->inventory[INVENTORY_LIGHTNINGAMMO] > 0) |
| 1303 |
return WEAPONINDEX_LIGHTNING; |
| 1304 |
#ifdef MISSIONPACK |
| 1305 |
else if (bs->inventory[INVENTORY_CHAINGUN] > 0 && bs->inventory[INVENTORY_BELT] > 0) |
| 1306 |
return WEAPONINDEX_CHAINGUN; |
| 1307 |
else if (bs->inventory[INVENTORY_NAILGUN] > 0 && bs->inventory[INVENTORY_NAILS] > 0) |
| 1308 |
return WEAPONINDEX_NAILGUN; |
| 1309 |
else if (bs->inventory[INVENTORY_PROXLAUNCHER] > 0 && bs->inventory[INVENTORY_MINES] > 0) |
| 1310 |
return WEAPONINDEX_PROXLAUNCHER; |
| 1311 |
#endif |
| 1312 |
else if (bs->inventory[INVENTORY_GRENADELAUNCHER] > 0 && bs->inventory[INVENTORY_GRENADES] > 0) |
| 1313 |
return WEAPONINDEX_GRENADE_LAUNCHER; |
| 1314 |
else if (bs->inventory[INVENTORY_RAILGUN] > 0 && bs->inventory[INVENTORY_SLUGS] > 0) |
| 1315 |
return WEAPONINDEX_RAILGUN; |
| 1316 |
else if (bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 && bs->inventory[INVENTORY_ROCKETS] > 0) |
| 1317 |
return WEAPONINDEX_ROCKET_LAUNCHER; |
| 1318 |
else if (bs->inventory[INVENTORY_BFG10K] > 0 && bs->inventory[INVENTORY_BFGAMMO] > 0) |
| 1319 |
return WEAPONINDEX_BFG; |
| 1320 |
else { |
| 1321 |
return -1; |
| 1322 |
} |
| 1323 |
} |
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
void BotClearPath(bot_state_t *bs, bot_moveresult_t *moveresult) { |
| 1333 |
int i, bestmine; |
| 1334 |
float dist, bestdist; |
| 1335 |
vec3_t target, dir; |
| 1336 |
bsp_trace_t bsptrace; |
| 1337 |
entityState_t state; |
| 1338 |
|
| 1339 |
|
| 1340 |
if (bs->kamikazebody) { |
| 1341 |
|
| 1342 |
if ( !(moveresult->flags & (MOVERESULT_MOVEMENTVIEW | MOVERESULT_MOVEMENTWEAPON)) ) { |
| 1343 |
|
| 1344 |
BotAI_GetEntityState(bs->kamikazebody, &state); |
| 1345 |
VectorCopy(state.pos.trBase, target); |
| 1346 |
target[2] += 8; |
| 1347 |
VectorSubtract(target, bs->eye, dir); |
| 1348 |
vectoangles(dir, moveresult->ideal_viewangles); |
| 1349 |
|
| 1350 |
moveresult->weapon = BotSelectActivateWeapon(bs); |
| 1351 |
if (moveresult->weapon == -1) { |
| 1352 |
|
| 1353 |
moveresult->weapon = 0; |
| 1354 |
} |
| 1355 |
if (moveresult->weapon) { |
| 1356 |
|
| 1357 |
moveresult->flags |= MOVERESULT_MOVEMENTWEAPON | MOVERESULT_MOVEMENTVIEW; |
| 1358 |
|
| 1359 |
if (bs->cur_ps.weapon == moveresult->weapon) { |
| 1360 |
|
| 1361 |
if (InFieldOfVision(bs->viewangles, 20, moveresult->ideal_viewangles)) { |
| 1362 |
|
| 1363 |
BotAI_Trace(&bsptrace, bs->eye, NULL, NULL, target, bs->entitynum, MASK_SHOT); |
| 1364 |
|
| 1365 |
if (bsptrace.fraction >= 1.0 || bsptrace.ent == state.number) { |
| 1366 |
|
| 1367 |
trap_EA_Attack(bs->client); |
| 1368 |
} |
| 1369 |
} |
| 1370 |
} |
| 1371 |
} |
| 1372 |
} |
| 1373 |
} |
| 1374 |
if (moveresult->flags & MOVERESULT_BLOCKEDBYAVOIDSPOT) { |
| 1375 |
bs->blockedbyavoidspot_time = FloatTime() + 5; |
| 1376 |
} |
| 1377 |
|
| 1378 |
if (bs->blockedbyavoidspot_time > FloatTime() && |
| 1379 |
!(moveresult->flags & (MOVERESULT_MOVEMENTVIEW | MOVERESULT_MOVEMENTWEAPON)) ) { |
| 1380 |
bestdist = 300; |
| 1381 |
bestmine = -1; |
| 1382 |
for (i = 0; i < bs->numproxmines; i++) { |
| 1383 |
BotAI_GetEntityState(bs->proxmines[i], &state); |
| 1384 |
VectorSubtract(state.pos.trBase, bs->origin, dir); |
| 1385 |
dist = VectorLength(dir); |
| 1386 |
if (dist < bestdist) { |
| 1387 |
bestdist = dist; |
| 1388 |
bestmine = i; |
| 1389 |
} |
| 1390 |
} |
| 1391 |
if (bestmine != -1) { |
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
BotAI_GetEntityState(bs->proxmines[bestmine], &state); |
| 1398 |
VectorCopy(state.pos.trBase, target); |
| 1399 |
target[2] += 2; |
| 1400 |
VectorSubtract(target, bs->eye, dir); |
| 1401 |
vectoangles(dir, moveresult->ideal_viewangles); |
| 1402 |
|
| 1403 |
if (bs->inventory[INVENTORY_PLASMAGUN] > 0 && bs->inventory[INVENTORY_CELLS] > 0) |
| 1404 |
moveresult->weapon = WEAPONINDEX_PLASMAGUN; |
| 1405 |
else if (bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 && bs->inventory[INVENTORY_ROCKETS] > 0) |
| 1406 |
moveresult->weapon = WEAPONINDEX_ROCKET_LAUNCHER; |
| 1407 |
else if (bs->inventory[INVENTORY_BFG10K] > 0 && bs->inventory[INVENTORY_BFGAMMO] > 0) |
| 1408 |
moveresult->weapon = WEAPONINDEX_BFG; |
| 1409 |
else { |
| 1410 |
moveresult->weapon = 0; |
| 1411 |
} |
| 1412 |
if (moveresult->weapon) { |
| 1413 |
|
| 1414 |
moveresult->flags |= MOVERESULT_MOVEMENTWEAPON | MOVERESULT_MOVEMENTVIEW; |
| 1415 |
|
| 1416 |
if (bs->cur_ps.weapon == moveresult->weapon) { |
| 1417 |
|
| 1418 |
if (InFieldOfVision(bs->viewangles, 20, moveresult->ideal_viewangles)) { |
| 1419 |
|
| 1420 |
BotAI_Trace(&bsptrace, bs->eye, NULL, NULL, target, bs->entitynum, MASK_SHOT); |
| 1421 |
|
| 1422 |
if (bsptrace.fraction >= 1.0 || bsptrace.ent == state.number) { |
| 1423 |
|
| 1424 |
trap_EA_Attack(bs->client); |
| 1425 |
} |
| 1426 |
} |
| 1427 |
} |
| 1428 |
} |
| 1429 |
} |
| 1430 |
} |
| 1431 |
} |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
void AIEnter_Seek_ActivateEntity(bot_state_t *bs, char *s) { |
| 1439 |
BotRecordNodeSwitch(bs, "activate entity", "", s); |
| 1440 |
bs->ainode = AINode_Seek_ActivateEntity; |
| 1441 |
} |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
int AINode_Seek_ActivateEntity(bot_state_t *bs) { |
| 1449 |
bot_goal_t *goal; |
| 1450 |
vec3_t target, dir, ideal_viewangles; |
| 1451 |
bot_moveresult_t moveresult; |
| 1452 |
int targetvisible; |
| 1453 |
bsp_trace_t bsptrace; |
| 1454 |
aas_entityinfo_t entinfo; |
| 1455 |
|
| 1456 |
if (BotIsObserver(bs)) { |
| 1457 |
BotClearActivateGoalStack(bs); |
| 1458 |
AIEnter_Observer(bs, "active entity: observer"); |
| 1459 |
return qfalse; |
| 1460 |
} |
| 1461 |
|
| 1462 |
if (BotIntermission(bs)) { |
| 1463 |
BotClearActivateGoalStack(bs); |
| 1464 |
AIEnter_Intermission(bs, "activate entity: intermission"); |
| 1465 |
return qfalse; |
| 1466 |
} |
| 1467 |
|
| 1468 |
if (BotIsDead(bs)) { |
| 1469 |
BotClearActivateGoalStack(bs); |
| 1470 |
AIEnter_Respawn(bs, "activate entity: bot dead"); |
| 1471 |
return qfalse; |
| 1472 |
} |
| 1473 |
|
| 1474 |
bs->tfl = TFL_DEFAULT; |
| 1475 |
if (bot_grapple.integer) bs->tfl |= TFL_GRAPPLEHOOK; |
| 1476 |
|
| 1477 |
if (BotInLavaOrSlime(bs)) bs->tfl |= TFL_LAVA|TFL_SLIME; |
| 1478 |
|
| 1479 |
BotMapScripts(bs); |
| 1480 |
|
| 1481 |
bs->enemy = -1; |
| 1482 |
|
| 1483 |
if (!bs->activatestack) { |
| 1484 |
BotClearActivateGoalStack(bs); |
| 1485 |
AIEnter_Seek_NBG(bs, "activate entity: no goal"); |
| 1486 |
return qfalse; |
| 1487 |
} |
| 1488 |
|
| 1489 |
goal = &bs->activatestack->goal; |
| 1490 |
|
| 1491 |
targetvisible = qfalse; |
| 1492 |
|
| 1493 |
if (bs->activatestack->shoot) { |
| 1494 |
|
| 1495 |
BotAI_Trace(&bsptrace, bs->eye, NULL, NULL, bs->activatestack->target, bs->entitynum, MASK_SHOT); |
| 1496 |
|
| 1497 |
if (bsptrace.fraction >= 1.0 || bsptrace.ent == goal->entitynum) { |
| 1498 |
targetvisible = qtrue; |
| 1499 |
|
| 1500 |
if (bs->cur_ps.weapon == bs->activatestack->weapon) { |
| 1501 |
VectorSubtract(bs->activatestack->target, bs->eye, dir); |
| 1502 |
vectoangles(dir, ideal_viewangles); |
| 1503 |
|
| 1504 |
if (InFieldOfVision(bs->viewangles, 20, ideal_viewangles)) { |
| 1505 |
trap_EA_Attack(bs->client); |
| 1506 |
} |
| 1507 |
} |
| 1508 |
} |
| 1509 |
} |
| 1510 |
|
| 1511 |
if (targetvisible) { |
| 1512 |
|
| 1513 |
BotEntityInfo(goal->entitynum, &entinfo); |
| 1514 |
|
| 1515 |
if (!VectorCompare(bs->activatestack->origin, entinfo.origin)) { |
| 1516 |
#ifdef DEBUG |
| 1517 |
BotAI_Print(PRT_MESSAGE, "hit shootable button or trigger\n"); |
| 1518 |
#endif |
| 1519 |
bs->activatestack->time = 0; |
| 1520 |
} |
| 1521 |
|
| 1522 |
if (bs->activatestack->time < FloatTime()) { |
| 1523 |
BotPopFromActivateGoalStack(bs); |
| 1524 |
|
| 1525 |
if (bs->activatestack) { |
| 1526 |
bs->activatestack->time = FloatTime() + 10; |
| 1527 |
return qfalse; |
| 1528 |
} |
| 1529 |
AIEnter_Seek_NBG(bs, "activate entity: time out"); |
| 1530 |
return qfalse; |
| 1531 |
} |
| 1532 |
memset(&moveresult, 0, sizeof(bot_moveresult_t)); |
| 1533 |
} |
| 1534 |
else { |
| 1535 |
|
| 1536 |
if (!goal) { |
| 1537 |
bs->activatestack->time = 0; |
| 1538 |
} |
| 1539 |
|
| 1540 |
else if (!bs->activatestack->shoot) { |
| 1541 |
|
| 1542 |
if (trap_BotTouchingGoal(bs->origin, goal)) { |
| 1543 |
#ifdef DEBUG |
| 1544 |
BotAI_Print(PRT_MESSAGE, "touched button or trigger\n"); |
| 1545 |
#endif |
| 1546 |
bs->activatestack->time = 0; |
| 1547 |
} |
| 1548 |
} |
| 1549 |
|
| 1550 |
if (bs->activatestack->time < FloatTime()) { |
| 1551 |
BotPopFromActivateGoalStack(bs); |
| 1552 |
|
| 1553 |
if (bs->activatestack) { |
| 1554 |
bs->activatestack->time = FloatTime() + 10; |
| 1555 |
return qfalse; |
| 1556 |
} |
| 1557 |
AIEnter_Seek_NBG(bs, "activate entity: activated"); |
| 1558 |
return qfalse; |
| 1559 |
} |
| 1560 |
|
| 1561 |
if (BotAIPredictObstacles(bs, goal)) |
| 1562 |
return qfalse; |
| 1563 |
|
| 1564 |
BotSetupForMovement(bs); |
| 1565 |
|
| 1566 |
trap_BotMoveToGoal(&moveresult, bs->ms, goal, bs->tfl); |
| 1567 |
|
| 1568 |
if (moveresult.failure) { |
| 1569 |
|
| 1570 |
trap_BotResetAvoidReach(bs->ms); |
| 1571 |
|
| 1572 |
bs->activatestack->time = 0; |
| 1573 |
} |
| 1574 |
|
| 1575 |
BotAIBlocked(bs, &moveresult, qtrue); |
| 1576 |
} |
| 1577 |
|
| 1578 |
BotClearPath(bs, &moveresult); |
| 1579 |
|
| 1580 |
if (bs->activatestack->shoot) { |
| 1581 |
|
| 1582 |
if (!(moveresult.flags & MOVERESULT_MOVEMENTVIEW)) { |
| 1583 |
VectorSubtract(bs->activatestack->target, bs->eye, dir); |
| 1584 |
vectoangles(dir, moveresult.ideal_viewangles); |
| 1585 |
moveresult.flags |= MOVERESULT_MOVEMENTVIEW; |
| 1586 |
} |
| 1587 |
|
| 1588 |
if (!(moveresult.flags & MOVERESULT_MOVEMENTWEAPON)) { |
| 1589 |
moveresult.flags |= MOVERESULT_MOVEMENTWEAPON; |
| 1590 |
|
| 1591 |
bs->activatestack->weapon = BotSelectActivateWeapon(bs); |
| 1592 |
if (bs->activatestack->weapon == -1) { |
| 1593 |
|
| 1594 |
bs->activatestack->weapon = 0; |
| 1595 |
} |
| 1596 |
moveresult.weapon = bs->activatestack->weapon; |
| 1597 |
} |
| 1598 |
} |
| 1599 |
|
| 1600 |
if (moveresult.flags & (MOVERESULT_MOVEMENTVIEWSET|MOVERESULT_MOVEMENTVIEW|MOVERESULT_SWIMVIEW)) { |
| 1601 |
VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); |
| 1602 |
} |
| 1603 |
|
| 1604 |
else if (moveresult.flags & MOVERESULT_WAITING) { |
| 1605 |
if (random() < bs->thinktime * 0.8) { |
| 1606 |
BotRoamGoal(bs, target); |
| 1607 |
VectorSubtract(target, bs->origin, dir); |
| 1608 |
vectoangles(dir, bs->ideal_viewangles); |
| 1609 |
bs->ideal_viewangles[2] *= 0.5; |
| 1610 |
} |
| 1611 |
} |
| 1612 |
else if (!(bs->flags & BFL_IDEALVIEWSET)) { |
| 1613 |
if (trap_BotMovementViewTarget(bs->ms, goal, bs->tfl, 300, target)) { |
| 1614 |
VectorSubtract(target, bs->origin, dir); |
| 1615 |
vectoangles(dir, bs->ideal_viewangles); |
| 1616 |
} |
| 1617 |
else { |
| 1618 |
vectoangles(moveresult.movedir, bs->ideal_viewangles); |
| 1619 |
} |
| 1620 |
bs->ideal_viewangles[2] *= 0.5; |
| 1621 |
} |
| 1622 |
|
| 1623 |
if (moveresult.flags & MOVERESULT_MOVEMENTWEAPON) |
| 1624 |
bs->weaponnum = moveresult.weapon; |
| 1625 |
|
| 1626 |
if (BotFindEnemy(bs, -1)) { |
| 1627 |
if (BotWantsToRetreat(bs)) { |
| 1628 |
|
| 1629 |
AIEnter_Battle_NBG(bs, "activate entity: found enemy"); |
| 1630 |
} |
| 1631 |
else { |
| 1632 |
trap_BotResetLastAvoidReach(bs->ms); |
| 1633 |
|
| 1634 |
trap_BotEmptyGoalStack(bs->gs); |
| 1635 |
|
| 1636 |
AIEnter_Battle_Fight(bs, "activate entity: found enemy"); |
| 1637 |
} |
| 1638 |
BotClearActivateGoalStack(bs); |
| 1639 |
} |
| 1640 |
return qtrue; |
| 1641 |
} |
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
void AIEnter_Seek_NBG(bot_state_t *bs, char *s) { |
| 1649 |
bot_goal_t goal; |
| 1650 |
char buf[144]; |
| 1651 |
|
| 1652 |
if (trap_BotGetTopGoal(bs->gs, &goal)) { |
| 1653 |
trap_BotGoalName(goal.number, buf, 144); |
| 1654 |
BotRecordNodeSwitch(bs, "seek NBG", buf, s); |
| 1655 |
} |
| 1656 |
else { |
| 1657 |
BotRecordNodeSwitch(bs, "seek NBG", "no goal", s); |
| 1658 |
} |
| 1659 |
bs->ainode = AINode_Seek_NBG; |
| 1660 |
} |
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
int AINode_Seek_NBG(bot_state_t *bs) { |
| 1668 |
bot_goal_t goal; |
| 1669 |
vec3_t target, dir; |
| 1670 |
bot_moveresult_t moveresult; |
| 1671 |
|
| 1672 |
if (BotIsObserver(bs)) { |
| 1673 |
AIEnter_Observer(bs, "seek nbg: observer"); |
| 1674 |
return qfalse; |
| 1675 |
} |
| 1676 |
|
| 1677 |
if (BotIntermission(bs)) { |
| 1678 |
AIEnter_Intermission(bs, "seek nbg: intermision"); |
| 1679 |
return qfalse; |
| 1680 |
} |
| 1681 |
|
| 1682 |
if (BotIsDead(bs)) { |
| 1683 |
AIEnter_Respawn(bs, "seek nbg: bot dead"); |
| 1684 |
return qfalse; |
| 1685 |
} |
| 1686 |
|
| 1687 |
bs->tfl = TFL_DEFAULT; |
| 1688 |
if (bot_grapple.integer) bs->tfl |= TFL_GRAPPLEHOOK; |
| 1689 |
|
| 1690 |
if (BotInLavaOrSlime(bs)) bs->tfl |= TFL_LAVA|TFL_SLIME; |
| 1691 |
|
| 1692 |
if (BotCanAndWantsToRocketJump(bs)) { |
| 1693 |
bs->tfl |= TFL_ROCKETJUMP; |
| 1694 |
} |
| 1695 |
|
| 1696 |
BotMapScripts(bs); |
| 1697 |
|
| 1698 |
bs->enemy = -1; |
| 1699 |
|
| 1700 |
if (!trap_BotGetTopGoal(bs->gs, &goal)) bs->nbg_time = 0; |
| 1701 |
|
| 1702 |
else if (BotReachedGoal(bs, &goal)) { |
| 1703 |
BotChooseWeapon(bs); |
| 1704 |
bs->nbg_time = 0; |
| 1705 |
} |
| 1706 |
|
| 1707 |
if (bs->nbg_time < FloatTime()) { |
| 1708 |
|
| 1709 |
trap_BotPopGoal(bs->gs); |
| 1710 |
|
| 1711 |
|
| 1712 |
bs->check_time = FloatTime() + 0.05; |
| 1713 |
|
| 1714 |
AIEnter_Seek_LTG(bs, "seek nbg: time out"); |
| 1715 |
return qfalse; |
| 1716 |
} |
| 1717 |
|
| 1718 |
if (BotAIPredictObstacles(bs, &goal)) |
| 1719 |
return qfalse; |
| 1720 |
|
| 1721 |
BotSetupForMovement(bs); |
| 1722 |
|
| 1723 |
trap_BotMoveToGoal(&moveresult, bs->ms, &goal, bs->tfl); |
| 1724 |
|
| 1725 |
if (moveresult.failure) { |
| 1726 |
|
| 1727 |
trap_BotResetAvoidReach(bs->ms); |
| 1728 |
bs->nbg_time = 0; |
| 1729 |
} |
| 1730 |
|
| 1731 |
BotAIBlocked(bs, &moveresult, qtrue); |
| 1732 |
|
| 1733 |
BotClearPath(bs, &moveresult); |
| 1734 |
|
| 1735 |
if (moveresult.flags & (MOVERESULT_MOVEMENTVIEWSET|MOVERESULT_MOVEMENTVIEW|MOVERESULT_SWIMVIEW)) { |
| 1736 |
VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); |
| 1737 |
} |
| 1738 |
|
| 1739 |
else if (moveresult.flags & MOVERESULT_WAITING) { |
| 1740 |
if (random() < bs->thinktime * 0.8) { |
| 1741 |
BotRoamGoal(bs, target); |
| 1742 |
VectorSubtract(target, bs->origin, dir); |
| 1743 |
vectoangles(dir, bs->ideal_viewangles); |
| 1744 |
bs->ideal_viewangles[2] *= 0.5; |
| 1745 |
} |
| 1746 |
} |
| 1747 |
else if (!(bs->flags & BFL_IDEALVIEWSET)) { |
| 1748 |
if (!trap_BotGetSecondGoal(bs->gs, &goal)) trap_BotGetTopGoal(bs->gs, &goal); |
| 1749 |
if (trap_BotMovementViewTarget(bs->ms, &goal, bs->tfl, 300, target)) { |
| 1750 |
VectorSubtract(target, bs->origin, dir); |
| 1751 |
vectoangles(dir, bs->ideal_viewangles); |
| 1752 |
} |
| 1753 |
|
| 1754 |
else vectoangles(moveresult.movedir, bs->ideal_viewangles); |
| 1755 |
bs->ideal_viewangles[2] *= 0.5; |
| 1756 |
} |
| 1757 |
|
| 1758 |
if (moveresult.flags & MOVERESULT_MOVEMENTWEAPON) bs->weaponnum = moveresult.weapon; |
| 1759 |
|
| 1760 |
if (BotFindEnemy(bs, -1)) { |
| 1761 |
if (BotWantsToRetreat(bs)) { |
| 1762 |
|
| 1763 |
AIEnter_Battle_NBG(bs, "seek nbg: found enemy"); |
| 1764 |
} |
| 1765 |
else { |
| 1766 |
trap_BotResetLastAvoidReach(bs->ms); |
| 1767 |
|
| 1768 |
trap_BotEmptyGoalStack(bs->gs); |
| 1769 |
|
| 1770 |
AIEnter_Battle_Fight(bs, "seek nbg: found enemy"); |
| 1771 |
} |
| 1772 |
} |
| 1773 |
return qtrue; |
| 1774 |
} |
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
|
| 1781 |
void AIEnter_Seek_LTG(bot_state_t *bs, char *s) { |
| 1782 |
bot_goal_t goal; |
| 1783 |
char buf[144]; |
| 1784 |
|
| 1785 |
if (trap_BotGetTopGoal(bs->gs, &goal)) { |
| 1786 |
trap_BotGoalName(goal.number, buf, 144); |
| 1787 |
BotRecordNodeSwitch(bs, "seek LTG", buf, s); |
| 1788 |
} |
| 1789 |
else { |
| 1790 |
BotRecordNodeSwitch(bs, "seek LTG", "no goal", s); |
| 1791 |
} |
| 1792 |
bs->ainode = AINode_Seek_LTG; |
| 1793 |
} |
| 1794 |
|
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
int AINode_Seek_LTG(bot_state_t *bs) |
| 1801 |
{ |
| 1802 |
bot_goal_t goal; |
| 1803 |
vec3_t target, dir; |
| 1804 |
bot_moveresult_t moveresult; |
| 1805 |
int range; |
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
if (BotIsObserver(bs)) { |
| 1810 |
AIEnter_Observer(bs, "seek ltg: observer"); |
| 1811 |
return qfalse; |
| 1812 |
} |
| 1813 |
|
| 1814 |
if (BotIntermission(bs)) { |
| 1815 |
AIEnter_Intermission(bs, "seek ltg: intermission"); |
| 1816 |
return qfalse; |
| 1817 |
} |
| 1818 |
|
| 1819 |
if (BotIsDead(bs)) { |
| 1820 |
AIEnter_Respawn(bs, "seek ltg: bot dead"); |
| 1821 |
return qfalse; |
| 1822 |
} |
| 1823 |
|
| 1824 |
if (BotChat_Random(bs)) { |
| 1825 |
bs->stand_time = FloatTime() + BotChatTime(bs); |
| 1826 |
AIEnter_Stand(bs, "seek ltg: random chat"); |
| 1827 |
return qfalse; |
| 1828 |
} |
| 1829 |
|
| 1830 |
bs->tfl = TFL_DEFAULT; |
| 1831 |
if (bot_grapple.integer) bs->tfl |= TFL_GRAPPLEHOOK; |
| 1832 |
|
| 1833 |
if (BotInLavaOrSlime(bs)) bs->tfl |= TFL_LAVA|TFL_SLIME; |
| 1834 |
|
| 1835 |
if (BotCanAndWantsToRocketJump(bs)) { |
| 1836 |
bs->tfl |= TFL_ROCKETJUMP; |
| 1837 |
} |
| 1838 |
|
| 1839 |
BotMapScripts(bs); |
| 1840 |
|
| 1841 |
bs->enemy = -1; |
| 1842 |
|
| 1843 |
if (bs->killedenemy_time > FloatTime() - 2) { |
| 1844 |
if (random() < bs->thinktime * 1) { |
| 1845 |
trap_EA_Gesture(bs->client); |
| 1846 |
} |
| 1847 |
} |
| 1848 |
|
| 1849 |
if (BotFindEnemy(bs, -1)) { |
| 1850 |
if (BotWantsToRetreat(bs)) { |
| 1851 |
|
| 1852 |
AIEnter_Battle_Retreat(bs, "seek ltg: found enemy"); |
| 1853 |
return qfalse; |
| 1854 |
} |
| 1855 |
else { |
| 1856 |
trap_BotResetLastAvoidReach(bs->ms); |
| 1857 |
|
| 1858 |
trap_BotEmptyGoalStack(bs->gs); |
| 1859 |
|
| 1860 |
AIEnter_Battle_Fight(bs, "seek ltg: found enemy"); |
| 1861 |
return qfalse; |
| 1862 |
} |
| 1863 |
} |
| 1864 |
|
| 1865 |
BotTeamGoals(bs, qfalse); |
| 1866 |
|
| 1867 |
if (!BotLongTermGoal(bs, bs->tfl, qfalse, &goal)) { |
| 1868 |
return qtrue; |
| 1869 |
} |
| 1870 |
|
| 1871 |
if (bs->check_time < FloatTime()) { |
| 1872 |
bs->check_time = FloatTime() + 0.5; |
| 1873 |
|
| 1874 |
BotWantsToCamp(bs); |
| 1875 |
|
| 1876 |
if (bs->ltgtype == LTG_DEFENDKEYAREA) range = 400; |
| 1877 |
else range = 150; |
| 1878 |
|
| 1879 |
#ifdef CTF |
| 1880 |
if (gametype == GT_CTF) { |
| 1881 |
|
| 1882 |
if (BotCTFCarryingFlag(bs)) |
| 1883 |
range = 50; |
| 1884 |
} |
| 1885 |
#endif |
| 1886 |
#ifdef MISSIONPACK |
| 1887 |
else if (gametype == GT_1FCTF) { |
| 1888 |
if (Bot1FCTFCarryingFlag(bs)) |
| 1889 |
range = 50; |
| 1890 |
} |
| 1891 |
else if (gametype == GT_HARVESTER) { |
| 1892 |
if (BotHarvesterCarryingCubes(bs)) |
| 1893 |
range = 80; |
| 1894 |
} |
| 1895 |
#endif |
| 1896 |
|
| 1897 |
if (BotNearbyGoal(bs, bs->tfl, &goal, range)) { |
| 1898 |
trap_BotResetLastAvoidReach(bs->ms); |
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
bs->nbg_time = FloatTime() + 4 + range * 0.01; |
| 1905 |
AIEnter_Seek_NBG(bs, "ltg seek: nbg"); |
| 1906 |
return qfalse; |
| 1907 |
} |
| 1908 |
} |
| 1909 |
|
| 1910 |
if (BotAIPredictObstacles(bs, &goal)) |
| 1911 |
return qfalse; |
| 1912 |
|
| 1913 |
BotSetupForMovement(bs); |
| 1914 |
|
| 1915 |
trap_BotMoveToGoal(&moveresult, bs->ms, &goal, bs->tfl); |
| 1916 |
|
| 1917 |
if (moveresult.failure) { |
| 1918 |
|
| 1919 |
trap_BotResetAvoidReach(bs->ms); |
| 1920 |
|
| 1921 |
bs->ltg_time = 0; |
| 1922 |
} |
| 1923 |
|
| 1924 |
BotAIBlocked(bs, &moveresult, qtrue); |
| 1925 |
|
| 1926 |
BotClearPath(bs, &moveresult); |
| 1927 |
|
| 1928 |
if (moveresult.flags & (MOVERESULT_MOVEMENTVIEWSET|MOVERESULT_MOVEMENTVIEW|MOVERESULT_SWIMVIEW)) { |
| 1929 |
VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); |
| 1930 |
} |
| 1931 |
|
| 1932 |
else if (moveresult.flags & MOVERESULT_WAITING) { |
| 1933 |
if (random() < bs->thinktime * 0.8) { |
| 1934 |
BotRoamGoal(bs, target); |
| 1935 |
VectorSubtract(target, bs->origin, dir); |
| 1936 |
vectoangles(dir, bs->ideal_viewangles); |
| 1937 |
bs->ideal_viewangles[2] *= 0.5; |
| 1938 |
} |
| 1939 |
} |
| 1940 |
else if (!(bs->flags & BFL_IDEALVIEWSET)) { |
| 1941 |
if (trap_BotMovementViewTarget(bs->ms, &goal, bs->tfl, 300, target)) { |
| 1942 |
VectorSubtract(target, bs->origin, dir); |
| 1943 |
vectoangles(dir, bs->ideal_viewangles); |
| 1944 |
} |
| 1945 |
|
| 1946 |
else if (VectorLengthSquared(moveresult.movedir)) { |
| 1947 |
vectoangles(moveresult.movedir, bs->ideal_viewangles); |
| 1948 |
} |
| 1949 |
else if (random() < bs->thinktime * 0.8) { |
| 1950 |
BotRoamGoal(bs, target); |
| 1951 |
VectorSubtract(target, bs->origin, dir); |
| 1952 |
vectoangles(dir, bs->ideal_viewangles); |
| 1953 |
bs->ideal_viewangles[2] *= 0.5; |
| 1954 |
} |
| 1955 |
bs->ideal_viewangles[2] *= 0.5; |
| 1956 |
} |
| 1957 |
|
| 1958 |
if (moveresult.flags & MOVERESULT_MOVEMENTWEAPON) bs->weaponnum = moveresult.weapon; |
| 1959 |
|
| 1960 |
return qtrue; |
| 1961 |
} |
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
void AIEnter_Battle_Fight(bot_state_t *bs, char *s) { |
| 1969 |
BotRecordNodeSwitch(bs, "battle fight", "", s); |
| 1970 |
trap_BotResetLastAvoidReach(bs->ms); |
| 1971 |
bs->ainode = AINode_Battle_Fight; |
| 1972 |
bs->flags &= ~BFL_FIGHTSUICIDAL; |
| 1973 |
} |
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
void AIEnter_Battle_SuicidalFight(bot_state_t *bs, char *s) { |
| 1981 |
BotRecordNodeSwitch(bs, "battle fight", "", s); |
| 1982 |
trap_BotResetLastAvoidReach(bs->ms); |
| 1983 |
bs->ainode = AINode_Battle_Fight; |
| 1984 |
bs->flags |= BFL_FIGHTSUICIDAL; |
| 1985 |
} |
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
int AINode_Battle_Fight(bot_state_t *bs) { |
| 1993 |
int areanum; |
| 1994 |
vec3_t target; |
| 1995 |
aas_entityinfo_t entinfo; |
| 1996 |
bot_moveresult_t moveresult; |
| 1997 |
|
| 1998 |
if (BotIsObserver(bs)) { |
| 1999 |
AIEnter_Observer(bs, "battle fight: observer"); |
| 2000 |
return qfalse; |
| 2001 |
} |
| 2002 |
|
| 2003 |
|
| 2004 |
if (BotIntermission(bs)) { |
| 2005 |
AIEnter_Intermission(bs, "battle fight: intermission"); |
| 2006 |
return qfalse; |
| 2007 |
} |
| 2008 |
|
| 2009 |
if (BotIsDead(bs)) { |
| 2010 |
AIEnter_Respawn(bs, "battle fight: bot dead"); |
| 2011 |
return qfalse; |
| 2012 |
} |
| 2013 |
|
| 2014 |
if (BotFindEnemy(bs, bs->enemy)) { |
| 2015 |
#ifdef DEBUG |
| 2016 |
BotAI_Print(PRT_MESSAGE, "found new better enemy\n"); |
| 2017 |
#endif |
| 2018 |
} |
| 2019 |
|
| 2020 |
if (bs->enemy < 0) { |
| 2021 |
AIEnter_Seek_LTG(bs, "battle fight: no enemy"); |
| 2022 |
return qfalse; |
| 2023 |
} |
| 2024 |
|
| 2025 |
BotEntityInfo(bs->enemy, &entinfo); |
| 2026 |
|
| 2027 |
if (bs->enemydeath_time) { |
| 2028 |
if (bs->enemydeath_time < FloatTime() - 1.0) { |
| 2029 |
bs->enemydeath_time = 0; |
| 2030 |
if (bs->enemysuicide) { |
| 2031 |
BotChat_EnemySuicide(bs); |
| 2032 |
} |
| 2033 |
if (bs->lastkilledplayer == bs->enemy && BotChat_Kill(bs)) { |
| 2034 |
bs->stand_time = FloatTime() + BotChatTime(bs); |
| 2035 |
AIEnter_Stand(bs, "battle fight: enemy dead"); |
| 2036 |
} |
| 2037 |
else { |
| 2038 |
bs->ltg_time = 0; |
| 2039 |
AIEnter_Seek_LTG(bs, "battle fight: enemy dead"); |
| 2040 |
} |
| 2041 |
return qfalse; |
| 2042 |
} |
| 2043 |
} |
| 2044 |
else { |
| 2045 |
if (EntityIsDead(&entinfo)) { |
| 2046 |
bs->enemydeath_time = FloatTime(); |
| 2047 |
} |
| 2048 |
} |
| 2049 |
|
| 2050 |
if (EntityIsInvisible(&entinfo) && !EntityIsShooting(&entinfo)) { |
| 2051 |
if (random() < 0.2) { |
| 2052 |
AIEnter_Seek_LTG(bs, "battle fight: invisible"); |
| 2053 |
return qfalse; |
| 2054 |
} |
| 2055 |
} |
| 2056 |
|
| 2057 |
VectorCopy(entinfo.origin, target); |
| 2058 |
|
| 2059 |
if (bs->enemy >= MAX_CLIENTS) { |
| 2060 |
#ifdef MISSIONPACK |
| 2061 |
|
| 2062 |
if ( bs->enemy == redobelisk.entitynum || |
| 2063 |
bs->enemy == blueobelisk.entitynum ) { |
| 2064 |
target[2] += 16; |
| 2065 |
} |
| 2066 |
#endif |
| 2067 |
} |
| 2068 |
|
| 2069 |
areanum = BotPointAreaNum(target); |
| 2070 |
if (areanum && trap_AAS_AreaReachability(areanum)) { |
| 2071 |
VectorCopy(target, bs->lastenemyorigin); |
| 2072 |
bs->lastenemyareanum = areanum; |
| 2073 |
} |
| 2074 |
|
| 2075 |
BotUpdateBattleInventory(bs, bs->enemy); |
| 2076 |
|
| 2077 |
if (bs->lastframe_health > bs->inventory[INVENTORY_HEALTH]) { |
| 2078 |
if (BotChat_HitNoDeath(bs)) { |
| 2079 |
bs->stand_time = FloatTime() + BotChatTime(bs); |
| 2080 |
AIEnter_Stand(bs, "battle fight: chat health decreased"); |
| 2081 |
return qfalse; |
| 2082 |
} |
| 2083 |
} |
| 2084 |
|
| 2085 |
if (bs->cur_ps.persistant[PERS_HITS] > bs->lasthitcount) { |
| 2086 |
if (BotChat_HitNoKill(bs)) { |
| 2087 |
bs->stand_time = FloatTime() + BotChatTime(bs); |
| 2088 |
AIEnter_Stand(bs, "battle fight: chat hit someone"); |
| 2089 |
return qfalse; |
| 2090 |
} |
| 2091 |
} |
| 2092 |
|
| 2093 |
if (!BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy)) { |
| 2094 |
#ifdef MISSIONPACK |
| 2095 |
if (bs->enemy == redobelisk.entitynum || bs->enemy == blueobelisk.entitynum) { |
| 2096 |
AIEnter_Battle_Chase(bs, "battle fight: obelisk out of sight"); |
| 2097 |
return qfalse; |
| 2098 |
} |
| 2099 |
#endif |
| 2100 |
if (BotWantsToChase(bs)) { |
| 2101 |
AIEnter_Battle_Chase(bs, "battle fight: enemy out of sight"); |
| 2102 |
return qfalse; |
| 2103 |
} |
| 2104 |
else { |
| 2105 |
AIEnter_Seek_LTG(bs, "battle fight: enemy out of sight"); |
| 2106 |
return qfalse; |
| 2107 |
} |
| 2108 |
} |
| 2109 |
|
| 2110 |
BotBattleUseItems(bs); |
| 2111 |
|
| 2112 |
bs->tfl = TFL_DEFAULT; |
| 2113 |
if (bot_grapple.integer) bs->tfl |= TFL_GRAPPLEHOOK; |
| 2114 |
|
| 2115 |
if (BotInLavaOrSlime(bs)) bs->tfl |= TFL_LAVA|TFL_SLIME; |
| 2116 |
|
| 2117 |
if (BotCanAndWantsToRocketJump(bs)) { |
| 2118 |
bs->tfl |= TFL_ROCKETJUMP; |
| 2119 |
} |
| 2120 |
|
| 2121 |
BotChooseWeapon(bs); |
| 2122 |
|
| 2123 |
moveresult = BotAttackMove(bs, bs->tfl); |
| 2124 |
|
| 2125 |
if (moveresult.failure) { |
| 2126 |
|
| 2127 |
trap_BotResetAvoidReach(bs->ms); |
| 2128 |
|
| 2129 |
bs->ltg_time = 0; |
| 2130 |
} |
| 2131 |
|
| 2132 |
BotAIBlocked(bs, &moveresult, qfalse); |
| 2133 |
|
| 2134 |
BotAimAtEnemy(bs); |
| 2135 |
|
| 2136 |
BotCheckAttack(bs); |
| 2137 |
|
| 2138 |
if (!(bs->flags & BFL_FIGHTSUICIDAL)) { |
| 2139 |
if (BotWantsToRetreat(bs)) { |
| 2140 |
AIEnter_Battle_Retreat(bs, "battle fight: wants to retreat"); |
| 2141 |
return qtrue; |
| 2142 |
} |
| 2143 |
} |
| 2144 |
return qtrue; |
| 2145 |
} |
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
void AIEnter_Battle_Chase(bot_state_t *bs, char *s) { |
| 2153 |
BotRecordNodeSwitch(bs, "battle chase", "", s); |
| 2154 |
bs->chase_time = FloatTime(); |
| 2155 |
bs->ainode = AINode_Battle_Chase; |
| 2156 |
} |
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
|
| 2162 |
|
| 2163 |
int AINode_Battle_Chase(bot_state_t *bs) |
| 2164 |
{ |
| 2165 |
bot_goal_t goal; |
| 2166 |
vec3_t target, dir; |
| 2167 |
bot_moveresult_t moveresult; |
| 2168 |
float range; |
| 2169 |
|
| 2170 |
if (BotIsObserver(bs)) { |
| 2171 |
AIEnter_Observer(bs, "battle chase: observer"); |
| 2172 |
return qfalse; |
| 2173 |
} |
| 2174 |
|
| 2175 |
if (BotIntermission(bs)) { |
| 2176 |
AIEnter_Intermission(bs, "battle chase: intermission"); |
| 2177 |
return qfalse; |
| 2178 |
} |
| 2179 |
|
| 2180 |
if (BotIsDead(bs)) { |
| 2181 |
AIEnter_Respawn(bs, "battle chase: bot dead"); |
| 2182 |
return qfalse; |
| 2183 |
} |
| 2184 |
|
| 2185 |
if (bs->enemy < 0) { |
| 2186 |
AIEnter_Seek_LTG(bs, "battle chase: no enemy"); |
| 2187 |
return qfalse; |
| 2188 |
} |
| 2189 |
|
| 2190 |
if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy)) { |
| 2191 |
AIEnter_Battle_Fight(bs, "battle chase"); |
| 2192 |
return qfalse; |
| 2193 |
} |
| 2194 |
|
| 2195 |
if (BotFindEnemy(bs, -1)) { |
| 2196 |
AIEnter_Battle_Fight(bs, "battle chase: better enemy"); |
| 2197 |
return qfalse; |
| 2198 |
} |
| 2199 |
|
| 2200 |
if (!bs->lastenemyareanum) { |
| 2201 |
AIEnter_Seek_LTG(bs, "battle chase: no enemy area"); |
| 2202 |
return qfalse; |
| 2203 |
} |
| 2204 |
|
| 2205 |
bs->tfl = TFL_DEFAULT; |
| 2206 |
if (bot_grapple.integer) bs->tfl |= TFL_GRAPPLEHOOK; |
| 2207 |
|
| 2208 |
if (BotInLavaOrSlime(bs)) bs->tfl |= TFL_LAVA|TFL_SLIME; |
| 2209 |
|
| 2210 |
if (BotCanAndWantsToRocketJump(bs)) { |
| 2211 |
bs->tfl |= TFL_ROCKETJUMP; |
| 2212 |
} |
| 2213 |
|
| 2214 |
BotMapScripts(bs); |
| 2215 |
|
| 2216 |
goal.entitynum = bs->enemy; |
| 2217 |
goal.areanum = bs->lastenemyareanum; |
| 2218 |
VectorCopy(bs->lastenemyorigin, goal.origin); |
| 2219 |
VectorSet(goal.mins, -8, -8, -8); |
| 2220 |
VectorSet(goal.maxs, 8, 8, 8); |
| 2221 |
|
| 2222 |
if (trap_BotTouchingGoal(bs->origin, &goal)) bs->chase_time = 0; |
| 2223 |
|
| 2224 |
if (!bs->chase_time || bs->chase_time < FloatTime() - 10) { |
| 2225 |
AIEnter_Seek_LTG(bs, "battle chase: time out"); |
| 2226 |
return qfalse; |
| 2227 |
} |
| 2228 |
|
| 2229 |
if (bs->check_time < FloatTime()) { |
| 2230 |
bs->check_time = FloatTime() + 1; |
| 2231 |
range = 150; |
| 2232 |
|
| 2233 |
if (BotNearbyGoal(bs, bs->tfl, &goal, range)) { |
| 2234 |
|
| 2235 |
bs->nbg_time = FloatTime() + 0.1 * range + 1; |
| 2236 |
trap_BotResetLastAvoidReach(bs->ms); |
| 2237 |
AIEnter_Battle_NBG(bs, "battle chase: nbg"); |
| 2238 |
return qfalse; |
| 2239 |
} |
| 2240 |
} |
| 2241 |
|
| 2242 |
BotUpdateBattleInventory(bs, bs->enemy); |
| 2243 |
|
| 2244 |
BotSetupForMovement(bs); |
| 2245 |
|
| 2246 |
trap_BotMoveToGoal(&moveresult, bs->ms, &goal, bs->tfl); |
| 2247 |
|
| 2248 |
if (moveresult.failure) { |
| 2249 |
|
| 2250 |
trap_BotResetAvoidReach(bs->ms); |
| 2251 |
|
| 2252 |
bs->ltg_time = 0; |
| 2253 |
} |
| 2254 |
|
| 2255 |
BotAIBlocked(bs, &moveresult, qfalse); |
| 2256 |
|
| 2257 |
if (moveresult.flags & (MOVERESULT_MOVEMENTVIEWSET|MOVERESULT_MOVEMENTVIEW|MOVERESULT_SWIMVIEW)) { |
| 2258 |
VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); |
| 2259 |
} |
| 2260 |
else if (!(bs->flags & BFL_IDEALVIEWSET)) { |
| 2261 |
if (bs->chase_time > FloatTime() - 2) { |
| 2262 |
BotAimAtEnemy(bs); |
| 2263 |
} |
| 2264 |
else { |
| 2265 |
if (trap_BotMovementViewTarget(bs->ms, &goal, bs->tfl, 300, target)) { |
| 2266 |
VectorSubtract(target, bs->origin, dir); |
| 2267 |
vectoangles(dir, bs->ideal_viewangles); |
| 2268 |
} |
| 2269 |
else { |
| 2270 |
vectoangles(moveresult.movedir, bs->ideal_viewangles); |
| 2271 |
} |
| 2272 |
} |
| 2273 |
bs->ideal_viewangles[2] *= 0.5; |
| 2274 |
} |
| 2275 |
|
| 2276 |
if (moveresult.flags & MOVERESULT_MOVEMENTWEAPON) bs->weaponnum = moveresult.weapon; |
| 2277 |
|
| 2278 |
if (bs->areanum == bs->lastenemyareanum) bs->chase_time = 0; |
| 2279 |
|
| 2280 |
if (BotWantsToRetreat(bs)) { |
| 2281 |
AIEnter_Battle_Retreat(bs, "battle chase: wants to retreat"); |
| 2282 |
return qtrue; |
| 2283 |
} |
| 2284 |
return qtrue; |
| 2285 |
} |
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
void AIEnter_Battle_Retreat(bot_state_t *bs, char *s) { |
| 2293 |
BotRecordNodeSwitch(bs, "battle retreat", "", s); |
| 2294 |
bs->ainode = AINode_Battle_Retreat; |
| 2295 |
} |
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
int AINode_Battle_Retreat(bot_state_t *bs) { |
| 2303 |
bot_goal_t goal; |
| 2304 |
aas_entityinfo_t entinfo; |
| 2305 |
bot_moveresult_t moveresult; |
| 2306 |
vec3_t target, dir; |
| 2307 |
float attack_skill, range; |
| 2308 |
int areanum; |
| 2309 |
|
| 2310 |
if (BotIsObserver(bs)) { |
| 2311 |
AIEnter_Observer(bs, "battle retreat: observer"); |
| 2312 |
return qfalse; |
| 2313 |
} |
| 2314 |
|
| 2315 |
if (BotIntermission(bs)) { |
| 2316 |
AIEnter_Intermission(bs, "battle retreat: intermission"); |
| 2317 |
return qfalse; |
| 2318 |
} |
| 2319 |
|
| 2320 |
if (BotIsDead(bs)) { |
| 2321 |
AIEnter_Respawn(bs, "battle retreat: bot dead"); |
| 2322 |
return qfalse; |
| 2323 |
} |
| 2324 |
|
| 2325 |
if (bs->enemy < 0) { |
| 2326 |
AIEnter_Seek_LTG(bs, "battle retreat: no enemy"); |
| 2327 |
return qfalse; |
| 2328 |
} |
| 2329 |
|
| 2330 |
BotEntityInfo(bs->enemy, &entinfo); |
| 2331 |
if (EntityIsDead(&entinfo)) { |
| 2332 |
AIEnter_Seek_LTG(bs, "battle retreat: enemy dead"); |
| 2333 |
return qfalse; |
| 2334 |
} |
| 2335 |
|
| 2336 |
if (BotFindEnemy(bs, bs->enemy)) { |
| 2337 |
#ifdef DEBUG |
| 2338 |
BotAI_Print(PRT_MESSAGE, "found new better enemy\n"); |
| 2339 |
#endif |
| 2340 |
} |
| 2341 |
|
| 2342 |
bs->tfl = TFL_DEFAULT; |
| 2343 |
if (bot_grapple.integer) bs->tfl |= TFL_GRAPPLEHOOK; |
| 2344 |
|
| 2345 |
if (BotInLavaOrSlime(bs)) bs->tfl |= TFL_LAVA|TFL_SLIME; |
| 2346 |
|
| 2347 |
BotMapScripts(bs); |
| 2348 |
|
| 2349 |
BotUpdateBattleInventory(bs, bs->enemy); |
| 2350 |
|
| 2351 |
if (BotWantsToChase(bs)) { |
| 2352 |
|
| 2353 |
trap_BotEmptyGoalStack(bs->gs); |
| 2354 |
|
| 2355 |
AIEnter_Battle_Chase(bs, "battle retreat: wants to chase"); |
| 2356 |
return qfalse; |
| 2357 |
} |
| 2358 |
|
| 2359 |
if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy)) { |
| 2360 |
bs->enemyvisible_time = FloatTime(); |
| 2361 |
VectorCopy(entinfo.origin, target); |
| 2362 |
|
| 2363 |
if (bs->enemy >= MAX_CLIENTS) { |
| 2364 |
#ifdef MISSIONPACK |
| 2365 |
|
| 2366 |
if ( bs->enemy == redobelisk.entitynum || |
| 2367 |
bs->enemy == blueobelisk.entitynum ) { |
| 2368 |
target[2] += 16; |
| 2369 |
} |
| 2370 |
#endif |
| 2371 |
} |
| 2372 |
|
| 2373 |
areanum = BotPointAreaNum(target); |
| 2374 |
if (areanum && trap_AAS_AreaReachability(areanum)) { |
| 2375 |
VectorCopy(target, bs->lastenemyorigin); |
| 2376 |
bs->lastenemyareanum = areanum; |
| 2377 |
} |
| 2378 |
} |
| 2379 |
|
| 2380 |
if (bs->enemyvisible_time < FloatTime() - 4) { |
| 2381 |
AIEnter_Seek_LTG(bs, "battle retreat: lost enemy"); |
| 2382 |
return qfalse; |
| 2383 |
} |
| 2384 |
|
| 2385 |
else if (bs->enemyvisible_time < FloatTime()) { |
| 2386 |
|
| 2387 |
if (BotFindEnemy(bs, -1)) { |
| 2388 |
AIEnter_Battle_Fight(bs, "battle retreat: another enemy"); |
| 2389 |
return qfalse; |
| 2390 |
} |
| 2391 |
} |
| 2392 |
|
| 2393 |
BotTeamGoals(bs, qtrue); |
| 2394 |
|
| 2395 |
BotBattleUseItems(bs); |
| 2396 |
|
| 2397 |
if (!BotLongTermGoal(bs, bs->tfl, qtrue, &goal)) { |
| 2398 |
AIEnter_Battle_SuicidalFight(bs, "battle retreat: no way out"); |
| 2399 |
return qfalse; |
| 2400 |
} |
| 2401 |
|
| 2402 |
if (bs->check_time < FloatTime()) { |
| 2403 |
bs->check_time = FloatTime() + 1; |
| 2404 |
range = 150; |
| 2405 |
#ifdef CTF |
| 2406 |
if (gametype == GT_CTF) { |
| 2407 |
|
| 2408 |
if (BotCTFCarryingFlag(bs)) |
| 2409 |
range = 50; |
| 2410 |
} |
| 2411 |
#endif |
| 2412 |
#ifdef MISSIONPACK |
| 2413 |
else if (gametype == GT_1FCTF) { |
| 2414 |
if (Bot1FCTFCarryingFlag(bs)) |
| 2415 |
range = 50; |
| 2416 |
} |
| 2417 |
else if (gametype == GT_HARVESTER) { |
| 2418 |
if (BotHarvesterCarryingCubes(bs)) |
| 2419 |
range = 80; |
| 2420 |
} |
| 2421 |
#endif |
| 2422 |
|
| 2423 |
if (BotNearbyGoal(bs, bs->tfl, &goal, range)) { |
| 2424 |
trap_BotResetLastAvoidReach(bs->ms); |
| 2425 |
|
| 2426 |
bs->nbg_time = FloatTime() + range / 100 + 1; |
| 2427 |
AIEnter_Battle_NBG(bs, "battle retreat: nbg"); |
| 2428 |
return qfalse; |
| 2429 |
} |
| 2430 |
} |
| 2431 |
|
| 2432 |
BotSetupForMovement(bs); |
| 2433 |
|
| 2434 |
trap_BotMoveToGoal(&moveresult, bs->ms, &goal, bs->tfl); |
| 2435 |
|
| 2436 |
if (moveresult.failure) { |
| 2437 |
|
| 2438 |
trap_BotResetAvoidReach(bs->ms); |
| 2439 |
|
| 2440 |
bs->ltg_time = 0; |
| 2441 |
} |
| 2442 |
|
| 2443 |
BotAIBlocked(bs, &moveresult, qfalse); |
| 2444 |
|
| 2445 |
BotChooseWeapon(bs); |
| 2446 |
|
| 2447 |
if (moveresult.flags & (MOVERESULT_MOVEMENTVIEW|MOVERESULT_SWIMVIEW)) { |
| 2448 |
VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); |
| 2449 |
} |
| 2450 |
else if (!(moveresult.flags & MOVERESULT_MOVEMENTVIEWSET) |
| 2451 |
&& !(bs->flags & BFL_IDEALVIEWSET) ) { |
| 2452 |
attack_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_ATTACK_SKILL, 0, 1); |
| 2453 |
|
| 2454 |
if (attack_skill > 0.3) { |
| 2455 |
BotAimAtEnemy(bs); |
| 2456 |
} |
| 2457 |
else { |
| 2458 |
if (trap_BotMovementViewTarget(bs->ms, &goal, bs->tfl, 300, target)) { |
| 2459 |
VectorSubtract(target, bs->origin, dir); |
| 2460 |
vectoangles(dir, bs->ideal_viewangles); |
| 2461 |
} |
| 2462 |
else { |
| 2463 |
vectoangles(moveresult.movedir, bs->ideal_viewangles); |
| 2464 |
} |
| 2465 |
bs->ideal_viewangles[2] *= 0.5; |
| 2466 |
} |
| 2467 |
} |
| 2468 |
|
| 2469 |
if (moveresult.flags & MOVERESULT_MOVEMENTWEAPON) bs->weaponnum = moveresult.weapon; |
| 2470 |
|
| 2471 |
BotCheckAttack(bs); |
| 2472 |
|
| 2473 |
return qtrue; |
| 2474 |
} |
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
void AIEnter_Battle_NBG(bot_state_t *bs, char *s) { |
| 2482 |
BotRecordNodeSwitch(bs, "battle NBG", "", s); |
| 2483 |
bs->ainode = AINode_Battle_NBG; |
| 2484 |
} |
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
int AINode_Battle_NBG(bot_state_t *bs) { |
| 2492 |
int areanum; |
| 2493 |
bot_goal_t goal; |
| 2494 |
aas_entityinfo_t entinfo; |
| 2495 |
bot_moveresult_t moveresult; |
| 2496 |
float attack_skill; |
| 2497 |
vec3_t target, dir; |
| 2498 |
|
| 2499 |
if (BotIsObserver(bs)) { |
| 2500 |
AIEnter_Observer(bs, "battle nbg: observer"); |
| 2501 |
return qfalse; |
| 2502 |
} |
| 2503 |
|
| 2504 |
if (BotIntermission(bs)) { |
| 2505 |
AIEnter_Intermission(bs, "battle nbg: intermission"); |
| 2506 |
return qfalse; |
| 2507 |
} |
| 2508 |
|
| 2509 |
if (BotIsDead(bs)) { |
| 2510 |
AIEnter_Respawn(bs, "battle nbg: bot dead"); |
| 2511 |
return qfalse; |
| 2512 |
} |
| 2513 |
|
| 2514 |
if (bs->enemy < 0) { |
| 2515 |
AIEnter_Seek_NBG(bs, "battle nbg: no enemy"); |
| 2516 |
return qfalse; |
| 2517 |
} |
| 2518 |
|
| 2519 |
BotEntityInfo(bs->enemy, &entinfo); |
| 2520 |
if (EntityIsDead(&entinfo)) { |
| 2521 |
AIEnter_Seek_NBG(bs, "battle nbg: enemy dead"); |
| 2522 |
return qfalse; |
| 2523 |
} |
| 2524 |
|
| 2525 |
bs->tfl = TFL_DEFAULT; |
| 2526 |
if (bot_grapple.integer) bs->tfl |= TFL_GRAPPLEHOOK; |
| 2527 |
|
| 2528 |
if (BotInLavaOrSlime(bs)) bs->tfl |= TFL_LAVA|TFL_SLIME; |
| 2529 |
|
| 2530 |
if (BotCanAndWantsToRocketJump(bs)) { |
| 2531 |
bs->tfl |= TFL_ROCKETJUMP; |
| 2532 |
} |
| 2533 |
|
| 2534 |
BotMapScripts(bs); |
| 2535 |
|
| 2536 |
if (BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy)) { |
| 2537 |
bs->enemyvisible_time = FloatTime(); |
| 2538 |
VectorCopy(entinfo.origin, target); |
| 2539 |
|
| 2540 |
if (bs->enemy >= MAX_CLIENTS) { |
| 2541 |
#ifdef MISSIONPACK |
| 2542 |
|
| 2543 |
if ( bs->enemy == redobelisk.entitynum || |
| 2544 |
bs->enemy == blueobelisk.entitynum ) { |
| 2545 |
target[2] += 16; |
| 2546 |
} |
| 2547 |
#endif |
| 2548 |
} |
| 2549 |
|
| 2550 |
areanum = BotPointAreaNum(target); |
| 2551 |
if (areanum && trap_AAS_AreaReachability(areanum)) { |
| 2552 |
VectorCopy(target, bs->lastenemyorigin); |
| 2553 |
bs->lastenemyareanum = areanum; |
| 2554 |
} |
| 2555 |
} |
| 2556 |
|
| 2557 |
if (!trap_BotGetTopGoal(bs->gs, &goal)) { |
| 2558 |
bs->nbg_time = 0; |
| 2559 |
} |
| 2560 |
else if (BotReachedGoal(bs, &goal)) { |
| 2561 |
bs->nbg_time = 0; |
| 2562 |
} |
| 2563 |
|
| 2564 |
if (bs->nbg_time < FloatTime()) { |
| 2565 |
|
| 2566 |
trap_BotPopGoal(bs->gs); |
| 2567 |
|
| 2568 |
if (trap_BotGetTopGoal(bs->gs, &goal)) |
| 2569 |
AIEnter_Battle_Retreat(bs, "battle nbg: time out"); |
| 2570 |
else |
| 2571 |
AIEnter_Battle_Fight(bs, "battle nbg: time out"); |
| 2572 |
|
| 2573 |
return qfalse; |
| 2574 |
} |
| 2575 |
|
| 2576 |
BotSetupForMovement(bs); |
| 2577 |
|
| 2578 |
trap_BotMoveToGoal(&moveresult, bs->ms, &goal, bs->tfl); |
| 2579 |
|
| 2580 |
if (moveresult.failure) { |
| 2581 |
|
| 2582 |
trap_BotResetAvoidReach(bs->ms); |
| 2583 |
|
| 2584 |
bs->nbg_time = 0; |
| 2585 |
} |
| 2586 |
|
| 2587 |
BotAIBlocked(bs, &moveresult, qfalse); |
| 2588 |
|
| 2589 |
BotUpdateBattleInventory(bs, bs->enemy); |
| 2590 |
|
| 2591 |
BotChooseWeapon(bs); |
| 2592 |
|
| 2593 |
if (moveresult.flags & (MOVERESULT_MOVEMENTVIEW|MOVERESULT_SWIMVIEW)) { |
| 2594 |
VectorCopy(moveresult.ideal_viewangles, bs->ideal_viewangles); |
| 2595 |
} |
| 2596 |
else if (!(moveresult.flags & MOVERESULT_MOVEMENTVIEWSET) |
| 2597 |
&& !(bs->flags & BFL_IDEALVIEWSET)) { |
| 2598 |
attack_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_ATTACK_SKILL, 0, 1); |
| 2599 |
|
| 2600 |
if (attack_skill > 0.3) { |
| 2601 |
|
| 2602 |
BotAimAtEnemy(bs); |
| 2603 |
} |
| 2604 |
else { |
| 2605 |
if (trap_BotMovementViewTarget(bs->ms, &goal, bs->tfl, 300, target)) { |
| 2606 |
VectorSubtract(target, bs->origin, dir); |
| 2607 |
vectoangles(dir, bs->ideal_viewangles); |
| 2608 |
} |
| 2609 |
else { |
| 2610 |
vectoangles(moveresult.movedir, bs->ideal_viewangles); |
| 2611 |
} |
| 2612 |
bs->ideal_viewangles[2] *= 0.5; |
| 2613 |
} |
| 2614 |
} |
| 2615 |
|
| 2616 |
if (moveresult.flags & MOVERESULT_MOVEMENTWEAPON) bs->weaponnum = moveresult.weapon; |
| 2617 |
|
| 2618 |
BotCheckAttack(bs); |
| 2619 |
|
| 2620 |
return qtrue; |
| 2621 |
} |
| 2622 |
|