| 1 |
/* |
| 2 |
=========================================================================== |
| 3 |
Copyright (C) 1999-2005 Id Software, Inc. |
| 4 |
|
| 5 |
This file is part of Quake III Arena source code. |
| 6 |
|
| 7 |
Quake III Arena source code is free software; you can redistribute it |
| 8 |
and/or modify it under the terms of the GNU General Public License as |
| 9 |
published by the Free Software Foundation; either version 2 of the License, |
| 10 |
or (at your option) any later version. |
| 11 |
|
| 12 |
Quake III Arena source code is distributed in the hope that it will be |
| 13 |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with Quake III Arena source code; if not, write to the Free Software |
| 19 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
=========================================================================== |
| 21 |
*/ |
| 22 |
// |
| 23 |
|
| 24 |
/***************************************************************************** |
| 25 |
* name: ai_dmq3.c |
| 26 |
* |
| 27 |
* desc: Quake3 bot AI |
| 28 |
* |
| 29 |
* $Archive: /MissionPack/code/game/ai_dmq3.c $ |
| 30 |
* |
| 31 |
*****************************************************************************/ |
| 32 |
|
| 33 |
|
| 34 |
#include "g_local.h" |
| 35 |
#include "../botlib/botlib.h" |
| 36 |
#include "../botlib/be_aas.h" |
| 37 |
#include "../botlib/be_ea.h" |
| 38 |
#include "../botlib/be_ai_char.h" |
| 39 |
#include "../botlib/be_ai_chat.h" |
| 40 |
#include "../botlib/be_ai_gen.h" |
| 41 |
#include "../botlib/be_ai_goal.h" |
| 42 |
#include "../botlib/be_ai_move.h" |
| 43 |
#include "../botlib/be_ai_weap.h" |
| 44 |
// |
| 45 |
#include "ai_main.h" |
| 46 |
#include "ai_dmq3.h" |
| 47 |
#include "ai_chat.h" |
| 48 |
#include "ai_cmd.h" |
| 49 |
#include "ai_dmnet.h" |
| 50 |
#include "ai_team.h" |
| 51 |
// |
| 52 |
#include "chars.h" //characteristics |
| 53 |
#include "inv.h" //indexes into the inventory |
| 54 |
#include "syn.h" //synonyms |
| 55 |
#include "match.h" //string matching types and vars |
| 56 |
|
| 57 |
// for the voice chats |
| 58 |
#include "../../ui/menudef.h" // sos001205 - for q3_ui also |
| 59 |
|
| 60 |
// from aasfile.h |
| 61 |
#define AREACONTENTS_MOVER 1024 |
| 62 |
#define AREACONTENTS_MODELNUMSHIFT 24 |
| 63 |
#define AREACONTENTS_MAXMODELNUM 0xFF |
| 64 |
#define AREACONTENTS_MODELNUM (AREACONTENTS_MAXMODELNUM << AREACONTENTS_MODELNUMSHIFT) |
| 65 |
|
| 66 |
#define IDEAL_ATTACKDIST 140 |
| 67 |
|
| 68 |
#define MAX_WAYPOINTS 128 |
| 69 |
|
| 70 |
#define MAX_EPAIRKEY 128 |
| 71 |
// |
| 72 |
bot_waypoint_t botai_waypoints[MAX_WAYPOINTS]; |
| 73 |
bot_waypoint_t *botai_freewaypoints; |
| 74 |
|
| 75 |
//NOTE: not using a cvars which can be updated because the game should be reloaded anyway |
| 76 |
int gametype; //game type |
| 77 |
int maxclients; //maximum number of clients |
| 78 |
|
| 79 |
vmCvar_t bot_grapple; |
| 80 |
vmCvar_t bot_rocketjump; |
| 81 |
vmCvar_t bot_fastchat; |
| 82 |
vmCvar_t bot_nochat; |
| 83 |
vmCvar_t bot_testrchat; |
| 84 |
vmCvar_t bot_challenge; |
| 85 |
vmCvar_t bot_predictobstacles; |
| 86 |
vmCvar_t g_spSkill; |
| 87 |
|
| 88 |
extern vmCvar_t bot_developer; |
| 89 |
|
| 90 |
vec3_t lastteleport_origin; //last teleport event origin |
| 91 |
float lastteleport_time; //last teleport event time |
| 92 |
int max_bspmodelindex; //maximum BSP model index |
| 93 |
|
| 94 |
//CTF flag goals |
| 95 |
bot_goal_t ctf_redflag; |
| 96 |
bot_goal_t ctf_blueflag; |
| 97 |
//Domination goals: |
| 98 |
bot_goal_t dom_points_bot[MAX_DOMINATION_POINTS]; |
| 99 |
bot_goal_t ctf_neutralflag; |
| 100 |
bot_goal_t redobelisk; |
| 101 |
bot_goal_t blueobelisk; |
| 102 |
bot_goal_t neutralobelisk; |
| 103 |
|
| 104 |
#define MAX_ALTROUTEGOALS 32 |
| 105 |
|
| 106 |
int altroutegoals_setup; |
| 107 |
aas_altroutegoal_t red_altroutegoals[MAX_ALTROUTEGOALS]; |
| 108 |
int red_numaltroutegoals; |
| 109 |
aas_altroutegoal_t blue_altroutegoals[MAX_ALTROUTEGOALS]; |
| 110 |
int blue_numaltroutegoals; |
| 111 |
|
| 112 |
/* |
| 113 |
================== |
| 114 |
untrap_BotGetLevelItemGoal |
| 115 |
*same as trap_BotGetLevelItemGoal, but respects the gametype flag! |
| 116 |
================== |
| 117 |
*/ |
| 118 |
int untrap_BotGetLevelItemGoal(int start, char *classname, void /* struct bot_goal_s */ *goal) { |
| 119 |
static char *gametypeNames[] = {"ffa", "tournament", "single", "team", "ctf", "oneflag", "obelisk", "harvester", "elimination", "ctf", "lms", "dd", "dom"}; |
| 120 |
char allowedGametypes[MAX_EPAIRKEY]; |
| 121 |
char *gametypeName; |
| 122 |
|
| 123 |
start = trap_BotGetLevelItemGoal(start,classname,goal); |
| 124 |
while(start>-1) { |
| 125 |
if(!trap_AAS_ValueForBSPEpairKey(start,"gametype",allowedGametypes,MAX_EPAIRKEY)) |
| 126 |
return start; //No gametype flag |
| 127 |
if( gametype >= GT_FFA && gametype < GT_MAX_GAME_TYPE ) { |
| 128 |
gametypeName = gametypeNames[gametype]; |
| 129 |
if(strstr( allowedGametypes, gametypeName )) |
| 130 |
{ |
| 131 |
//In gametype strig |
| 132 |
return start; |
| 133 |
} |
| 134 |
} |
| 135 |
else |
| 136 |
return start; |
| 137 |
start = trap_BotGetLevelItemGoal(start,classname,goal); |
| 138 |
} |
| 139 |
return -1; |
| 140 |
} |
| 141 |
|
| 142 |
/* |
| 143 |
================== |
| 144 |
BotSetUserInfo |
| 145 |
================== |
| 146 |
*/ |
| 147 |
void BotSetUserInfo(bot_state_t *bs, char *key, char *value) { |
| 148 |
char userinfo[MAX_INFO_STRING]; |
| 149 |
|
| 150 |
trap_GetUserinfo(bs->client, userinfo, sizeof(userinfo)); |
| 151 |
Info_SetValueForKey(userinfo, key, value); |
| 152 |
trap_SetUserinfo(bs->client, userinfo); |
| 153 |
ClientUserinfoChanged( bs->client ); |
| 154 |
} |
| 155 |
|
| 156 |
/* |
| 157 |
================== |
| 158 |
BotCTFCarryingFlag |
| 159 |
================== |
| 160 |
*/ |
| 161 |
int BotCTFCarryingFlag(bot_state_t *bs) { |
| 162 |
if (gametype != GT_CTF && gametype!=GT_CTF_ELIMINATION) return CTF_FLAG_NONE; |
| 163 |
|
| 164 |
if (bs->inventory[INVENTORY_REDFLAG] > 0) return CTF_FLAG_RED; |
| 165 |
else if (bs->inventory[INVENTORY_BLUEFLAG] > 0) return CTF_FLAG_BLUE; |
| 166 |
return CTF_FLAG_NONE; |
| 167 |
} |
| 168 |
|
| 169 |
/* |
| 170 |
================== |
| 171 |
BotTeam |
| 172 |
================== |
| 173 |
*/ |
| 174 |
int BotTeam(bot_state_t *bs) { |
| 175 |
if (bs->client < 0 || bs->client >= MAX_CLIENTS) { |
| 176 |
return qfalse; |
| 177 |
} |
| 178 |
|
| 179 |
if (level.clients[bs->client].sess.sessionTeam == TEAM_RED) { |
| 180 |
return TEAM_RED; |
| 181 |
} else if (level.clients[bs->client].sess.sessionTeam == TEAM_BLUE) { |
| 182 |
return TEAM_BLUE; |
| 183 |
} |
| 184 |
|
| 185 |
return TEAM_FREE; |
| 186 |
} |
| 187 |
|
| 188 |
/* |
| 189 |
================== |
| 190 |
BotOppositeTeam |
| 191 |
================== |
| 192 |
*/ |
| 193 |
int BotOppositeTeam(bot_state_t *bs) { |
| 194 |
switch(BotTeam(bs)) { |
| 195 |
case TEAM_RED: return TEAM_BLUE; |
| 196 |
case TEAM_BLUE: return TEAM_RED; |
| 197 |
default: return TEAM_FREE; |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
/* |
| 202 |
================== |
| 203 |
BotEnemyFlag |
| 204 |
================== |
| 205 |
*/ |
| 206 |
bot_goal_t *BotEnemyFlag(bot_state_t *bs) { |
| 207 |
if (BotTeam(bs) == TEAM_RED) { |
| 208 |
return &ctf_blueflag; |
| 209 |
} |
| 210 |
else { |
| 211 |
return &ctf_redflag; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
/* |
| 216 |
================== |
| 217 |
BotTeamFlag |
| 218 |
================== |
| 219 |
*/ |
| 220 |
bot_goal_t *BotTeamFlag(bot_state_t *bs) { |
| 221 |
if (BotTeam(bs) == TEAM_RED) { |
| 222 |
return &ctf_redflag; |
| 223 |
} |
| 224 |
else { |
| 225 |
return &ctf_blueflag; |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
/* |
| 231 |
================== |
| 232 |
EntityIsDead |
| 233 |
================== |
| 234 |
*/ |
| 235 |
qboolean EntityIsDead(aas_entityinfo_t *entinfo) { |
| 236 |
playerState_t ps; |
| 237 |
|
| 238 |
if (entinfo->number >= 0 && entinfo->number < MAX_CLIENTS) { |
| 239 |
//retrieve the current client state |
| 240 |
BotAI_GetClientState( entinfo->number, &ps ); |
| 241 |
if (ps.pm_type != PM_NORMAL) return qtrue; |
| 242 |
} |
| 243 |
return qfalse; |
| 244 |
} |
| 245 |
|
| 246 |
/* |
| 247 |
================== |
| 248 |
EntityCarriesFlag |
| 249 |
================== |
| 250 |
*/ |
| 251 |
qboolean EntityCarriesFlag(aas_entityinfo_t *entinfo) { |
| 252 |
if ( entinfo->powerups & ( 1 << PW_REDFLAG ) ) |
| 253 |
return qtrue; |
| 254 |
if ( entinfo->powerups & ( 1 << PW_BLUEFLAG ) ) |
| 255 |
return qtrue; |
| 256 |
if ( entinfo->powerups & ( 1 << PW_NEUTRALFLAG ) ) |
| 257 |
return qtrue; |
| 258 |
return qfalse; |
| 259 |
} |
| 260 |
|
| 261 |
/* |
| 262 |
================== |
| 263 |
EntityIsInvisible |
| 264 |
================== |
| 265 |
*/ |
| 266 |
qboolean EntityIsInvisible(aas_entityinfo_t *entinfo) { |
| 267 |
// the flag is always visible |
| 268 |
if (EntityCarriesFlag(entinfo)) { |
| 269 |
return qfalse; |
| 270 |
} |
| 271 |
if (entinfo->powerups & (1 << PW_INVIS)) { |
| 272 |
return qtrue; |
| 273 |
} |
| 274 |
return qfalse; |
| 275 |
} |
| 276 |
|
| 277 |
/* |
| 278 |
================== |
| 279 |
EntityIsShooting |
| 280 |
================== |
| 281 |
*/ |
| 282 |
qboolean EntityIsShooting(aas_entityinfo_t *entinfo) { |
| 283 |
if (entinfo->flags & EF_FIRING) { |
| 284 |
return qtrue; |
| 285 |
} |
| 286 |
return qfalse; |
| 287 |
} |
| 288 |
|
| 289 |
/* |
| 290 |
================== |
| 291 |
EntityIsChatting |
| 292 |
================== |
| 293 |
*/ |
| 294 |
qboolean EntityIsChatting(aas_entityinfo_t *entinfo) { |
| 295 |
if (entinfo->flags & EF_TALK) { |
| 296 |
return qtrue; |
| 297 |
} |
| 298 |
return qfalse; |
| 299 |
} |
| 300 |
|
| 301 |
/* |
| 302 |
================== |
| 303 |
EntityHasQuad |
| 304 |
================== |
| 305 |
*/ |
| 306 |
qboolean EntityHasQuad(aas_entityinfo_t *entinfo) { |
| 307 |
if (entinfo->powerups & (1 << PW_QUAD)) { |
| 308 |
return qtrue; |
| 309 |
} |
| 310 |
return qfalse; |
| 311 |
} |
| 312 |
|
| 313 |
/* |
| 314 |
================== |
| 315 |
EntityHasKamikze |
| 316 |
================== |
| 317 |
*/ |
| 318 |
qboolean EntityHasKamikaze(aas_entityinfo_t *entinfo) { |
| 319 |
if (entinfo->flags & EF_KAMIKAZE) { |
| 320 |
return qtrue; |
| 321 |
} |
| 322 |
return qfalse; |
| 323 |
} |
| 324 |
|
| 325 |
/* |
| 326 |
================== |
| 327 |
EntityCarriesCubes |
| 328 |
================== |
| 329 |
*/ |
| 330 |
qboolean EntityCarriesCubes(aas_entityinfo_t *entinfo) { |
| 331 |
entityState_t state; |
| 332 |
|
| 333 |
if (gametype != GT_HARVESTER) |
| 334 |
return qfalse; |
| 335 |
//FIXME: get this info from the aas_entityinfo_t ? |
| 336 |
BotAI_GetEntityState(entinfo->number, &state); |
| 337 |
if (state.generic1 > 0) |
| 338 |
return qtrue; |
| 339 |
return qfalse; |
| 340 |
} |
| 341 |
|
| 342 |
/* |
| 343 |
================== |
| 344 |
Bot1FCTFCarryingFlag |
| 345 |
================== |
| 346 |
*/ |
| 347 |
int Bot1FCTFCarryingFlag(bot_state_t *bs) { |
| 348 |
if (gametype != GT_1FCTF) return qfalse; |
| 349 |
|
| 350 |
if (bs->inventory[INVENTORY_NEUTRALFLAG] > 0) return qtrue; |
| 351 |
return qfalse; |
| 352 |
} |
| 353 |
|
| 354 |
/* |
| 355 |
================== |
| 356 |
BotHarvesterCarryingCubes |
| 357 |
================== |
| 358 |
*/ |
| 359 |
int BotHarvesterCarryingCubes(bot_state_t *bs) { |
| 360 |
if (gametype != GT_HARVESTER) return qfalse; |
| 361 |
|
| 362 |
if (bs->inventory[INVENTORY_REDCUBE] > 0) return qtrue; |
| 363 |
if (bs->inventory[INVENTORY_BLUECUBE] > 0) return qtrue; |
| 364 |
return qfalse; |
| 365 |
} |
| 366 |
//#endif |
| 367 |
|
| 368 |
/* |
| 369 |
================== |
| 370 |
BotRememberLastOrderedTask |
| 371 |
================== |
| 372 |
*/ |
| 373 |
void BotRememberLastOrderedTask(bot_state_t *bs) { |
| 374 |
if (!bs->ordered) { |
| 375 |
return; |
| 376 |
} |
| 377 |
bs->lastgoal_decisionmaker = bs->decisionmaker; |
| 378 |
bs->lastgoal_ltgtype = bs->ltgtype; |
| 379 |
memcpy(&bs->lastgoal_teamgoal, &bs->teamgoal, sizeof(bot_goal_t)); |
| 380 |
bs->lastgoal_teammate = bs->teammate; |
| 381 |
} |
| 382 |
|
| 383 |
/* |
| 384 |
================== |
| 385 |
BotSetTeamStatus |
| 386 |
================== |
| 387 |
*/ |
| 388 |
void BotSetTeamStatus(bot_state_t *bs) { |
| 389 |
int teamtask; |
| 390 |
aas_entityinfo_t entinfo; |
| 391 |
|
| 392 |
teamtask = TEAMTASK_PATROL; |
| 393 |
|
| 394 |
switch(bs->ltgtype) { |
| 395 |
case LTG_TEAMHELP: |
| 396 |
break; |
| 397 |
case LTG_TEAMACCOMPANY: |
| 398 |
BotEntityInfo(bs->teammate, &entinfo); |
| 399 |
if ( ( (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION || gametype == GT_1FCTF) && EntityCarriesFlag(&entinfo)) |
| 400 |
|| ( gametype == GT_HARVESTER && EntityCarriesCubes(&entinfo)) ) { |
| 401 |
teamtask = TEAMTASK_ESCORT; |
| 402 |
} |
| 403 |
else { |
| 404 |
teamtask = TEAMTASK_FOLLOW; |
| 405 |
} |
| 406 |
break; |
| 407 |
case LTG_DEFENDKEYAREA: |
| 408 |
teamtask = TEAMTASK_DEFENSE; |
| 409 |
break; |
| 410 |
case LTG_GETFLAG: |
| 411 |
teamtask = TEAMTASK_OFFENSE; |
| 412 |
break; |
| 413 |
case LTG_RUSHBASE: |
| 414 |
teamtask = TEAMTASK_DEFENSE; |
| 415 |
break; |
| 416 |
case LTG_RETURNFLAG: |
| 417 |
teamtask = TEAMTASK_RETRIEVE; |
| 418 |
break; |
| 419 |
case LTG_CAMP: |
| 420 |
case LTG_CAMPORDER: |
| 421 |
teamtask = TEAMTASK_CAMP; |
| 422 |
break; |
| 423 |
case LTG_PATROL: |
| 424 |
teamtask = TEAMTASK_PATROL; |
| 425 |
break; |
| 426 |
case LTG_GETITEM: |
| 427 |
teamtask = TEAMTASK_PATROL; |
| 428 |
break; |
| 429 |
case LTG_KILL: |
| 430 |
teamtask = TEAMTASK_PATROL; |
| 431 |
break; |
| 432 |
case LTG_HARVEST: |
| 433 |
teamtask = TEAMTASK_OFFENSE; |
| 434 |
break; |
| 435 |
case LTG_ATTACKENEMYBASE: |
| 436 |
teamtask = TEAMTASK_OFFENSE; |
| 437 |
break; |
| 438 |
case LTG_POINTA: |
| 439 |
if(BotTeam(bs) == TEAM_BLUE) |
| 440 |
teamtask = TEAMTASK_OFFENSE; |
| 441 |
else |
| 442 |
teamtask = TEAMTASK_DEFENSE; |
| 443 |
case LTG_POINTB: |
| 444 |
if(BotTeam(bs) == TEAM_RED) |
| 445 |
teamtask = TEAMTASK_OFFENSE; |
| 446 |
else |
| 447 |
teamtask = TEAMTASK_DEFENSE; |
| 448 |
default: |
| 449 |
teamtask = TEAMTASK_PATROL; |
| 450 |
break; |
| 451 |
} |
| 452 |
BotSetUserInfo(bs, "teamtask", va("%d", teamtask)); |
| 453 |
} |
| 454 |
|
| 455 |
/* |
| 456 |
================== |
| 457 |
BotSetLastOrderedTask |
| 458 |
================== |
| 459 |
*/ |
| 460 |
int BotSetLastOrderedTask(bot_state_t *bs) { |
| 461 |
|
| 462 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 463 |
// don't go back to returning the flag if it's at the base |
| 464 |
if ( bs->lastgoal_ltgtype == LTG_RETURNFLAG ) { |
| 465 |
if ( BotTeam(bs) == TEAM_RED ) { |
| 466 |
if ( bs->redflagstatus == 0 ) { |
| 467 |
bs->lastgoal_ltgtype = 0; |
| 468 |
} |
| 469 |
} |
| 470 |
else { |
| 471 |
if ( bs->blueflagstatus == 0 ) { |
| 472 |
bs->lastgoal_ltgtype = 0; |
| 473 |
} |
| 474 |
} |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
if ( bs->lastgoal_ltgtype ) { |
| 479 |
bs->decisionmaker = bs->lastgoal_decisionmaker; |
| 480 |
bs->ordered = qtrue; |
| 481 |
bs->ltgtype = bs->lastgoal_ltgtype; |
| 482 |
memcpy(&bs->teamgoal, &bs->lastgoal_teamgoal, sizeof(bot_goal_t)); |
| 483 |
bs->teammate = bs->lastgoal_teammate; |
| 484 |
bs->teamgoal_time = FloatTime() + 300; |
| 485 |
BotSetTeamStatus(bs); |
| 486 |
// |
| 487 |
if ( gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 488 |
if ( bs->ltgtype == LTG_GETFLAG ) { |
| 489 |
bot_goal_t *tb, *eb; |
| 490 |
int tt, et; |
| 491 |
|
| 492 |
tb = BotTeamFlag(bs); |
| 493 |
eb = BotEnemyFlag(bs); |
| 494 |
tt = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, tb->areanum, TFL_DEFAULT); |
| 495 |
et = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, eb->areanum, TFL_DEFAULT); |
| 496 |
// if the travel time towards the enemy base is larger than towards our base |
| 497 |
if (et > tt) { |
| 498 |
//get an alternative route goal towards the enemy base |
| 499 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 500 |
} |
| 501 |
} |
| 502 |
} |
| 503 |
return qtrue; |
| 504 |
} |
| 505 |
return qfalse; |
| 506 |
} |
| 507 |
|
| 508 |
/* |
| 509 |
================== |
| 510 |
BotRefuseOrder |
| 511 |
================== |
| 512 |
*/ |
| 513 |
void BotRefuseOrder(bot_state_t *bs) { |
| 514 |
if (!bs->ordered) |
| 515 |
return; |
| 516 |
// if the bot was ordered to do something |
| 517 |
if ( bs->order_time && bs->order_time > FloatTime() - 10 ) { |
| 518 |
trap_EA_Action(bs->client, ACTION_NEGATIVE); |
| 519 |
BotVoiceChat(bs, bs->decisionmaker, VOICECHAT_NO); |
| 520 |
bs->order_time = 0; |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
/* |
| 525 |
================== |
| 526 |
BotCTFSeekGoals |
| 527 |
================== |
| 528 |
*/ |
| 529 |
void BotCTFSeekGoals(bot_state_t *bs) { |
| 530 |
float rnd, l1, l2; |
| 531 |
int flagstatus, c; |
| 532 |
vec3_t dir; |
| 533 |
aas_entityinfo_t entinfo; |
| 534 |
|
| 535 |
//when carrying a flag in ctf the bot should rush to the base |
| 536 |
if (BotCTFCarryingFlag(bs)) { |
| 537 |
//if not already rushing to the base |
| 538 |
if (bs->ltgtype != LTG_RUSHBASE) { |
| 539 |
BotRefuseOrder(bs); |
| 540 |
bs->ltgtype = LTG_RUSHBASE; |
| 541 |
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME; |
| 542 |
bs->rushbaseaway_time = 0; |
| 543 |
bs->decisionmaker = bs->client; |
| 544 |
bs->ordered = qfalse; |
| 545 |
// |
| 546 |
switch(BotTeam(bs)) { |
| 547 |
case TEAM_RED: VectorSubtract(bs->origin, ctf_blueflag.origin, dir); break; |
| 548 |
case TEAM_BLUE: VectorSubtract(bs->origin, ctf_redflag.origin, dir); break; |
| 549 |
default: VectorSet(dir, 999, 999, 999); break; |
| 550 |
} |
| 551 |
// if the bot picked up the flag very close to the enemy base |
| 552 |
if ( VectorLength(dir) < 128 ) { |
| 553 |
// get an alternative route goal through the enemy base |
| 554 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 555 |
} else { |
| 556 |
// don't use any alt route goal, just get the hell out of the base |
| 557 |
bs->altroutegoal.areanum = 0; |
| 558 |
} |
| 559 |
BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_OFFENSE)); |
| 560 |
BotVoiceChat(bs, -1, VOICECHAT_IHAVEFLAG); |
| 561 |
} |
| 562 |
else if (bs->rushbaseaway_time > FloatTime()) { |
| 563 |
if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus; |
| 564 |
else flagstatus = bs->blueflagstatus; |
| 565 |
//if the flag is back |
| 566 |
if (flagstatus == 0) { |
| 567 |
bs->rushbaseaway_time = 0; |
| 568 |
} |
| 569 |
} |
| 570 |
return; |
| 571 |
} |
| 572 |
// if the bot decided to follow someone |
| 573 |
if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) { |
| 574 |
// if the team mate being accompanied no longer carries the flag |
| 575 |
BotEntityInfo(bs->teammate, &entinfo); |
| 576 |
if (!EntityCarriesFlag(&entinfo)) { |
| 577 |
bs->ltgtype = 0; |
| 578 |
} |
| 579 |
} |
| 580 |
// |
| 581 |
if (BotTeam(bs) == TEAM_RED) flagstatus = bs->redflagstatus * 2 + bs->blueflagstatus; |
| 582 |
else flagstatus = bs->blueflagstatus * 2 + bs->redflagstatus; |
| 583 |
//if our team has the enemy flag and our flag is at the base |
| 584 |
if (flagstatus == 1) { |
| 585 |
// |
| 586 |
if (bs->owndecision_time < FloatTime()) { |
| 587 |
//if Not defending the base already |
| 588 |
if (!(bs->ltgtype == LTG_DEFENDKEYAREA && |
| 589 |
(bs->teamgoal.number == ctf_redflag.number || |
| 590 |
bs->teamgoal.number == ctf_blueflag.number))) { |
| 591 |
//if there is a visible team mate flag carrier |
| 592 |
c = BotTeamFlagCarrierVisible(bs); |
| 593 |
if (c >= 0 && |
| 594 |
// and not already following the team mate flag carrier |
| 595 |
(bs->ltgtype != LTG_TEAMACCOMPANY || bs->teammate != c)) { |
| 596 |
// |
| 597 |
BotRefuseOrder(bs); |
| 598 |
//follow the flag carrier |
| 599 |
bs->decisionmaker = bs->client; |
| 600 |
bs->ordered = qfalse; |
| 601 |
//the team mate |
| 602 |
bs->teammate = c; |
| 603 |
//last time the team mate was visible |
| 604 |
bs->teammatevisible_time = FloatTime(); |
| 605 |
//no message |
| 606 |
bs->teammessage_time = 0; |
| 607 |
//no arrive message |
| 608 |
bs->arrive_time = 1; |
| 609 |
// |
| 610 |
BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW); |
| 611 |
//get the team goal time |
| 612 |
bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME; |
| 613 |
bs->ltgtype = LTG_TEAMACCOMPANY; |
| 614 |
bs->formation_dist = 3.5 * 32; //3.5 meter |
| 615 |
BotSetTeamStatus(bs); |
| 616 |
bs->owndecision_time = FloatTime() + 5; |
| 617 |
} |
| 618 |
} |
| 619 |
} |
| 620 |
return; |
| 621 |
} |
| 622 |
//if the enemy has our flag |
| 623 |
else if (flagstatus == 2) { |
| 624 |
// |
| 625 |
if (bs->owndecision_time < FloatTime()) { |
| 626 |
//if enemy flag carrier is visible |
| 627 |
c = BotEnemyFlagCarrierVisible(bs); |
| 628 |
if (c >= 0) { |
| 629 |
//FIXME: fight enemy flag carrier |
| 630 |
} |
| 631 |
//if not already doing something important |
| 632 |
if (bs->ltgtype != LTG_GETFLAG && |
| 633 |
bs->ltgtype != LTG_RETURNFLAG && |
| 634 |
bs->ltgtype != LTG_TEAMHELP && |
| 635 |
bs->ltgtype != LTG_TEAMACCOMPANY && |
| 636 |
bs->ltgtype != LTG_CAMPORDER && |
| 637 |
bs->ltgtype != LTG_PATROL && |
| 638 |
bs->ltgtype != LTG_GETITEM) { |
| 639 |
|
| 640 |
BotRefuseOrder(bs); |
| 641 |
bs->decisionmaker = bs->client; |
| 642 |
bs->ordered = qfalse; |
| 643 |
// |
| 644 |
if (random() < 0.5) { |
| 645 |
//go for the enemy flag |
| 646 |
bs->ltgtype = LTG_GETFLAG; |
| 647 |
} |
| 648 |
else { |
| 649 |
bs->ltgtype = LTG_RETURNFLAG; |
| 650 |
} |
| 651 |
//no team message |
| 652 |
bs->teammessage_time = 0; |
| 653 |
//set the time the bot will stop getting the flag |
| 654 |
bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME; |
| 655 |
//get an alternative route goal towards the enemy base |
| 656 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 657 |
// |
| 658 |
BotSetTeamStatus(bs); |
| 659 |
bs->owndecision_time = FloatTime() + 5; |
| 660 |
} |
| 661 |
} |
| 662 |
return; |
| 663 |
} |
| 664 |
//if both flags Not at their bases |
| 665 |
else if (flagstatus == 3) { |
| 666 |
// |
| 667 |
if (bs->owndecision_time < FloatTime()) { |
| 668 |
// if not trying to return the flag and not following the team flag carrier |
| 669 |
if ( bs->ltgtype != LTG_RETURNFLAG && bs->ltgtype != LTG_TEAMACCOMPANY ) { |
| 670 |
// |
| 671 |
c = BotTeamFlagCarrierVisible(bs); |
| 672 |
// if there is a visible team mate flag carrier |
| 673 |
if (c >= 0) { |
| 674 |
BotRefuseOrder(bs); |
| 675 |
//follow the flag carrier |
| 676 |
bs->decisionmaker = bs->client; |
| 677 |
bs->ordered = qfalse; |
| 678 |
//the team mate |
| 679 |
bs->teammate = c; |
| 680 |
//last time the team mate was visible |
| 681 |
bs->teammatevisible_time = FloatTime(); |
| 682 |
//no message |
| 683 |
bs->teammessage_time = 0; |
| 684 |
//no arrive message |
| 685 |
bs->arrive_time = 1; |
| 686 |
// |
| 687 |
BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW); |
| 688 |
//get the team goal time |
| 689 |
bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME; |
| 690 |
bs->ltgtype = LTG_TEAMACCOMPANY; |
| 691 |
bs->formation_dist = 3.5 * 32; //3.5 meter |
| 692 |
// |
| 693 |
BotSetTeamStatus(bs); |
| 694 |
bs->owndecision_time = FloatTime() + 5; |
| 695 |
} |
| 696 |
else { |
| 697 |
BotRefuseOrder(bs); |
| 698 |
bs->decisionmaker = bs->client; |
| 699 |
bs->ordered = qfalse; |
| 700 |
//get the enemy flag |
| 701 |
bs->teammessage_time = FloatTime() + 2 * random(); |
| 702 |
//get the flag |
| 703 |
bs->ltgtype = LTG_RETURNFLAG; |
| 704 |
//set the time the bot will stop getting the flag |
| 705 |
bs->teamgoal_time = FloatTime() + CTF_RETURNFLAG_TIME; |
| 706 |
//get an alternative route goal towards the enemy base |
| 707 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 708 |
// |
| 709 |
BotSetTeamStatus(bs); |
| 710 |
bs->owndecision_time = FloatTime() + 5; |
| 711 |
} |
| 712 |
} |
| 713 |
} |
| 714 |
return; |
| 715 |
} |
| 716 |
// don't just do something wait for the bot team leader to give orders |
| 717 |
if (BotTeamLeader(bs)) { |
| 718 |
return; |
| 719 |
} |
| 720 |
// if the bot is ordered to do something |
| 721 |
if ( bs->lastgoal_ltgtype ) { |
| 722 |
bs->teamgoal_time += 60; |
| 723 |
} |
| 724 |
// if the bot decided to do something on it's own and has a last ordered goal |
| 725 |
if ( !bs->ordered && bs->lastgoal_ltgtype ) { |
| 726 |
bs->ltgtype = 0; |
| 727 |
} |
| 728 |
//if already a CTF or team goal |
| 729 |
if (bs->ltgtype == LTG_TEAMHELP || |
| 730 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 731 |
bs->ltgtype == LTG_DEFENDKEYAREA || |
| 732 |
bs->ltgtype == LTG_GETFLAG || |
| 733 |
bs->ltgtype == LTG_RUSHBASE || |
| 734 |
bs->ltgtype == LTG_RETURNFLAG || |
| 735 |
bs->ltgtype == LTG_CAMPORDER || |
| 736 |
bs->ltgtype == LTG_PATROL || |
| 737 |
bs->ltgtype == LTG_GETITEM || |
| 738 |
bs->ltgtype == LTG_MAKELOVE_UNDER || |
| 739 |
bs->ltgtype == LTG_MAKELOVE_ONTOP) { |
| 740 |
return; |
| 741 |
} |
| 742 |
// |
| 743 |
if (BotSetLastOrderedTask(bs)) |
| 744 |
return; |
| 745 |
// |
| 746 |
if (bs->owndecision_time > FloatTime()) |
| 747 |
return;; |
| 748 |
//if the bot is roaming |
| 749 |
if (bs->ctfroam_time > FloatTime()) |
| 750 |
return; |
| 751 |
//if the bot has anough aggression to decide what to do |
| 752 |
if (BotAggression(bs) < 50) |
| 753 |
return; |
| 754 |
//set the time to send a message to the team mates |
| 755 |
bs->teammessage_time = FloatTime() + 2 * random(); |
| 756 |
// |
| 757 |
if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) { |
| 758 |
if (bs->teamtaskpreference & TEAMTP_ATTACKER) { |
| 759 |
l1 = 0.7f; |
| 760 |
} |
| 761 |
else { |
| 762 |
l1 = 0.2f; |
| 763 |
} |
| 764 |
l2 = 0.9f; |
| 765 |
} |
| 766 |
else { |
| 767 |
l1 = 0.4f; |
| 768 |
l2 = 0.7f; |
| 769 |
} |
| 770 |
//get the flag or defend the base |
| 771 |
rnd = random(); |
| 772 |
if (rnd < l1 && ctf_redflag.areanum && ctf_blueflag.areanum) { |
| 773 |
bs->decisionmaker = bs->client; |
| 774 |
bs->ordered = qfalse; |
| 775 |
bs->ltgtype = LTG_GETFLAG; |
| 776 |
//set the time the bot will stop getting the flag |
| 777 |
bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME; |
| 778 |
//get an alternative route goal towards the enemy base |
| 779 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 780 |
BotSetTeamStatus(bs); |
| 781 |
} |
| 782 |
else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) { |
| 783 |
bs->decisionmaker = bs->client; |
| 784 |
bs->ordered = qfalse; |
| 785 |
// |
| 786 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t)); |
| 787 |
else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t)); |
| 788 |
//set the ltg type |
| 789 |
bs->ltgtype = LTG_DEFENDKEYAREA; |
| 790 |
//set the time the bot stops defending the base |
| 791 |
bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME; |
| 792 |
bs->defendaway_time = 0; |
| 793 |
BotSetTeamStatus(bs); |
| 794 |
} |
| 795 |
else { |
| 796 |
bs->ltgtype = 0; |
| 797 |
//set the time the bot will stop roaming |
| 798 |
bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME; |
| 799 |
BotSetTeamStatus(bs); |
| 800 |
} |
| 801 |
bs->owndecision_time = FloatTime() + 5; |
| 802 |
#ifdef DEBUG |
| 803 |
BotPrintTeamGoal(bs); |
| 804 |
#endif //DEBUG |
| 805 |
} |
| 806 |
|
| 807 |
/* |
| 808 |
================== |
| 809 |
BotCTFRetreatGoals |
| 810 |
================== |
| 811 |
*/ |
| 812 |
void BotCTFRetreatGoals(bot_state_t *bs) { |
| 813 |
//when carrying a flag in ctf the bot should rush to the base |
| 814 |
if (BotCTFCarryingFlag(bs)) { |
| 815 |
//if not already rushing to the base |
| 816 |
if (bs->ltgtype != LTG_RUSHBASE) { |
| 817 |
BotRefuseOrder(bs); |
| 818 |
bs->ltgtype = LTG_RUSHBASE; |
| 819 |
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME; |
| 820 |
bs->rushbaseaway_time = 0; |
| 821 |
bs->decisionmaker = bs->client; |
| 822 |
bs->ordered = qfalse; |
| 823 |
BotSetTeamStatus(bs); |
| 824 |
} |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
/* |
| 829 |
================== |
| 830 |
BotDomSeekGoals |
| 831 |
================== |
| 832 |
*/ |
| 833 |
|
| 834 |
/*void BotDomSeekGoals(bot_state_t *bs) { |
| 835 |
int index; |
| 836 |
bs->ltgtype = LTG_DOMHOLD; //For debugging we are forcing roam |
| 837 |
|
| 838 |
index=0; |
| 839 |
//dom_points_bot[i] |
| 840 |
|
| 841 |
if(bs->ltgtype == LTG_DOMHOLD) { |
| 842 |
//index = 0; |
| 843 |
index = ((rand()) % (level.domination_points_count)); |
| 844 |
} |
| 845 |
|
| 846 |
//if(bs->ltgtype == LTG_DOMROAM) { |
| 847 |
|
| 848 |
//} |
| 849 |
|
| 850 |
memcpy(&bs->teamgoal, &dom_points_bot[index], sizeof(bot_goal_t)); |
| 851 |
|
| 852 |
BotAlternateRoute(bs, &bs->teamgoal); |
| 853 |
|
| 854 |
BotSetTeamStatus(bs); |
| 855 |
}*/ |
| 856 |
|
| 857 |
/* |
| 858 |
================== |
| 859 |
BotDDSeekGoals |
| 860 |
================== |
| 861 |
*/ |
| 862 |
|
| 863 |
void BotDDSeekGoals(bot_state_t *bs) { |
| 864 |
|
| 865 |
/*if (bs->ltgtype == LTG_TEAMHELP || |
| 866 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 867 |
bs->ltgtype == LTG_CAMPORDER || |
| 868 |
bs->ltgtype == LTG_PATROL || |
| 869 |
bs->ltgtype == LTG_GETITEM) { |
| 870 |
return; |
| 871 |
}*/ |
| 872 |
|
| 873 |
if(bs->ltgtype == LTG_POINTA) |
| 874 |
memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t)); |
| 875 |
if(bs->ltgtype == LTG_POINTB) |
| 876 |
memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t)); |
| 877 |
|
| 878 |
if(bs->ltgtype == LTG_POINTA || bs->ltgtype == LTG_POINTB) |
| 879 |
return; |
| 880 |
|
| 881 |
if(rand()%2==0) |
| 882 |
bs->ltgtype = LTG_POINTA; |
| 883 |
else |
| 884 |
bs->ltgtype = LTG_POINTB; |
| 885 |
|
| 886 |
if(bs->ltgtype == LTG_POINTA) { |
| 887 |
memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t)); |
| 888 |
if(BotTeam(bs) == TEAM_BLUE) |
| 889 |
BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_OFFENSE)); |
| 890 |
else |
| 891 |
BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_DEFENSE)); |
| 892 |
} else |
| 893 |
if(bs->ltgtype == LTG_POINTB) { |
| 894 |
memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t)); |
| 895 |
if(BotTeam(bs) == TEAM_RED) |
| 896 |
BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_OFFENSE)); |
| 897 |
else |
| 898 |
BotSetUserInfo(bs, "teamtask", va("%d", TEAMTASK_DEFENSE)); |
| 899 |
} |
| 900 |
|
| 901 |
|
| 902 |
} |
| 903 |
|
| 904 |
/* |
| 905 |
================== |
| 906 |
Bot1FCTFSeekGoals |
| 907 |
================== |
| 908 |
*/ |
| 909 |
void Bot1FCTFSeekGoals(bot_state_t *bs) { |
| 910 |
aas_entityinfo_t entinfo; |
| 911 |
float rnd, l1, l2; |
| 912 |
int c; |
| 913 |
|
| 914 |
//when carrying a flag in ctf the bot should rush to the base |
| 915 |
if (Bot1FCTFCarryingFlag(bs)) { |
| 916 |
//if not already rushing to the base |
| 917 |
if (bs->ltgtype != LTG_RUSHBASE) { |
| 918 |
BotRefuseOrder(bs); |
| 919 |
bs->ltgtype = LTG_RUSHBASE; |
| 920 |
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME; |
| 921 |
bs->rushbaseaway_time = 0; |
| 922 |
bs->decisionmaker = bs->client; |
| 923 |
bs->ordered = qfalse; |
| 924 |
//get an alternative route goal towards the enemy base |
| 925 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 926 |
// |
| 927 |
BotSetTeamStatus(bs); |
| 928 |
BotVoiceChat(bs, -1, VOICECHAT_IHAVEFLAG); |
| 929 |
} |
| 930 |
return; |
| 931 |
} |
| 932 |
// if the bot decided to follow someone |
| 933 |
if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) { |
| 934 |
// if the team mate being accompanied no longer carries the flag |
| 935 |
BotEntityInfo(bs->teammate, &entinfo); |
| 936 |
if (!EntityCarriesFlag(&entinfo)) { |
| 937 |
bs->ltgtype = 0; |
| 938 |
} |
| 939 |
} |
| 940 |
//our team has the flag |
| 941 |
if (bs->neutralflagstatus == 1) { |
| 942 |
if (bs->owndecision_time < FloatTime()) { |
| 943 |
// if not already following someone |
| 944 |
if (bs->ltgtype != LTG_TEAMACCOMPANY) { |
| 945 |
//if there is a visible team mate flag carrier |
| 946 |
c = BotTeamFlagCarrierVisible(bs); |
| 947 |
if (c >= 0) { |
| 948 |
BotRefuseOrder(bs); |
| 949 |
//follow the flag carrier |
| 950 |
bs->decisionmaker = bs->client; |
| 951 |
bs->ordered = qfalse; |
| 952 |
//the team mate |
| 953 |
bs->teammate = c; |
| 954 |
//last time the team mate was visible |
| 955 |
bs->teammatevisible_time = FloatTime(); |
| 956 |
//no message |
| 957 |
bs->teammessage_time = 0; |
| 958 |
//no arrive message |
| 959 |
bs->arrive_time = 1; |
| 960 |
// |
| 961 |
BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW); |
| 962 |
//get the team goal time |
| 963 |
bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME; |
| 964 |
bs->ltgtype = LTG_TEAMACCOMPANY; |
| 965 |
bs->formation_dist = 3.5 * 32; //3.5 meter |
| 966 |
BotSetTeamStatus(bs); |
| 967 |
bs->owndecision_time = FloatTime() + 5; |
| 968 |
return; |
| 969 |
} |
| 970 |
} |
| 971 |
//if already a CTF or team goal |
| 972 |
if (bs->ltgtype == LTG_TEAMHELP || |
| 973 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 974 |
bs->ltgtype == LTG_DEFENDKEYAREA || |
| 975 |
bs->ltgtype == LTG_GETFLAG || |
| 976 |
bs->ltgtype == LTG_RUSHBASE || |
| 977 |
bs->ltgtype == LTG_CAMPORDER || |
| 978 |
bs->ltgtype == LTG_PATROL || |
| 979 |
bs->ltgtype == LTG_ATTACKENEMYBASE || |
| 980 |
bs->ltgtype == LTG_GETITEM || |
| 981 |
bs->ltgtype == LTG_MAKELOVE_UNDER || |
| 982 |
bs->ltgtype == LTG_MAKELOVE_ONTOP) { |
| 983 |
return; |
| 984 |
} |
| 985 |
//if not already attacking the enemy base |
| 986 |
if (bs->ltgtype != LTG_ATTACKENEMYBASE) { |
| 987 |
BotRefuseOrder(bs); |
| 988 |
bs->decisionmaker = bs->client; |
| 989 |
bs->ordered = qfalse; |
| 990 |
// |
| 991 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t)); |
| 992 |
else memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t)); |
| 993 |
//set the ltg type |
| 994 |
bs->ltgtype = LTG_ATTACKENEMYBASE; |
| 995 |
//set the time the bot will stop getting the flag |
| 996 |
bs->teamgoal_time = FloatTime() + TEAM_ATTACKENEMYBASE_TIME; |
| 997 |
BotSetTeamStatus(bs); |
| 998 |
bs->owndecision_time = FloatTime() + 5; |
| 999 |
} |
| 1000 |
} |
| 1001 |
return; |
| 1002 |
} |
| 1003 |
//enemy team has the flag |
| 1004 |
else if (bs->neutralflagstatus == 2) { |
| 1005 |
if (bs->owndecision_time < FloatTime()) { |
| 1006 |
c = BotEnemyFlagCarrierVisible(bs); |
| 1007 |
if (c >= 0) { |
| 1008 |
//FIXME: attack enemy flag carrier |
| 1009 |
} |
| 1010 |
//if already a CTF or team goal |
| 1011 |
if (bs->ltgtype == LTG_TEAMHELP || |
| 1012 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 1013 |
bs->ltgtype == LTG_CAMPORDER || |
| 1014 |
bs->ltgtype == LTG_PATROL || |
| 1015 |
bs->ltgtype == LTG_GETITEM) { |
| 1016 |
return; |
| 1017 |
} |
| 1018 |
// if not already defending the base |
| 1019 |
if (bs->ltgtype != LTG_DEFENDKEYAREA) { |
| 1020 |
BotRefuseOrder(bs); |
| 1021 |
bs->decisionmaker = bs->client; |
| 1022 |
bs->ordered = qfalse; |
| 1023 |
// |
| 1024 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t)); |
| 1025 |
else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t)); |
| 1026 |
//set the ltg type |
| 1027 |
bs->ltgtype = LTG_DEFENDKEYAREA; |
| 1028 |
//set the time the bot stops defending the base |
| 1029 |
bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME; |
| 1030 |
bs->defendaway_time = 0; |
| 1031 |
BotSetTeamStatus(bs); |
| 1032 |
bs->owndecision_time = FloatTime() + 5; |
| 1033 |
} |
| 1034 |
} |
| 1035 |
return; |
| 1036 |
} |
| 1037 |
// don't just do something wait for the bot team leader to give orders |
| 1038 |
if (BotTeamLeader(bs)) { |
| 1039 |
return; |
| 1040 |
} |
| 1041 |
// if the bot is ordered to do something |
| 1042 |
if ( bs->lastgoal_ltgtype ) { |
| 1043 |
bs->teamgoal_time += 60; |
| 1044 |
} |
| 1045 |
// if the bot decided to do something on it's own and has a last ordered goal |
| 1046 |
if ( !bs->ordered && bs->lastgoal_ltgtype ) { |
| 1047 |
bs->ltgtype = 0; |
| 1048 |
} |
| 1049 |
//if already a CTF or team goal |
| 1050 |
if (bs->ltgtype == LTG_TEAMHELP || |
| 1051 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 1052 |
bs->ltgtype == LTG_DEFENDKEYAREA || |
| 1053 |
bs->ltgtype == LTG_GETFLAG || |
| 1054 |
bs->ltgtype == LTG_RUSHBASE || |
| 1055 |
bs->ltgtype == LTG_RETURNFLAG || |
| 1056 |
bs->ltgtype == LTG_CAMPORDER || |
| 1057 |
bs->ltgtype == LTG_PATROL || |
| 1058 |
bs->ltgtype == LTG_ATTACKENEMYBASE || |
| 1059 |
bs->ltgtype == LTG_GETITEM || |
| 1060 |
bs->ltgtype == LTG_MAKELOVE_UNDER || |
| 1061 |
bs->ltgtype == LTG_MAKELOVE_ONTOP) { |
| 1062 |
return; |
| 1063 |
} |
| 1064 |
// |
| 1065 |
if (BotSetLastOrderedTask(bs)) |
| 1066 |
return; |
| 1067 |
// |
| 1068 |
if (bs->owndecision_time > FloatTime()) |
| 1069 |
return;; |
| 1070 |
//if the bot is roaming |
| 1071 |
if (bs->ctfroam_time > FloatTime()) |
| 1072 |
return; |
| 1073 |
//if the bot has anough aggression to decide what to do |
| 1074 |
if (BotAggression(bs) < 50) |
| 1075 |
return; |
| 1076 |
//set the time to send a message to the team mates |
| 1077 |
bs->teammessage_time = FloatTime() + 2 * random(); |
| 1078 |
// |
| 1079 |
if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) { |
| 1080 |
if (bs->teamtaskpreference & TEAMTP_ATTACKER) { |
| 1081 |
l1 = 0.7f; |
| 1082 |
} |
| 1083 |
else { |
| 1084 |
l1 = 0.2f; |
| 1085 |
} |
| 1086 |
l2 = 0.9f; |
| 1087 |
} |
| 1088 |
else { |
| 1089 |
l1 = 0.4f; |
| 1090 |
l2 = 0.7f; |
| 1091 |
} |
| 1092 |
//get the flag or defend the base |
| 1093 |
rnd = random(); |
| 1094 |
if (rnd < l1 && ctf_neutralflag.areanum) { |
| 1095 |
bs->decisionmaker = bs->client; |
| 1096 |
bs->ordered = qfalse; |
| 1097 |
bs->ltgtype = LTG_GETFLAG; |
| 1098 |
//set the time the bot will stop getting the flag |
| 1099 |
bs->teamgoal_time = FloatTime() + CTF_GETFLAG_TIME; |
| 1100 |
BotSetTeamStatus(bs); |
| 1101 |
} |
| 1102 |
else if (rnd < l2 && ctf_redflag.areanum && ctf_blueflag.areanum) { |
| 1103 |
bs->decisionmaker = bs->client; |
| 1104 |
bs->ordered = qfalse; |
| 1105 |
// |
| 1106 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &ctf_redflag, sizeof(bot_goal_t)); |
| 1107 |
else memcpy(&bs->teamgoal, &ctf_blueflag, sizeof(bot_goal_t)); |
| 1108 |
//set the ltg type |
| 1109 |
bs->ltgtype = LTG_DEFENDKEYAREA; |
| 1110 |
//set the time the bot stops defending the base |
| 1111 |
bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME; |
| 1112 |
bs->defendaway_time = 0; |
| 1113 |
BotSetTeamStatus(bs); |
| 1114 |
} |
| 1115 |
else { |
| 1116 |
bs->ltgtype = 0; |
| 1117 |
//set the time the bot will stop roaming |
| 1118 |
bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME; |
| 1119 |
BotSetTeamStatus(bs); |
| 1120 |
} |
| 1121 |
bs->owndecision_time = FloatTime() + 5; |
| 1122 |
#ifdef DEBUG |
| 1123 |
BotPrintTeamGoal(bs); |
| 1124 |
#endif //DEBUG |
| 1125 |
} |
| 1126 |
|
| 1127 |
/* |
| 1128 |
================== |
| 1129 |
Bot1FCTFRetreatGoals |
| 1130 |
================== |
| 1131 |
*/ |
| 1132 |
void Bot1FCTFRetreatGoals(bot_state_t *bs) { |
| 1133 |
//when carrying a flag in ctf the bot should rush to the enemy base |
| 1134 |
if (Bot1FCTFCarryingFlag(bs)) { |
| 1135 |
//if not already rushing to the base |
| 1136 |
if (bs->ltgtype != LTG_RUSHBASE) { |
| 1137 |
BotRefuseOrder(bs); |
| 1138 |
bs->ltgtype = LTG_RUSHBASE; |
| 1139 |
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME; |
| 1140 |
bs->rushbaseaway_time = 0; |
| 1141 |
bs->decisionmaker = bs->client; |
| 1142 |
bs->ordered = qfalse; |
| 1143 |
//get an alternative route goal towards the enemy base |
| 1144 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 1145 |
BotSetTeamStatus(bs); |
| 1146 |
} |
| 1147 |
} |
| 1148 |
} |
| 1149 |
|
| 1150 |
/* |
| 1151 |
================== |
| 1152 |
BotObeliskSeekGoals |
| 1153 |
================== |
| 1154 |
*/ |
| 1155 |
void BotObeliskSeekGoals(bot_state_t *bs) { |
| 1156 |
float rnd, l1, l2; |
| 1157 |
|
| 1158 |
// don't just do something wait for the bot team leader to give orders |
| 1159 |
if (BotTeamLeader(bs)) { |
| 1160 |
return; |
| 1161 |
} |
| 1162 |
// if the bot is ordered to do something |
| 1163 |
if ( bs->lastgoal_ltgtype ) { |
| 1164 |
bs->teamgoal_time += 60; |
| 1165 |
} |
| 1166 |
//if already a team goal |
| 1167 |
if (bs->ltgtype == LTG_TEAMHELP || |
| 1168 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 1169 |
bs->ltgtype == LTG_DEFENDKEYAREA || |
| 1170 |
bs->ltgtype == LTG_GETFLAG || |
| 1171 |
bs->ltgtype == LTG_RUSHBASE || |
| 1172 |
bs->ltgtype == LTG_RETURNFLAG || |
| 1173 |
bs->ltgtype == LTG_CAMPORDER || |
| 1174 |
bs->ltgtype == LTG_PATROL || |
| 1175 |
bs->ltgtype == LTG_ATTACKENEMYBASE || |
| 1176 |
bs->ltgtype == LTG_GETITEM || |
| 1177 |
bs->ltgtype == LTG_MAKELOVE_UNDER || |
| 1178 |
bs->ltgtype == LTG_MAKELOVE_ONTOP) { |
| 1179 |
return; |
| 1180 |
} |
| 1181 |
// |
| 1182 |
if (BotSetLastOrderedTask(bs)) |
| 1183 |
return; |
| 1184 |
//if the bot is roaming |
| 1185 |
if (bs->ctfroam_time > FloatTime()) |
| 1186 |
return; |
| 1187 |
//if the bot has anough aggression to decide what to do |
| 1188 |
if (BotAggression(bs) < 50) |
| 1189 |
return; |
| 1190 |
//set the time to send a message to the team mates |
| 1191 |
bs->teammessage_time = FloatTime() + 2 * random(); |
| 1192 |
// |
| 1193 |
if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) { |
| 1194 |
if (bs->teamtaskpreference & TEAMTP_ATTACKER) { |
| 1195 |
l1 = 0.7f; |
| 1196 |
} |
| 1197 |
else { |
| 1198 |
l1 = 0.2f; |
| 1199 |
} |
| 1200 |
l2 = 0.9f; |
| 1201 |
} |
| 1202 |
else { |
| 1203 |
l1 = 0.4f; |
| 1204 |
l2 = 0.7f; |
| 1205 |
} |
| 1206 |
//get the flag or defend the base |
| 1207 |
rnd = random(); |
| 1208 |
if (rnd < l1 && redobelisk.areanum && blueobelisk.areanum) { |
| 1209 |
bs->decisionmaker = bs->client; |
| 1210 |
bs->ordered = qfalse; |
| 1211 |
// |
| 1212 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t)); |
| 1213 |
else memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t)); |
| 1214 |
//set the ltg type |
| 1215 |
bs->ltgtype = LTG_ATTACKENEMYBASE; |
| 1216 |
//set the time the bot will stop attacking the enemy base |
| 1217 |
bs->teamgoal_time = FloatTime() + TEAM_ATTACKENEMYBASE_TIME; |
| 1218 |
//get an alternate route goal towards the enemy base |
| 1219 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 1220 |
BotSetTeamStatus(bs); |
| 1221 |
} |
| 1222 |
else if (rnd < l2 && redobelisk.areanum && blueobelisk.areanum) { |
| 1223 |
bs->decisionmaker = bs->client; |
| 1224 |
bs->ordered = qfalse; |
| 1225 |
// |
| 1226 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t)); |
| 1227 |
else memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t)); |
| 1228 |
//set the ltg type |
| 1229 |
bs->ltgtype = LTG_DEFENDKEYAREA; |
| 1230 |
//set the time the bot stops defending the base |
| 1231 |
bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME; |
| 1232 |
bs->defendaway_time = 0; |
| 1233 |
BotSetTeamStatus(bs); |
| 1234 |
} |
| 1235 |
else { |
| 1236 |
bs->ltgtype = 0; |
| 1237 |
//set the time the bot will stop roaming |
| 1238 |
bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME; |
| 1239 |
BotSetTeamStatus(bs); |
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
/* |
| 1244 |
================== |
| 1245 |
BotGoHarvest |
| 1246 |
================== |
| 1247 |
*/ |
| 1248 |
void BotGoHarvest(bot_state_t *bs) { |
| 1249 |
// |
| 1250 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t)); |
| 1251 |
else memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t)); |
| 1252 |
//set the ltg type |
| 1253 |
bs->ltgtype = LTG_HARVEST; |
| 1254 |
//set the time the bot will stop harvesting |
| 1255 |
bs->teamgoal_time = FloatTime() + TEAM_HARVEST_TIME; |
| 1256 |
bs->harvestaway_time = 0; |
| 1257 |
BotSetTeamStatus(bs); |
| 1258 |
} |
| 1259 |
|
| 1260 |
/* |
| 1261 |
================== |
| 1262 |
BotObeliskRetreatGoals |
| 1263 |
================== |
| 1264 |
*/ |
| 1265 |
void BotObeliskRetreatGoals(bot_state_t *bs) { |
| 1266 |
//nothing special |
| 1267 |
} |
| 1268 |
|
| 1269 |
/* |
| 1270 |
================== |
| 1271 |
BotHarvesterSeekGoals |
| 1272 |
================== |
| 1273 |
*/ |
| 1274 |
void BotHarvesterSeekGoals(bot_state_t *bs) { |
| 1275 |
aas_entityinfo_t entinfo; |
| 1276 |
float rnd, l1, l2; |
| 1277 |
int c; |
| 1278 |
|
| 1279 |
//when carrying cubes in harvester the bot should rush to the base |
| 1280 |
if (BotHarvesterCarryingCubes(bs)) { |
| 1281 |
//if not already rushing to the base |
| 1282 |
if (bs->ltgtype != LTG_RUSHBASE) { |
| 1283 |
BotRefuseOrder(bs); |
| 1284 |
bs->ltgtype = LTG_RUSHBASE; |
| 1285 |
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME; |
| 1286 |
bs->rushbaseaway_time = 0; |
| 1287 |
bs->decisionmaker = bs->client; |
| 1288 |
bs->ordered = qfalse; |
| 1289 |
//get an alternative route goal towards the enemy base |
| 1290 |
BotGetAlternateRouteGoal(bs, BotOppositeTeam(bs)); |
| 1291 |
// |
| 1292 |
BotSetTeamStatus(bs); |
| 1293 |
} |
| 1294 |
return; |
| 1295 |
} |
| 1296 |
// don't just do something wait for the bot team leader to give orders |
| 1297 |
if (BotTeamLeader(bs)) { |
| 1298 |
return; |
| 1299 |
} |
| 1300 |
// if the bot decided to follow someone |
| 1301 |
if ( bs->ltgtype == LTG_TEAMACCOMPANY && !bs->ordered ) { |
| 1302 |
// if the team mate being accompanied no longer carries the flag |
| 1303 |
BotEntityInfo(bs->teammate, &entinfo); |
| 1304 |
if (!EntityCarriesCubes(&entinfo)) { |
| 1305 |
bs->ltgtype = 0; |
| 1306 |
} |
| 1307 |
} |
| 1308 |
// if the bot is ordered to do something |
| 1309 |
if ( bs->lastgoal_ltgtype ) { |
| 1310 |
bs->teamgoal_time += 60; |
| 1311 |
} |
| 1312 |
//if not yet doing something |
| 1313 |
if (bs->ltgtype == LTG_TEAMHELP || |
| 1314 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 1315 |
bs->ltgtype == LTG_DEFENDKEYAREA || |
| 1316 |
bs->ltgtype == LTG_GETFLAG || |
| 1317 |
bs->ltgtype == LTG_CAMPORDER || |
| 1318 |
bs->ltgtype == LTG_PATROL || |
| 1319 |
bs->ltgtype == LTG_ATTACKENEMYBASE || |
| 1320 |
bs->ltgtype == LTG_HARVEST || |
| 1321 |
bs->ltgtype == LTG_GETITEM || |
| 1322 |
bs->ltgtype == LTG_MAKELOVE_UNDER || |
| 1323 |
bs->ltgtype == LTG_MAKELOVE_ONTOP) { |
| 1324 |
return; |
| 1325 |
} |
| 1326 |
// |
| 1327 |
if (BotSetLastOrderedTask(bs)) |
| 1328 |
return; |
| 1329 |
//if the bot is roaming |
| 1330 |
if (bs->ctfroam_time > FloatTime()) |
| 1331 |
return; |
| 1332 |
//if the bot has anough aggression to decide what to do |
| 1333 |
if (BotAggression(bs) < 50) |
| 1334 |
return; |
| 1335 |
//set the time to send a message to the team mates |
| 1336 |
bs->teammessage_time = FloatTime() + 2 * random(); |
| 1337 |
// |
| 1338 |
c = BotEnemyCubeCarrierVisible(bs); |
| 1339 |
if (c >= 0) { |
| 1340 |
//FIXME: attack enemy cube carrier |
| 1341 |
} |
| 1342 |
if (bs->ltgtype != LTG_TEAMACCOMPANY) { |
| 1343 |
//if there is a visible team mate carrying cubes |
| 1344 |
c = BotTeamCubeCarrierVisible(bs); |
| 1345 |
if (c >= 0) { |
| 1346 |
//follow the team mate carrying cubes |
| 1347 |
bs->decisionmaker = bs->client; |
| 1348 |
bs->ordered = qfalse; |
| 1349 |
//the team mate |
| 1350 |
bs->teammate = c; |
| 1351 |
//last time the team mate was visible |
| 1352 |
bs->teammatevisible_time = FloatTime(); |
| 1353 |
//no message |
| 1354 |
bs->teammessage_time = 0; |
| 1355 |
//no arrive message |
| 1356 |
bs->arrive_time = 1; |
| 1357 |
// |
| 1358 |
BotVoiceChat(bs, bs->teammate, VOICECHAT_ONFOLLOW); |
| 1359 |
//get the team goal time |
| 1360 |
bs->teamgoal_time = FloatTime() + TEAM_ACCOMPANY_TIME; |
| 1361 |
bs->ltgtype = LTG_TEAMACCOMPANY; |
| 1362 |
bs->formation_dist = 3.5 * 32; //3.5 meter |
| 1363 |
BotSetTeamStatus(bs); |
| 1364 |
return; |
| 1365 |
} |
| 1366 |
} |
| 1367 |
// |
| 1368 |
if (bs->teamtaskpreference & (TEAMTP_ATTACKER|TEAMTP_DEFENDER)) { |
| 1369 |
if (bs->teamtaskpreference & TEAMTP_ATTACKER) { |
| 1370 |
l1 = 0.7f; |
| 1371 |
} |
| 1372 |
else { |
| 1373 |
l1 = 0.2f; |
| 1374 |
} |
| 1375 |
l2 = 0.9f; |
| 1376 |
} |
| 1377 |
else { |
| 1378 |
l1 = 0.4f; |
| 1379 |
l2 = 0.7f; |
| 1380 |
} |
| 1381 |
// |
| 1382 |
rnd = random(); |
| 1383 |
if (rnd < l1 && redobelisk.areanum && blueobelisk.areanum) { |
| 1384 |
bs->decisionmaker = bs->client; |
| 1385 |
bs->ordered = qfalse; |
| 1386 |
BotGoHarvest(bs); |
| 1387 |
} |
| 1388 |
else if (rnd < l2 && redobelisk.areanum && blueobelisk.areanum) { |
| 1389 |
bs->decisionmaker = bs->client; |
| 1390 |
bs->ordered = qfalse; |
| 1391 |
// |
| 1392 |
if (BotTeam(bs) == TEAM_RED) memcpy(&bs->teamgoal, &redobelisk, sizeof(bot_goal_t)); |
| 1393 |
else memcpy(&bs->teamgoal, &blueobelisk, sizeof(bot_goal_t)); |
| 1394 |
//set the ltg type |
| 1395 |
bs->ltgtype = LTG_DEFENDKEYAREA; |
| 1396 |
//set the time the bot stops defending the base |
| 1397 |
bs->teamgoal_time = FloatTime() + TEAM_DEFENDKEYAREA_TIME; |
| 1398 |
bs->defendaway_time = 0; |
| 1399 |
BotSetTeamStatus(bs); |
| 1400 |
} |
| 1401 |
else { |
| 1402 |
bs->ltgtype = 0; |
| 1403 |
//set the time the bot will stop roaming |
| 1404 |
bs->ctfroam_time = FloatTime() + CTF_ROAM_TIME; |
| 1405 |
BotSetTeamStatus(bs); |
| 1406 |
} |
| 1407 |
} |
| 1408 |
|
| 1409 |
/* |
| 1410 |
================== |
| 1411 |
BotHarvesterRetreatGoals |
| 1412 |
================== |
| 1413 |
*/ |
| 1414 |
void BotHarvesterRetreatGoals(bot_state_t *bs) { |
| 1415 |
//when carrying cubes in harvester the bot should rush to the base |
| 1416 |
if (BotHarvesterCarryingCubes(bs)) { |
| 1417 |
//if not already rushing to the base |
| 1418 |
if (bs->ltgtype != LTG_RUSHBASE) { |
| 1419 |
BotRefuseOrder(bs); |
| 1420 |
bs->ltgtype = LTG_RUSHBASE; |
| 1421 |
bs->teamgoal_time = FloatTime() + CTF_RUSHBASE_TIME; |
| 1422 |
bs->rushbaseaway_time = 0; |
| 1423 |
bs->decisionmaker = bs->client; |
| 1424 |
bs->ordered = qfalse; |
| 1425 |
BotSetTeamStatus(bs); |
| 1426 |
} |
| 1427 |
return; |
| 1428 |
} |
| 1429 |
} |
| 1430 |
//#endif |
| 1431 |
|
| 1432 |
/* |
| 1433 |
================== |
| 1434 |
BotTeamGoals |
| 1435 |
================== |
| 1436 |
*/ |
| 1437 |
void BotTeamGoals(bot_state_t *bs, int retreat) { |
| 1438 |
|
| 1439 |
if ( retreat ) { |
| 1440 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION ) { |
| 1441 |
BotCTFRetreatGoals(bs); |
| 1442 |
} |
| 1443 |
else if (gametype == GT_1FCTF) { |
| 1444 |
Bot1FCTFRetreatGoals(bs); |
| 1445 |
} |
| 1446 |
else if (gametype == GT_OBELISK) { |
| 1447 |
BotObeliskRetreatGoals(bs); |
| 1448 |
} |
| 1449 |
else if (gametype == GT_HARVESTER) { |
| 1450 |
BotHarvesterRetreatGoals(bs); |
| 1451 |
} |
| 1452 |
} |
| 1453 |
else { |
| 1454 |
if (gametype == GT_CTF|| gametype == GT_CTF_ELIMINATION) { |
| 1455 |
//decide what to do in CTF mode |
| 1456 |
BotCTFSeekGoals(bs); |
| 1457 |
} |
| 1458 |
else if (gametype == GT_1FCTF) { |
| 1459 |
Bot1FCTFSeekGoals(bs); |
| 1460 |
} |
| 1461 |
else if (gametype == GT_OBELISK) { |
| 1462 |
BotObeliskSeekGoals(bs); |
| 1463 |
} |
| 1464 |
else if (gametype == GT_HARVESTER) { |
| 1465 |
BotHarvesterSeekGoals(bs); |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
if(gametype == GT_DOUBLE_D) //Don't care about retreat |
| 1470 |
BotDDSeekGoals(bs); |
| 1471 |
|
| 1472 |
//if(gametype == GT_DOMINATION) //Don't care about retreat |
| 1473 |
// BotDomSeekGoals(bs); |
| 1474 |
|
| 1475 |
// reset the order time which is used to see if |
| 1476 |
// we decided to refuse an order |
| 1477 |
bs->order_time = 0; |
| 1478 |
} |
| 1479 |
|
| 1480 |
/* |
| 1481 |
================== |
| 1482 |
BotPointAreaNum |
| 1483 |
================== |
| 1484 |
*/ |
| 1485 |
int BotPointAreaNum(vec3_t origin) { |
| 1486 |
int areanum, numareas, areas[10]; |
| 1487 |
vec3_t end; |
| 1488 |
|
| 1489 |
areanum = trap_AAS_PointAreaNum(origin); |
| 1490 |
if (areanum) return areanum; |
| 1491 |
VectorCopy(origin, end); |
| 1492 |
end[2] += 10; |
| 1493 |
numareas = trap_AAS_TraceAreas(origin, end, areas, NULL, 10); |
| 1494 |
if (numareas > 0) return areas[0]; |
| 1495 |
return 0; |
| 1496 |
} |
| 1497 |
|
| 1498 |
/* |
| 1499 |
================== |
| 1500 |
ClientName |
| 1501 |
================== |
| 1502 |
*/ |
| 1503 |
char *ClientName(int client, char *name, int size) { |
| 1504 |
char buf[MAX_INFO_STRING]; |
| 1505 |
|
| 1506 |
if (client < 0 || client >= MAX_CLIENTS) { |
| 1507 |
BotAI_Print(PRT_ERROR, "ClientName: client out of range\n"); |
| 1508 |
return "[client out of range]"; |
| 1509 |
} |
| •1510 |
trap_GetConfigstring(CS_PLAYERS + client, buf, sizeof (buf)); |
| 1511 |
Q_strncpyz(name, Info_ValueForKey(buf, "n"), size); |
| 1512 |
Q_CleanStr(name); |
| 1513 |
return name; |
| 1514 |
} |
| 1515 |
|
| 1516 |
/* |
| 1517 |
================== |
| 1518 |
ClientSkin |
| 1519 |
================== |
| 1520 |
*/ |
| 1521 |
char *ClientSkin(int client, char *skin, int size) { |
| 1522 |
char buf[MAX_INFO_STRING]; |
| 1523 |
|
| 1524 |
if (client < 0 || client >= MAX_CLIENTS) { |
| 1525 |
BotAI_Print(PRT_ERROR, "ClientSkin: client out of range\n"); |
| 1526 |
return "[client out of range]"; |
| 1527 |
} |
| •1528 |
trap_GetConfigstring(CS_PLAYERS + client, buf, sizeof (buf)); |
| 1529 |
Q_strncpyz(skin, Info_ValueForKey(buf, "model"), size); |
| 1530 |
return skin; |
| 1531 |
} |
| 1532 |
|
| 1533 |
/* |
| 1534 |
================== |
| 1535 |
ClientFromName |
| 1536 |
================== |
| 1537 |
*/ |
| 1538 |
int ClientFromName(char *name) { |
| 1539 |
int i; |
| 1540 |
char buf[MAX_INFO_STRING]; |
| 1541 |
static int maxclients; |
| 1542 |
|
| 1543 |
if (!maxclients) |
| 1544 |
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients"); |
| 1545 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 1546 |
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf)); |
| 1547 |
Q_CleanStr( buf ); |
| 1548 |
if (!Q_stricmp(Info_ValueForKey(buf, "n"), name)) return i; |
| 1549 |
} |
| 1550 |
return -1; |
| 1551 |
} |
| 1552 |
|
| 1553 |
/* |
| 1554 |
================== |
| 1555 |
ClientOnSameTeamFromName |
| 1556 |
================== |
| 1557 |
*/ |
| 1558 |
int ClientOnSameTeamFromName(bot_state_t *bs, char *name) { |
| 1559 |
int i; |
| 1560 |
char buf[MAX_INFO_STRING]; |
| 1561 |
static int maxclients; |
| 1562 |
|
| 1563 |
if (!maxclients) |
| 1564 |
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients"); |
| 1565 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 1566 |
if (!BotSameTeam(bs, i)) |
| 1567 |
continue; |
| 1568 |
trap_GetConfigstring(CS_PLAYERS+i, buf, sizeof(buf)); |
| 1569 |
Q_CleanStr( buf ); |
| 1570 |
if (!Q_stricmp(Info_ValueForKey(buf, "n"), name)) return i; |
| 1571 |
} |
| 1572 |
return -1; |
| 1573 |
} |
| 1574 |
|
| 1575 |
/* |
| 1576 |
================== |
| 1577 |
stristr |
| 1578 |
================== |
| 1579 |
*/ |
| 1580 |
char *stristr(char *str, char *charset) { |
| 1581 |
int i; |
| 1582 |
|
| 1583 |
while(*str) { |
| 1584 |
for (i = 0; charset[i] && str[i]; i++) { |
| 1585 |
if (toupper(charset[i]) != toupper(str[i])) break; |
| 1586 |
} |
| 1587 |
if (!charset[i]) return str; |
| 1588 |
str++; |
| 1589 |
} |
| 1590 |
return NULL; |
| 1591 |
} |
| 1592 |
|
| 1593 |
/* |
| 1594 |
================== |
| 1595 |
EasyClientName |
| 1596 |
================== |
| 1597 |
*/ |
| 1598 |
char *EasyClientName(int client, char *buf, int size) { |
| 1599 |
int i; |
| 1600 |
char *str1, *str2, *ptr, c; |
| 1601 |
char name[128]; |
| 1602 |
|
| 1603 |
ClientName(client, name, sizeof(name)); |
| 1604 |
for (i = 0; name[i]; i++) name[i] &= 127; |
| 1605 |
//remove all spaces |
| 1606 |
for (ptr = strstr(name, " "); ptr; ptr = strstr(name, " ")) { |
| 1607 |
memmove(ptr, ptr+1, strlen(ptr+1)+1); |
| 1608 |
} |
| 1609 |
//check for [x] and ]x[ clan names |
| 1610 |
str1 = strstr(name, "["); |
| 1611 |
str2 = strstr(name, "]"); |
| 1612 |
if (str1 && str2) { |
| 1613 |
if (str2 > str1) memmove(str1, str2+1, strlen(str2+1)+1); |
| 1614 |
else memmove(str2, str1+1, strlen(str1+1)+1); |
| 1615 |
} |
| 1616 |
//remove Mr prefix |
| 1617 |
if ((name[0] == 'm' || name[0] == 'M') && |
| 1618 |
(name[1] == 'r' || name[1] == 'R')) { |
| 1619 |
memmove(name, name+2, strlen(name+2)+1); |
| 1620 |
} |
| 1621 |
//only allow lower case alphabet characters |
| 1622 |
ptr = name; |
| 1623 |
while(*ptr) { |
| 1624 |
c = *ptr; |
| 1625 |
if ((c >= 'a' && c <= 'z') || |
| 1626 |
(c >= '0' && c <= '9') || c == '_') { |
| 1627 |
ptr++; |
| 1628 |
} |
| 1629 |
else if (c >= 'A' && c <= 'Z') { |
| 1630 |
*ptr += 'a' - 'A'; |
| 1631 |
ptr++; |
| 1632 |
} |
| 1633 |
else { |
| 1634 |
memmove(ptr, ptr+1, strlen(ptr + 1)+1); |
| 1635 |
} |
| 1636 |
} |
| •1637 |
Q_strncpyz(buf, name, size); |
| 1638 |
return buf; |
| 1639 |
} |
| 1640 |
|
| 1641 |
/* |
| 1642 |
================== |
| 1643 |
BotSynonymContext |
| 1644 |
================== |
| 1645 |
*/ |
| 1646 |
int BotSynonymContext(bot_state_t *bs) { |
| 1647 |
int context; |
| 1648 |
|
| 1649 |
context = CONTEXT_NORMAL|CONTEXT_NEARBYITEM|CONTEXT_NAMES; |
| 1650 |
// |
| 1651 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION |
| 1652 |
|| gametype == GT_1FCTF |
| 1653 |
) { |
| 1654 |
if (BotTeam(bs) == TEAM_RED) context |= CONTEXT_CTFREDTEAM; |
| 1655 |
else context |= CONTEXT_CTFBLUETEAM; |
| 1656 |
} |
| 1657 |
else if (gametype == GT_OBELISK) { |
| 1658 |
if (BotTeam(bs) == TEAM_RED) context |= CONTEXT_OBELISKREDTEAM; |
| 1659 |
else context |= CONTEXT_OBELISKBLUETEAM; |
| 1660 |
} |
| 1661 |
else if (gametype == GT_HARVESTER) { |
| 1662 |
if (BotTeam(bs) == TEAM_RED) context |= CONTEXT_HARVESTERREDTEAM; |
| 1663 |
else context |= CONTEXT_HARVESTERBLUETEAM; |
| 1664 |
} |
| 1665 |
return context; |
| 1666 |
} |
| 1667 |
|
| 1668 |
/* |
| 1669 |
================== |
| 1670 |
BotChooseWeapon |
| 1671 |
================== |
| 1672 |
*/ |
| 1673 |
void BotChooseWeapon(bot_state_t *bs) { |
| 1674 |
int newweaponnum; |
| 1675 |
|
| 1676 |
if (bs->cur_ps.weaponstate == WEAPON_RAISING || |
| 1677 |
bs->cur_ps.weaponstate == WEAPON_DROPPING) { |
| 1678 |
trap_EA_SelectWeapon(bs->client, bs->weaponnum); |
| 1679 |
} |
| 1680 |
else { |
| 1681 |
if(g_instantgib.integer) |
| 1682 |
newweaponnum = WP_RAILGUN; |
| 1683 |
else if(g_rockets.integer) |
| 1684 |
newweaponnum = WP_ROCKET_LAUNCHER; |
| 1685 |
else |
| 1686 |
newweaponnum = trap_BotChooseBestFightWeapon(bs->ws, bs->inventory); |
| 1687 |
if (bs->weaponnum != newweaponnum) bs->weaponchange_time = FloatTime(); |
| 1688 |
bs->weaponnum = newweaponnum; |
| 1689 |
//BotAI_Print(PRT_MESSAGE, "bs->weaponnum = %d\n", bs->weaponnum); |
| 1690 |
trap_EA_SelectWeapon(bs->client, bs->weaponnum); |
| 1691 |
} |
| 1692 |
} |
| 1693 |
|
| 1694 |
/* |
| 1695 |
================== |
| 1696 |
BotSetupForMovement |
| 1697 |
================== |
| 1698 |
*/ |
| 1699 |
void BotSetupForMovement(bot_state_t *bs) { |
| 1700 |
bot_initmove_t initmove; |
| 1701 |
|
| 1702 |
memset(&initmove, 0, sizeof(bot_initmove_t)); |
| 1703 |
VectorCopy(bs->cur_ps.origin, initmove.origin); |
| 1704 |
VectorCopy(bs->cur_ps.velocity, initmove.velocity); |
| 1705 |
VectorClear(initmove.viewoffset); |
| 1706 |
initmove.viewoffset[2] += bs->cur_ps.viewheight; |
| 1707 |
initmove.entitynum = bs->entitynum; |
| 1708 |
initmove.client = bs->client; |
| 1709 |
initmove.thinktime = bs->thinktime; |
| 1710 |
//set the onground flag |
| 1711 |
if (bs->cur_ps.groundEntityNum != ENTITYNUM_NONE) initmove.or_moveflags |= MFL_ONGROUND; |
| 1712 |
//set the teleported flag |
| 1713 |
if ((bs->cur_ps.pm_flags & PMF_TIME_KNOCKBACK) && (bs->cur_ps.pm_time > 0)) { |
| 1714 |
initmove.or_moveflags |= MFL_TELEPORTED; |
| 1715 |
} |
| 1716 |
//set the waterjump flag |
| 1717 |
if ((bs->cur_ps.pm_flags & PMF_TIME_WATERJUMP) && (bs->cur_ps.pm_time > 0)) { |
| 1718 |
initmove.or_moveflags |= MFL_WATERJUMP; |
| 1719 |
} |
| 1720 |
//set presence type |
| 1721 |
if (bs->cur_ps.pm_flags & PMF_DUCKED) initmove.presencetype = PRESENCE_CROUCH; |
| 1722 |
else initmove.presencetype = PRESENCE_NORMAL; |
| 1723 |
// |
| 1724 |
if (bs->walker > 0.5) initmove.or_moveflags |= MFL_WALK; |
| 1725 |
// |
| 1726 |
VectorCopy(bs->viewangles, initmove.viewangles); |
| 1727 |
// |
| 1728 |
trap_BotInitMoveState(bs->ms, &initmove); |
| 1729 |
} |
| 1730 |
|
| 1731 |
/* |
| 1732 |
================== |
| 1733 |
BotCheckItemPickup |
| 1734 |
================== |
| 1735 |
*/ |
| 1736 |
void BotCheckItemPickup(bot_state_t *bs, int *oldinventory) { |
| 1737 |
int offence, leader; |
| 1738 |
|
| 1739 |
if (gametype <= GT_TEAM && g_ffa_gt==0) |
| 1740 |
return; |
| 1741 |
|
| 1742 |
offence = -1; |
| 1743 |
// go into offence if picked up the kamikaze or invulnerability |
| 1744 |
if (!oldinventory[INVENTORY_KAMIKAZE] && bs->inventory[INVENTORY_KAMIKAZE] >= 1) { |
| 1745 |
offence = qtrue; |
| 1746 |
} |
| 1747 |
if (!oldinventory[INVENTORY_INVULNERABILITY] && bs->inventory[INVENTORY_INVULNERABILITY] >= 1) { |
| 1748 |
offence = qtrue; |
| 1749 |
} |
| 1750 |
// if not already wearing the kamikaze or invulnerability |
| 1751 |
if (!bs->inventory[INVENTORY_KAMIKAZE] && !bs->inventory[INVENTORY_INVULNERABILITY]) { |
| 1752 |
if (!oldinventory[INVENTORY_SCOUT] && bs->inventory[INVENTORY_SCOUT] >= 1) { |
| 1753 |
offence = qtrue; |
| 1754 |
} |
| 1755 |
if (!oldinventory[INVENTORY_GUARD] && bs->inventory[INVENTORY_GUARD] >= 1) { |
| 1756 |
offence = qtrue; |
| 1757 |
} |
| 1758 |
if (!oldinventory[INVENTORY_DOUBLER] && bs->inventory[INVENTORY_DOUBLER] >= 1) { |
| 1759 |
offence = qfalse; |
| 1760 |
} |
| 1761 |
if (!oldinventory[INVENTORY_AMMOREGEN] && bs->inventory[INVENTORY_AMMOREGEN] >= 1) { |
| 1762 |
offence = qfalse; |
| 1763 |
} |
| 1764 |
} |
| 1765 |
|
| 1766 |
if (offence >= 0) { |
| 1767 |
leader = ClientFromName(bs->teamleader); |
| 1768 |
if (offence) { |
| 1769 |
if (!(bs->teamtaskpreference & TEAMTP_ATTACKER)) { |
| 1770 |
// if we have a bot team leader |
| 1771 |
if (BotTeamLeader(bs)) { |
| 1772 |
// tell the leader we want to be on offence |
| 1773 |
BotVoiceChat(bs, leader, VOICECHAT_WANTONOFFENSE); |
| 1774 |
//BotAI_BotInitialChat(bs, "wantoffence", NULL); |
| 1775 |
//trap_BotEnterChat(bs->cs, leader, CHAT_TELL); |
| 1776 |
} |
| 1777 |
else if (g_spSkill.integer <= 3) { |
| 1778 |
if ( ( bs->ltgtype != LTG_GETFLAG ) && |
| 1779 |
( bs->ltgtype != LTG_ATTACKENEMYBASE ) && |
| 1780 |
( bs->ltgtype != LTG_HARVEST ) && |
| 1781 |
( ( ( gametype != GT_CTF ) && |
| 1782 |
( gametype != GT_CTF_ELIMINATION ) ) || |
| 1783 |
( ( bs->redflagstatus == 0 ) && |
| 1784 |
( bs->blueflagstatus == 0 ) ) ) && |
| 1785 |
( ( gametype != GT_1FCTF ) || |
| 1786 |
( bs->neutralflagstatus == 0 ) ) ) { |
| 1787 |
// tell the leader we want to be on offence |
| 1788 |
BotVoiceChat(bs, leader, VOICECHAT_WANTONOFFENSE); |
| 1789 |
//BotAI_BotInitialChat(bs, "wantoffence", NULL); |
| 1790 |
//trap_BotEnterChat(bs->cs, leader, CHAT_TELL); |
| 1791 |
} |
| 1792 |
bs->teamtaskpreference |= TEAMTP_ATTACKER; |
| 1793 |
} |
| 1794 |
} |
| 1795 |
bs->teamtaskpreference &= ~TEAMTP_DEFENDER; |
| 1796 |
} |
| 1797 |
else { |
| 1798 |
if (!(bs->teamtaskpreference & TEAMTP_DEFENDER)) { |
| 1799 |
// if we have a bot team leader |
| 1800 |
if (BotTeamLeader(bs)) { |
| 1801 |
// tell the leader we want to be on defense |
| 1802 |
BotVoiceChat(bs, -1, VOICECHAT_WANTONDEFENSE); |
| 1803 |
//BotAI_BotInitialChat(bs, "wantdefence", NULL); |
| 1804 |
//trap_BotEnterChat(bs->cs, leader, CHAT_TELL); |
| 1805 |
} |
| 1806 |
else if ( (g_spSkill.integer <= 3) && |
| 1807 |
( bs->ltgtype != LTG_DEFENDKEYAREA ) && |
| 1808 |
( ( ( gametype != GT_CTF ) && |
| 1809 |
( gametype != GT_CTF_ELIMINATION ) ) || |
| 1810 |
( ( bs->redflagstatus == 0 ) && |
| 1811 |
( bs->blueflagstatus == 0 ) ) ) && |
| 1812 |
( ( gametype != GT_1FCTF ) || |
| 1813 |
( bs->neutralflagstatus == 0 ) ) ) { |
| 1814 |
|
| 1815 |
// tell the leader we want to be on defense |
| 1816 |
BotVoiceChat(bs, -1, VOICECHAT_WANTONDEFENSE); |
| 1817 |
//BotAI_BotInitialChat(bs, "wantdefence", NULL); |
| 1818 |
//trap_BotEnterChat(bs->cs, leader, CHAT_TELL); |
| 1819 |
} |
| 1820 |
bs->teamtaskpreference |= TEAMTP_DEFENDER; |
| 1821 |
} |
| 1822 |
bs->teamtaskpreference &= ~TEAMTP_ATTACKER; |
| 1823 |
} |
| 1824 |
} |
| 1825 |
//#endif |
| 1826 |
} |
| 1827 |
|
| 1828 |
/* |
| 1829 |
================== |
| 1830 |
BotUpdateInventory |
| 1831 |
================== |
| 1832 |
*/ |
| 1833 |
void BotUpdateInventory(bot_state_t *bs) { |
| 1834 |
int oldinventory[MAX_ITEMS]; |
| 1835 |
|
| 1836 |
memcpy(oldinventory, bs->inventory, sizeof(oldinventory)); |
| 1837 |
//armor |
| 1838 |
bs->inventory[INVENTORY_ARMOR] = bs->cur_ps.stats[STAT_ARMOR]; |
| 1839 |
//weapons |
| 1840 |
bs->inventory[INVENTORY_GAUNTLET] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_GAUNTLET)) != 0; |
| 1841 |
bs->inventory[INVENTORY_SHOTGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_SHOTGUN)) != 0; |
| 1842 |
bs->inventory[INVENTORY_MACHINEGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_MACHINEGUN)) != 0; |
| 1843 |
bs->inventory[INVENTORY_GRENADELAUNCHER] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_GRENADE_LAUNCHER)) != 0; |
| 1844 |
bs->inventory[INVENTORY_ROCKETLAUNCHER] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_ROCKET_LAUNCHER)) != 0; |
| 1845 |
bs->inventory[INVENTORY_LIGHTNING] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_LIGHTNING)) != 0; |
| 1846 |
bs->inventory[INVENTORY_RAILGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_RAILGUN)) != 0; |
| 1847 |
bs->inventory[INVENTORY_PLASMAGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_PLASMAGUN)) != 0; |
| 1848 |
bs->inventory[INVENTORY_BFG10K] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_BFG)) != 0; |
| 1849 |
bs->inventory[INVENTORY_GRAPPLINGHOOK] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_GRAPPLING_HOOK)) != 0; |
| 1850 |
bs->inventory[INVENTORY_NAILGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_NAILGUN)) != 0;; |
| 1851 |
bs->inventory[INVENTORY_PROXLAUNCHER] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_PROX_LAUNCHER)) != 0;; |
| 1852 |
bs->inventory[INVENTORY_CHAINGUN] = (bs->cur_ps.stats[STAT_WEAPONS] & (1 << WP_CHAINGUN)) != 0;; |
| 1853 |
//ammo |
| 1854 |
bs->inventory[INVENTORY_SHELLS] = bs->cur_ps.ammo[WP_SHOTGUN]; |
| 1855 |
bs->inventory[INVENTORY_BULLETS] = bs->cur_ps.ammo[WP_MACHINEGUN]; |
| 1856 |
bs->inventory[INVENTORY_GRENADES] = bs->cur_ps.ammo[WP_GRENADE_LAUNCHER]; |
| 1857 |
bs->inventory[INVENTORY_CELLS] = bs->cur_ps.ammo[WP_PLASMAGUN]; |
| 1858 |
bs->inventory[INVENTORY_LIGHTNINGAMMO] = bs->cur_ps.ammo[WP_LIGHTNING]; |
| 1859 |
bs->inventory[INVENTORY_ROCKETS] = bs->cur_ps.ammo[WP_ROCKET_LAUNCHER]; |
| 1860 |
bs->inventory[INVENTORY_SLUGS] = bs->cur_ps.ammo[WP_RAILGUN]; |
| 1861 |
bs->inventory[INVENTORY_BFGAMMO] = bs->cur_ps.ammo[WP_BFG]; |
| 1862 |
bs->inventory[INVENTORY_NAILS] = bs->cur_ps.ammo[WP_NAILGUN]; |
| 1863 |
bs->inventory[INVENTORY_MINES] = bs->cur_ps.ammo[WP_PROX_LAUNCHER]; |
| 1864 |
bs->inventory[INVENTORY_BELT] = bs->cur_ps.ammo[WP_CHAINGUN]; |
| 1865 |
//powerups |
| 1866 |
bs->inventory[INVENTORY_HEALTH] = bs->cur_ps.stats[STAT_HEALTH]; |
| 1867 |
bs->inventory[INVENTORY_TELEPORTER] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_TELEPORTER; |
| 1868 |
bs->inventory[INVENTORY_MEDKIT] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_MEDKIT; |
| 1869 |
bs->inventory[INVENTORY_KAMIKAZE] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_KAMIKAZE; |
| 1870 |
bs->inventory[INVENTORY_PORTAL] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_PORTAL; |
| 1871 |
bs->inventory[INVENTORY_INVULNERABILITY] = bs->cur_ps.stats[STAT_HOLDABLE_ITEM] == MODELINDEX_INVULNERABILITY; |
| 1872 |
bs->inventory[INVENTORY_QUAD] = bs->cur_ps.powerups[PW_QUAD] != 0; |
| 1873 |
bs->inventory[INVENTORY_ENVIRONMENTSUIT] = bs->cur_ps.powerups[PW_BATTLESUIT] != 0; |
| 1874 |
bs->inventory[INVENTORY_HASTE] = bs->cur_ps.powerups[PW_HASTE] != 0; |
| 1875 |
bs->inventory[INVENTORY_INVISIBILITY] = bs->cur_ps.powerups[PW_INVIS] != 0; |
| 1876 |
bs->inventory[INVENTORY_REGEN] = bs->cur_ps.powerups[PW_REGEN] != 0; |
| 1877 |
bs->inventory[INVENTORY_FLIGHT] = bs->cur_ps.powerups[PW_FLIGHT] != 0; |
| •1878 |
#ifdef HAVE_STAT_PERSISTANT_POWERUP |
| 1879 |
bs->inventory[INVENTORY_SCOUT] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_SCOUT; |
| 1880 |
bs->inventory[INVENTORY_GUARD] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_GUARD; |
| 1881 |
bs->inventory[INVENTORY_DOUBLER] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_DOUBLER; |
| 1882 |
bs->inventory[INVENTORY_AMMOREGEN] = bs->cur_ps.stats[STAT_PERSISTANT_POWERUP] == MODELINDEX_AMMOREGEN; |
| •1883 |
#endif |
| 1884 |
bs->inventory[INVENTORY_REDFLAG] = bs->cur_ps.powerups[PW_REDFLAG] != 0; |
| 1885 |
bs->inventory[INVENTORY_BLUEFLAG] = bs->cur_ps.powerups[PW_BLUEFLAG] != 0; |
| 1886 |
bs->inventory[INVENTORY_NEUTRALFLAG] = bs->cur_ps.powerups[PW_NEUTRALFLAG] != 0; |
| 1887 |
if (BotTeam(bs) == TEAM_RED) { |
| 1888 |
bs->inventory[INVENTORY_REDCUBE] = bs->cur_ps.generic1; |
| 1889 |
bs->inventory[INVENTORY_BLUECUBE] = 0; |
| 1890 |
} |
| 1891 |
else { |
| 1892 |
bs->inventory[INVENTORY_REDCUBE] = 0; |
| 1893 |
bs->inventory[INVENTORY_BLUECUBE] = bs->cur_ps.generic1; |
| 1894 |
} |
| 1895 |
BotCheckItemPickup(bs, oldinventory); |
| 1896 |
} |
| 1897 |
|
| 1898 |
/* |
| 1899 |
================== |
| 1900 |
BotUpdateBattleInventory |
| 1901 |
================== |
| 1902 |
*/ |
| 1903 |
void BotUpdateBattleInventory(bot_state_t *bs, int enemy) { |
| 1904 |
vec3_t dir; |
| 1905 |
aas_entityinfo_t entinfo; |
| 1906 |
|
| 1907 |
BotEntityInfo(enemy, &entinfo); |
| 1908 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 1909 |
bs->inventory[ENEMY_HEIGHT] = (int) dir[2]; |
| 1910 |
dir[2] = 0; |
| 1911 |
bs->inventory[ENEMY_HORIZONTAL_DIST] = (int) VectorLength(dir); |
| 1912 |
//FIXME: add num visible enemies and num visible team mates to the inventory |
| 1913 |
} |
| 1914 |
|
| 1915 |
/* |
| 1916 |
================== |
| 1917 |
BotUseKamikaze |
| 1918 |
================== |
| 1919 |
*/ |
| 1920 |
#define KAMIKAZE_DIST 1024 |
| 1921 |
|
| 1922 |
void BotUseKamikaze(bot_state_t *bs) { |
| 1923 |
int c, teammates, enemies; |
| 1924 |
aas_entityinfo_t entinfo; |
| 1925 |
vec3_t dir, target; |
| 1926 |
bot_goal_t *goal; |
| 1927 |
bsp_trace_t trace; |
| 1928 |
|
| 1929 |
//if the bot has no kamikaze |
| 1930 |
if (bs->inventory[INVENTORY_KAMIKAZE] <= 0) |
| 1931 |
return; |
| 1932 |
if (bs->kamikaze_time > FloatTime()) |
| 1933 |
return; |
| 1934 |
bs->kamikaze_time = FloatTime() + 0.2; |
| 1935 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 1936 |
//never use kamikaze if the team flag carrier is visible |
| 1937 |
if (BotCTFCarryingFlag(bs)) |
| 1938 |
return; |
| 1939 |
c = BotTeamFlagCarrierVisible(bs); |
| 1940 |
if (c >= 0) { |
| 1941 |
BotEntityInfo(c, &entinfo); |
| 1942 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 1943 |
if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) |
| 1944 |
return; |
| 1945 |
} |
| 1946 |
c = BotEnemyFlagCarrierVisible(bs); |
| 1947 |
if (c >= 0) { |
| 1948 |
BotEntityInfo(c, &entinfo); |
| 1949 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 1950 |
if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) { |
| 1951 |
trap_EA_Use(bs->client); |
| 1952 |
return; |
| 1953 |
} |
| 1954 |
} |
| 1955 |
} |
| 1956 |
else if (gametype == GT_1FCTF) { |
| 1957 |
//never use kamikaze if the team flag carrier is visible |
| 1958 |
if (Bot1FCTFCarryingFlag(bs)) |
| 1959 |
return; |
| 1960 |
c = BotTeamFlagCarrierVisible(bs); |
| 1961 |
if (c >= 0) { |
| 1962 |
BotEntityInfo(c, &entinfo); |
| 1963 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 1964 |
if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) |
| 1965 |
return; |
| 1966 |
} |
| 1967 |
c = BotEnemyFlagCarrierVisible(bs); |
| 1968 |
if (c >= 0) { |
| 1969 |
BotEntityInfo(c, &entinfo); |
| 1970 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 1971 |
if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) { |
| 1972 |
trap_EA_Use(bs->client); |
| 1973 |
return; |
| 1974 |
} |
| 1975 |
} |
| 1976 |
} |
| 1977 |
else if (gametype == GT_OBELISK) { |
| 1978 |
switch(BotTeam(bs)) { |
| 1979 |
case TEAM_RED: goal = &blueobelisk; break; |
| 1980 |
default: goal = &redobelisk; break; |
| 1981 |
} |
| 1982 |
//if the obelisk is visible |
| 1983 |
VectorCopy(goal->origin, target); |
| 1984 |
target[2] += 1; |
| 1985 |
VectorSubtract(bs->origin, target, dir); |
| 1986 |
if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST * 0.9)) { |
| 1987 |
BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID); |
| 1988 |
if (trace.fraction >= 1 || trace.ent == goal->entitynum) { |
| 1989 |
trap_EA_Use(bs->client); |
| 1990 |
return; |
| 1991 |
} |
| 1992 |
} |
| 1993 |
} |
| 1994 |
else if (gametype == GT_HARVESTER) { |
| 1995 |
// |
| 1996 |
if (BotHarvesterCarryingCubes(bs)) |
| 1997 |
return; |
| 1998 |
//never use kamikaze if a team mate carrying cubes is visible |
| 1999 |
c = BotTeamCubeCarrierVisible(bs); |
| 2000 |
if (c >= 0) { |
| 2001 |
BotEntityInfo(c, &entinfo); |
| 2002 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 2003 |
if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) |
| 2004 |
return; |
| 2005 |
} |
| 2006 |
c = BotEnemyCubeCarrierVisible(bs); |
| 2007 |
if (c >= 0) { |
| 2008 |
BotEntityInfo(c, &entinfo); |
| 2009 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 2010 |
if (VectorLengthSquared(dir) < Square(KAMIKAZE_DIST)) { |
| 2011 |
trap_EA_Use(bs->client); |
| 2012 |
return; |
| 2013 |
} |
| 2014 |
} |
| 2015 |
} |
| 2016 |
// |
| 2017 |
BotVisibleTeamMatesAndEnemies(bs, &teammates, &enemies, KAMIKAZE_DIST); |
| 2018 |
// |
| 2019 |
if (enemies > 2 && enemies > teammates+1) { |
| 2020 |
trap_EA_Use(bs->client); |
| 2021 |
return; |
| 2022 |
} |
| 2023 |
} |
| 2024 |
|
| 2025 |
/* |
| 2026 |
================== |
| 2027 |
BotUseInvulnerability |
| 2028 |
================== |
| 2029 |
*/ |
| 2030 |
void BotUseInvulnerability(bot_state_t *bs) { |
| 2031 |
int c; |
| 2032 |
vec3_t dir, target; |
| 2033 |
bot_goal_t *goal; |
| 2034 |
bsp_trace_t trace; |
| 2035 |
|
| 2036 |
//if the bot has no invulnerability |
| 2037 |
if (bs->inventory[INVENTORY_INVULNERABILITY] <= 0) |
| 2038 |
return; |
| 2039 |
if (bs->invulnerability_time > FloatTime()) |
| 2040 |
return; |
| 2041 |
bs->invulnerability_time = FloatTime() + 0.2; |
| 2042 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 2043 |
//never use kamikaze if the team flag carrier is visible |
| 2044 |
if (BotCTFCarryingFlag(bs)) |
| 2045 |
return; |
| 2046 |
c = BotEnemyFlagCarrierVisible(bs); |
| 2047 |
if (c >= 0) |
| 2048 |
return; |
| 2049 |
//if near enemy flag and the flag is visible |
| 2050 |
switch(BotTeam(bs)) { |
| 2051 |
case TEAM_RED: goal = &ctf_blueflag; break; |
| 2052 |
default: goal = &ctf_redflag; break; |
| 2053 |
} |
| 2054 |
//if the obelisk is visible |
| 2055 |
VectorCopy(goal->origin, target); |
| 2056 |
target[2] += 1; |
| 2057 |
VectorSubtract(bs->origin, target, dir); |
| 2058 |
if (VectorLengthSquared(dir) < Square(200)) { |
| 2059 |
BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID); |
| 2060 |
if (trace.fraction >= 1 || trace.ent == goal->entitynum) { |
| 2061 |
trap_EA_Use(bs->client); |
| 2062 |
return; |
| 2063 |
} |
| 2064 |
} |
| 2065 |
} |
| 2066 |
else if (gametype == GT_1FCTF) { |
| 2067 |
//never use kamikaze if the team flag carrier is visible |
| 2068 |
if (Bot1FCTFCarryingFlag(bs)) |
| 2069 |
return; |
| 2070 |
c = BotEnemyFlagCarrierVisible(bs); |
| 2071 |
if (c >= 0) |
| 2072 |
return; |
| 2073 |
//if near enemy flag and the flag is visible |
| 2074 |
switch(BotTeam(bs)) { |
| 2075 |
case TEAM_RED: goal = &ctf_blueflag; break; |
| 2076 |
default: goal = &ctf_redflag; break; |
| 2077 |
} |
| 2078 |
//if the obelisk is visible |
| 2079 |
VectorCopy(goal->origin, target); |
| 2080 |
target[2] += 1; |
| 2081 |
VectorSubtract(bs->origin, target, dir); |
| 2082 |
if (VectorLengthSquared(dir) < Square(200)) { |
| 2083 |
BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID); |
| 2084 |
if (trace.fraction >= 1 || trace.ent == goal->entitynum) { |
| 2085 |
trap_EA_Use(bs->client); |
| 2086 |
return; |
| 2087 |
} |
| 2088 |
} |
| 2089 |
} |
| 2090 |
else if (gametype == GT_OBELISK) { |
| 2091 |
switch(BotTeam(bs)) { |
| 2092 |
case TEAM_RED: goal = &blueobelisk; break; |
| 2093 |
default: goal = &redobelisk; break; |
| 2094 |
} |
| 2095 |
//if the obelisk is visible |
| 2096 |
VectorCopy(goal->origin, target); |
| 2097 |
target[2] += 1; |
| 2098 |
VectorSubtract(bs->origin, target, dir); |
| 2099 |
if (VectorLengthSquared(dir) < Square(300)) { |
| 2100 |
BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID); |
| 2101 |
if (trace.fraction >= 1 || trace.ent == goal->entitynum) { |
| 2102 |
trap_EA_Use(bs->client); |
| 2103 |
return; |
| 2104 |
} |
| 2105 |
} |
| 2106 |
} |
| 2107 |
else if (gametype == GT_HARVESTER) { |
| 2108 |
// |
| 2109 |
if (BotHarvesterCarryingCubes(bs)) |
| 2110 |
return; |
| 2111 |
c = BotEnemyCubeCarrierVisible(bs); |
| 2112 |
if (c >= 0) |
| 2113 |
return; |
| 2114 |
//if near enemy base and enemy base is visible |
| 2115 |
switch(BotTeam(bs)) { |
| 2116 |
case TEAM_RED: goal = &blueobelisk; break; |
| 2117 |
default: goal = &redobelisk; break; |
| 2118 |
} |
| 2119 |
//if the obelisk is visible |
| 2120 |
VectorCopy(goal->origin, target); |
| 2121 |
target[2] += 1; |
| 2122 |
VectorSubtract(bs->origin, target, dir); |
| 2123 |
if (VectorLengthSquared(dir) < Square(200)) { |
| 2124 |
BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID); |
| 2125 |
if (trace.fraction >= 1 || trace.ent == goal->entitynum) { |
| 2126 |
trap_EA_Use(bs->client); |
| 2127 |
return; |
| 2128 |
} |
| 2129 |
} |
| 2130 |
} |
| 2131 |
} |
| 2132 |
|
| 2133 |
/* |
| 2134 |
================== |
| 2135 |
BotBattleUseItems |
| 2136 |
================== |
| 2137 |
*/ |
| 2138 |
void BotBattleUseItems(bot_state_t *bs) { |
| 2139 |
if (bs->inventory[INVENTORY_HEALTH] < 40) { |
| 2140 |
if (bs->inventory[INVENTORY_TELEPORTER] > 0) { |
| 2141 |
if (!BotCTFCarryingFlag(bs) |
| 2142 |
&& !Bot1FCTFCarryingFlag(bs) |
| 2143 |
&& !BotHarvesterCarryingCubes(bs) |
| 2144 |
) { |
| 2145 |
trap_EA_Use(bs->client); |
| 2146 |
} |
| 2147 |
} |
| 2148 |
} |
| 2149 |
if (bs->inventory[INVENTORY_HEALTH] < 60) { |
| 2150 |
if (bs->inventory[INVENTORY_MEDKIT] > 0) { |
| 2151 |
trap_EA_Use(bs->client); |
| 2152 |
} |
| 2153 |
} |
| 2154 |
BotUseKamikaze(bs); |
| 2155 |
BotUseInvulnerability(bs); |
| 2156 |
} |
| 2157 |
|
| 2158 |
/* |
| 2159 |
================== |
| 2160 |
BotSetTeleportTime |
| 2161 |
================== |
| 2162 |
*/ |
| 2163 |
void BotSetTeleportTime(bot_state_t *bs) { |
| 2164 |
if ((bs->cur_ps.eFlags ^ bs->last_eFlags) & EF_TELEPORT_BIT) { |
| 2165 |
bs->teleport_time = FloatTime(); |
| 2166 |
} |
| 2167 |
bs->last_eFlags = bs->cur_ps.eFlags; |
| 2168 |
} |
| 2169 |
|
| 2170 |
/* |
| 2171 |
================== |
| 2172 |
BotIsDead |
| 2173 |
================== |
| 2174 |
*/ |
| 2175 |
qboolean BotIsDead(bot_state_t *bs) { |
| 2176 |
return (bs->cur_ps.pm_type == PM_DEAD); |
| 2177 |
} |
| 2178 |
|
| 2179 |
/* |
| 2180 |
================== |
| 2181 |
BotIsObserver |
| 2182 |
================== |
| 2183 |
*/ |
| 2184 |
qboolean BotIsObserver(bot_state_t *bs) { |
| 2185 |
char buf[MAX_INFO_STRING]; |
| 2186 |
if (bs->cur_ps.pm_type == PM_SPECTATOR) return qtrue; |
| 2187 |
trap_GetConfigstring(CS_PLAYERS+bs->client, buf, sizeof(buf)); |
| 2188 |
if (atoi(Info_ValueForKey(buf, "t")) == TEAM_SPECTATOR) return qtrue; |
| 2189 |
return qfalse; |
| 2190 |
} |
| 2191 |
|
| 2192 |
/* |
| 2193 |
================== |
| 2194 |
BotIntermission |
| 2195 |
================== |
| 2196 |
*/ |
| 2197 |
qboolean BotIntermission(bot_state_t *bs) { |
| 2198 |
//NOTE: we shouldn't be looking at the game code... |
| 2199 |
if (level.intermissiontime) return qtrue; |
| 2200 |
return (bs->cur_ps.pm_type == PM_FREEZE || bs->cur_ps.pm_type == PM_INTERMISSION); |
| 2201 |
} |
| 2202 |
|
| 2203 |
/* |
| 2204 |
================== |
| 2205 |
BotInLavaOrSlime |
| 2206 |
================== |
| 2207 |
*/ |
| 2208 |
qboolean BotInLavaOrSlime(bot_state_t *bs) { |
| 2209 |
vec3_t feet; |
| 2210 |
|
| 2211 |
VectorCopy(bs->origin, feet); |
| 2212 |
feet[2] -= 23; |
| 2213 |
return (trap_AAS_PointContents(feet) & (CONTENTS_LAVA|CONTENTS_SLIME)); |
| 2214 |
} |
| 2215 |
|
| 2216 |
/* |
| 2217 |
================== |
| 2218 |
BotCreateWayPoint |
| 2219 |
================== |
| 2220 |
*/ |
| 2221 |
bot_waypoint_t *BotCreateWayPoint(char *name, vec3_t origin, int areanum) { |
| 2222 |
bot_waypoint_t *wp; |
| 2223 |
vec3_t waypointmins = {-8, -8, -8}, waypointmaxs = {8, 8, 8}; |
| 2224 |
|
| 2225 |
wp = botai_freewaypoints; |
| 2226 |
if ( !wp ) { |
| 2227 |
BotAI_Print( PRT_WARNING, "BotCreateWayPoint: Out of waypoints\n" ); |
| 2228 |
return NULL; |
| 2229 |
} |
| 2230 |
botai_freewaypoints = botai_freewaypoints->next; |
| 2231 |
|
| 2232 |
Q_strncpyz( wp->name, name, sizeof(wp->name) ); |
| 2233 |
VectorCopy(origin, wp->goal.origin); |
| 2234 |
VectorCopy(waypointmins, wp->goal.mins); |
| 2235 |
VectorCopy(waypointmaxs, wp->goal.maxs); |
| 2236 |
wp->goal.areanum = areanum; |
| 2237 |
wp->next = NULL; |
| 2238 |
wp->prev = NULL; |
| 2239 |
return wp; |
| 2240 |
} |
| 2241 |
|
| 2242 |
/* |
| 2243 |
================== |
| 2244 |
BotFindWayPoint |
| 2245 |
================== |
| 2246 |
*/ |
| 2247 |
bot_waypoint_t *BotFindWayPoint(bot_waypoint_t *waypoints, char *name) { |
| 2248 |
bot_waypoint_t *wp; |
| 2249 |
|
| 2250 |
for (wp = waypoints; wp; wp = wp->next) { |
| 2251 |
if (!Q_stricmp(wp->name, name)) return wp; |
| 2252 |
} |
| 2253 |
return NULL; |
| 2254 |
} |
| 2255 |
|
| 2256 |
/* |
| 2257 |
================== |
| 2258 |
BotFreeWaypoints |
| 2259 |
================== |
| 2260 |
*/ |
| 2261 |
void BotFreeWaypoints(bot_waypoint_t *wp) { |
| 2262 |
bot_waypoint_t *nextwp; |
| 2263 |
|
| 2264 |
for (; wp; wp = nextwp) { |
| 2265 |
nextwp = wp->next; |
| 2266 |
wp->next = botai_freewaypoints; |
| 2267 |
botai_freewaypoints = wp; |
| 2268 |
} |
| 2269 |
} |
| 2270 |
|
| 2271 |
/* |
| 2272 |
================== |
| 2273 |
BotInitWaypoints |
| 2274 |
================== |
| 2275 |
*/ |
| 2276 |
void BotInitWaypoints(void) { |
| 2277 |
int i; |
| 2278 |
|
| 2279 |
botai_freewaypoints = NULL; |
| 2280 |
for (i = 0; i < MAX_WAYPOINTS; i++) { |
| 2281 |
botai_waypoints[i].next = botai_freewaypoints; |
| 2282 |
botai_freewaypoints = &botai_waypoints[i]; |
| 2283 |
} |
| 2284 |
} |
| 2285 |
|
| 2286 |
/* |
| 2287 |
================== |
| 2288 |
TeamPlayIsOn |
| 2289 |
================== |
| 2290 |
*/ |
| 2291 |
int TeamPlayIsOn(void) { |
| 2292 |
return ( gametype >= GT_TEAM && g_ffa_gt!=1); |
| 2293 |
} |
| 2294 |
|
| 2295 |
/* |
| 2296 |
================== |
| 2297 |
BotAggression |
| 2298 |
================== |
| 2299 |
*/ |
| 2300 |
float BotAggression(bot_state_t *bs) { |
| 2301 |
//if the bot has quad |
| 2302 |
if (bs->inventory[INVENTORY_QUAD]) { |
| 2303 |
//if the bot is not holding the gauntlet or the enemy is really nearby |
| 2304 |
if (bs->weaponnum != WP_GAUNTLET || |
| 2305 |
bs->inventory[ENEMY_HORIZONTAL_DIST] < 80) { |
| 2306 |
return 70; |
| 2307 |
} |
| 2308 |
} |
| 2309 |
//if the enemy is located way higher than the bot |
| 2310 |
if (bs->inventory[ENEMY_HEIGHT] > 200) return 0; |
| 2311 |
//if the bot is very low on health |
| 2312 |
if (bs->inventory[INVENTORY_HEALTH] < 60) return 0; |
| 2313 |
//if the bot is low on health |
| 2314 |
if (bs->inventory[INVENTORY_HEALTH] < 80) { |
| 2315 |
//if the bot has insufficient armor |
| 2316 |
if (bs->inventory[INVENTORY_ARMOR] < 40) return 0; |
| 2317 |
} |
| 2318 |
//if the bot can use the bfg |
| 2319 |
if (bs->inventory[INVENTORY_BFG10K] > 0 && |
| 2320 |
bs->inventory[INVENTORY_BFGAMMO] > 7) return 100; |
| 2321 |
//if the bot can use the railgun |
| 2322 |
if (bs->inventory[INVENTORY_RAILGUN] > 0 && |
| 2323 |
bs->inventory[INVENTORY_SLUGS] > 5) return 95; |
| 2324 |
//if the bot can use the lightning gun |
| 2325 |
if (bs->inventory[INVENTORY_LIGHTNING] > 0 && |
| 2326 |
bs->inventory[INVENTORY_LIGHTNINGAMMO] > 50) return 90; |
| 2327 |
//if the bot can use the rocketlauncher |
| 2328 |
if (bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 && |
| 2329 |
bs->inventory[INVENTORY_ROCKETS] > 5) return 90; |
| 2330 |
//if the bot can use the plasmagun |
| 2331 |
if (bs->inventory[INVENTORY_PLASMAGUN] > 0 && |
| 2332 |
bs->inventory[INVENTORY_CELLS] > 40) return 85; |
| 2333 |
//if the bot can use the grenade launcher |
| 2334 |
if (bs->inventory[INVENTORY_GRENADELAUNCHER] > 0 && |
| 2335 |
bs->inventory[INVENTORY_GRENADES] > 10) return 80; |
| 2336 |
//if the bot can use the shotgun |
| 2337 |
if (bs->inventory[INVENTORY_SHOTGUN] > 0 && |
| 2338 |
bs->inventory[INVENTORY_SHELLS] > 10) return 50; |
| 2339 |
//otherwise the bot is not feeling too good |
| 2340 |
return 0; |
| 2341 |
} |
| 2342 |
|
| 2343 |
/* |
| 2344 |
================== |
| 2345 |
BotFeelingBad |
| 2346 |
================== |
| 2347 |
*/ |
| 2348 |
float BotFeelingBad(bot_state_t *bs) { |
| 2349 |
if (bs->weaponnum == WP_GAUNTLET) { |
| 2350 |
return 100; |
| 2351 |
} |
| 2352 |
if (bs->inventory[INVENTORY_HEALTH] < 40) { |
| 2353 |
return 100; |
| 2354 |
} |
| 2355 |
if (bs->weaponnum == WP_MACHINEGUN) { |
| 2356 |
return 90; |
| 2357 |
} |
| 2358 |
if (bs->inventory[INVENTORY_HEALTH] < 60) { |
| 2359 |
return 80; |
| 2360 |
} |
| 2361 |
return 0; |
| 2362 |
} |
| 2363 |
|
| 2364 |
/* |
| 2365 |
================== |
| 2366 |
BotWantsToRetreat |
| 2367 |
================== |
| 2368 |
*/ |
| 2369 |
int BotWantsToRetreat(bot_state_t *bs) { |
| 2370 |
aas_entityinfo_t entinfo; |
| 2371 |
|
| 2372 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 2373 |
//always retreat when carrying a CTF flag |
| 2374 |
if (BotCTFCarryingFlag(bs)) |
| 2375 |
return qtrue; |
| 2376 |
} |
| 2377 |
else if (gametype == GT_1FCTF) { |
| 2378 |
//if carrying the flag then always retreat |
| 2379 |
if (Bot1FCTFCarryingFlag(bs)) |
| 2380 |
return qtrue; |
| 2381 |
} |
| 2382 |
else if (gametype == GT_OBELISK) { |
| 2383 |
//the bots should be dedicated to attacking the enemy obelisk |
| 2384 |
if (bs->ltgtype == LTG_ATTACKENEMYBASE) { |
| 2385 |
if (bs->enemy != redobelisk.entitynum && |
| 2386 |
bs->enemy != blueobelisk.entitynum) { |
| 2387 |
return qtrue; |
| 2388 |
} |
| 2389 |
} |
| 2390 |
if (BotFeelingBad(bs) > 50) { |
| 2391 |
return qtrue; |
| 2392 |
} |
| 2393 |
return qfalse; |
| 2394 |
} |
| 2395 |
else if (gametype == GT_HARVESTER) { |
| 2396 |
//if carrying cubes then always retreat |
| 2397 |
if (BotHarvesterCarryingCubes(bs)) return qtrue; |
| 2398 |
} |
| 2399 |
// |
| 2400 |
if (bs->enemy >= 0) { |
| 2401 |
//if the enemy is carrying a flag |
| 2402 |
BotEntityInfo(bs->enemy, &entinfo); |
| 2403 |
// if the enemy is carrying a flag |
| 2404 |
if (EntityCarriesFlag(&entinfo)) return qfalse; |
| 2405 |
#ifdef MISSIONPACK |
| 2406 |
// if the enemy is carrying cubes |
| 2407 |
if (EntityCarriesCubes(&entinfo)) return qfalse; |
| 2408 |
#endif |
| 2409 |
} |
| 2410 |
//if the bot is getting the flag |
| 2411 |
if (bs->ltgtype == LTG_GETFLAG) |
| 2412 |
return qtrue; |
| 2413 |
// |
| 2414 |
if (BotAggression(bs) < 50) |
| 2415 |
return qtrue; |
| 2416 |
return qfalse; |
| 2417 |
} |
| 2418 |
|
| 2419 |
/* |
| 2420 |
================== |
| 2421 |
BotWantsToChase |
| 2422 |
================== |
| 2423 |
*/ |
| 2424 |
int BotWantsToChase(bot_state_t *bs) { |
| 2425 |
aas_entityinfo_t entinfo; |
| 2426 |
|
| 2427 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 2428 |
//never chase when carrying a CTF flag |
| 2429 |
if (BotCTFCarryingFlag(bs)) |
| 2430 |
return qfalse; |
| 2431 |
//always chase if the enemy is carrying a flag |
| 2432 |
BotEntityInfo(bs->enemy, &entinfo); |
| 2433 |
if (EntityCarriesFlag(&entinfo)) |
| 2434 |
return qtrue; |
| 2435 |
} |
| 2436 |
else if (gametype == GT_1FCTF) { |
| 2437 |
//never chase if carrying the flag |
| 2438 |
if (Bot1FCTFCarryingFlag(bs)) |
| 2439 |
return qfalse; |
| 2440 |
//always chase if the enemy is carrying a flag |
| 2441 |
BotEntityInfo(bs->enemy, &entinfo); |
| 2442 |
if (EntityCarriesFlag(&entinfo)) |
| 2443 |
return qtrue; |
| 2444 |
} |
| 2445 |
else if (gametype == GT_OBELISK) { |
| 2446 |
//the bots should be dedicated to attacking the enemy obelisk |
| 2447 |
if (bs->ltgtype == LTG_ATTACKENEMYBASE) { |
| 2448 |
if (bs->enemy != redobelisk.entitynum && |
| 2449 |
bs->enemy != blueobelisk.entitynum) { |
| 2450 |
return qfalse; |
| 2451 |
} |
| 2452 |
} |
| 2453 |
} |
| 2454 |
else if (gametype == GT_HARVESTER) { |
| 2455 |
//never chase if carrying cubes |
| 2456 |
if (BotHarvesterCarryingCubes(bs)) return qfalse; |
| 2457 |
|
| 2458 |
BotEntityInfo(bs->enemy, &entinfo); |
| 2459 |
// always chase if the enemy is carrying cubes |
| 2460 |
if (EntityCarriesCubes(&entinfo)) return qtrue; |
| 2461 |
} |
| 2462 |
//if the bot is getting the flag |
| 2463 |
if (bs->ltgtype == LTG_GETFLAG) |
| 2464 |
return qfalse; |
| 2465 |
// |
| 2466 |
if (BotAggression(bs) > 50) |
| 2467 |
return qtrue; |
| 2468 |
return qfalse; |
| 2469 |
} |
| 2470 |
|
| 2471 |
/* |
| 2472 |
================== |
| 2473 |
BotWantsToHelp |
| 2474 |
================== |
| 2475 |
*/ |
| 2476 |
int BotWantsToHelp(bot_state_t *bs) { |
| 2477 |
return qtrue; |
| 2478 |
} |
| 2479 |
|
| 2480 |
/* |
| 2481 |
================== |
| 2482 |
BotCanAndWantsToRocketJump |
| 2483 |
================== |
| 2484 |
*/ |
| 2485 |
int BotCanAndWantsToRocketJump(bot_state_t *bs) { |
| 2486 |
float rocketjumper; |
| 2487 |
|
| 2488 |
//if rocket jumping is disabled |
| 2489 |
if (!bot_rocketjump.integer) return qfalse; |
| 2490 |
//if no rocket launcher |
| 2491 |
if (bs->inventory[INVENTORY_ROCKETLAUNCHER] <= 0) return qfalse; |
| 2492 |
//if low on rockets |
| 2493 |
if (bs->inventory[INVENTORY_ROCKETS] < 3) return qfalse; |
| 2494 |
//Sago: Special rule - always happy to rocket jump in elimination, eCTF end LMS if |
| 2495 |
if ( (g_gametype.integer==GT_ELIMINATION || g_gametype.integer==GT_CTF_ELIMINATION || g_gametype.integer==GT_LMS ) |
| 2496 |
&& g_elimination_selfdamage.integer==0) { |
| 2497 |
return qtrue; |
| 2498 |
} |
| 2499 |
//never rocket jump with the Quad |
| 2500 |
if (bs->inventory[INVENTORY_QUAD]) return qfalse; |
| 2501 |
//if low on health |
| 2502 |
if (bs->inventory[INVENTORY_HEALTH] < 60) return qfalse; |
| 2503 |
//if not full health |
| 2504 |
if (bs->inventory[INVENTORY_HEALTH] < 90) { |
| 2505 |
//if the bot has insufficient armor |
| 2506 |
if (bs->inventory[INVENTORY_ARMOR] < 40) return qfalse; |
| 2507 |
} |
| 2508 |
rocketjumper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_WEAPONJUMPING, 0, 1); |
| 2509 |
if (rocketjumper < 0.5) return qfalse; |
| 2510 |
return qtrue; |
| 2511 |
} |
| 2512 |
|
| 2513 |
/* |
| 2514 |
================== |
| 2515 |
BotHasPersistantPowerupAndWeapon |
| 2516 |
================== |
| 2517 |
*/ |
| 2518 |
int BotHasPersistantPowerupAndWeapon(bot_state_t *bs) { |
| 2519 |
// if the bot does not have a persistant powerup |
| 2520 |
//Sago - FIXME - This causes problems if there are no persistant powerups |
| 2521 |
/* if (!bs->inventory[INVENTORY_SCOUT] && |
| 2522 |
!bs->inventory[INVENTORY_GUARD] && |
| 2523 |
!bs->inventory[INVENTORY_DOUBLER] && |
| 2524 |
!bs->inventory[INVENTORY_AMMOREGEN] ) { |
| 2525 |
return qfalse; |
| 2526 |
}*/ |
| 2527 |
//if the bot is very low on health |
| 2528 |
if (bs->inventory[INVENTORY_HEALTH] < 60) return qfalse; |
| 2529 |
//if the bot is low on health |
| 2530 |
if (bs->inventory[INVENTORY_HEALTH] < 80) { |
| 2531 |
//if the bot has insufficient armor |
| 2532 |
if (bs->inventory[INVENTORY_ARMOR] < 40) return qfalse; |
| 2533 |
} |
| 2534 |
//if the bot can use the bfg |
| 2535 |
if (bs->inventory[INVENTORY_BFG10K] > 0 && |
| 2536 |
bs->inventory[INVENTORY_BFGAMMO] > 7) return qtrue; |
| 2537 |
//if the bot can use the railgun |
| 2538 |
if (bs->inventory[INVENTORY_RAILGUN] > 0 && |
| 2539 |
bs->inventory[INVENTORY_SLUGS] > 5) return qtrue; |
| 2540 |
//if the bot can use the lightning gun |
| 2541 |
if (bs->inventory[INVENTORY_LIGHTNING] > 0 && |
| 2542 |
bs->inventory[INVENTORY_LIGHTNINGAMMO] > 50) return qtrue; |
| 2543 |
//if the bot can use the rocketlauncher |
| 2544 |
if (bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 && |
| 2545 |
bs->inventory[INVENTORY_ROCKETS] > 5) return qtrue; |
| 2546 |
// |
| 2547 |
if (bs->inventory[INVENTORY_NAILGUN] > 0 && |
| 2548 |
bs->inventory[INVENTORY_NAILS] > 5) return qtrue; |
| 2549 |
// |
| 2550 |
if (bs->inventory[INVENTORY_PROXLAUNCHER] > 0 && |
| 2551 |
bs->inventory[INVENTORY_MINES] > 5) return qtrue; |
| 2552 |
// |
| 2553 |
if (bs->inventory[INVENTORY_CHAINGUN] > 0 && |
| 2554 |
bs->inventory[INVENTORY_BELT] > 40) return qtrue; |
| 2555 |
//if the bot can use the plasmagun |
| 2556 |
if (bs->inventory[INVENTORY_PLASMAGUN] > 0 && |
| 2557 |
bs->inventory[INVENTORY_CELLS] > 20) return qtrue; |
| 2558 |
return qfalse; |
| 2559 |
} |
| 2560 |
|
| 2561 |
/* |
| 2562 |
================== |
| 2563 |
BotGoCamp |
| 2564 |
================== |
| 2565 |
*/ |
| 2566 |
void BotGoCamp(bot_state_t *bs, bot_goal_t *goal) { |
| 2567 |
float camper; |
| 2568 |
|
| 2569 |
bs->decisionmaker = bs->client; |
| 2570 |
//set message time to zero so bot will NOT show any message |
| 2571 |
bs->teammessage_time = 0; |
| 2572 |
//set the ltg type |
| 2573 |
bs->ltgtype = LTG_CAMP; |
| 2574 |
//set the team goal |
| 2575 |
memcpy(&bs->teamgoal, goal, sizeof(bot_goal_t)); |
| 2576 |
//get the team goal time |
| 2577 |
camper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CAMPER, 0, 1); |
| 2578 |
if (camper > 0.99) bs->teamgoal_time = FloatTime() + 99999; |
| 2579 |
else bs->teamgoal_time = FloatTime() + 120 + 180 * camper + random() * 15; |
| 2580 |
//set the last time the bot started camping |
| 2581 |
bs->camp_time = FloatTime(); |
| 2582 |
//the teammate that requested the camping |
| 2583 |
bs->teammate = 0; |
| 2584 |
//do NOT type arrive message |
| 2585 |
bs->arrive_time = 1; |
| 2586 |
} |
| 2587 |
|
| 2588 |
/* |
| 2589 |
================== |
| 2590 |
BotWantsToCamp |
| 2591 |
================== |
| 2592 |
*/ |
| 2593 |
int BotWantsToCamp(bot_state_t *bs) { |
| 2594 |
float camper; |
| 2595 |
int cs, traveltime, besttraveltime; |
| 2596 |
bot_goal_t goal, bestgoal; |
| 2597 |
|
| 2598 |
camper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CAMPER, 0, 1); |
| 2599 |
if (camper < 0.1) return qfalse; |
| 2600 |
//if the bot has a team goal |
| 2601 |
if (bs->ltgtype == LTG_TEAMHELP || |
| 2602 |
bs->ltgtype == LTG_TEAMACCOMPANY || |
| 2603 |
bs->ltgtype == LTG_DEFENDKEYAREA || |
| 2604 |
bs->ltgtype == LTG_GETFLAG || |
| 2605 |
bs->ltgtype == LTG_RUSHBASE || |
| 2606 |
bs->ltgtype == LTG_CAMP || |
| 2607 |
bs->ltgtype == LTG_CAMPORDER || |
| 2608 |
bs->ltgtype == LTG_PATROL) { |
| 2609 |
return qfalse; |
| 2610 |
} |
| 2611 |
//if camped recently |
| 2612 |
if (bs->camp_time > FloatTime() - 60 + 300 * (1-camper)) return qfalse; |
| 2613 |
// |
| 2614 |
if (random() > camper) { |
| 2615 |
bs->camp_time = FloatTime(); |
| 2616 |
return qfalse; |
| 2617 |
} |
| 2618 |
//if the bot isn't healthy anough |
| 2619 |
if (BotAggression(bs) < 50) return qfalse; |
| 2620 |
//the bot should have at least have the rocket launcher, the railgun or the bfg10k with some ammo |
| 2621 |
if ((bs->inventory[INVENTORY_ROCKETLAUNCHER] <= 0 || bs->inventory[INVENTORY_ROCKETS] < 10) && |
| 2622 |
(bs->inventory[INVENTORY_RAILGUN] <= 0 || bs->inventory[INVENTORY_SLUGS] < 10) && |
| 2623 |
(bs->inventory[INVENTORY_BFG10K] <= 0 || bs->inventory[INVENTORY_BFGAMMO] < 10)) { |
| 2624 |
return qfalse; |
| 2625 |
} |
| 2626 |
//find the closest camp spot |
| 2627 |
besttraveltime = 99999; |
| 2628 |
for (cs = trap_BotGetNextCampSpotGoal(0, &goal); cs; cs = trap_BotGetNextCampSpotGoal(cs, &goal)) { |
| 2629 |
traveltime = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, goal.areanum, TFL_DEFAULT); |
| 2630 |
if (traveltime && traveltime < besttraveltime) { |
| 2631 |
besttraveltime = traveltime; |
| 2632 |
memcpy(&bestgoal, &goal, sizeof(bot_goal_t)); |
| 2633 |
} |
| 2634 |
} |
| 2635 |
if (besttraveltime > 150) return qfalse; |
| 2636 |
//ok found a camp spot, go camp there |
| 2637 |
BotGoCamp(bs, &bestgoal); |
| 2638 |
bs->ordered = qfalse; |
| 2639 |
// |
| 2640 |
return qtrue; |
| 2641 |
} |
| 2642 |
|
| 2643 |
/* |
| 2644 |
================== |
| 2645 |
BotDontAvoid |
| 2646 |
================== |
| 2647 |
*/ |
| 2648 |
void BotDontAvoid(bot_state_t *bs, char *itemname) { |
| 2649 |
bot_goal_t goal; |
| 2650 |
int num; |
| 2651 |
|
| 2652 |
num = trap_BotGetLevelItemGoal(-1, itemname, &goal); |
| 2653 |
while(num >= 0) { |
| 2654 |
trap_BotRemoveFromAvoidGoals(bs->gs, goal.number); |
| 2655 |
num = trap_BotGetLevelItemGoal(num, itemname, &goal); |
| 2656 |
} |
| 2657 |
} |
| 2658 |
|
| 2659 |
/* |
| 2660 |
================== |
| 2661 |
BotGoForPowerups |
| 2662 |
================== |
| 2663 |
*/ |
| 2664 |
void BotGoForPowerups(bot_state_t *bs) { |
| 2665 |
|
| 2666 |
//don't avoid any of the powerups anymore |
| 2667 |
BotDontAvoid(bs, "Quad Damage"); |
| 2668 |
BotDontAvoid(bs, "Regeneration"); |
| 2669 |
BotDontAvoid(bs, "Battle Suit"); |
| 2670 |
BotDontAvoid(bs, "Speed"); |
| 2671 |
BotDontAvoid(bs, "Invisibility"); |
| 2672 |
//BotDontAvoid(bs, "Flight"); |
| 2673 |
//reset the long term goal time so the bot will go for the powerup |
| 2674 |
//NOTE: the long term goal type doesn't change |
| 2675 |
bs->ltg_time = 0; |
| 2676 |
} |
| 2677 |
|
| 2678 |
/* |
| 2679 |
================== |
| 2680 |
BotRoamGoal |
| 2681 |
================== |
| 2682 |
*/ |
| 2683 |
void BotRoamGoal(bot_state_t *bs, vec3_t goal) { |
| 2684 |
int pc, i; |
| 2685 |
float len, rnd; |
| 2686 |
vec3_t dir, bestorg, belowbestorg; |
| 2687 |
bsp_trace_t trace; |
| 2688 |
|
| 2689 |
for (i = 0; i < 10; i++) { |
| 2690 |
//start at the bot origin |
| 2691 |
VectorCopy(bs->origin, bestorg); |
| 2692 |
rnd = random(); |
| 2693 |
if (rnd > 0.25) { |
| 2694 |
//add a random value to the x-coordinate |
| 2695 |
if (random() < 0.5) bestorg[0] -= 800 * random() + 100; |
| 2696 |
else bestorg[0] += 800 * random() + 100; |
| 2697 |
} |
| 2698 |
if (rnd < 0.75) { |
| 2699 |
//add a random value to the y-coordinate |
| 2700 |
if (random() < 0.5) bestorg[1] -= 800 * random() + 100; |
| 2701 |
else bestorg[1] += 800 * random() + 100; |
| 2702 |
} |
| 2703 |
//add a random value to the z-coordinate (NOTE: 48 = maxjump?) |
| 2704 |
bestorg[2] += 2 * 48 * crandom(); |
| 2705 |
//trace a line from the origin to the roam target |
| 2706 |
BotAI_Trace(&trace, bs->origin, NULL, NULL, bestorg, bs->entitynum, MASK_SOLID); |
| 2707 |
//direction and length towards the roam target |
| 2708 |
VectorSubtract(trace.endpos, bs->origin, dir); |
| 2709 |
len = VectorNormalize(dir); |
| 2710 |
//if the roam target is far away anough |
| 2711 |
if (len > 200) { |
| 2712 |
//the roam target is in the given direction before walls |
| 2713 |
VectorScale(dir, len * trace.fraction - 40, dir); |
| 2714 |
VectorAdd(bs->origin, dir, bestorg); |
| 2715 |
//get the coordinates of the floor below the roam target |
| 2716 |
belowbestorg[0] = bestorg[0]; |
| 2717 |
belowbestorg[1] = bestorg[1]; |
| 2718 |
belowbestorg[2] = bestorg[2] - 800; |
| 2719 |
BotAI_Trace(&trace, bestorg, NULL, NULL, belowbestorg, bs->entitynum, MASK_SOLID); |
| 2720 |
// |
| 2721 |
if (!trace.startsolid) { |
| 2722 |
trace.endpos[2]++; |
| 2723 |
pc = trap_PointContents(trace.endpos, bs->entitynum); |
| 2724 |
if (!(pc & (CONTENTS_LAVA | CONTENTS_SLIME))) { |
| 2725 |
VectorCopy(bestorg, goal); |
| 2726 |
return; |
| 2727 |
} |
| 2728 |
} |
| 2729 |
} |
| 2730 |
} |
| 2731 |
VectorCopy(bestorg, goal); |
| 2732 |
} |
| 2733 |
|
| 2734 |
/* |
| 2735 |
================== |
| 2736 |
BotAttackMove |
| 2737 |
================== |
| 2738 |
*/ |
| 2739 |
bot_moveresult_t BotAttackMove(bot_state_t *bs, int tfl) { |
| 2740 |
int movetype, i, attackentity; |
| 2741 |
float attack_skill, jumper, croucher, dist, strafechange_time; |
| 2742 |
float attack_dist, attack_range; |
| 2743 |
vec3_t forward, backward, sideward, hordir, up = {0, 0, 1}; |
| 2744 |
aas_entityinfo_t entinfo; |
| 2745 |
bot_moveresult_t moveresult; |
| 2746 |
bot_goal_t goal; |
| 2747 |
|
| 2748 |
attackentity = bs->enemy; |
| 2749 |
// |
| 2750 |
if (bs->attackchase_time > FloatTime()) { |
| 2751 |
//create the chase goal |
| 2752 |
goal.entitynum = attackentity; |
| 2753 |
goal.areanum = bs->lastenemyareanum; |
| 2754 |
VectorCopy(bs->lastenemyorigin, goal.origin); |
| 2755 |
VectorSet(goal.mins, -8, -8, -8); |
| 2756 |
VectorSet(goal.maxs, 8, 8, 8); |
| 2757 |
//initialize the movement state |
| 2758 |
BotSetupForMovement(bs); |
| 2759 |
//move towards the goal |
| 2760 |
trap_BotMoveToGoal(&moveresult, bs->ms, &goal, tfl); |
| 2761 |
return moveresult; |
| 2762 |
} |
| 2763 |
// |
| 2764 |
memset(&moveresult, 0, sizeof(bot_moveresult_t)); |
| 2765 |
// |
| 2766 |
attack_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_ATTACK_SKILL, 0, 1); |
| 2767 |
jumper = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_JUMPER, 0, 1); |
| 2768 |
croucher = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CROUCHER, 0, 1); |
| 2769 |
//if the bot is really stupid |
| 2770 |
if (attack_skill < 0.2) return moveresult; |
| 2771 |
//initialize the movement state |
| 2772 |
BotSetupForMovement(bs); |
| 2773 |
//get the enemy entity info |
| 2774 |
BotEntityInfo(attackentity, &entinfo); |
| 2775 |
//direction towards the enemy |
| 2776 |
VectorSubtract(entinfo.origin, bs->origin, forward); |
| 2777 |
//the distance towards the enemy |
| 2778 |
dist = VectorNormalize(forward); |
| 2779 |
VectorNegate(forward, backward); |
| 2780 |
//walk, crouch or jump |
| 2781 |
movetype = MOVE_WALK; |
| 2782 |
// |
| 2783 |
if (bs->attackcrouch_time < FloatTime() - 1) { |
| 2784 |
if (random() < jumper) { |
| 2785 |
movetype = MOVE_JUMP; |
| 2786 |
} |
| 2787 |
//wait at least one second before crouching again |
| 2788 |
else if (bs->attackcrouch_time < FloatTime() - 1 && random() < croucher) { |
| 2789 |
bs->attackcrouch_time = FloatTime() + croucher * 5; |
| 2790 |
} |
| 2791 |
} |
| 2792 |
if (bs->attackcrouch_time > FloatTime()) movetype = MOVE_CROUCH; |
| 2793 |
//if the bot should jump |
| 2794 |
if (movetype == MOVE_JUMP) { |
| 2795 |
//if jumped last frame |
| 2796 |
if (bs->attackjump_time > FloatTime()) { |
| 2797 |
movetype = MOVE_WALK; |
| 2798 |
} |
| 2799 |
else { |
| 2800 |
bs->attackjump_time = FloatTime() + 1; |
| 2801 |
} |
| 2802 |
} |
| 2803 |
if (bs->cur_ps.weapon == WP_GAUNTLET) { |
| 2804 |
attack_dist = 0; |
| 2805 |
attack_range = 0; |
| 2806 |
} |
| 2807 |
else { |
| 2808 |
attack_dist = IDEAL_ATTACKDIST; |
| 2809 |
attack_range = 40; |
| 2810 |
} |
| 2811 |
//if the bot is stupid |
| 2812 |
if (attack_skill <= 0.4) { |
| 2813 |
//just walk to or away from the enemy |
| 2814 |
if (dist > attack_dist + attack_range) { |
| 2815 |
if (trap_BotMoveInDirection(bs->ms, forward, 400, movetype)) return moveresult; |
| 2816 |
} |
| 2817 |
if (dist < attack_dist - attack_range) { |
| 2818 |
if (trap_BotMoveInDirection(bs->ms, backward, 400, movetype)) return moveresult; |
| 2819 |
} |
| 2820 |
return moveresult; |
| 2821 |
} |
| 2822 |
//increase the strafe time |
| 2823 |
bs->attackstrafe_time += bs->thinktime; |
| 2824 |
//get the strafe change time |
| 2825 |
strafechange_time = 0.4 + (1 - attack_skill) * 0.2; |
| 2826 |
if (attack_skill > 0.7) strafechange_time += crandom() * 0.2; |
| 2827 |
//if the strafe direction should be changed |
| 2828 |
if (bs->attackstrafe_time > strafechange_time) { |
| 2829 |
//some magic number :) |
| 2830 |
if (random() > 0.935) { |
| 2831 |
//flip the strafe direction |
| 2832 |
bs->flags ^= BFL_STRAFERIGHT; |
| 2833 |
bs->attackstrafe_time = 0; |
| 2834 |
} |
| 2835 |
} |
| 2836 |
// |
| 2837 |
for (i = 0; i < 2; i++) { |
| 2838 |
hordir[0] = forward[0]; |
| 2839 |
hordir[1] = forward[1]; |
| 2840 |
hordir[2] = 0; |
| 2841 |
VectorNormalize(hordir); |
| 2842 |
//get the sideward vector |
| 2843 |
CrossProduct(hordir, up, sideward); |
| 2844 |
//reverse the vector depending on the strafe direction |
| 2845 |
if (bs->flags & BFL_STRAFERIGHT) VectorNegate(sideward, sideward); |
| 2846 |
//randomly go back a little |
| 2847 |
if (random() > 0.9) { |
| 2848 |
VectorAdd(sideward, backward, sideward); |
| 2849 |
} |
| 2850 |
else { |
| 2851 |
//walk forward or backward to get at the ideal attack distance |
| 2852 |
if (dist > attack_dist + attack_range) { |
| 2853 |
VectorAdd(sideward, forward, sideward); |
| 2854 |
} |
| 2855 |
else if (dist < attack_dist - attack_range) { |
| 2856 |
VectorAdd(sideward, backward, sideward); |
| 2857 |
} |
| 2858 |
} |
| 2859 |
//perform the movement |
| 2860 |
if (trap_BotMoveInDirection(bs->ms, sideward, 400, movetype)) |
| 2861 |
return moveresult; |
| 2862 |
//movement failed, flip the strafe direction |
| 2863 |
bs->flags ^= BFL_STRAFERIGHT; |
| 2864 |
bs->attackstrafe_time = 0; |
| 2865 |
} |
| 2866 |
//bot couldn't do any usefull movement |
| 2867 |
// bs->attackchase_time = AAS_Time() + 6; |
| 2868 |
return moveresult; |
| 2869 |
} |
| 2870 |
|
| 2871 |
/* |
| 2872 |
================== |
| 2873 |
BotSameTeam |
| 2874 |
================== |
| 2875 |
*/ |
| 2876 |
int BotSameTeam(bot_state_t *bs, int entnum) { |
| 2877 |
if (bs->client < 0 || bs->client >= MAX_CLIENTS) { |
| 2878 |
//BotAI_Print(PRT_ERROR, "BotSameTeam: client out of range\n"); |
| 2879 |
return qfalse; |
| 2880 |
} |
| 2881 |
if (entnum < 0 || entnum >= MAX_CLIENTS) { |
| 2882 |
//BotAI_Print(PRT_ERROR, "BotSameTeam: client out of range\n"); |
| 2883 |
return qfalse; |
| 2884 |
} |
| 2885 |
if ( gametype >= GT_TEAM && g_ffa_gt!=1) { |
| 2886 |
/*Sago: I don't know why they decided to check the configstring instead of the real value. |
| 2887 |
For some reason bots sometimes gets a wrong config string when chaning gametypes. |
| 2888 |
Now we check the real value: */ |
| 2889 |
if(level.clients[bs->client].sess.sessionTeam==level.clients[entnum].sess.sessionTeam) return qtrue; |
| 2890 |
} |
| 2891 |
return qfalse; |
| 2892 |
} |
| 2893 |
|
| 2894 |
/* |
| 2895 |
================== |
| 2896 |
InFieldOfVision |
| 2897 |
================== |
| 2898 |
*/ |
| 2899 |
qboolean InFieldOfVision(vec3_t viewangles, float fov, vec3_t angles) |
| 2900 |
{ |
| 2901 |
int i; |
| 2902 |
float diff, angle; |
| 2903 |
|
| 2904 |
for (i = 0; i < 2; i++) { |
| 2905 |
angle = AngleMod(viewangles[i]); |
| 2906 |
angles[i] = AngleMod(angles[i]); |
| 2907 |
diff = angles[i] - angle; |
| 2908 |
if (angles[i] > angle) { |
| 2909 |
if (diff > 180.0) diff -= 360.0; |
| 2910 |
} |
| 2911 |
else { |
| 2912 |
if (diff < -180.0) diff += 360.0; |
| 2913 |
} |
| 2914 |
if (diff > 0) { |
| 2915 |
if (diff > fov * 0.5) return qfalse; |
| 2916 |
} |
| 2917 |
else { |
| 2918 |
if (diff < -fov * 0.5) return qfalse; |
| 2919 |
} |
| 2920 |
} |
| 2921 |
return qtrue; |
| 2922 |
} |
| 2923 |
|
| 2924 |
/* |
| 2925 |
================== |
| 2926 |
BotEntityVisible |
| 2927 |
|
| 2928 |
returns visibility in the range [0, 1] taking fog and water surfaces into account |
| 2929 |
================== |
| 2930 |
*/ |
| 2931 |
float BotEntityVisible(int viewer, vec3_t eye, vec3_t viewangles, float fov, int ent) { |
| 2932 |
int i, contents_mask, passent, hitent, infog, inwater, otherinfog, pc; |
| 2933 |
float squaredfogdist, waterfactor, vis, bestvis; |
| 2934 |
bsp_trace_t trace; |
| 2935 |
aas_entityinfo_t entinfo; |
| 2936 |
vec3_t dir, entangles, start, end, middle; |
| 2937 |
|
| 2938 |
//calculate middle of bounding box |
| 2939 |
BotEntityInfo(ent, &entinfo); |
| 2940 |
VectorAdd(entinfo.mins, entinfo.maxs, middle); |
| 2941 |
VectorScale(middle, 0.5, middle); |
| 2942 |
VectorAdd(entinfo.origin, middle, middle); |
| 2943 |
//check if entity is within field of vision |
| 2944 |
VectorSubtract(middle, eye, dir); |
| 2945 |
vectoangles(dir, entangles); |
| 2946 |
if (!InFieldOfVision(viewangles, fov, entangles)) return 0; |
| 2947 |
// |
| 2948 |
pc = trap_AAS_PointContents(eye); |
| 2949 |
infog = (pc & CONTENTS_FOG); |
| 2950 |
inwater = (pc & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER)); |
| 2951 |
// |
| 2952 |
bestvis = 0; |
| 2953 |
for (i = 0; i < 3; i++) { |
| 2954 |
//if the point is not in potential visible sight |
| 2955 |
//if (!AAS_inPVS(eye, middle)) continue; |
| 2956 |
// |
| 2957 |
contents_mask = CONTENTS_SOLID|CONTENTS_PLAYERCLIP; |
| 2958 |
passent = viewer; |
| 2959 |
hitent = ent; |
| 2960 |
VectorCopy(eye, start); |
| 2961 |
VectorCopy(middle, end); |
| 2962 |
//if the entity is in water, lava or slime |
| 2963 |
if (trap_AAS_PointContents(middle) & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER)) { |
| 2964 |
contents_mask |= (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER); |
| 2965 |
} |
| 2966 |
//if eye is in water, lava or slime |
| 2967 |
if (inwater) { |
| 2968 |
if (!(contents_mask & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER))) { |
| 2969 |
passent = ent; |
| 2970 |
hitent = viewer; |
| 2971 |
VectorCopy(middle, start); |
| 2972 |
VectorCopy(eye, end); |
| 2973 |
} |
| 2974 |
contents_mask ^= (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER); |
| 2975 |
} |
| 2976 |
//trace from start to end |
| 2977 |
BotAI_Trace(&trace, start, NULL, NULL, end, passent, contents_mask); |
| 2978 |
//if water was hit |
| 2979 |
waterfactor = 1.0; |
| 2980 |
if (trace.contents & (CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER)) { |
| 2981 |
//if the water surface is translucent |
| 2982 |
if (1) { |
| 2983 |
//trace through the water |
| 2984 |
contents_mask &= ~(CONTENTS_LAVA|CONTENTS_SLIME|CONTENTS_WATER); |
| 2985 |
BotAI_Trace(&trace, trace.endpos, NULL, NULL, end, passent, contents_mask); |
| 2986 |
waterfactor = 0.5; |
| 2987 |
} |
| 2988 |
} |
| 2989 |
//if a full trace or the hitent was hit |
| 2990 |
if (trace.fraction >= 1 || trace.ent == hitent) { |
| 2991 |
//check for fog, assuming there's only one fog brush where |
| 2992 |
//either the viewer or the entity is in or both are in |
| 2993 |
otherinfog = (trap_AAS_PointContents(middle) & CONTENTS_FOG); |
| 2994 |
if (infog && otherinfog) { |
| 2995 |
VectorSubtract(trace.endpos, eye, dir); |
| 2996 |
squaredfogdist = VectorLengthSquared(dir); |
| 2997 |
} |
| 2998 |
else if (infog) { |
| 2999 |
VectorCopy(trace.endpos, start); |
| 3000 |
BotAI_Trace(&trace, start, NULL, NULL, eye, viewer, CONTENTS_FOG); |
| 3001 |
VectorSubtract(eye, trace.endpos, dir); |
| 3002 |
squaredfogdist = VectorLengthSquared(dir); |
| 3003 |
} |
| 3004 |
else if (otherinfog) { |
| 3005 |
VectorCopy(trace.endpos, end); |
| 3006 |
BotAI_Trace(&trace, eye, NULL, NULL, end, viewer, CONTENTS_FOG); |
| 3007 |
VectorSubtract(end, trace.endpos, dir); |
| 3008 |
squaredfogdist = VectorLengthSquared(dir); |
| 3009 |
} |
| 3010 |
else { |
| 3011 |
//if the entity and the viewer are not in fog assume there's no fog in between |
| 3012 |
squaredfogdist = 0; |
| 3013 |
} |
| 3014 |
//decrease visibility with the view distance through fog |
| 3015 |
vis = 1 / ((squaredfogdist * 0.001) < 1 ? 1 : (squaredfogdist * 0.001)); |
| 3016 |
//if entering water visibility is reduced |
| 3017 |
vis *= waterfactor; |
| 3018 |
// |
| 3019 |
if (vis > bestvis) bestvis = vis; |
| 3020 |
//if pretty much no fog |
| 3021 |
if (bestvis >= 0.95) return bestvis; |
| 3022 |
} |
| 3023 |
//check bottom and top of bounding box as well |
| 3024 |
if (i == 0) middle[2] += entinfo.mins[2]; |
| 3025 |
else if (i == 1) middle[2] += entinfo.maxs[2] - entinfo.mins[2]; |
| 3026 |
} |
| 3027 |
return bestvis; |
| 3028 |
} |
| 3029 |
|
| 3030 |
/* |
| 3031 |
================== |
| 3032 |
BotFindEnemy |
| 3033 |
================== |
| 3034 |
*/ |
| 3035 |
int BotFindEnemy(bot_state_t *bs, int curenemy) { |
| 3036 |
int i, healthdecrease; |
| 3037 |
float f, alertness, easyfragger, vis; |
| 3038 |
float squaredist, cursquaredist; |
| 3039 |
aas_entityinfo_t entinfo, curenemyinfo; |
| 3040 |
vec3_t dir, angles; |
| 3041 |
|
| 3042 |
alertness = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_ALERTNESS, 0, 1); |
| 3043 |
easyfragger = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_EASY_FRAGGER, 0, 1); |
| 3044 |
//check if the health decreased |
| 3045 |
healthdecrease = bs->lasthealth > bs->inventory[INVENTORY_HEALTH]; |
| 3046 |
//remember the current health value |
| 3047 |
bs->lasthealth = bs->inventory[INVENTORY_HEALTH]; |
| 3048 |
// |
| 3049 |
if (curenemy >= 0) { |
| 3050 |
BotEntityInfo(curenemy, &curenemyinfo); |
| 3051 |
if (EntityCarriesFlag(&curenemyinfo)) return qfalse; |
| 3052 |
VectorSubtract(curenemyinfo.origin, bs->origin, dir); |
| 3053 |
cursquaredist = VectorLengthSquared(dir); |
| 3054 |
} |
| 3055 |
else { |
| 3056 |
cursquaredist = 0; |
| 3057 |
} |
| 3058 |
if (gametype == GT_OBELISK) { |
| 3059 |
vec3_t target; |
| 3060 |
bot_goal_t *goal; |
| 3061 |
bsp_trace_t trace; |
| 3062 |
|
| 3063 |
if (BotTeam(bs) == TEAM_RED) |
| 3064 |
goal = &blueobelisk; |
| 3065 |
else |
| 3066 |
goal = &redobelisk; |
| 3067 |
//if the obelisk is visible |
| 3068 |
VectorCopy(goal->origin, target); |
| 3069 |
target[2] += 1; |
| 3070 |
BotAI_Trace(&trace, bs->eye, NULL, NULL, target, bs->client, CONTENTS_SOLID); |
| 3071 |
if (trace.fraction >= 1 || trace.ent == goal->entitynum) { |
| 3072 |
if (goal->entitynum == bs->enemy) { |
| 3073 |
return qfalse; |
| 3074 |
} |
| 3075 |
bs->enemy = goal->entitynum; |
| 3076 |
bs->enemysight_time = FloatTime(); |
| 3077 |
bs->enemysuicide = qfalse; |
| 3078 |
bs->enemydeath_time = 0; |
| 3079 |
bs->enemyvisible_time = FloatTime(); |
| 3080 |
return qtrue; |
| 3081 |
} |
| 3082 |
} |
| 3083 |
// |
| 3084 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3085 |
|
| 3086 |
if (i == bs->client) continue; |
| 3087 |
//if it's the current enemy |
| 3088 |
if (i == curenemy) continue; |
| 3089 |
// |
| 3090 |
BotEntityInfo(i, &entinfo); |
| 3091 |
// |
| 3092 |
if (!entinfo.valid) continue; |
| 3093 |
//if the enemy isn't dead and the enemy isn't the bot self |
| 3094 |
if (EntityIsDead(&entinfo) || entinfo.number == bs->entitynum) continue; |
| 3095 |
//if the enemy is invisible and not shooting |
| 3096 |
if (EntityIsInvisible(&entinfo) && !EntityIsShooting(&entinfo)) { |
| 3097 |
continue; |
| 3098 |
} |
| 3099 |
//Neil Torontos unlagged |
| 3100 |
//unlagged - misc |
| 3101 |
// this has nothing to do with lag compensation, but it's great for testing |
| 3102 |
if ( g_entities[i].flags & FL_NOTARGET ) continue; |
| 3103 |
//unlagged - misc |
| 3104 |
//if not an easy fragger don't shoot at chatting players |
| 3105 |
if (easyfragger < 0.5 && EntityIsChatting(&entinfo)) continue; |
| 3106 |
// |
| 3107 |
if (lastteleport_time > FloatTime() - 3) { |
| 3108 |
VectorSubtract(entinfo.origin, lastteleport_origin, dir); |
| 3109 |
if (VectorLengthSquared(dir) < Square(70)) continue; |
| 3110 |
} |
| 3111 |
//calculate the distance towards the enemy |
| 3112 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 3113 |
squaredist = VectorLengthSquared(dir); |
| 3114 |
//if this entity is not carrying a flag |
| 3115 |
if (!EntityCarriesFlag(&entinfo)) |
| 3116 |
{ |
| 3117 |
//if this enemy is further away than the current one |
| 3118 |
if (curenemy >= 0 && squaredist > cursquaredist) continue; |
| 3119 |
} //end if |
| 3120 |
//if the bot has no |
| 3121 |
if (squaredist > Square(900.0 + alertness * 4000.0)) continue; |
| 3122 |
//if on the same team |
| 3123 |
if (BotSameTeam(bs, i)) continue; |
| 3124 |
//if the bot's health decreased or the enemy is shooting |
| 3125 |
if (curenemy < 0 && (healthdecrease || EntityIsShooting(&entinfo))) |
| 3126 |
f = 360; |
| 3127 |
else |
| 3128 |
f = 90 + 90 - (90 - (squaredist > Square(810) ? Square(810) : squaredist) / (810 * 9)); |
| 3129 |
//check if the enemy is visible |
| 3130 |
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, f, i); |
| 3131 |
if (vis <= 0) continue; |
| 3132 |
//if the enemy is quite far away, not shooting and the bot is not damaged |
| 3133 |
if (curenemy < 0 && squaredist > Square(100) && !healthdecrease && !EntityIsShooting(&entinfo)) |
| 3134 |
{ |
| 3135 |
//check if we can avoid this enemy |
| 3136 |
VectorSubtract(bs->origin, entinfo.origin, dir); |
| 3137 |
vectoangles(dir, angles); |
| 3138 |
//if the bot isn't in the fov of the enemy |
| 3139 |
if (!InFieldOfVision(entinfo.angles, 90, angles)) { |
| 3140 |
//update some stuff for this enemy |
| 3141 |
BotUpdateBattleInventory(bs, i); |
| 3142 |
//if the bot doesn't really want to fight |
| 3143 |
if (BotWantsToRetreat(bs)) continue; |
| 3144 |
} |
| 3145 |
} |
| 3146 |
//found an enemy |
| 3147 |
bs->enemy = entinfo.number; |
| 3148 |
if (curenemy >= 0) bs->enemysight_time = FloatTime() - 2; |
| 3149 |
else bs->enemysight_time = FloatTime(); |
| 3150 |
bs->enemysuicide = qfalse; |
| 3151 |
bs->enemydeath_time = 0; |
| 3152 |
bs->enemyvisible_time = FloatTime(); |
| 3153 |
return qtrue; |
| 3154 |
} |
| 3155 |
return qfalse; |
| 3156 |
} |
| 3157 |
|
| 3158 |
/* |
| 3159 |
================== |
| 3160 |
BotTeamFlagCarrierVisible |
| 3161 |
================== |
| 3162 |
*/ |
| 3163 |
int BotTeamFlagCarrierVisible(bot_state_t *bs) { |
| 3164 |
int i; |
| 3165 |
float vis; |
| 3166 |
aas_entityinfo_t entinfo; |
| 3167 |
|
| 3168 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3169 |
if (i == bs->client) |
| 3170 |
continue; |
| 3171 |
// |
| 3172 |
BotEntityInfo(i, &entinfo); |
| 3173 |
//if this player is active |
| 3174 |
if (!entinfo.valid) |
| 3175 |
continue; |
| 3176 |
//if this player is carrying a flag |
| 3177 |
if (!EntityCarriesFlag(&entinfo)) |
| 3178 |
continue; |
| 3179 |
//if the flag carrier is not on the same team |
| 3180 |
if (!BotSameTeam(bs, i)) |
| 3181 |
continue; |
| 3182 |
//if the flag carrier is not visible |
| 3183 |
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i); |
| 3184 |
if (vis <= 0) |
| 3185 |
continue; |
| 3186 |
// |
| 3187 |
return i; |
| 3188 |
} |
| 3189 |
return -1; |
| 3190 |
} |
| 3191 |
|
| 3192 |
/* |
| 3193 |
================== |
| 3194 |
BotTeamFlagCarrier |
| 3195 |
================== |
| 3196 |
*/ |
| 3197 |
int BotTeamFlagCarrier(bot_state_t *bs) { |
| 3198 |
int i; |
| 3199 |
aas_entityinfo_t entinfo; |
| 3200 |
|
| 3201 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3202 |
if (i == bs->client) |
| 3203 |
continue; |
| 3204 |
// |
| 3205 |
BotEntityInfo(i, &entinfo); |
| 3206 |
//if this player is active |
| 3207 |
if (!entinfo.valid) |
| 3208 |
continue; |
| 3209 |
//if this player is carrying a flag |
| 3210 |
if (!EntityCarriesFlag(&entinfo)) |
| 3211 |
continue; |
| 3212 |
//if the flag carrier is not on the same team |
| 3213 |
if (!BotSameTeam(bs, i)) |
| 3214 |
continue; |
| 3215 |
// |
| 3216 |
return i; |
| 3217 |
} |
| 3218 |
return -1; |
| 3219 |
} |
| 3220 |
|
| 3221 |
/* |
| 3222 |
================== |
| 3223 |
BotEnemyFlagCarrierVisible |
| 3224 |
================== |
| 3225 |
*/ |
| 3226 |
int BotEnemyFlagCarrierVisible(bot_state_t *bs) { |
| 3227 |
int i; |
| 3228 |
float vis; |
| 3229 |
aas_entityinfo_t entinfo; |
| 3230 |
|
| 3231 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3232 |
if (i == bs->client) |
| 3233 |
continue; |
| 3234 |
// |
| 3235 |
BotEntityInfo(i, &entinfo); |
| 3236 |
//if this player is active |
| 3237 |
if (!entinfo.valid) |
| 3238 |
continue; |
| 3239 |
//if this player is carrying a flag |
| 3240 |
if (!EntityCarriesFlag(&entinfo)) |
| 3241 |
continue; |
| 3242 |
//if the flag carrier is on the same team |
| 3243 |
if (BotSameTeam(bs, i)) |
| 3244 |
continue; |
| 3245 |
//if the flag carrier is not visible |
| 3246 |
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i); |
| 3247 |
if (vis <= 0) |
| 3248 |
continue; |
| 3249 |
// |
| 3250 |
return i; |
| 3251 |
} |
| 3252 |
return -1; |
| 3253 |
} |
| 3254 |
|
| 3255 |
/* |
| 3256 |
================== |
| 3257 |
BotVisibleTeamMatesAndEnemies |
| 3258 |
================== |
| 3259 |
*/ |
| 3260 |
void BotVisibleTeamMatesAndEnemies(bot_state_t *bs, int *teammates, int *enemies, float range) { |
| 3261 |
int i; |
| 3262 |
float vis; |
| 3263 |
aas_entityinfo_t entinfo; |
| 3264 |
vec3_t dir; |
| 3265 |
|
| 3266 |
if (teammates) |
| 3267 |
*teammates = 0; |
| 3268 |
if (enemies) |
| 3269 |
*enemies = 0; |
| 3270 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3271 |
if (i == bs->client) |
| 3272 |
continue; |
| 3273 |
// |
| 3274 |
BotEntityInfo(i, &entinfo); |
| 3275 |
//if this player is active |
| 3276 |
if (!entinfo.valid) |
| 3277 |
continue; |
| 3278 |
//if this player is carrying a flag |
| 3279 |
if (!EntityCarriesFlag(&entinfo)) |
| 3280 |
continue; |
| 3281 |
//if not within range |
| 3282 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 3283 |
if (VectorLengthSquared(dir) > Square(range)) |
| 3284 |
continue; |
| 3285 |
//if the flag carrier is not visible |
| 3286 |
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i); |
| 3287 |
if (vis <= 0) |
| 3288 |
continue; |
| 3289 |
//if the flag carrier is on the same team |
| 3290 |
if (BotSameTeam(bs, i)) { |
| 3291 |
if (teammates) |
| 3292 |
(*teammates)++; |
| 3293 |
} |
| 3294 |
else { |
| 3295 |
if (enemies) |
| 3296 |
(*enemies)++; |
| 3297 |
} |
| 3298 |
} |
| 3299 |
} |
| 3300 |
|
| 3301 |
/* |
| 3302 |
================== |
| 3303 |
BotTeamCubeCarrierVisible |
| 3304 |
================== |
| 3305 |
*/ |
| 3306 |
int BotTeamCubeCarrierVisible(bot_state_t *bs) { |
| 3307 |
int i; |
| 3308 |
float vis; |
| 3309 |
aas_entityinfo_t entinfo; |
| 3310 |
|
| 3311 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3312 |
if (i == bs->client) continue; |
| 3313 |
// |
| 3314 |
BotEntityInfo(i, &entinfo); |
| 3315 |
//if this player is active |
| 3316 |
if (!entinfo.valid) continue; |
| 3317 |
//if this player is carrying a flag |
| 3318 |
if (!EntityCarriesCubes(&entinfo)) continue; |
| 3319 |
//if the flag carrier is not on the same team |
| 3320 |
if (!BotSameTeam(bs, i)) continue; |
| 3321 |
//if the flag carrier is not visible |
| 3322 |
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i); |
| 3323 |
if (vis <= 0) continue; |
| 3324 |
// |
| 3325 |
return i; |
| 3326 |
} |
| 3327 |
return -1; |
| 3328 |
} |
| 3329 |
|
| 3330 |
/* |
| 3331 |
================== |
| 3332 |
BotEnemyCubeCarrierVisible |
| 3333 |
================== |
| 3334 |
*/ |
| 3335 |
int BotEnemyCubeCarrierVisible(bot_state_t *bs) { |
| 3336 |
int i; |
| 3337 |
float vis; |
| 3338 |
aas_entityinfo_t entinfo; |
| 3339 |
|
| 3340 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3341 |
if (i == bs->client) |
| 3342 |
continue; |
| 3343 |
// |
| 3344 |
BotEntityInfo(i, &entinfo); |
| 3345 |
//if this player is active |
| 3346 |
if (!entinfo.valid) |
| 3347 |
continue; |
| 3348 |
//if this player is carrying a flag |
| 3349 |
if (!EntityCarriesCubes(&entinfo)) continue; |
| 3350 |
//if the flag carrier is on the same team |
| 3351 |
if (BotSameTeam(bs, i)) |
| 3352 |
continue; |
| 3353 |
//if the flag carrier is not visible |
| 3354 |
vis = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, i); |
| 3355 |
if (vis <= 0) |
| 3356 |
continue; |
| 3357 |
// |
| 3358 |
return i; |
| 3359 |
} |
| 3360 |
return -1; |
| 3361 |
} |
| 3362 |
//#endif |
| 3363 |
|
| 3364 |
/* |
| 3365 |
================== |
| 3366 |
BotAimAtEnemy |
| 3367 |
================== |
| 3368 |
*/ |
| 3369 |
void BotAimAtEnemy(bot_state_t *bs) { |
| 3370 |
int i, enemyvisible; |
| 3371 |
float dist, f, aim_skill, aim_accuracy, speed, reactiontime; |
| 3372 |
vec3_t dir, bestorigin, end, start, groundtarget, cmdmove, enemyvelocity; |
| 3373 |
vec3_t mins = {-4,-4,-4}, maxs = {4, 4, 4}; |
| 3374 |
weaponinfo_t wi; |
| 3375 |
aas_entityinfo_t entinfo; |
| 3376 |
bot_goal_t goal; |
| 3377 |
bsp_trace_t trace; |
| 3378 |
vec3_t target; |
| 3379 |
|
| 3380 |
//if the bot has no enemy |
| 3381 |
if (bs->enemy < 0) { |
| 3382 |
return; |
| 3383 |
} |
| 3384 |
//get the enemy entity information |
| 3385 |
BotEntityInfo(bs->enemy, &entinfo); |
| 3386 |
//if this is not a player (should be an obelisk) |
| 3387 |
if (bs->enemy >= MAX_CLIENTS) { |
| 3388 |
//if the obelisk is visible |
| 3389 |
VectorCopy(entinfo.origin, target); |
| 3390 |
// if attacking an obelisk |
| 3391 |
if ( bs->enemy == redobelisk.entitynum || |
| 3392 |
bs->enemy == blueobelisk.entitynum ) { |
| 3393 |
target[2] += 32; |
| 3394 |
} |
| 3395 |
//aim at the obelisk |
| 3396 |
VectorSubtract(target, bs->eye, dir); |
| 3397 |
vectoangles(dir, bs->ideal_viewangles); |
| 3398 |
//set the aim target before trying to attack |
| 3399 |
VectorCopy(target, bs->aimtarget); |
| 3400 |
return; |
| 3401 |
} |
| 3402 |
// |
| 3403 |
//BotAI_Print(PRT_MESSAGE, "client %d: aiming at client %d\n", bs->entitynum, bs->enemy); |
| 3404 |
// |
| 3405 |
aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL, 0, 1); |
| 3406 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY, 0, 1); |
| 3407 |
// |
| 3408 |
if (aim_skill > 0.95) { |
| 3409 |
//don't aim too early |
| 3410 |
reactiontime = 0.5 * trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_REACTIONTIME, 0, 1); |
| 3411 |
if (bs->enemysight_time > FloatTime() - reactiontime) return; |
| 3412 |
if (bs->teleport_time > FloatTime() - reactiontime) return; |
| 3413 |
} |
| 3414 |
|
| 3415 |
//get the weapon information |
| 3416 |
trap_BotGetWeaponInfo(bs->ws, bs->weaponnum, &wi); |
| 3417 |
//get the weapon specific aim accuracy and or aim skill |
| 3418 |
if (wi.number == WP_MACHINEGUN) { |
| 3419 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_MACHINEGUN, 0, 1); |
| 3420 |
} |
| 3421 |
else if (wi.number == WP_SHOTGUN) { |
| 3422 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_SHOTGUN, 0, 1); |
| 3423 |
} |
| 3424 |
else if (wi.number == WP_GRENADE_LAUNCHER) { |
| 3425 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_GRENADELAUNCHER, 0, 1); |
| 3426 |
aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_GRENADELAUNCHER, 0, 1); |
| 3427 |
} |
| 3428 |
else if (wi.number == WP_ROCKET_LAUNCHER) { |
| 3429 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_ROCKETLAUNCHER, 0, 1); |
| 3430 |
aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_ROCKETLAUNCHER, 0, 1); |
| 3431 |
} |
| 3432 |
else if (wi.number == WP_LIGHTNING) { |
| 3433 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_LIGHTNING, 0, 1); |
| 3434 |
} |
| 3435 |
else if (wi.number == WP_RAILGUN) { |
| 3436 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_RAILGUN, 0, 1); |
| 3437 |
} |
| 3438 |
else if (wi.number == WP_PLASMAGUN) { |
| 3439 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_PLASMAGUN, 0, 1); |
| 3440 |
aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_PLASMAGUN, 0, 1); |
| 3441 |
} |
| 3442 |
else if (wi.number == WP_BFG) { |
| 3443 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY_BFG10K, 0, 1); |
| 3444 |
aim_skill = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_SKILL_BFG10K, 0, 1); |
| 3445 |
} |
| 3446 |
// |
| 3447 |
if (aim_accuracy <= 0) aim_accuracy = 0.0001f; |
| 3448 |
//get the enemy entity information |
| 3449 |
BotEntityInfo(bs->enemy, &entinfo); |
| 3450 |
//if the enemy is invisible then shoot crappy most of the time |
| 3451 |
if (EntityIsInvisible(&entinfo)) { |
| 3452 |
if (random() > 0.1) aim_accuracy *= 0.4f; |
| 3453 |
} |
| 3454 |
// |
| 3455 |
VectorSubtract(entinfo.origin, entinfo.lastvisorigin, enemyvelocity); |
| 3456 |
VectorScale(enemyvelocity, 1 / entinfo.update_time, enemyvelocity); |
| 3457 |
//enemy origin and velocity is remembered every 0.5 seconds |
| 3458 |
if (bs->enemyposition_time < FloatTime()) { |
| 3459 |
// |
| 3460 |
bs->enemyposition_time = FloatTime() + 0.5; |
| 3461 |
VectorCopy(enemyvelocity, bs->enemyvelocity); |
| 3462 |
VectorCopy(entinfo.origin, bs->enemyorigin); |
| 3463 |
} |
| 3464 |
//if not extremely skilled |
| 3465 |
if (aim_skill < 0.9) { |
| 3466 |
VectorSubtract(entinfo.origin, bs->enemyorigin, dir); |
| 3467 |
//if the enemy moved a bit |
| 3468 |
if (VectorLengthSquared(dir) > Square(48)) { |
| 3469 |
//if the enemy changed direction |
| 3470 |
if (DotProduct(bs->enemyvelocity, enemyvelocity) < 0) { |
| 3471 |
//aim accuracy should be worse now |
| 3472 |
aim_accuracy *= 0.7f; |
| 3473 |
} |
| 3474 |
} |
| 3475 |
} |
| 3476 |
//check visibility of enemy |
| 3477 |
enemyvisible = BotEntityVisible(bs->entitynum, bs->eye, bs->viewangles, 360, bs->enemy); |
| 3478 |
//if the enemy is visible |
| 3479 |
if (enemyvisible) { |
| 3480 |
// |
| 3481 |
VectorCopy(entinfo.origin, bestorigin); |
| 3482 |
bestorigin[2] += 8; |
| 3483 |
//get the start point shooting from |
| 3484 |
//NOTE: the x and y projectile start offsets are ignored |
| 3485 |
VectorCopy(bs->origin, start); |
| 3486 |
start[2] += bs->cur_ps.viewheight; |
| 3487 |
start[2] += wi.offset[2]; |
| 3488 |
// |
| 3489 |
BotAI_Trace(&trace, start, mins, maxs, bestorigin, bs->entitynum, MASK_SHOT); |
| 3490 |
//if the enemy is NOT hit |
| 3491 |
if (trace.fraction <= 1 && trace.ent != entinfo.number) { |
| 3492 |
bestorigin[2] += 16; |
| 3493 |
} |
| 3494 |
//if it is not an instant hit weapon the bot might want to predict the enemy |
| 3495 |
if (wi.speed) { |
| 3496 |
// |
| 3497 |
VectorSubtract(bestorigin, bs->origin, dir); |
| 3498 |
dist = VectorLength(dir); |
| 3499 |
VectorSubtract(entinfo.origin, bs->enemyorigin, dir); |
| 3500 |
//if the enemy is NOT pretty far away and strafing just small steps left and right |
| 3501 |
if (!(dist > 100 && VectorLengthSquared(dir) < Square(32))) { |
| 3502 |
//if skilled anough do exact prediction |
| 3503 |
if (aim_skill > 0.8 && |
| 3504 |
//if the weapon is ready to fire |
| 3505 |
bs->cur_ps.weaponstate == WEAPON_READY) { |
| 3506 |
aas_clientmove_t move; |
| 3507 |
vec3_t origin; |
| 3508 |
|
| 3509 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 3510 |
//distance towards the enemy |
| 3511 |
dist = VectorLength(dir); |
| 3512 |
//direction the enemy is moving in |
| 3513 |
VectorSubtract(entinfo.origin, entinfo.lastvisorigin, dir); |
| 3514 |
// |
| 3515 |
VectorScale(dir, 1 / entinfo.update_time, dir); |
| 3516 |
// |
| 3517 |
VectorCopy(entinfo.origin, origin); |
| 3518 |
origin[2] += 1; |
| 3519 |
// |
| 3520 |
VectorClear(cmdmove); |
| 3521 |
//AAS_ClearShownDebugLines(); |
| 3522 |
trap_AAS_PredictClientMovement(&move, bs->enemy, origin, |
| 3523 |
PRESENCE_CROUCH, qfalse, |
| 3524 |
dir, cmdmove, 0, |
| 3525 |
dist * 10 / wi.speed, 0.1f, 0, 0, qfalse); |
| 3526 |
VectorCopy(move.endpos, bestorigin); |
| 3527 |
//BotAI_Print(PRT_MESSAGE, "%1.1f predicted speed = %f, frames = %f\n", FloatTime(), VectorLength(dir), dist * 10 / wi.speed); |
| 3528 |
} |
| 3529 |
//if not that skilled do linear prediction |
| 3530 |
else if (aim_skill > 0.4) { |
| 3531 |
VectorSubtract(entinfo.origin, bs->origin, dir); |
| 3532 |
//distance towards the enemy |
| 3533 |
dist = VectorLength(dir); |
| 3534 |
//direction the enemy is moving in |
| 3535 |
VectorSubtract(entinfo.origin, entinfo.lastvisorigin, dir); |
| 3536 |
dir[2] = 0; |
| 3537 |
// |
| 3538 |
speed = VectorNormalize(dir) / entinfo.update_time; |
| 3539 |
//botimport.Print(PRT_MESSAGE, "speed = %f, wi->speed = %f\n", speed, wi->speed); |
| 3540 |
//best spot to aim at |
| 3541 |
VectorMA(entinfo.origin, (dist / wi.speed) * speed, dir, bestorigin); |
| 3542 |
} |
| 3543 |
} |
| 3544 |
} |
| 3545 |
//if the projectile does radial damage |
| 3546 |
if (aim_skill > 0.6 && wi.proj.damagetype & DAMAGETYPE_RADIAL) { |
| 3547 |
//if the enemy isn't standing significantly higher than the bot |
| 3548 |
if (entinfo.origin[2] < bs->origin[2] + 16) { |
| 3549 |
//try to aim at the ground in front of the enemy |
| 3550 |
VectorCopy(entinfo.origin, end); |
| 3551 |
end[2] -= 64; |
| 3552 |
BotAI_Trace(&trace, entinfo.origin, NULL, NULL, end, entinfo.number, MASK_SHOT); |
| 3553 |
// |
| 3554 |
VectorCopy(bestorigin, groundtarget); |
| 3555 |
if (trace.startsolid) groundtarget[2] = entinfo.origin[2] - 16; |
| 3556 |
else groundtarget[2] = trace.endpos[2] - 8; |
| 3557 |
//trace a line from projectile start to ground target |
| 3558 |
BotAI_Trace(&trace, start, NULL, NULL, groundtarget, bs->entitynum, MASK_SHOT); |
| 3559 |
//if hitpoint is not vertically too far from the ground target |
| 3560 |
if (fabs(trace.endpos[2] - groundtarget[2]) < 50) { |
| 3561 |
VectorSubtract(trace.endpos, groundtarget, dir); |
| 3562 |
//if the hitpoint is near anough the ground target |
| 3563 |
if (VectorLengthSquared(dir) < Square(60)) { |
| 3564 |
VectorSubtract(trace.endpos, start, dir); |
| 3565 |
//if the hitpoint is far anough from the bot |
| 3566 |
if (VectorLengthSquared(dir) > Square(100)) { |
| 3567 |
//check if the bot is visible from the ground target |
| 3568 |
trace.endpos[2] += 1; |
| 3569 |
BotAI_Trace(&trace, trace.endpos, NULL, NULL, entinfo.origin, entinfo.number, MASK_SHOT); |
| 3570 |
if (trace.fraction >= 1) { |
| 3571 |
//botimport.Print(PRT_MESSAGE, "%1.1f aiming at ground\n", AAS_Time()); |
| 3572 |
VectorCopy(groundtarget, bestorigin); |
| 3573 |
} |
| 3574 |
} |
| 3575 |
} |
| 3576 |
} |
| 3577 |
} |
| 3578 |
} |
| 3579 |
bestorigin[0] += 20 * crandom() * (1 - aim_accuracy); |
| 3580 |
bestorigin[1] += 20 * crandom() * (1 - aim_accuracy); |
| 3581 |
bestorigin[2] += 10 * crandom() * (1 - aim_accuracy); |
| 3582 |
} |
| 3583 |
else { |
| 3584 |
// |
| 3585 |
VectorCopy(bs->lastenemyorigin, bestorigin); |
| 3586 |
bestorigin[2] += 8; |
| 3587 |
//if the bot is skilled anough |
| 3588 |
if (aim_skill > 0.5) { |
| 3589 |
//do prediction shots around corners |
| 3590 |
if (wi.number == WP_BFG || |
| 3591 |
wi.number == WP_ROCKET_LAUNCHER || |
| 3592 |
wi.number == WP_GRENADE_LAUNCHER) { |
| 3593 |
//create the chase goal |
| 3594 |
goal.entitynum = bs->client; |
| 3595 |
goal.areanum = bs->areanum; |
| 3596 |
VectorCopy(bs->eye, goal.origin); |
| 3597 |
VectorSet(goal.mins, -8, -8, -8); |
| 3598 |
VectorSet(goal.maxs, 8, 8, 8); |
| 3599 |
// |
| 3600 |
if (trap_BotPredictVisiblePosition(bs->lastenemyorigin, bs->lastenemyareanum, &goal, TFL_DEFAULT, target)) { |
| 3601 |
VectorSubtract(target, bs->eye, dir); |
| 3602 |
if (VectorLengthSquared(dir) > Square(80)) { |
| 3603 |
VectorCopy(target, bestorigin); |
| 3604 |
bestorigin[2] -= 20; |
| 3605 |
} |
| 3606 |
} |
| 3607 |
aim_accuracy = 1; |
| 3608 |
} |
| 3609 |
} |
| 3610 |
} |
| 3611 |
// |
| 3612 |
if (enemyvisible) { |
| 3613 |
BotAI_Trace(&trace, bs->eye, NULL, NULL, bestorigin, bs->entitynum, MASK_SHOT); |
| 3614 |
VectorCopy(trace.endpos, bs->aimtarget); |
| 3615 |
} |
| 3616 |
else { |
| 3617 |
VectorCopy(bestorigin, bs->aimtarget); |
| 3618 |
} |
| 3619 |
//get aim direction |
| 3620 |
VectorSubtract(bestorigin, bs->eye, dir); |
| 3621 |
// |
| 3622 |
if (wi.number == WP_MACHINEGUN || |
| 3623 |
wi.number == WP_SHOTGUN || |
| 3624 |
wi.number == WP_LIGHTNING || |
| 3625 |
wi.number == WP_RAILGUN) { |
| 3626 |
//distance towards the enemy |
| 3627 |
dist = VectorLength(dir); |
| 3628 |
if (dist > 150) dist = 150; |
| 3629 |
f = 0.6 + dist / 150 * 0.4; |
| 3630 |
aim_accuracy *= f; |
| 3631 |
} |
| 3632 |
//add some random stuff to the aim direction depending on the aim accuracy |
| 3633 |
if (aim_accuracy < 0.8) { |
| 3634 |
VectorNormalize(dir); |
| 3635 |
for (i = 0; i < 3; i++) dir[i] += 0.3 * crandom() * (1 - aim_accuracy); |
| 3636 |
} |
| 3637 |
//set the ideal view angles |
| 3638 |
vectoangles(dir, bs->ideal_viewangles); |
| 3639 |
//take the weapon spread into account for lower skilled bots |
| 3640 |
bs->ideal_viewangles[PITCH] += 6 * wi.vspread * crandom() * (1 - aim_accuracy); |
| 3641 |
bs->ideal_viewangles[PITCH] = AngleMod(bs->ideal_viewangles[PITCH]); |
| 3642 |
bs->ideal_viewangles[YAW] += 6 * wi.hspread * crandom() * (1 - aim_accuracy); |
| 3643 |
bs->ideal_viewangles[YAW] = AngleMod(bs->ideal_viewangles[YAW]); |
| 3644 |
//if the bots should be really challenging |
| 3645 |
if (bot_challenge.integer) { |
| 3646 |
//if the bot is really accurate and has the enemy in view for some time |
| 3647 |
if (aim_accuracy > 0.9 && bs->enemysight_time < FloatTime() - 1) { |
| 3648 |
//set the view angles directly |
| 3649 |
if (bs->ideal_viewangles[PITCH] > 180) bs->ideal_viewangles[PITCH] -= 360; |
| 3650 |
VectorCopy(bs->ideal_viewangles, bs->viewangles); |
| 3651 |
trap_EA_View(bs->client, bs->viewangles); |
| 3652 |
} |
| 3653 |
} |
| 3654 |
} |
| 3655 |
|
| 3656 |
/* |
| 3657 |
================== |
| 3658 |
BotCheckAttack |
| 3659 |
================== |
| 3660 |
*/ |
| 3661 |
void BotCheckAttack(bot_state_t *bs) { |
| 3662 |
float points, reactiontime, fov, firethrottle; |
| 3663 |
int attackentity; |
| 3664 |
bsp_trace_t bsptrace; |
| 3665 |
//float selfpreservation; |
| 3666 |
vec3_t forward, right, start, end, dir, angles; |
| 3667 |
weaponinfo_t wi; |
| 3668 |
bsp_trace_t trace; |
| 3669 |
aas_entityinfo_t entinfo; |
| 3670 |
vec3_t mins = {-8, -8, -8}, maxs = {8, 8, 8}; |
| 3671 |
|
| 3672 |
attackentity = bs->enemy; |
| 3673 |
// |
| 3674 |
BotEntityInfo(attackentity, &entinfo); |
| 3675 |
// if not attacking a player |
| 3676 |
if (attackentity >= MAX_CLIENTS) { |
| 3677 |
// if attacking an obelisk |
| 3678 |
if ( entinfo.number == redobelisk.entitynum || |
| 3679 |
entinfo.number == blueobelisk.entitynum ) { |
| 3680 |
// if obelisk is respawning return |
| 3681 |
if ( g_entities[entinfo.number].activator && |
| 3682 |
g_entities[entinfo.number].activator->s.frame == 2 ) { |
| 3683 |
return; |
| 3684 |
} |
| 3685 |
} |
| 3686 |
} |
| 3687 |
// |
| 3688 |
reactiontime = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_REACTIONTIME, 0, 1); |
| 3689 |
if (bs->enemysight_time > FloatTime() - reactiontime) return; |
| 3690 |
if (bs->teleport_time > FloatTime() - reactiontime) return; |
| 3691 |
//if changing weapons |
| 3692 |
if (bs->weaponchange_time > FloatTime() - 0.1) return; |
| 3693 |
//check fire throttle characteristic |
| 3694 |
if (bs->firethrottlewait_time > FloatTime()) return; |
| 3695 |
firethrottle = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_FIRETHROTTLE, 0, 1); |
| 3696 |
if (bs->firethrottleshoot_time < FloatTime()) { |
| 3697 |
if (random() > firethrottle) { |
| 3698 |
bs->firethrottlewait_time = FloatTime() + firethrottle; |
| 3699 |
bs->firethrottleshoot_time = 0; |
| 3700 |
} |
| 3701 |
else { |
| 3702 |
bs->firethrottleshoot_time = FloatTime() + 1 - firethrottle; |
| 3703 |
bs->firethrottlewait_time = 0; |
| 3704 |
} |
| 3705 |
} |
| 3706 |
// |
| 3707 |
// |
| 3708 |
VectorSubtract(bs->aimtarget, bs->eye, dir); |
| 3709 |
// |
| 3710 |
if (bs->weaponnum == WP_GAUNTLET) { |
| 3711 |
if (VectorLengthSquared(dir) > Square(60)) { |
| 3712 |
return; |
| 3713 |
} |
| 3714 |
} |
| 3715 |
if (VectorLengthSquared(dir) < Square(100)) |
| 3716 |
fov = 120; |
| 3717 |
else |
| 3718 |
fov = 50; |
| 3719 |
// |
| 3720 |
vectoangles(dir, angles); |
| 3721 |
if (!InFieldOfVision(bs->viewangles, fov, angles)) |
| 3722 |
return; |
| 3723 |
BotAI_Trace(&bsptrace, bs->eye, NULL, NULL, bs->aimtarget, bs->client, CONTENTS_SOLID|CONTENTS_PLAYERCLIP); |
| 3724 |
if (bsptrace.fraction < 1 && bsptrace.ent != attackentity) |
| 3725 |
return; |
| 3726 |
|
| 3727 |
//get the weapon info |
| 3728 |
trap_BotGetWeaponInfo(bs->ws, bs->weaponnum, &wi); |
| 3729 |
//get the start point shooting from |
| 3730 |
VectorCopy(bs->origin, start); |
| 3731 |
start[2] += bs->cur_ps.viewheight; |
| 3732 |
AngleVectors(bs->viewangles, forward, right, NULL); |
| 3733 |
start[0] += forward[0] * wi.offset[0] + right[0] * wi.offset[1]; |
| 3734 |
start[1] += forward[1] * wi.offset[0] + right[1] * wi.offset[1]; |
| 3735 |
start[2] += forward[2] * wi.offset[0] + right[2] * wi.offset[1] + wi.offset[2]; |
| 3736 |
//end point aiming at |
| 3737 |
VectorMA(start, 1000, forward, end); |
| 3738 |
//a little back to make sure not inside a very close enemy |
| 3739 |
VectorMA(start, -12, forward, start); |
| 3740 |
BotAI_Trace(&trace, start, mins, maxs, end, bs->entitynum, MASK_SHOT); |
| 3741 |
//if the entity is a client |
| 3742 |
if (trace.ent >= 0 && trace.ent < MAX_CLIENTS) { |
| 3743 |
if (trace.ent != attackentity) { |
| 3744 |
//if a teammate is hit |
| 3745 |
if (BotSameTeam(bs, trace.ent)) |
| 3746 |
return; |
| 3747 |
} |
| 3748 |
} |
| 3749 |
//if won't hit the enemy or not attacking a player (obelisk) |
| 3750 |
if (trace.ent != attackentity || attackentity >= MAX_CLIENTS) { |
| 3751 |
//if the projectile does radial damage |
| 3752 |
if (wi.proj.damagetype & DAMAGETYPE_RADIAL) { |
| 3753 |
if (trace.fraction * 1000 < wi.proj.radius) { |
| 3754 |
points = (wi.proj.damage - 0.5 * trace.fraction * 1000) * 0.5; |
| 3755 |
if (points > 0) { |
| 3756 |
return; |
| 3757 |
} |
| 3758 |
} |
| 3759 |
//FIXME: check if a teammate gets radial damage |
| 3760 |
} |
| 3761 |
} |
| 3762 |
//if fire has to be release to activate weapon |
| 3763 |
if (wi.flags & WFL_FIRERELEASED) { |
| 3764 |
if (bs->flags & BFL_ATTACKED) { |
| 3765 |
trap_EA_Attack(bs->client); |
| 3766 |
} |
| 3767 |
} |
| 3768 |
else { |
| 3769 |
trap_EA_Attack(bs->client); |
| 3770 |
} |
| 3771 |
bs->flags ^= BFL_ATTACKED; |
| 3772 |
} |
| 3773 |
|
| 3774 |
/* |
| 3775 |
================== |
| 3776 |
BotMapScripts |
| 3777 |
================== |
| 3778 |
*/ |
| 3779 |
void BotMapScripts(bot_state_t *bs) { |
| 3780 |
char info[1024]; |
| 3781 |
char mapname[128]; |
| 3782 |
int i, shootbutton; |
| 3783 |
float aim_accuracy; |
| 3784 |
aas_entityinfo_t entinfo; |
| 3785 |
vec3_t dir; |
| 3786 |
|
| 3787 |
trap_GetServerinfo(info, sizeof(info)); |
| 3788 |
|
| •3789 |
Q_strncpyz(mapname, Info_ValueForKey(info, "mapname"), sizeof (mapname)); |
| 3790 |
|
| 3791 |
if (!Q_stricmp(mapname, "q3tourney6")) { |
| 3792 |
vec3_t mins = {700, 204, 672}, maxs = {964, 468, 680}; |
| 3793 |
vec3_t buttonorg = {304, 352, 920}; |
| 3794 |
//NOTE: NEVER use the func_bobbing in q3tourney6 |
| 3795 |
bs->tfl &= ~TFL_FUNCBOB; |
| 3796 |
//if the bot is below the bounding box |
| 3797 |
if (bs->origin[0] > mins[0] && bs->origin[0] < maxs[0]) { |
| 3798 |
if (bs->origin[1] > mins[1] && bs->origin[1] < maxs[1]) { |
| 3799 |
if (bs->origin[2] < mins[2]) { |
| 3800 |
return; |
| 3801 |
} |
| 3802 |
} |
| 3803 |
} |
| 3804 |
shootbutton = qfalse; |
| 3805 |
//if an enemy is below this bounding box then shoot the button |
| 3806 |
for (i = 0; i < maxclients && i < MAX_CLIENTS; i++) { |
| 3807 |
|
| 3808 |
if (i == bs->client) continue; |
| 3809 |
// |
| 3810 |
BotEntityInfo(i, &entinfo); |
| 3811 |
// |
| 3812 |
if (!entinfo.valid) continue; |
| 3813 |
//if the enemy isn't dead and the enemy isn't the bot self |
| 3814 |
if (EntityIsDead(&entinfo) || entinfo.number == bs->entitynum) continue; |
| 3815 |
// |
| 3816 |
if (entinfo.origin[0] > mins[0] && entinfo.origin[0] < maxs[0]) { |
| 3817 |
if (entinfo.origin[1] > mins[1] && entinfo.origin[1] < maxs[1]) { |
| 3818 |
if (entinfo.origin[2] < mins[2]) { |
| 3819 |
//if there's a team mate below the crusher |
| 3820 |
if (BotSameTeam(bs, i)) { |
| 3821 |
shootbutton = qfalse; |
| 3822 |
break; |
| 3823 |
} |
| 3824 |
else { |
| 3825 |
shootbutton = qtrue; |
| 3826 |
} |
| 3827 |
} |
| 3828 |
} |
| 3829 |
} |
| 3830 |
} |
| 3831 |
if (shootbutton) { |
| 3832 |
bs->flags |= BFL_IDEALVIEWSET; |
| 3833 |
VectorSubtract(buttonorg, bs->eye, dir); |
| 3834 |
vectoangles(dir, bs->ideal_viewangles); |
| 3835 |
aim_accuracy = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_AIM_ACCURACY, 0, 1); |
| 3836 |
bs->ideal_viewangles[PITCH] += 8 * crandom() * (1 - aim_accuracy); |
| 3837 |
bs->ideal_viewangles[PITCH] = AngleMod(bs->ideal_viewangles[PITCH]); |
| 3838 |
bs->ideal_viewangles[YAW] += 8 * crandom() * (1 - aim_accuracy); |
| 3839 |
bs->ideal_viewangles[YAW] = AngleMod(bs->ideal_viewangles[YAW]); |
| 3840 |
// |
| 3841 |
if (InFieldOfVision(bs->viewangles, 20, bs->ideal_viewangles)) { |
| 3842 |
trap_EA_Attack(bs->client); |
| 3843 |
} |
| 3844 |
} |
| 3845 |
} |
| 3846 |
else if (!Q_stricmp(mapname, "mpq3tourney6")) { |
| 3847 |
//NOTE: NEVER use the func_bobbing in mpq3tourney6 |
| 3848 |
bs->tfl &= ~TFL_FUNCBOB; |
| 3849 |
} |
| 3850 |
} |
| 3851 |
|
| 3852 |
/* |
| 3853 |
================== |
| 3854 |
BotSetMovedir |
| 3855 |
================== |
| 3856 |
*/ |
| 3857 |
// bk001205 - made these static |
| 3858 |
static vec3_t VEC_UP = {0, -1, 0}; |
| 3859 |
static vec3_t MOVEDIR_UP = {0, 0, 1}; |
| 3860 |
static vec3_t VEC_DOWN = {0, -2, 0}; |
| 3861 |
static vec3_t MOVEDIR_DOWN = {0, 0, -1}; |
| 3862 |
|
| 3863 |
void BotSetMovedir(vec3_t angles, vec3_t movedir) { |
| 3864 |
if (VectorCompare(angles, VEC_UP)) { |
| 3865 |
VectorCopy(MOVEDIR_UP, movedir); |
| 3866 |
} |
| 3867 |
else if (VectorCompare(angles, VEC_DOWN)) { |
| 3868 |
VectorCopy(MOVEDIR_DOWN, movedir); |
| 3869 |
} |
| 3870 |
else { |
| 3871 |
AngleVectors(angles, movedir, NULL, NULL); |
| 3872 |
} |
| 3873 |
} |
| 3874 |
|
| 3875 |
/* |
| 3876 |
================== |
| 3877 |
BotModelMinsMaxs |
| 3878 |
|
| 3879 |
this is ugly |
| 3880 |
================== |
| 3881 |
*/ |
| 3882 |
int BotModelMinsMaxs(int modelindex, int eType, int contents, vec3_t mins, vec3_t maxs) { |
| 3883 |
gentity_t *ent; |
| 3884 |
int i; |
| 3885 |
|
| 3886 |
ent = &g_entities[0]; |
| 3887 |
for (i = 0; i < level.num_entities; i++, ent++) { |
| 3888 |
if ( !ent->inuse ) { |
| 3889 |
continue; |
| 3890 |
} |
| 3891 |
if ( eType && ent->s.eType != eType) { |
| 3892 |
continue; |
| 3893 |
} |
| 3894 |
if ( contents && ent->r.contents != contents) { |
| 3895 |
continue; |
| 3896 |
} |
| 3897 |
if (ent->s.modelindex == modelindex) { |
| 3898 |
if (mins) |
| 3899 |
VectorAdd(ent->r.currentOrigin, ent->r.mins, mins); |
| 3900 |
if (maxs) |
| 3901 |
VectorAdd(ent->r.currentOrigin, ent->r.maxs, maxs); |
| 3902 |
return i; |
| 3903 |
} |
| 3904 |
} |
| 3905 |
if (mins) |
| 3906 |
VectorClear(mins); |
| 3907 |
if (maxs) |
| 3908 |
VectorClear(maxs); |
| 3909 |
return 0; |
| 3910 |
} |
| 3911 |
|
| 3912 |
/* |
| 3913 |
================== |
| 3914 |
BotFuncButtonGoal |
| 3915 |
================== |
| 3916 |
*/ |
| 3917 |
int BotFuncButtonActivateGoal(bot_state_t *bs, int bspent, bot_activategoal_t *activategoal) { |
| 3918 |
int i, areas[10], numareas, modelindex, entitynum; |
| 3919 |
char model[128]; |
| 3920 |
float lip, dist, health, angle; |
| 3921 |
vec3_t size, start, end, mins, maxs, angles, points[10]; |
| 3922 |
vec3_t movedir, origin, goalorigin, bboxmins, bboxmaxs; |
| 3923 |
vec3_t extramins = {1, 1, 1}, extramaxs = {-1, -1, -1}; |
| 3924 |
bsp_trace_t bsptrace; |
| 3925 |
|
| 3926 |
activategoal->shoot = qfalse; |
| 3927 |
VectorClear(activategoal->target); |
| 3928 |
//create a bot goal towards the button |
| 3929 |
trap_AAS_ValueForBSPEpairKey(bspent, "model", model, sizeof(model)); |
| 3930 |
if (!*model) |
| 3931 |
return qfalse; |
| 3932 |
modelindex = atoi(model+1); |
| 3933 |
if (!modelindex) |
| 3934 |
return qfalse; |
| 3935 |
VectorClear(angles); |
| 3936 |
entitynum = BotModelMinsMaxs(modelindex, ET_MOVER, 0, mins, maxs); |
| 3937 |
//get the lip of the button |
| 3938 |
trap_AAS_FloatForBSPEpairKey(bspent, "lip", &lip); |
| 3939 |
if (!lip) lip = 4; |
| 3940 |
//get the move direction from the angle |
| 3941 |
trap_AAS_FloatForBSPEpairKey(bspent, "angle", &angle); |
| 3942 |
VectorSet(angles, 0, angle, 0); |
| 3943 |
BotSetMovedir(angles, movedir); |
| 3944 |
//button size |
| 3945 |
VectorSubtract(maxs, mins, size); |
| 3946 |
//button origin |
| 3947 |
VectorAdd(mins, maxs, origin); |
| 3948 |
VectorScale(origin, 0.5, origin); |
| 3949 |
//touch distance of the button |
| 3950 |
dist = fabs(movedir[0]) * size[0] + fabs(movedir[1]) * size[1] + fabs(movedir[2]) * size[2]; |
| 3951 |
dist *= 0.5; |
| 3952 |
// |
| 3953 |
trap_AAS_FloatForBSPEpairKey(bspent, "health", &health); |
| 3954 |
//if the button is shootable |
| 3955 |
if (health) { |
| 3956 |
//calculate the shoot target |
| 3957 |
VectorMA(origin, -dist, movedir, goalorigin); |
| 3958 |
// |
| 3959 |
VectorCopy(goalorigin, activategoal->target); |
| 3960 |
activategoal->shoot = qtrue; |
| 3961 |
// |
| 3962 |
BotAI_Trace(&bsptrace, bs->eye, NULL, NULL, goalorigin, bs->entitynum, MASK_SHOT); |
| 3963 |
// if the button is visible from the current position |
| 3964 |
if (bsptrace.fraction >= 1.0 || bsptrace.ent == entitynum) { |
| 3965 |
// |
| 3966 |
activategoal->goal.entitynum = entitynum; //NOTE: this is the entity number of the shootable button |
| 3967 |
activategoal->goal.number = 0; |
| 3968 |
activategoal->goal.flags = 0; |
| 3969 |
VectorCopy(bs->origin, activategoal->goal.origin); |
| 3970 |
activategoal->goal.areanum = bs->areanum; |
| 3971 |
VectorSet(activategoal->goal.mins, -8, -8, -8); |
| 3972 |
VectorSet(activategoal->goal.maxs, 8, 8, 8); |
| 3973 |
// |
| 3974 |
return qtrue; |
| 3975 |
} |
| 3976 |
else { |
| 3977 |
//create a goal from where the button is visible and shoot at the button from there |
| 3978 |
//add bounding box size to the dist |
| 3979 |
trap_AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bboxmins, bboxmaxs); |
| 3980 |
for (i = 0; i < 3; i++) { |
| 3981 |
if (movedir[i] < 0) dist += fabs(movedir[i]) * fabs(bboxmaxs[i]); |
| 3982 |
else dist += fabs(movedir[i]) * fabs(bboxmins[i]); |
| 3983 |
} |
| 3984 |
//calculate the goal origin |
| 3985 |
VectorMA(origin, -dist, movedir, goalorigin); |
| 3986 |
// |
| 3987 |
VectorCopy(goalorigin, start); |
| 3988 |
start[2] += 24; |
| 3989 |
VectorCopy(start, end); |
| 3990 |
end[2] -= 512; |
| 3991 |
numareas = trap_AAS_TraceAreas(start, end, areas, points, 10); |
| 3992 |
// |
| 3993 |
for (i = numareas-1; i >= 0; i--) { |
| 3994 |
if (trap_AAS_AreaReachability(areas[i])) { |
| 3995 |
break; |
| 3996 |
} |
| 3997 |
} |
| 3998 |
if (i < 0) { |
| 3999 |
// FIXME: trace forward and maybe in other directions to find a valid area |
| 4000 |
} |
| 4001 |
if (i >= 0) { |
| 4002 |
// |
| 4003 |
VectorCopy(points[i], activategoal->goal.origin); |
| 4004 |
activategoal->goal.areanum = areas[i]; |
| 4005 |
VectorSet(activategoal->goal.mins, 8, 8, 8); |
| 4006 |
VectorSet(activategoal->goal.maxs, -8, -8, -8); |
| 4007 |
// |
| 4008 |
for (i = 0; i < 3; i++) |
| 4009 |
{ |
| 4010 |
if (movedir[i] < 0) activategoal->goal.maxs[i] += fabs(movedir[i]) * fabs(extramaxs[i]); |
| 4011 |
else activategoal->goal.mins[i] += fabs(movedir[i]) * fabs(extramins[i]); |
| 4012 |
} //end for |
| 4013 |
// |
| 4014 |
activategoal->goal.entitynum = entitynum; |
| 4015 |
activategoal->goal.number = 0; |
| 4016 |
activategoal->goal.flags = 0; |
| 4017 |
return qtrue; |
| 4018 |
} |
| 4019 |
} |
| 4020 |
return qfalse; |
| 4021 |
} |
| 4022 |
else { |
| 4023 |
//add bounding box size to the dist |
| 4024 |
trap_AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bboxmins, bboxmaxs); |
| 4025 |
for (i = 0; i < 3; i++) { |
| 4026 |
if (movedir[i] < 0) dist += fabs(movedir[i]) * fabs(bboxmaxs[i]); |
| 4027 |
else dist += fabs(movedir[i]) * fabs(bboxmins[i]); |
| 4028 |
} |
| 4029 |
//calculate the goal origin |
| 4030 |
VectorMA(origin, -dist, movedir, goalorigin); |
| 4031 |
// |
| 4032 |
VectorCopy(goalorigin, start); |
| 4033 |
start[2] += 24; |
| 4034 |
VectorCopy(start, end); |
| 4035 |
end[2] -= 100; |
| 4036 |
numareas = trap_AAS_TraceAreas(start, end, areas, NULL, 10); |
| 4037 |
// |
| 4038 |
for (i = 0; i < numareas; i++) { |
| 4039 |
if (trap_AAS_AreaReachability(areas[i])) { |
| 4040 |
break; |
| 4041 |
} |
| 4042 |
} |
| 4043 |
if (i < numareas) { |
| 4044 |
// |
| 4045 |
VectorCopy(origin, activategoal->goal.origin); |
| 4046 |
activategoal->goal.areanum = areas[i]; |
| 4047 |
VectorSubtract(mins, origin, activategoal->goal.mins); |
| 4048 |
VectorSubtract(maxs, origin, activategoal->goal.maxs); |
| 4049 |
// |
| 4050 |
for (i = 0; i < 3; i++) |
| 4051 |
{ |
| 4052 |
if (movedir[i] < 0) activategoal->goal.maxs[i] += fabs(movedir[i]) * fabs(extramaxs[i]); |
| 4053 |
else activategoal->goal.mins[i] += fabs(movedir[i]) * fabs(extramins[i]); |
| 4054 |
} //end for |
| 4055 |
// |
| 4056 |
activategoal->goal.entitynum = entitynum; |
| 4057 |
activategoal->goal.number = 0; |
| 4058 |
activategoal->goal.flags = 0; |
| 4059 |
return qtrue; |
| 4060 |
} |
| 4061 |
} |
| 4062 |
return qfalse; |
| 4063 |
} |
| 4064 |
|
| 4065 |
/* |
| 4066 |
================== |
| 4067 |
BotFuncDoorGoal |
| 4068 |
================== |
| 4069 |
*/ |
| 4070 |
int BotFuncDoorActivateGoal(bot_state_t *bs, int bspent, bot_activategoal_t *activategoal) { |
| 4071 |
int modelindex, entitynum; |
| 4072 |
char model[MAX_INFO_STRING]; |
| 4073 |
vec3_t mins, maxs, origin, angles; |
| 4074 |
|
| 4075 |
//shoot at the shootable door |
| 4076 |
trap_AAS_ValueForBSPEpairKey(bspent, "model", model, sizeof(model)); |
| 4077 |
if (!*model) |
| 4078 |
return qfalse; |
| 4079 |
modelindex = atoi(model+1); |
| 4080 |
if (!modelindex) |
| 4081 |
return qfalse; |
| 4082 |
VectorClear(angles); |
| 4083 |
entitynum = BotModelMinsMaxs(modelindex, ET_MOVER, 0, mins, maxs); |
| 4084 |
//door origin |
| 4085 |
VectorAdd(mins, maxs, origin); |
| 4086 |
VectorScale(origin, 0.5, origin); |
| 4087 |
VectorCopy(origin, activategoal->target); |
| 4088 |
activategoal->shoot = qtrue; |
| 4089 |
// |
| 4090 |
activategoal->goal.entitynum = entitynum; //NOTE: this is the entity number of the shootable door |
| 4091 |
activategoal->goal.number = 0; |
| 4092 |
activategoal->goal.flags = 0; |
| 4093 |
VectorCopy(bs->origin, activategoal->goal.origin); |
| 4094 |
activategoal->goal.areanum = bs->areanum; |
| 4095 |
VectorSet(activategoal->goal.mins, -8, -8, -8); |
| 4096 |
VectorSet(activategoal->goal.maxs, 8, 8, 8); |
| 4097 |
return qtrue; |
| 4098 |
} |
| 4099 |
|
| 4100 |
/* |
| 4101 |
================== |
| 4102 |
BotTriggerMultipleGoal |
| 4103 |
================== |
| 4104 |
*/ |
| 4105 |
int BotTriggerMultipleActivateGoal(bot_state_t *bs, int bspent, bot_activategoal_t *activategoal) { |
| 4106 |
int i, areas[10], numareas, modelindex, entitynum; |
| 4107 |
char model[128]; |
| 4108 |
vec3_t start, end, mins, maxs, angles; |
| 4109 |
vec3_t origin, goalorigin; |
| 4110 |
|
| 4111 |
activategoal->shoot = qfalse; |
| 4112 |
VectorClear(activategoal->target); |
| 4113 |
//create a bot goal towards the trigger |
| 4114 |
trap_AAS_ValueForBSPEpairKey(bspent, "model", model, sizeof(model)); |
| 4115 |
if (!*model) |
| 4116 |
return qfalse; |
| 4117 |
modelindex = atoi(model+1); |
| 4118 |
if (!modelindex) |
| 4119 |
return qfalse; |
| 4120 |
VectorClear(angles); |
| 4121 |
entitynum = BotModelMinsMaxs(modelindex, 0, CONTENTS_TRIGGER, mins, maxs); |
| 4122 |
//trigger origin |
| 4123 |
VectorAdd(mins, maxs, origin); |
| 4124 |
VectorScale(origin, 0.5, origin); |
| 4125 |
VectorCopy(origin, goalorigin); |
| 4126 |
// |
| 4127 |
VectorCopy(goalorigin, start); |
| 4128 |
start[2] += 24; |
| 4129 |
VectorCopy(start, end); |
| 4130 |
end[2] -= 100; |
| 4131 |
numareas = trap_AAS_TraceAreas(start, end, areas, NULL, 10); |
| 4132 |
// |
| 4133 |
for (i = 0; i < numareas; i++) { |
| 4134 |
if (trap_AAS_AreaReachability(areas[i])) { |
| 4135 |
break; |
| 4136 |
} |
| 4137 |
} |
| 4138 |
if (i < numareas) { |
| 4139 |
VectorCopy(origin, activategoal->goal.origin); |
| 4140 |
activategoal->goal.areanum = areas[i]; |
| 4141 |
VectorSubtract(mins, origin, activategoal->goal.mins); |
| 4142 |
VectorSubtract(maxs, origin, activategoal->goal.maxs); |
| 4143 |
// |
| 4144 |
activategoal->goal.entitynum = entitynum; |
| 4145 |
activategoal->goal.number = 0; |
| 4146 |
activategoal->goal.flags = 0; |
| 4147 |
return qtrue; |
| 4148 |
} |
| 4149 |
return qfalse; |
| 4150 |
} |
| 4151 |
|
| 4152 |
/* |
| 4153 |
================== |
| 4154 |
BotPopFromActivateGoalStack |
| 4155 |
================== |
| 4156 |
*/ |
| 4157 |
int BotPopFromActivateGoalStack(bot_state_t *bs) { |
| 4158 |
if (!bs->activatestack) |
| 4159 |
return qfalse; |
| 4160 |
BotEnableActivateGoalAreas(bs->activatestack, qtrue); |
| 4161 |
bs->activatestack->inuse = qfalse; |
| 4162 |
bs->activatestack->justused_time = FloatTime(); |
| 4163 |
bs->activatestack = bs->activatestack->next; |
| 4164 |
return qtrue; |
| 4165 |
} |
| 4166 |
|
| 4167 |
/* |
| 4168 |
================== |
| 4169 |
BotPushOntoActivateGoalStack |
| 4170 |
================== |
| 4171 |
*/ |
| 4172 |
int BotPushOntoActivateGoalStack(bot_state_t *bs, bot_activategoal_t *activategoal) { |
| 4173 |
int i, best; |
| 4174 |
float besttime; |
| 4175 |
|
| 4176 |
best = -1; |
| 4177 |
besttime = FloatTime() + 9999; |
| 4178 |
// |
| 4179 |
for (i = 0; i < MAX_ACTIVATESTACK; i++) { |
| 4180 |
if (!bs->activategoalheap[i].inuse) { |
| 4181 |
if (bs->activategoalheap[i].justused_time < besttime) { |
| 4182 |
besttime = bs->activategoalheap[i].justused_time; |
| 4183 |
best = i; |
| 4184 |
} |
| 4185 |
} |
| 4186 |
} |
| 4187 |
if (best != -1) { |
| 4188 |
memcpy(&bs->activategoalheap[best], activategoal, sizeof(bot_activategoal_t)); |
| 4189 |
bs->activategoalheap[best].inuse = qtrue; |
| 4190 |
bs->activategoalheap[best].next = bs->activatestack; |
| 4191 |
bs->activatestack = &bs->activategoalheap[best]; |
| 4192 |
return qtrue; |
| 4193 |
} |
| 4194 |
return qfalse; |
| 4195 |
} |
| 4196 |
|
| 4197 |
/* |
| 4198 |
================== |
| 4199 |
BotClearActivateGoalStack |
| 4200 |
================== |
| 4201 |
*/ |
| 4202 |
void BotClearActivateGoalStack(bot_state_t *bs) { |
| 4203 |
while(bs->activatestack) |
| 4204 |
BotPopFromActivateGoalStack(bs); |
| 4205 |
} |
| 4206 |
|
| 4207 |
/* |
| 4208 |
================== |
| 4209 |
BotEnableActivateGoalAreas |
| 4210 |
================== |
| 4211 |
*/ |
| 4212 |
void BotEnableActivateGoalAreas(bot_activategoal_t *activategoal, int enable) { |
| 4213 |
int i; |
| 4214 |
|
| 4215 |
if (activategoal->areasdisabled == !enable) |
| 4216 |
return; |
| 4217 |
for (i = 0; i < activategoal->numareas; i++) |
| 4218 |
trap_AAS_EnableRoutingArea( activategoal->areas[i], enable ); |
| 4219 |
activategoal->areasdisabled = !enable; |
| 4220 |
} |
| 4221 |
|
| 4222 |
/* |
| 4223 |
================== |
| 4224 |
BotIsGoingToActivateEntity |
| 4225 |
================== |
| 4226 |
*/ |
| 4227 |
int BotIsGoingToActivateEntity(bot_state_t *bs, int entitynum) { |
| 4228 |
bot_activategoal_t *a; |
| 4229 |
int i; |
| 4230 |
|
| 4231 |
for (a = bs->activatestack; a; a = a->next) { |
| 4232 |
if (a->time < FloatTime()) |
| 4233 |
continue; |
| 4234 |
if (a->goal.entitynum == entitynum) |
| 4235 |
return qtrue; |
| 4236 |
} |
| 4237 |
for (i = 0; i < MAX_ACTIVATESTACK; i++) { |
| 4238 |
if (bs->activategoalheap[i].inuse) |
| 4239 |
continue; |
| 4240 |
// |
| 4241 |
if (bs->activategoalheap[i].goal.entitynum == entitynum) { |
| 4242 |
// if the bot went for this goal less than 2 seconds ago |
| 4243 |
if (bs->activategoalheap[i].justused_time > FloatTime() - 2) |
| 4244 |
return qtrue; |
| 4245 |
} |
| 4246 |
} |
| 4247 |
return qfalse; |
| 4248 |
} |
| 4249 |
|
| 4250 |
/* |
| 4251 |
================== |
| 4252 |
BotGetActivateGoal |
| 4253 |
|
| 4254 |
returns the number of the bsp entity to activate |
| 4255 |
goal->entitynum will be set to the game entity to activate |
| 4256 |
================== |
| 4257 |
*/ |
| 4258 |
//#define OBSTACLEDEBUG |
| 4259 |
|
| 4260 |
int BotGetActivateGoal(bot_state_t *bs, int entitynum, bot_activategoal_t *activategoal) { |
| 4261 |
int i, ent, cur_entities[10], spawnflags, modelindex, areas[MAX_ACTIVATEAREAS*2], numareas, t; |
| 4262 |
char model[MAX_INFO_STRING], tmpmodel[128]; |
| 4263 |
char target[128], classname[128]; |
| 4264 |
float health; |
| 4265 |
char targetname[10][128]; |
| 4266 |
aas_entityinfo_t entinfo; |
| 4267 |
aas_areainfo_t areainfo; |
| 4268 |
vec3_t origin, angles, absmins, absmaxs; |
| 4269 |
|
| 4270 |
memset(activategoal, 0, sizeof(bot_activategoal_t)); |
| 4271 |
BotEntityInfo(entitynum, &entinfo); |
| 4272 |
Com_sprintf(model, sizeof( model ), "*%d", entinfo.modelindex); |
| 4273 |
for (ent = trap_AAS_NextBSPEntity(0); ent; ent = trap_AAS_NextBSPEntity(ent)) { |
| 4274 |
if (!trap_AAS_ValueForBSPEpairKey(ent, "model", tmpmodel, sizeof(tmpmodel))) continue; |
| 4275 |
if (!strcmp(model, tmpmodel)) break; |
| 4276 |
} |
| 4277 |
if (!ent) { |
| 4278 |
BotAI_Print(PRT_ERROR, "BotGetActivateGoal: no entity found with model %s\n", model); |
| 4279 |
return 0; |
| 4280 |
} |
| 4281 |
trap_AAS_ValueForBSPEpairKey(ent, "classname", classname, sizeof(classname)); |
| 4282 |
if (!*classname) { |
| 4283 |
BotAI_Print(PRT_ERROR, "BotGetActivateGoal: entity with model %s has no classname\n", model); |
| 4284 |
return 0; |
| 4285 |
} |
| 4286 |
//if it is a door |
| 4287 |
if (!strcmp(classname, "func_door")) { |
| 4288 |
if (trap_AAS_FloatForBSPEpairKey(ent, "health", &health)) { |
| 4289 |
//if the door has health then the door must be shot to open |
| 4290 |
if (health) { |
| 4291 |
BotFuncDoorActivateGoal(bs, ent, activategoal); |
| 4292 |
return ent; |
| 4293 |
} |
| 4294 |
} |
| 4295 |
// |
| 4296 |
trap_AAS_IntForBSPEpairKey(ent, "spawnflags", &spawnflags); |
| 4297 |
// if the door starts open then just wait for the door to return |
| 4298 |
if ( spawnflags & 1 ) |
| 4299 |
return 0; |
| 4300 |
//get the door origin |
| 4301 |
if (!trap_AAS_VectorForBSPEpairKey(ent, "origin", origin)) { |
| 4302 |
VectorClear(origin); |
| 4303 |
} |
| 4304 |
//if the door is open or opening already |
| 4305 |
if (!VectorCompare(origin, entinfo.origin)) |
| 4306 |
return 0; |
| 4307 |
// store all the areas the door is in |
| 4308 |
trap_AAS_ValueForBSPEpairKey(ent, "model", model, sizeof(model)); |
| 4309 |
if (*model) { |
| 4310 |
modelindex = atoi(model+1); |
| 4311 |
if (modelindex) { |
| 4312 |
VectorClear(angles); |
| 4313 |
BotModelMinsMaxs(modelindex, ET_MOVER, 0, absmins, absmaxs); |
| 4314 |
// |
| 4315 |
numareas = trap_AAS_BBoxAreas(absmins, absmaxs, areas, MAX_ACTIVATEAREAS*2); |
| 4316 |
// store the areas with reachabilities first |
| 4317 |
for (i = 0; i < numareas; i++) { |
| 4318 |
if (activategoal->numareas >= MAX_ACTIVATEAREAS) |
| 4319 |
break; |
| 4320 |
if ( !trap_AAS_AreaReachability(areas[i]) ) { |
| 4321 |
continue; |
| 4322 |
} |
| 4323 |
trap_AAS_AreaInfo(areas[i], &areainfo); |
| 4324 |
if (areainfo.contents & AREACONTENTS_MOVER) { |
| 4325 |
activategoal->areas[activategoal->numareas++] = areas[i]; |
| 4326 |
} |
| 4327 |
} |
| 4328 |
// store any remaining areas |
| 4329 |
for (i = 0; i < numareas; i++) { |
| 4330 |
if (activategoal->numareas >= MAX_ACTIVATEAREAS) |
| 4331 |
break; |
| 4332 |
if ( trap_AAS_AreaReachability(areas[i]) ) { |
| 4333 |
continue; |
| 4334 |
} |
| 4335 |
trap_AAS_AreaInfo(areas[i], &areainfo); |
| 4336 |
if (areainfo.contents & AREACONTENTS_MOVER) { |
| 4337 |
activategoal->areas[activategoal->numareas++] = areas[i]; |
| 4338 |
} |
| 4339 |
} |
| 4340 |
} |
| 4341 |
} |
| 4342 |
} |
| 4343 |
// if the bot is blocked by or standing on top of a button |
| 4344 |
if (!strcmp(classname, "func_button")) { |
| 4345 |
return 0; |
| 4346 |
} |
| 4347 |
// get the targetname so we can find an entity with a matching target |
| 4348 |
if (!trap_AAS_ValueForBSPEpairKey(ent, "targetname", targetname[0], sizeof(targetname[0]))) { |
| 4349 |
if (bot_developer.integer) { |
| 4350 |
BotAI_Print(PRT_ERROR, "BotGetActivateGoal: entity with model \"%s\" has no targetname\n", model); |
| 4351 |
} |
| 4352 |
return 0; |
| 4353 |
} |
| 4354 |
// allow tree-like activation |
| 4355 |
cur_entities[0] = trap_AAS_NextBSPEntity(0); |
| 4356 |
for (i = 0; i >= 0 && i < 10;) { |
| 4357 |
for (ent = cur_entities[i]; ent; ent = trap_AAS_NextBSPEntity(ent)) { |
| 4358 |
if (!trap_AAS_ValueForBSPEpairKey(ent, "target", target, sizeof(target))) continue; |
| 4359 |
if (!strcmp(targetname[i], target)) { |
| 4360 |
cur_entities[i] = trap_AAS_NextBSPEntity(ent); |
| 4361 |
break; |
| 4362 |
} |
| 4363 |
} |
| 4364 |
if (!ent) { |
| 4365 |
if (bot_developer.integer) { |
| 4366 |
BotAI_Print(PRT_ERROR, "BotGetActivateGoal: no entity with target \"%s\"\n", targetname[i]); |
| 4367 |
} |
| 4368 |
i--; |
| 4369 |
continue; |
| 4370 |
} |
| 4371 |
if (!trap_AAS_ValueForBSPEpairKey(ent, "classname", classname, sizeof(classname))) { |
| 4372 |
if (bot_developer.integer) { |
| 4373 |
BotAI_Print(PRT_ERROR, "BotGetActivateGoal: entity with target \"%s\" has no classname\n", targetname[i]); |
| 4374 |
} |
| 4375 |
continue; |
| 4376 |
} |
| 4377 |
// BSP button model |
| 4378 |
if (!strcmp(classname, "func_button")) { |
| 4379 |
// |
| 4380 |
if (!BotFuncButtonActivateGoal(bs, ent, activategoal)) |
| 4381 |
continue; |
| 4382 |
// if the bot tries to activate this button already |
| 4383 |
if ( bs->activatestack && bs->activatestack->inuse && |
| 4384 |
bs->activatestack->goal.entitynum == activategoal->goal.entitynum && |
| 4385 |
bs->activatestack->time > FloatTime() && |
| 4386 |
bs->activatestack->start_time < FloatTime() - 2) |
| 4387 |
continue; |
| 4388 |
// if the bot is in a reachability area |
| 4389 |
if ( trap_AAS_AreaReachability(bs->areanum) ) { |
| 4390 |
// disable all areas the blocking entity is in |
| 4391 |
BotEnableActivateGoalAreas( activategoal, qfalse ); |
| 4392 |
// |
| 4393 |
t = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, activategoal->goal.areanum, bs->tfl); |
| 4394 |
// if the button is not reachable |
| 4395 |
if (!t) { |
| 4396 |
continue; |
| 4397 |
} |
| 4398 |
activategoal->time = FloatTime() + t * 0.01 + 5; |
| 4399 |
} |
| 4400 |
return ent; |
| 4401 |
} |
| 4402 |
// invisible trigger multiple box |
| 4403 |
else if (!strcmp(classname, "trigger_multiple")) { |
| 4404 |
// |
| 4405 |
if (!BotTriggerMultipleActivateGoal(bs, ent, activategoal)) |
| 4406 |
continue; |
| 4407 |
// if the bot tries to activate this trigger already |
| 4408 |
if ( bs->activatestack && bs->activatestack->inuse && |
| 4409 |
bs->activatestack->goal.entitynum == activategoal->goal.entitynum && |
| 4410 |
bs->activatestack->time > FloatTime() && |
| 4411 |
bs->activatestack->start_time < FloatTime() - 2) |
| 4412 |
continue; |
| 4413 |
// if the bot is in a reachability area |
| 4414 |
if ( trap_AAS_AreaReachability(bs->areanum) ) { |
| 4415 |
// disable all areas the blocking entity is in |
| 4416 |
BotEnableActivateGoalAreas( activategoal, qfalse ); |
| 4417 |
// |
| 4418 |
t = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, activategoal->goal.areanum, bs->tfl); |
| 4419 |
// if the trigger is not reachable |
| 4420 |
if (!t) { |
| 4421 |
continue; |
| 4422 |
} |
| 4423 |
activategoal->time = FloatTime() + t * 0.01 + 5; |
| 4424 |
} |
| 4425 |
return ent; |
| 4426 |
} |
| 4427 |
else if (!strcmp(classname, "func_timer")) { |
| 4428 |
// just skip the func_timer |
| 4429 |
continue; |
| 4430 |
} |
| 4431 |
// the actual button or trigger might be linked through a target_relay or target_delay |
| 4432 |
else if (!strcmp(classname, "target_relay") || !strcmp(classname, "target_delay")) { |
| 4433 |
if (trap_AAS_ValueForBSPEpairKey(ent, "targetname", targetname[i+1], sizeof(targetname[0]))) { |
| 4434 |
i++; |
| 4435 |
cur_entities[i] = trap_AAS_NextBSPEntity(0); |
| 4436 |
} |
| 4437 |
} |
| 4438 |
} |
| 4439 |
#ifdef OBSTACLEDEBUG |
| 4440 |
BotAI_Print(PRT_ERROR, "BotGetActivateGoal: no valid activator for entity with target \"%s\"\n", targetname[0]); |
| 4441 |
#endif |
| 4442 |
return 0; |
| 4443 |
} |
| 4444 |
|
| 4445 |
/* |
| 4446 |
================== |
| 4447 |
BotGoForActivateGoal |
| 4448 |
================== |
| 4449 |
*/ |
| 4450 |
int BotGoForActivateGoal(bot_state_t *bs, bot_activategoal_t *activategoal) { |
| 4451 |
aas_entityinfo_t activateinfo; |
| 4452 |
|
| 4453 |
activategoal->inuse = qtrue; |
| 4454 |
if (!activategoal->time) |
| 4455 |
activategoal->time = FloatTime() + 10; |
| 4456 |
activategoal->start_time = FloatTime(); |
| 4457 |
BotEntityInfo(activategoal->goal.entitynum, &activateinfo); |
| 4458 |
VectorCopy(activateinfo.origin, activategoal->origin); |
| 4459 |
// |
| 4460 |
if (BotPushOntoActivateGoalStack(bs, activategoal)) { |
| 4461 |
// enter the activate entity AI node |
| 4462 |
AIEnter_Seek_ActivateEntity(bs, "BotGoForActivateGoal"); |
| 4463 |
return qtrue; |
| 4464 |
} |
| 4465 |
else { |
| 4466 |
// enable any routing areas that were disabled |
| 4467 |
BotEnableActivateGoalAreas(activategoal, qtrue); |
| 4468 |
return qfalse; |
| 4469 |
} |
| 4470 |
} |
| 4471 |
|
| 4472 |
/* |
| 4473 |
================== |
| 4474 |
BotPrintActivateGoalInfo |
| 4475 |
================== |
| 4476 |
*/ |
| 4477 |
void BotPrintActivateGoalInfo(bot_state_t *bs, bot_activategoal_t *activategoal, int bspent) { |
| 4478 |
char netname[MAX_NETNAME]; |
| 4479 |
char classname[128]; |
| 4480 |
char buf[128]; |
| 4481 |
|
| 4482 |
ClientName(bs->client, netname, sizeof(netname)); |
| 4483 |
trap_AAS_ValueForBSPEpairKey(bspent, "classname", classname, sizeof(classname)); |
| 4484 |
if (activategoal->shoot) { |
| 4485 |
Com_sprintf(buf, sizeof(buf), "%s: I have to shoot at a %s from %1.1f %1.1f %1.1f in area %d\n", |
| 4486 |
netname, classname, |
| 4487 |
activategoal->goal.origin[0], |
| 4488 |
activategoal->goal.origin[1], |
| 4489 |
activategoal->goal.origin[2], |
| 4490 |
activategoal->goal.areanum); |
| 4491 |
} |
| 4492 |
else { |
| 4493 |
Com_sprintf(buf, sizeof(buf), "%s: I have to activate a %s at %1.1f %1.1f %1.1f in area %d\n", |
| 4494 |
netname, classname, |
| 4495 |
activategoal->goal.origin[0], |
| 4496 |
activategoal->goal.origin[1], |
| 4497 |
activategoal->goal.origin[2], |
| 4498 |
activategoal->goal.areanum); |
| 4499 |
} |
| 4500 |
trap_EA_Say(bs->client, buf); |
| 4501 |
} |
| 4502 |
|
| 4503 |
/* |
| 4504 |
================== |
| 4505 |
BotRandomMove |
| 4506 |
================== |
| 4507 |
*/ |
| 4508 |
void BotRandomMove(bot_state_t *bs, bot_moveresult_t *moveresult) { |
| 4509 |
vec3_t dir, angles; |
| 4510 |
|
| 4511 |
angles[0] = 0; |
| 4512 |
angles[1] = random() * 360; |
| 4513 |
angles[2] = 0; |
| 4514 |
AngleVectors(angles, dir, NULL, NULL); |
| 4515 |
|
| 4516 |
trap_BotMoveInDirection(bs->ms, dir, 400, MOVE_WALK); |
| 4517 |
|
| 4518 |
moveresult->failure = qfalse; |
| 4519 |
VectorCopy(dir, moveresult->movedir); |
| 4520 |
} |
| 4521 |
|
| 4522 |
/* |
| 4523 |
================== |
| 4524 |
BotAIBlocked |
| 4525 |
|
| 4526 |
Very basic handling of bots being blocked by other entities. |
| 4527 |
Check what kind of entity is blocking the bot and try to activate |
| 4528 |
it. If that's not an option then try to walk around or over the entity. |
| 4529 |
Before the bot ends in this part of the AI it should predict which doors to |
| 4530 |
open, which buttons to activate etc. |
| 4531 |
================== |
| 4532 |
*/ |
| 4533 |
void BotAIBlocked(bot_state_t *bs, bot_moveresult_t *moveresult, int activate) { |
| 4534 |
int movetype, bspent; |
| 4535 |
vec3_t hordir, start, end, mins, maxs, sideward, angles, up = {0, 0, 1}; |
| 4536 |
aas_entityinfo_t entinfo; |
| 4537 |
bot_activategoal_t activategoal; |
| 4538 |
|
| 4539 |
// if the bot is not blocked by anything |
| 4540 |
if (!moveresult->blocked) { |
| 4541 |
bs->notblocked_time = FloatTime(); |
| 4542 |
return; |
| 4543 |
} |
| 4544 |
// if stuck in a solid area |
| 4545 |
if ( moveresult->type == RESULTTYPE_INSOLIDAREA ) { |
| 4546 |
// move in a random direction in the hope to get out |
| 4547 |
BotRandomMove(bs, moveresult); |
| 4548 |
// |
| 4549 |
return; |
| 4550 |
} |
| 4551 |
// get info for the entity that is blocking the bot |
| 4552 |
BotEntityInfo(moveresult->blockentity, &entinfo); |
| 4553 |
#ifdef OBSTACLEDEBUG |
| 4554 |
ClientName(bs->client, netname, sizeof(netname)); |
| 4555 |
BotAI_Print(PRT_MESSAGE, "%s: I'm blocked by model %d\n", netname, entinfo.modelindex); |
| 4556 |
#endif // OBSTACLEDEBUG |
| 4557 |
// if blocked by a bsp model and the bot wants to activate it |
| 4558 |
if (activate && entinfo.modelindex > 0 && entinfo.modelindex <= max_bspmodelindex) { |
| 4559 |
// find the bsp entity which should be activated in order to get the blocking entity out of the way |
| 4560 |
bspent = BotGetActivateGoal(bs, entinfo.number, &activategoal); |
| 4561 |
if (bspent) { |
| 4562 |
// |
| 4563 |
if (bs->activatestack && !bs->activatestack->inuse) |
| 4564 |
bs->activatestack = NULL; |
| 4565 |
// if not already trying to activate this entity |
| 4566 |
if (!BotIsGoingToActivateEntity(bs, activategoal.goal.entitynum)) { |
| 4567 |
// |
| 4568 |
BotGoForActivateGoal(bs, &activategoal); |
| 4569 |
} |
| 4570 |
// if ontop of an obstacle or |
| 4571 |
// if the bot is not in a reachability area it'll still |
| 4572 |
// need some dynamic obstacle avoidance, otherwise return |
| 4573 |
if (!(moveresult->flags & MOVERESULT_ONTOPOFOBSTACLE) && |
| 4574 |
trap_AAS_AreaReachability(bs->areanum)) |
| 4575 |
return; |
| 4576 |
} |
| 4577 |
else { |
| 4578 |
// enable any routing areas that were disabled |
| 4579 |
BotEnableActivateGoalAreas(&activategoal, qtrue); |
| 4580 |
} |
| 4581 |
} |
| 4582 |
// just some basic dynamic obstacle avoidance code |
| 4583 |
hordir[0] = moveresult->movedir[0]; |
| 4584 |
hordir[1] = moveresult->movedir[1]; |
| 4585 |
hordir[2] = 0; |
| 4586 |
// if no direction just take a random direction |
| 4587 |
if (VectorNormalize(hordir) < 0.1) { |
| 4588 |
VectorSet(angles, 0, 360 * random(), 0); |
| 4589 |
AngleVectors(angles, hordir, NULL, NULL); |
| 4590 |
} |
| 4591 |
// |
| 4592 |
//if (moveresult->flags & MOVERESULT_ONTOPOFOBSTACLE) movetype = MOVE_JUMP; |
| 4593 |
//else |
| 4594 |
movetype = MOVE_WALK; |
| 4595 |
// if there's an obstacle at the bot's feet and head then |
| 4596 |
// the bot might be able to crouch through |
| 4597 |
VectorCopy(bs->origin, start); |
| 4598 |
start[2] += 18; |
| 4599 |
VectorMA(start, 5, hordir, end); |
| 4600 |
VectorSet(mins, -16, -16, -24); |
| 4601 |
VectorSet(maxs, 16, 16, 4); |
| 4602 |
// |
| 4603 |
//bsptrace = AAS_Trace(start, mins, maxs, end, bs->entitynum, MASK_PLAYERSOLID); |
| 4604 |
//if (bsptrace.fraction >= 1) movetype = MOVE_CROUCH; |
| 4605 |
// get the sideward vector |
| 4606 |
CrossProduct(hordir, up, sideward); |
| 4607 |
// |
| 4608 |
if (bs->flags & BFL_AVOIDRIGHT) VectorNegate(sideward, sideward); |
| 4609 |
// try to crouch straight forward? |
| 4610 |
if (movetype != MOVE_CROUCH || !trap_BotMoveInDirection(bs->ms, hordir, 400, movetype)) { |
| 4611 |
// perform the movement |
| 4612 |
if (!trap_BotMoveInDirection(bs->ms, sideward, 400, movetype)) { |
| 4613 |
// flip the avoid direction flag |
| 4614 |
bs->flags ^= BFL_AVOIDRIGHT; |
| 4615 |
// flip the direction |
| 4616 |
// VectorNegate(sideward, sideward); |
| 4617 |
VectorMA(sideward, -1, hordir, sideward); |
| 4618 |
// move in the other direction |
| 4619 |
trap_BotMoveInDirection(bs->ms, sideward, 400, movetype); |
| 4620 |
} |
| 4621 |
} |
| 4622 |
// |
| 4623 |
if (bs->notblocked_time < FloatTime() - 0.4) { |
| 4624 |
// just reset goals and hope the bot will go into another direction? |
| 4625 |
// is this still needed?? |
| 4626 |
if (bs->ainode == AINode_Seek_NBG) bs->nbg_time = 0; |
| 4627 |
else if (bs->ainode == AINode_Seek_LTG) bs->ltg_time = 0; |
| 4628 |
} |
| 4629 |
} |
| 4630 |
|
| 4631 |
/* |
| 4632 |
================== |
| 4633 |
BotAIPredictObstacles |
| 4634 |
|
| 4635 |
Predict the route towards the goal and check if the bot |
| 4636 |
will be blocked by certain obstacles. When the bot has obstacles |
| 4637 |
on it's path the bot should figure out if they can be removed |
| 4638 |
by activating certain entities. |
| 4639 |
================== |
| 4640 |
*/ |
| 4641 |
int BotAIPredictObstacles(bot_state_t *bs, bot_goal_t *goal) { |
| 4642 |
int modelnum, entitynum, bspent; |
| 4643 |
bot_activategoal_t activategoal; |
| 4644 |
aas_predictroute_t route; |
| 4645 |
|
| 4646 |
if (!bot_predictobstacles.integer) |
| 4647 |
return qfalse; |
| 4648 |
|
| 4649 |
// always predict when the goal change or at regular intervals |
| 4650 |
if (bs->predictobstacles_goalareanum == goal->areanum && |
| 4651 |
bs->predictobstacles_time > FloatTime() - 6) { |
| 4652 |
return qfalse; |
| 4653 |
} |
| 4654 |
bs->predictobstacles_goalareanum = goal->areanum; |
| 4655 |
bs->predictobstacles_time = FloatTime(); |
| 4656 |
|
| 4657 |
// predict at most 100 areas or 10 seconds ahead |
| 4658 |
trap_AAS_PredictRoute(&route, bs->areanum, bs->origin, |
| 4659 |
goal->areanum, bs->tfl, 100, 1000, |
| 4660 |
RSE_USETRAVELTYPE|RSE_ENTERCONTENTS, |
| 4661 |
AREACONTENTS_MOVER, TFL_BRIDGE, 0); |
| 4662 |
// if bot has to travel through an area with a mover |
| 4663 |
if (route.stopevent & RSE_ENTERCONTENTS) { |
| 4664 |
// if the bot will run into a mover |
| 4665 |
if (route.endcontents & AREACONTENTS_MOVER) { |
| 4666 |
//NOTE: this only works with bspc 2.1 or higher |
| 4667 |
modelnum = (route.endcontents & AREACONTENTS_MODELNUM) >> AREACONTENTS_MODELNUMSHIFT; |
| 4668 |
if (modelnum) { |
| 4669 |
// |
| 4670 |
entitynum = BotModelMinsMaxs(modelnum, ET_MOVER, 0, NULL, NULL); |
| 4671 |
if (entitynum) { |
| 4672 |
//NOTE: BotGetActivateGoal already checks if the door is open or not |
| 4673 |
bspent = BotGetActivateGoal(bs, entitynum, &activategoal); |
| 4674 |
if (bspent) { |
| 4675 |
// |
| 4676 |
if (bs->activatestack && !bs->activatestack->inuse) |
| 4677 |
bs->activatestack = NULL; |
| 4678 |
// if not already trying to activate this entity |
| 4679 |
if (!BotIsGoingToActivateEntity(bs, activategoal.goal.entitynum)) { |
| 4680 |
// |
| 4681 |
//BotAI_Print(PRT_MESSAGE, "blocked by mover model %d, entity %d ?\n", modelnum, entitynum); |
| 4682 |
// |
| 4683 |
BotGoForActivateGoal(bs, &activategoal); |
| 4684 |
return qtrue; |
| 4685 |
} |
| 4686 |
else { |
| 4687 |
// enable any routing areas that were disabled |
| 4688 |
BotEnableActivateGoalAreas(&activategoal, qtrue); |
| 4689 |
} |
| 4690 |
} |
| 4691 |
} |
| 4692 |
} |
| 4693 |
} |
| 4694 |
} |
| 4695 |
else if (route.stopevent & RSE_USETRAVELTYPE) { |
| 4696 |
if (route.endtravelflags & TFL_BRIDGE) { |
| 4697 |
//FIXME: check if the bridge is available to travel over |
| 4698 |
} |
| 4699 |
} |
| 4700 |
return qfalse; |
| 4701 |
} |
| 4702 |
|
| 4703 |
/* |
| 4704 |
================== |
| 4705 |
BotCheckConsoleMessages |
| 4706 |
================== |
| 4707 |
*/ |
| 4708 |
void BotCheckConsoleMessages(bot_state_t *bs) { |
| 4709 |
char botname[MAX_NETNAME], message[MAX_MESSAGE_SIZE], netname[MAX_NETNAME], *ptr; |
| 4710 |
float chat_reply; |
| 4711 |
int context, handle; |
| 4712 |
bot_consolemessage_t m; |
| 4713 |
bot_match_t match; |
| 4714 |
|
| 4715 |
//the name of this bot |
| 4716 |
ClientName(bs->client, botname, sizeof(botname)); |
| 4717 |
// |
| 4718 |
while((handle = trap_BotNextConsoleMessage(bs->cs, &m)) != 0) { |
| 4719 |
//if the chat state is flooded with messages the bot will read them quickly |
| 4720 |
if (trap_BotNumConsoleMessages(bs->cs) < 10) { |
| 4721 |
//if it is a chat message the bot needs some time to read it |
| 4722 |
if (m.type == CMS_CHAT && m.time > FloatTime() - (1 + random())) break; |
| 4723 |
} |
| 4724 |
// |
| 4725 |
ptr = m.message; |
| 4726 |
//if it is a chat message then don't unify white spaces and don't |
| 4727 |
//replace synonyms in the netname |
| 4728 |
if (m.type == CMS_CHAT) { |
| 4729 |
// |
| 4730 |
if (trap_BotFindMatch(m.message, &match, MTCONTEXT_REPLYCHAT)) { |
| 4731 |
ptr = m.message + match.variables[MESSAGE].offset; |
| 4732 |
} |
| 4733 |
} |
| 4734 |
//unify the white spaces in the message |
| 4735 |
trap_UnifyWhiteSpaces(ptr); |
| 4736 |
//replace synonyms in the right context |
| 4737 |
context = BotSynonymContext(bs); |
| 4738 |
trap_BotReplaceSynonyms(ptr, context); |
| 4739 |
//if there's no match |
| 4740 |
if (!BotMatchMessage(bs, m.message)) { |
| 4741 |
//if it is a chat message |
| 4742 |
if (m.type == CMS_CHAT && !bot_nochat.integer) { |
| 4743 |
// |
| 4744 |
if (!trap_BotFindMatch(m.message, &match, MTCONTEXT_REPLYCHAT)) { |
| 4745 |
trap_BotRemoveConsoleMessage(bs->cs, handle); |
| 4746 |
continue; |
| 4747 |
} |
| 4748 |
//don't use eliza chats with team messages |
| 4749 |
if (match.subtype & ST_TEAM) { |
| 4750 |
trap_BotRemoveConsoleMessage(bs->cs, handle); |
| 4751 |
continue; |
| 4752 |
} |
| 4753 |
// |
| 4754 |
trap_BotMatchVariable(&match, NETNAME, netname, sizeof(netname)); |
| 4755 |
trap_BotMatchVariable(&match, MESSAGE, message, sizeof(message)); |
| 4756 |
//if this is a message from the bot self |
| 4757 |
if (bs->client == ClientFromName(netname)) { |
| 4758 |
trap_BotRemoveConsoleMessage(bs->cs, handle); |
| 4759 |
continue; |
| 4760 |
} |
| 4761 |
//unify the message |
| 4762 |
trap_UnifyWhiteSpaces(message); |
| 4763 |
// |
| 4764 |
trap_Cvar_Update(&bot_testrchat); |
| 4765 |
if (bot_testrchat.integer) { |
| 4766 |
// |
| 4767 |
trap_BotLibVarSet("bot_testrchat", "1"); |
| 4768 |
//if bot replies with a chat message |
| 4769 |
if (trap_BotReplyChat(bs->cs, message, context, CONTEXT_REPLY, |
| 4770 |
NULL, NULL, |
| 4771 |
NULL, NULL, |
| 4772 |
NULL, NULL, |
| 4773 |
botname, netname)) { |
| 4774 |
BotAI_Print(PRT_MESSAGE, "------------------------\n"); |
| 4775 |
} |
| 4776 |
else { |
| 4777 |
BotAI_Print(PRT_MESSAGE, "**** no valid reply ****\n"); |
| 4778 |
} |
| 4779 |
} |
| 4780 |
//if at a valid chat position and not chatting already and not in teamplay |
| 4781 |
else if (bs->ainode != AINode_Stand && BotValidChatPosition(bs) && !TeamPlayIsOn()) { |
| 4782 |
chat_reply = trap_Characteristic_BFloat(bs->character, CHARACTERISTIC_CHAT_REPLY, 0, 1); |
| 4783 |
if (random() < 1.5 / (NumBots()+1) && random() < chat_reply) { |
| 4784 |
//if bot replies with a chat message |
| 4785 |
if (trap_BotReplyChat(bs->cs, message, context, CONTEXT_REPLY, |
| 4786 |
NULL, NULL, |
| 4787 |
NULL, NULL, |
| 4788 |
NULL, NULL, |
| 4789 |
botname, netname)) { |
| 4790 |
//remove the console message |
| 4791 |
trap_BotRemoveConsoleMessage(bs->cs, handle); |
| 4792 |
bs->stand_time = FloatTime() + BotChatTime(bs); |
| 4793 |
AIEnter_Stand(bs, "BotCheckConsoleMessages: reply chat"); |
| 4794 |
//EA_Say(bs->client, bs->cs.chatmessage); |
| 4795 |
break; |
| 4796 |
} |
| 4797 |
} |
| 4798 |
} |
| 4799 |
} |
| 4800 |
} |
| 4801 |
//remove the console message |
| 4802 |
trap_BotRemoveConsoleMessage(bs->cs, handle); |
| 4803 |
} |
| 4804 |
} |
| 4805 |
|
| 4806 |
/* |
| 4807 |
================== |
| 4808 |
BotCheckEvents |
| 4809 |
================== |
| 4810 |
*/ |
| 4811 |
void BotCheckForGrenades(bot_state_t *bs, entityState_t *state) { |
| 4812 |
// if this is not a grenade |
| 4813 |
if (state->eType != ET_MISSILE || state->weapon != WP_GRENADE_LAUNCHER) |
| 4814 |
return; |
| 4815 |
// try to avoid the grenade |
| 4816 |
trap_BotAddAvoidSpot(bs->ms, state->pos.trBase, 160, AVOID_ALWAYS); |
| 4817 |
} |
| 4818 |
|
| 4819 |
|
| 4820 |
/* |
| 4821 |
================== |
| 4822 |
BotCheckForProxMines |
| 4823 |
================== |
| 4824 |
*/ |
| 4825 |
void BotCheckForProxMines(bot_state_t *bs, entityState_t *state) { |
| 4826 |
// if this is not a prox mine |
| 4827 |
if (state->eType != ET_MISSILE || state->weapon != WP_PROX_LAUNCHER) |
| 4828 |
return; |
| 4829 |
// if this prox mine is from someone on our own team |
| 4830 |
if (state->generic1 == BotTeam(bs)) |
| 4831 |
return; |
| 4832 |
// if the bot doesn't have a weapon to deactivate the mine |
| 4833 |
if (!(bs->inventory[INVENTORY_PLASMAGUN] > 0 && bs->inventory[INVENTORY_CELLS] > 0) && |
| 4834 |
!(bs->inventory[INVENTORY_ROCKETLAUNCHER] > 0 && bs->inventory[INVENTORY_ROCKETS] > 0) && |
| 4835 |
!(bs->inventory[INVENTORY_BFG10K] > 0 && bs->inventory[INVENTORY_BFGAMMO] > 0) ) { |
| 4836 |
return; |
| 4837 |
} |
| 4838 |
// try to avoid the prox mine |
| 4839 |
trap_BotAddAvoidSpot(bs->ms, state->pos.trBase, 160, AVOID_ALWAYS); |
| 4840 |
// |
| 4841 |
if (bs->numproxmines >= MAX_PROXMINES) |
| 4842 |
return; |
| 4843 |
bs->proxmines[bs->numproxmines] = state->number; |
| 4844 |
bs->numproxmines++; |
| 4845 |
} |
| 4846 |
|
| 4847 |
/* |
| 4848 |
================== |
| 4849 |
BotCheckForKamikazeBody |
| 4850 |
================== |
| 4851 |
*/ |
| 4852 |
void BotCheckForKamikazeBody(bot_state_t *bs, entityState_t *state) { |
| 4853 |
// if this entity is not wearing the kamikaze |
| 4854 |
if (!(state->eFlags & EF_KAMIKAZE)) |
| 4855 |
return; |
| 4856 |
// if this entity isn't dead |
| 4857 |
if (!(state->eFlags & EF_DEAD)) |
| 4858 |
return; |
| 4859 |
//remember this kamikaze body |
| 4860 |
bs->kamikazebody = state->number; |
| 4861 |
} |
| 4862 |
|
| 4863 |
/* |
| 4864 |
================== |
| 4865 |
BotCheckEvents |
| 4866 |
================== |
| 4867 |
*/ |
| 4868 |
void BotCheckEvents(bot_state_t *bs, entityState_t *state) { |
| 4869 |
int event; |
| 4870 |
char buf[128]; |
| 4871 |
aas_entityinfo_t entinfo; |
| 4872 |
|
| 4873 |
//NOTE: this sucks, we're accessing the gentity_t directly |
| 4874 |
//but there's no other fast way to do it right now |
| 4875 |
if (bs->entityeventTime[state->number] == g_entities[state->number].eventTime) { |
| 4876 |
return; |
| 4877 |
} |
| 4878 |
bs->entityeventTime[state->number] = g_entities[state->number].eventTime; |
| 4879 |
//if it's an event only entity |
| 4880 |
if (state->eType > ET_EVENTS) { |
| 4881 |
event = (state->eType - ET_EVENTS) & ~EV_EVENT_BITS; |
| 4882 |
} |
| 4883 |
else { |
| 4884 |
event = state->event & ~EV_EVENT_BITS; |
| 4885 |
} |
| 4886 |
// |
| 4887 |
switch(event) { |
| 4888 |
//client obituary event |
| 4889 |
case EV_OBITUARY: |
| 4890 |
{ |
| 4891 |
int target, attacker, mod; |
| 4892 |
|
| 4893 |
target = state->otherEntityNum; |
| 4894 |
attacker = state->otherEntityNum2; |
| 4895 |
mod = state->eventParm; |
| 4896 |
// |
| 4897 |
if (target == bs->client) { |
| 4898 |
bs->botdeathtype = mod; |
| 4899 |
bs->lastkilledby = attacker; |
| 4900 |
// |
| 4901 |
if (target == attacker || |
| 4902 |
target == ENTITYNUM_NONE || |
| 4903 |
target == ENTITYNUM_WORLD) bs->botsuicide = qtrue; |
| 4904 |
else bs->botsuicide = qfalse; |
| 4905 |
// |
| 4906 |
bs->num_deaths++; |
| 4907 |
} |
| 4908 |
//else if this client was killed by the bot |
| 4909 |
else if (attacker == bs->client) { |
| 4910 |
bs->enemydeathtype = mod; |
| 4911 |
bs->lastkilledplayer = target; |
| 4912 |
bs->killedenemy_time = FloatTime(); |
| 4913 |
// |
| 4914 |
bs->num_kills++; |
| 4915 |
} |
| 4916 |
else if (attacker == bs->enemy && target == attacker) { |
| 4917 |
bs->enemysuicide = qtrue; |
| 4918 |
} |
| 4919 |
// |
| 4920 |
if (gametype == GT_1FCTF) { |
| 4921 |
// |
| 4922 |
BotEntityInfo(target, &entinfo); |
| 4923 |
if ( entinfo.powerups & ( 1 << PW_NEUTRALFLAG ) ) { |
| 4924 |
if (!BotSameTeam(bs, target)) { |
| 4925 |
bs->neutralflagstatus = 3; //enemy dropped the flag |
| 4926 |
bs->flagstatuschanged = qtrue; |
| 4927 |
} |
| 4928 |
} |
| 4929 |
} |
| 4930 |
break; |
| 4931 |
} |
| 4932 |
case EV_GLOBAL_SOUND: |
| 4933 |
{ |
| 4934 |
if (state->eventParm < 0 || state->eventParm > MAX_SOUNDS) { |
| 4935 |
BotAI_Print(PRT_ERROR, "EV_GLOBAL_SOUND: eventParm (%d) out of range\n", state->eventParm); |
| 4936 |
break; |
| 4937 |
} |
| 4938 |
trap_GetConfigstring(CS_SOUNDS + state->eventParm, buf, sizeof(buf)); |
| 4939 |
/* |
| 4940 |
if (!strcmp(buf, "sound/teamplay/flagret_red.wav")) { |
| 4941 |
//red flag is returned |
| 4942 |
bs->redflagstatus = 0; |
| 4943 |
bs->flagstatuschanged = qtrue; |
| 4944 |
} |
| 4945 |
else if (!strcmp(buf, "sound/teamplay/flagret_blu.wav")) { |
| 4946 |
//blue flag is returned |
| 4947 |
bs->blueflagstatus = 0; |
| 4948 |
bs->flagstatuschanged = qtrue; |
| 4949 |
} |
| 4950 |
else*/ |
| 4951 |
if (!strcmp(buf, "sound/items/kamikazerespawn.wav" )) { |
| 4952 |
//the kamikaze respawned so dont avoid it |
| 4953 |
BotDontAvoid(bs, "Kamikaze"); |
| 4954 |
} |
| 4955 |
else |
| 4956 |
if (!strcmp(buf, "sound/items/poweruprespawn.wav")) { |
| 4957 |
//powerup respawned... go get it |
| 4958 |
BotGoForPowerups(bs); |
| 4959 |
} |
| 4960 |
break; |
| 4961 |
} |
| 4962 |
case EV_GLOBAL_TEAM_SOUND: |
| 4963 |
{ |
| 4964 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 4965 |
switch(state->eventParm) { |
| 4966 |
case GTS_RED_CAPTURE: |
| 4967 |
bs->blueflagstatus = 0; |
| 4968 |
bs->redflagstatus = 0; |
| 4969 |
bs->flagstatuschanged = qtrue; |
| 4970 |
break; //see BotMatch_CTF |
| 4971 |
case GTS_BLUE_CAPTURE: |
| 4972 |
bs->blueflagstatus = 0; |
| 4973 |
bs->redflagstatus = 0; |
| 4974 |
bs->flagstatuschanged = qtrue; |
| 4975 |
break; //see BotMatch_CTF |
| 4976 |
case GTS_RED_RETURN: |
| 4977 |
//blue flag is returned |
| 4978 |
bs->blueflagstatus = 0; |
| 4979 |
bs->flagstatuschanged = qtrue; |
| 4980 |
break; |
| 4981 |
case GTS_BLUE_RETURN: |
| 4982 |
//red flag is returned |
| 4983 |
bs->redflagstatus = 0; |
| 4984 |
bs->flagstatuschanged = qtrue; |
| 4985 |
break; |
| 4986 |
case GTS_RED_TAKEN: |
| 4987 |
//blue flag is taken |
| 4988 |
bs->blueflagstatus = 1; |
| 4989 |
bs->flagstatuschanged = qtrue; |
| 4990 |
break; //see BotMatch_CTF |
| 4991 |
case GTS_BLUE_TAKEN: |
| 4992 |
//red flag is taken |
| 4993 |
bs->redflagstatus = 1; |
| 4994 |
bs->flagstatuschanged = qtrue; |
| 4995 |
break; //see BotMatch_CTF |
| 4996 |
} |
| 4997 |
} |
| 4998 |
else if (gametype == GT_1FCTF) { |
| 4999 |
switch(state->eventParm) { |
| 5000 |
case GTS_RED_CAPTURE: |
| 5001 |
bs->neutralflagstatus = 0; |
| 5002 |
bs->flagstatuschanged = qtrue; |
| 5003 |
break; |
| 5004 |
case GTS_BLUE_CAPTURE: |
| 5005 |
bs->neutralflagstatus = 0; |
| 5006 |
bs->flagstatuschanged = qtrue; |
| 5007 |
break; |
| 5008 |
case GTS_RED_RETURN: |
| 5009 |
//flag has returned |
| 5010 |
bs->neutralflagstatus = 0; |
| 5011 |
bs->flagstatuschanged = qtrue; |
| 5012 |
break; |
| 5013 |
case GTS_BLUE_RETURN: |
| 5014 |
//flag has returned |
| 5015 |
bs->neutralflagstatus = 0; |
| 5016 |
bs->flagstatuschanged = qtrue; |
| 5017 |
break; |
| 5018 |
case GTS_RED_TAKEN: |
| 5019 |
bs->neutralflagstatus = BotTeam(bs) == TEAM_RED ? 2 : 1; //FIXME: check Team_TakeFlagSound in g_team.c |
| 5020 |
bs->flagstatuschanged = qtrue; |
| 5021 |
break; |
| 5022 |
case GTS_BLUE_TAKEN: |
| 5023 |
bs->neutralflagstatus = BotTeam(bs) == TEAM_BLUE ? 2 : 1; //FIXME: check Team_TakeFlagSound in g_team.c |
| 5024 |
bs->flagstatuschanged = qtrue; |
| 5025 |
break; |
| 5026 |
} |
| 5027 |
} |
| 5028 |
break; |
| 5029 |
} |
| 5030 |
case EV_PLAYER_TELEPORT_IN: |
| 5031 |
{ |
| 5032 |
VectorCopy(state->origin, lastteleport_origin); |
| 5033 |
lastteleport_time = FloatTime(); |
| 5034 |
break; |
| 5035 |
} |
| 5036 |
case EV_GENERAL_SOUND: |
| 5037 |
{ |
| 5038 |
//if this sound is played on the bot |
| 5039 |
if (state->number == bs->client) { |
| 5040 |
if (state->eventParm < 0 || state->eventParm > MAX_SOUNDS) { |
| 5041 |
BotAI_Print(PRT_ERROR, "EV_GENERAL_SOUND: eventParm (%d) out of range\n", state->eventParm); |
| 5042 |
break; |
| 5043 |
} |
| 5044 |
//check out the sound |
| 5045 |
trap_GetConfigstring(CS_SOUNDS + state->eventParm, buf, sizeof(buf)); |
| 5046 |
//if falling into a death pit |
| 5047 |
if (!strcmp(buf, "*falling1.wav")) { |
| 5048 |
//if the bot has a personal teleporter |
| 5049 |
if (bs->inventory[INVENTORY_TELEPORTER] > 0) { |
| 5050 |
//use the holdable item |
| 5051 |
trap_EA_Use(bs->client); |
| 5052 |
} |
| 5053 |
} |
| 5054 |
} |
| 5055 |
break; |
| 5056 |
} |
| 5057 |
case EV_FOOTSTEP: |
| 5058 |
case EV_FOOTSTEP_METAL: |
| 5059 |
case EV_FOOTSPLASH: |
| 5060 |
case EV_FOOTWADE: |
| 5061 |
case EV_SWIM: |
| 5062 |
case EV_FALL_SHORT: |
| 5063 |
case EV_FALL_MEDIUM: |
| 5064 |
case EV_FALL_FAR: |
| 5065 |
case EV_STEP_4: |
| 5066 |
case EV_STEP_8: |
| 5067 |
case EV_STEP_12: |
| 5068 |
case EV_STEP_16: |
| 5069 |
case EV_JUMP_PAD: |
| 5070 |
case EV_JUMP: |
| 5071 |
case EV_TAUNT: |
| 5072 |
case EV_WATER_TOUCH: |
| 5073 |
case EV_WATER_LEAVE: |
| 5074 |
case EV_WATER_UNDER: |
| 5075 |
case EV_WATER_CLEAR: |
| 5076 |
case EV_ITEM_PICKUP: |
| 5077 |
case EV_GLOBAL_ITEM_PICKUP: |
| 5078 |
case EV_NOAMMO: |
| 5079 |
case EV_CHANGE_WEAPON: |
| 5080 |
case EV_FIRE_WEAPON: |
| 5081 |
//FIXME: either add to sound queue or mark player as someone making noise |
| 5082 |
break; |
| 5083 |
case EV_USE_ITEM0: |
| 5084 |
case EV_USE_ITEM1: |
| 5085 |
case EV_USE_ITEM2: |
| 5086 |
case EV_USE_ITEM3: |
| 5087 |
case EV_USE_ITEM4: |
| 5088 |
case EV_USE_ITEM5: |
| 5089 |
case EV_USE_ITEM6: |
| 5090 |
case EV_USE_ITEM7: |
| 5091 |
case EV_USE_ITEM8: |
| 5092 |
case EV_USE_ITEM9: |
| 5093 |
case EV_USE_ITEM10: |
| 5094 |
case EV_USE_ITEM11: |
| 5095 |
case EV_USE_ITEM12: |
| 5096 |
case EV_USE_ITEM13: |
| 5097 |
case EV_USE_ITEM14: |
| 5098 |
break; |
| 5099 |
} |
| 5100 |
} |
| 5101 |
|
| 5102 |
/* |
| 5103 |
================== |
| 5104 |
BotCheckSnapshot |
| 5105 |
================== |
| 5106 |
*/ |
| 5107 |
void BotCheckSnapshot(bot_state_t *bs) { |
| 5108 |
int ent; |
| 5109 |
entityState_t state; |
| 5110 |
|
| 5111 |
//remove all avoid spots |
| 5112 |
trap_BotAddAvoidSpot(bs->ms, vec3_origin, 0, AVOID_CLEAR); |
| 5113 |
//reset kamikaze body |
| 5114 |
bs->kamikazebody = 0; |
| 5115 |
//reset number of proxmines |
| 5116 |
bs->numproxmines = 0; |
| 5117 |
// |
| 5118 |
ent = 0; |
| 5119 |
while( ( ent = BotAI_GetSnapshotEntity( bs->client, ent, &state ) ) != -1 ) { |
| 5120 |
//check the entity state for events |
| 5121 |
BotCheckEvents(bs, &state); |
| 5122 |
//check for grenades the bot should avoid |
| 5123 |
BotCheckForGrenades(bs, &state); |
| 5124 |
// |
| 5125 |
|
| 5126 |
//check for proximity mines which the bot should deactivate |
| 5127 |
BotCheckForProxMines(bs, &state); |
| 5128 |
//check for dead bodies with the kamikaze effect which should be gibbed |
| 5129 |
BotCheckForKamikazeBody(bs, &state); |
| 5130 |
} |
| 5131 |
//check the player state for events |
| 5132 |
BotAI_GetEntityState(bs->client, &state); |
| 5133 |
//copy the player state events to the entity state |
| 5134 |
state.event = bs->cur_ps.externalEvent; |
| 5135 |
state.eventParm = bs->cur_ps.externalEventParm; |
| 5136 |
// |
| 5137 |
BotCheckEvents(bs, &state); |
| 5138 |
} |
| 5139 |
|
| 5140 |
/* |
| 5141 |
================== |
| 5142 |
BotCheckAir |
| 5143 |
================== |
| 5144 |
*/ |
| 5145 |
void BotCheckAir(bot_state_t *bs) { |
| 5146 |
if (bs->inventory[INVENTORY_ENVIRONMENTSUIT] <= 0) { |
| 5147 |
if (trap_AAS_PointContents(bs->eye) & (CONTENTS_WATER|CONTENTS_SLIME|CONTENTS_LAVA)) { |
| 5148 |
return; |
| 5149 |
} |
| 5150 |
} |
| 5151 |
bs->lastair_time = FloatTime(); |
| 5152 |
} |
| 5153 |
|
| 5154 |
/* |
| 5155 |
================== |
| 5156 |
BotAlternateRoute |
| 5157 |
================== |
| 5158 |
*/ |
| 5159 |
bot_goal_t *BotAlternateRoute(bot_state_t *bs, bot_goal_t *goal) { |
| 5160 |
int t; |
| 5161 |
|
| 5162 |
// if the bot has an alternative route goal |
| 5163 |
if (bs->altroutegoal.areanum) { |
| 5164 |
// |
| 5165 |
if (bs->reachedaltroutegoal_time) |
| 5166 |
return goal; |
| 5167 |
// travel time towards alternative route goal |
| 5168 |
t = trap_AAS_AreaTravelTimeToGoalArea(bs->areanum, bs->origin, bs->altroutegoal.areanum, bs->tfl); |
| 5169 |
if (t && t < 20) { |
| 5170 |
//BotAI_Print(PRT_MESSAGE, "reached alternate route goal\n"); |
| 5171 |
bs->reachedaltroutegoal_time = FloatTime(); |
| 5172 |
} |
| 5173 |
memcpy(goal, &bs->altroutegoal, sizeof(bot_goal_t)); |
| 5174 |
return &bs->altroutegoal; |
| 5175 |
} |
| 5176 |
return goal; |
| 5177 |
} |
| 5178 |
|
| 5179 |
/* |
| 5180 |
================== |
| 5181 |
BotGetAlternateRouteGoal |
| 5182 |
================== |
| 5183 |
*/ |
| 5184 |
int BotGetAlternateRouteGoal(bot_state_t *bs, int base) { |
| 5185 |
aas_altroutegoal_t *altroutegoals; |
| 5186 |
bot_goal_t *goal; |
| 5187 |
int numaltroutegoals, rnd; |
| 5188 |
|
| 5189 |
if (base == TEAM_RED) { |
| 5190 |
altroutegoals = red_altroutegoals; |
| 5191 |
numaltroutegoals = red_numaltroutegoals; |
| 5192 |
} |
| 5193 |
else { |
| 5194 |
altroutegoals = blue_altroutegoals; |
| 5195 |
numaltroutegoals = blue_numaltroutegoals; |
| 5196 |
} |
| 5197 |
if (!numaltroutegoals) |
| 5198 |
return qfalse; |
| 5199 |
rnd = (float) random() * numaltroutegoals; |
| 5200 |
if (rnd >= numaltroutegoals) |
| 5201 |
rnd = numaltroutegoals-1; |
| 5202 |
goal = &bs->altroutegoal; |
| 5203 |
goal->areanum = altroutegoals[rnd].areanum; |
| 5204 |
VectorCopy(altroutegoals[rnd].origin, goal->origin); |
| 5205 |
VectorSet(goal->mins, -8, -8, -8); |
| 5206 |
VectorSet(goal->maxs, 8, 8, 8); |
| 5207 |
goal->entitynum = 0; |
| 5208 |
goal->iteminfo = 0; |
| 5209 |
goal->number = 0; |
| 5210 |
goal->flags = 0; |
| 5211 |
// |
| 5212 |
bs->reachedaltroutegoal_time = 0; |
| 5213 |
return qtrue; |
| 5214 |
} |
| 5215 |
|
| 5216 |
/* |
| 5217 |
================== |
| 5218 |
BotSetupAlternateRouteGoals |
| 5219 |
================== |
| 5220 |
*/ |
| 5221 |
void BotSetupAlternativeRouteGoals(void) { |
| 5222 |
|
| 5223 |
if (altroutegoals_setup) |
| 5224 |
return; |
| 5225 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 5226 |
if (trap_BotGetLevelItemGoal(-1, "Neutral Flag", &ctf_neutralflag) < 0) |
| 5227 |
BotAI_Print(PRT_WARNING, "No alt routes without Neutral Flag\n"); |
| 5228 |
if (ctf_neutralflag.areanum) { |
| 5229 |
// |
| 5230 |
red_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5231 |
ctf_neutralflag.origin, ctf_neutralflag.areanum, |
| 5232 |
ctf_redflag.origin, ctf_redflag.areanum, TFL_DEFAULT, |
| 5233 |
red_altroutegoals, MAX_ALTROUTEGOALS, |
| 5234 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5235 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5236 |
blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5237 |
ctf_neutralflag.origin, ctf_neutralflag.areanum, |
| 5238 |
ctf_blueflag.origin, ctf_blueflag.areanum, TFL_DEFAULT, |
| 5239 |
blue_altroutegoals, MAX_ALTROUTEGOALS, |
| 5240 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5241 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5242 |
} |
| 5243 |
} |
| 5244 |
else if (gametype == GT_1FCTF) { |
| 5245 |
if (trap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0) |
| 5246 |
BotAI_Print(PRT_WARNING, "One Flag CTF without Neutral Obelisk\n"); |
| 5247 |
red_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5248 |
ctf_neutralflag.origin, ctf_neutralflag.areanum, |
| 5249 |
ctf_redflag.origin, ctf_redflag.areanum, TFL_DEFAULT, |
| 5250 |
red_altroutegoals, MAX_ALTROUTEGOALS, |
| 5251 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5252 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5253 |
blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5254 |
ctf_neutralflag.origin, ctf_neutralflag.areanum, |
| 5255 |
ctf_blueflag.origin, ctf_blueflag.areanum, TFL_DEFAULT, |
| 5256 |
blue_altroutegoals, MAX_ALTROUTEGOALS, |
| 5257 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5258 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5259 |
} |
| 5260 |
else if (gametype == GT_OBELISK) { |
| 5261 |
if (trap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0) |
| 5262 |
BotAI_Print(PRT_WARNING, "Obelisk without neutral obelisk\n"); |
| 5263 |
// |
| 5264 |
red_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5265 |
neutralobelisk.origin, neutralobelisk.areanum, |
| 5266 |
redobelisk.origin, redobelisk.areanum, TFL_DEFAULT, |
| 5267 |
red_altroutegoals, MAX_ALTROUTEGOALS, |
| 5268 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5269 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5270 |
blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5271 |
neutralobelisk.origin, neutralobelisk.areanum, |
| 5272 |
blueobelisk.origin, blueobelisk.areanum, TFL_DEFAULT, |
| 5273 |
blue_altroutegoals, MAX_ALTROUTEGOALS, |
| 5274 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5275 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5276 |
} |
| 5277 |
else if (gametype == GT_HARVESTER) { |
| 5278 |
if (untrap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0) |
| 5279 |
BotAI_Print(PRT_WARNING, "Harvester without neutral obelisk\n"); |
| 5280 |
// |
| 5281 |
red_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5282 |
neutralobelisk.origin, neutralobelisk.areanum, |
| 5283 |
redobelisk.origin, redobelisk.areanum, TFL_DEFAULT, |
| 5284 |
red_altroutegoals, MAX_ALTROUTEGOALS, |
| 5285 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5286 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5287 |
blue_numaltroutegoals = trap_AAS_AlternativeRouteGoals( |
| 5288 |
neutralobelisk.origin, neutralobelisk.areanum, |
| 5289 |
blueobelisk.origin, blueobelisk.areanum, TFL_DEFAULT, |
| 5290 |
blue_altroutegoals, MAX_ALTROUTEGOALS, |
| 5291 |
ALTROUTEGOAL_CLUSTERPORTALS| |
| 5292 |
ALTROUTEGOAL_VIEWPORTALS); |
| 5293 |
} |
| 5294 |
altroutegoals_setup = qtrue; |
| 5295 |
} |
| 5296 |
|
| 5297 |
/* |
| 5298 |
================== |
| 5299 |
BotDeathmatchAI |
| 5300 |
================== |
| 5301 |
*/ |
| 5302 |
void BotDeathmatchAI(bot_state_t *bs, float thinktime) { |
| 5303 |
char gender[144], name[144], buf[144]; |
| 5304 |
char userinfo[MAX_INFO_STRING]; |
| 5305 |
int i; |
| 5306 |
|
| 5307 |
//if the bot has just been setup |
| 5308 |
if (bs->setupcount > 0) { |
| 5309 |
bs->setupcount--; |
| 5310 |
if (bs->setupcount > 0) return; |
| 5311 |
//get the gender characteristic |
| 5312 |
trap_Characteristic_String(bs->character, CHARACTERISTIC_GENDER, gender, sizeof(gender)); |
| 5313 |
//set the bot gender |
| 5314 |
trap_GetUserinfo(bs->client, userinfo, sizeof(userinfo)); |
| 5315 |
Info_SetValueForKey(userinfo, "sex", gender); |
| 5316 |
trap_SetUserinfo(bs->client, userinfo); |
| 5317 |
//set the team |
| 5318 |
if ( !bs->map_restart && g_gametype.integer != GT_TOURNAMENT ) { |
| 5319 |
Com_sprintf(buf, sizeof(buf), "team %s", bs->settings.team); |
| 5320 |
trap_EA_Command(bs->client, buf); |
| 5321 |
} |
| 5322 |
//set the chat gender |
| 5323 |
if (gender[0] == 'm') trap_BotSetChatGender(bs->cs, CHAT_GENDERMALE); |
| 5324 |
else if (gender[0] == 'f') trap_BotSetChatGender(bs->cs, CHAT_GENDERFEMALE); |
| 5325 |
else trap_BotSetChatGender(bs->cs, CHAT_GENDERLESS); |
| 5326 |
//set the chat name |
| 5327 |
ClientName(bs->client, name, sizeof(name)); |
| 5328 |
trap_BotSetChatName(bs->cs, name, bs->client); |
| 5329 |
// |
| 5330 |
bs->lastframe_health = bs->inventory[INVENTORY_HEALTH]; |
| 5331 |
bs->lasthitcount = bs->cur_ps.persistant[PERS_HITS]; |
| 5332 |
// |
| 5333 |
bs->setupcount = 0; |
| 5334 |
// |
| 5335 |
BotSetupAlternativeRouteGoals(); |
| 5336 |
} |
| 5337 |
//no ideal view set |
| 5338 |
bs->flags &= ~BFL_IDEALVIEWSET; |
| 5339 |
// |
| 5340 |
if (!BotIntermission(bs)) { |
| 5341 |
//set the teleport time |
| 5342 |
BotSetTeleportTime(bs); |
| 5343 |
//update some inventory values |
| 5344 |
BotUpdateInventory(bs); |
| 5345 |
//check out the snapshot |
| 5346 |
BotCheckSnapshot(bs); |
| 5347 |
//check for air |
| 5348 |
BotCheckAir(bs); |
| 5349 |
} |
| 5350 |
//check the console messages |
| 5351 |
BotCheckConsoleMessages(bs); |
| 5352 |
//if not in the intermission and not in observer mode |
| 5353 |
if (!BotIntermission(bs) && !BotIsObserver(bs)) { |
| 5354 |
//do team AI |
| 5355 |
BotTeamAI(bs); |
| 5356 |
} |
| 5357 |
//if the bot has no ai node |
| 5358 |
if (!bs->ainode) { |
| 5359 |
AIEnter_Seek_LTG(bs, "BotDeathmatchAI: no ai node"); |
| 5360 |
} |
| 5361 |
//if the bot entered the game less than 8 seconds ago |
| 5362 |
if (!bs->entergamechat && bs->entergame_time > FloatTime() - 8) { |
| 5363 |
if (BotChat_EnterGame(bs)) { |
| 5364 |
bs->stand_time = FloatTime() + BotChatTime(bs); |
| 5365 |
AIEnter_Stand(bs, "BotDeathmatchAI: chat enter game"); |
| 5366 |
} |
| 5367 |
bs->entergamechat = qtrue; |
| 5368 |
} |
| 5369 |
//reset the node switches from the previous frame |
| 5370 |
BotResetNodeSwitches(); |
| 5371 |
//execute AI nodes |
| 5372 |
for (i = 0; i < MAX_NODESWITCHES; i++) { |
| 5373 |
if (bs->ainode(bs)) break; |
| 5374 |
} |
| 5375 |
//if the bot removed itself :) |
| 5376 |
if (!bs->inuse) return; |
| 5377 |
//if the bot executed too many AI nodes |
| 5378 |
//Sago: FIXME - Outcommented this test... this is wrong |
| 5379 |
#ifdef DEBUG |
| 5380 |
if (i >= MAX_NODESWITCHES) { |
| 5381 |
trap_BotDumpGoalStack(bs->gs); |
| 5382 |
trap_BotDumpAvoidGoals(bs->gs); |
| 5383 |
BotDumpNodeSwitches(bs); |
| 5384 |
ClientName(bs->client, name, sizeof(name)); |
| 5385 |
BotAI_Print(PRT_ERROR, "%s at %1.1f switched more than %d AI nodes\n", name, FloatTime(), MAX_NODESWITCHES); |
| 5386 |
} |
| 5387 |
#endif |
| 5388 |
// |
| 5389 |
bs->lastframe_health = bs->inventory[INVENTORY_HEALTH]; |
| 5390 |
bs->lasthitcount = bs->cur_ps.persistant[PERS_HITS]; |
| 5391 |
} |
| 5392 |
|
| 5393 |
/* |
| 5394 |
================== |
| 5395 |
BotSetEntityNumForGoalWithModel |
| 5396 |
================== |
| 5397 |
*/ |
| 5398 |
void BotSetEntityNumForGoalWithModel(bot_goal_t *goal, int eType, char *modelname) { |
| 5399 |
gentity_t *ent; |
| 5400 |
int i, modelindex; |
| 5401 |
vec3_t dir; |
| 5402 |
|
| 5403 |
modelindex = G_ModelIndex( modelname ); |
| 5404 |
ent = &g_entities[0]; |
| 5405 |
for (i = 0; i < level.num_entities; i++, ent++) { |
| 5406 |
if ( !ent->inuse ) { |
| 5407 |
continue; |
| 5408 |
} |
| 5409 |
if ( eType && ent->s.eType != eType) { |
| 5410 |
continue; |
| 5411 |
} |
| 5412 |
if (ent->s.modelindex != modelindex) { |
| 5413 |
continue; |
| 5414 |
} |
| 5415 |
VectorSubtract(goal->origin, ent->s.origin, dir); |
| 5416 |
if (VectorLengthSquared(dir) < Square(10)) { |
| 5417 |
goal->entitynum = i; |
| 5418 |
return; |
| 5419 |
} |
| 5420 |
} |
| 5421 |
} |
| 5422 |
|
| 5423 |
/* |
| 5424 |
================== |
| 5425 |
BotSetEntityNumForGoal |
| 5426 |
================== |
| 5427 |
*/ |
| 5428 |
void BotSetEntityNumForGoal(bot_goal_t *goal, char *classname) { |
| 5429 |
gentity_t *ent; |
| 5430 |
int i; |
| 5431 |
vec3_t dir; |
| 5432 |
|
| 5433 |
ent = &g_entities[0]; |
| 5434 |
for (i = 0; i < level.num_entities; i++, ent++) { |
| 5435 |
if ( !ent->inuse ) { |
| 5436 |
continue; |
| 5437 |
} |
| 5438 |
if ( !Q_stricmp(ent->classname, classname) ) { |
| 5439 |
continue; |
| 5440 |
} |
| 5441 |
VectorSubtract(goal->origin, ent->s.origin, dir); |
| 5442 |
if (VectorLengthSquared(dir) < Square(10)) { |
| 5443 |
goal->entitynum = i; |
| 5444 |
return; |
| 5445 |
} |
| 5446 |
} |
| 5447 |
} |
| 5448 |
|
| 5449 |
/* |
| 5450 |
================== |
| 5451 |
BotGoalForBSPEntity |
| 5452 |
================== |
| 5453 |
*/ |
| 5454 |
int BotGoalForBSPEntity( char *classname, bot_goal_t *goal ) { |
| 5455 |
char value[MAX_INFO_STRING]; |
| 5456 |
vec3_t origin, start, end; |
| 5457 |
int ent, numareas, areas[10]; |
| 5458 |
|
| 5459 |
memset(goal, 0, sizeof(bot_goal_t)); |
| 5460 |
for (ent = trap_AAS_NextBSPEntity(0); ent; ent = trap_AAS_NextBSPEntity(ent)) { |
| 5461 |
if (!trap_AAS_ValueForBSPEpairKey(ent, "classname", value, sizeof(value))) |
| 5462 |
continue; |
| 5463 |
if (!strcmp(value, classname)) { |
| 5464 |
if (!trap_AAS_VectorForBSPEpairKey(ent, "origin", origin)) |
| 5465 |
return qfalse; |
| 5466 |
VectorCopy(origin, goal->origin); |
| 5467 |
VectorCopy(origin, start); |
| 5468 |
start[2] -= 32; |
| 5469 |
VectorCopy(origin, end); |
| 5470 |
end[2] += 32; |
| 5471 |
numareas = trap_AAS_TraceAreas(start, end, areas, NULL, 10); |
| 5472 |
if (!numareas) |
| 5473 |
return qfalse; |
| 5474 |
goal->areanum = areas[0]; |
| 5475 |
return qtrue; |
| 5476 |
} |
| 5477 |
} |
| 5478 |
return qfalse; |
| 5479 |
} |
| 5480 |
|
| 5481 |
/* |
| 5482 |
================== |
| 5483 |
BotSetupDeathmatchAI |
| 5484 |
================== |
| 5485 |
*/ |
| 5486 |
void BotSetupDeathmatchAI(void) { |
| 5487 |
int ent, modelnum,i; |
| 5488 |
char model[128]; |
| 5489 |
|
| 5490 |
gametype = trap_Cvar_VariableIntegerValue("g_gametype"); |
| 5491 |
maxclients = trap_Cvar_VariableIntegerValue("sv_maxclients"); |
| 5492 |
|
| 5493 |
trap_Cvar_Register(&bot_rocketjump, "bot_rocketjump", "1", 0); |
| 5494 |
trap_Cvar_Register(&bot_grapple, "bot_grapple", "0", 0); |
| 5495 |
trap_Cvar_Register(&bot_fastchat, "bot_fastchat", "0", 0); |
| 5496 |
trap_Cvar_Register(&bot_nochat, "bot_nochat", "0", 0); |
| 5497 |
trap_Cvar_Register(&bot_testrchat, "bot_testrchat", "0", 0); |
| 5498 |
trap_Cvar_Register(&bot_challenge, "bot_challenge", "0", 0); |
| 5499 |
trap_Cvar_Register(&bot_predictobstacles, "bot_predictobstacles", "1", 0); |
| 5500 |
trap_Cvar_Register(&g_spSkill, "g_spSkill", "2", 0); |
| 5501 |
// |
| 5502 |
if (gametype == GT_CTF || gametype == GT_CTF_ELIMINATION) { |
| 5503 |
if (untrap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) < 0) |
| 5504 |
BotAI_Print(PRT_WARNING, "CTF without Red Flag\n"); |
| 5505 |
if (untrap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0) |
| 5506 |
BotAI_Print(PRT_WARNING, "CTF without Blue Flag\n"); |
| 5507 |
} |
| 5508 |
else if (gametype == GT_DOUBLE_D) { |
| 5509 |
if (untrap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) < 0) |
| 5510 |
BotAI_Print(PRT_WARNING, "DD without Point A\n"); |
| 5511 |
if (untrap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0) |
| 5512 |
BotAI_Print(PRT_WARNING, "DD without Point B\n"); |
| 5513 |
} |
| 5514 |
else if (gametype == GT_DOMINATION) { |
| 5515 |
ent = untrap_BotGetLevelItemGoal(-1, "Domination point", &dom_points_bot[0]); |
| 5516 |
if(ent < 0) |
| 5517 |
BotAI_Print(PRT_WARNING, "Domination without a single domination point\n"); |
| 5518 |
else |
| 5519 |
BotSetEntityNumForGoal(&dom_points_bot[0], va("domination_point%i",0) ); |
| 5520 |
for(i=1;i<level.domination_points_count;i++) { |
| 5521 |
//Find next from the privius found entity |
| 5522 |
ent = untrap_BotGetLevelItemGoal(ent, "Domination point", &dom_points_bot[i]); |
| 5523 |
if(ent < 0) |
| 5524 |
BotAI_Print(PRT_WARNING, "Domination point %i not found!\n",i); |
| 5525 |
else |
| 5526 |
BotSetEntityNumForGoal(&dom_points_bot[0], va("domination_point%i",i) ); |
| 5527 |
} |
| 5528 |
//MAX_DOMINATION_POINTS |
| 5529 |
} |
| 5530 |
else if (gametype == GT_1FCTF) { |
| 5531 |
if (untrap_BotGetLevelItemGoal(-1, "Neutral Flag", &ctf_neutralflag) < 0) |
| 5532 |
BotAI_Print(PRT_WARNING, "One Flag CTF without Neutral Flag\n"); |
| 5533 |
if (untrap_BotGetLevelItemGoal(-1, "Red Flag", &ctf_redflag) < 0) |
| 5534 |
BotAI_Print(PRT_WARNING, "CTF without Red Flag\n"); |
| 5535 |
if (untrap_BotGetLevelItemGoal(-1, "Blue Flag", &ctf_blueflag) < 0) |
| 5536 |
BotAI_Print(PRT_WARNING, "CTF without Blue Flag\n"); |
| 5537 |
} |
| 5538 |
else if (gametype == GT_OBELISK) { |
| 5539 |
if (untrap_BotGetLevelItemGoal(-1, "Red Obelisk", &redobelisk) < 0) |
| 5540 |
BotAI_Print(PRT_WARNING, "Obelisk without red obelisk\n"); |
| 5541 |
BotSetEntityNumForGoal(&redobelisk, "team_redobelisk"); |
| 5542 |
if (untrap_BotGetLevelItemGoal(-1, "Blue Obelisk", &blueobelisk) < 0) |
| 5543 |
BotAI_Print(PRT_WARNING, "Obelisk without blue obelisk\n"); |
| 5544 |
BotSetEntityNumForGoal(&blueobelisk, "team_blueobelisk"); |
| 5545 |
} |
| 5546 |
else if (gametype == GT_HARVESTER) { |
| 5547 |
if (untrap_BotGetLevelItemGoal(-1, "Red Obelisk", &redobelisk) < 0) |
| 5548 |
BotAI_Print(PRT_WARNING, "Harvester without red obelisk\n"); |
| 5549 |
BotSetEntityNumForGoal(&redobelisk, "team_redobelisk"); |
| 5550 |
if (untrap_BotGetLevelItemGoal(-1, "Blue Obelisk", &blueobelisk) < 0) |
| 5551 |
BotAI_Print(PRT_WARNING, "Harvester without blue obelisk\n"); |
| 5552 |
BotSetEntityNumForGoal(&blueobelisk, "team_blueobelisk"); |
| 5553 |
if (untrap_BotGetLevelItemGoal(-1, "Neutral Obelisk", &neutralobelisk) < 0) |
| 5554 |
BotAI_Print(PRT_WARNING, "Harvester without neutral obelisk\n"); |
| 5555 |
BotSetEntityNumForGoal(&neutralobelisk, "team_neutralobelisk"); |
| 5556 |
} |
| 5557 |
|
| 5558 |
max_bspmodelindex = 0; |
| 5559 |
for (ent = trap_AAS_NextBSPEntity(0); ent; ent = trap_AAS_NextBSPEntity(ent)) { |
| 5560 |
if (!trap_AAS_ValueForBSPEpairKey(ent, "model", model, sizeof(model))) continue; |
| 5561 |
if (model[0] == '*') { |
| 5562 |
modelnum = atoi(model+1); |
| 5563 |
if (modelnum > max_bspmodelindex) |
| 5564 |
max_bspmodelindex = modelnum; |
| 5565 |
} |
| 5566 |
} |
| 5567 |
//initialize the waypoint heap |
| 5568 |
BotInitWaypoints(); |
| 5569 |
} |
| 5570 |
|
| 5571 |
/* |
| 5572 |
================== |
| 5573 |
BotShutdownDeathmatchAI |
| 5574 |
================== |
| 5575 |
*/ |
| 5576 |
void BotShutdownDeathmatchAI(void) { |
| 5577 |
altroutegoals_setup = qfalse; |
| 5578 |
} |