1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
|
/*
===========================================================================
Return to Castle Wolfenstein multiplayer GPL Source Code
Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
This file is part of the Return to Castle Wolfenstein multiplayer GPL Source Code (RTCW MP Source Code).
RTCW MP Source Code is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RTCW MP Source Code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RTCW MP Source Code. If not, see <http://www.gnu.org/licenses/>.
In addition, the RTCW MP Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the RTCW MP Source Code. If not, please request a copy in writing from id Software at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
//===========================================================================
//
// Name: ai_cast_events.c
// Function: Wolfenstein AI Character Events
// Programmer: Ridah
// Tab Size: 4 (real tabs)
//===========================================================================
#include "g_local.h"
#include "../qcommon/q_shared.h"
#include "../botlib/botlib.h" //bot lib interface
#include "../botlib/be_aas.h"
#include "../botlib/be_ea.h"
#include "../botlib/be_ai_gen.h"
#include "../botlib/be_ai_goal.h"
#include "../botlib/be_ai_move.h"
#include "../botlib/botai.h" //bot ai interface
#include "ai_cast.h"
/*
Contains response functions for various events that require specific handling
for Cast AI's.
*/
/*
============
AICast_Sight
============
*/
void AICast_Sight( gentity_t *ent, gentity_t *other, int lastSight ) {
cast_state_t *cs, *ocs;
cs = AICast_GetCastState( ent->s.number );
ocs = AICast_GetCastState( other->s.number );
//
// call the sightfunc for this cast, so we can play associated sounds, or do any character-specific things
//
if ( cs->sightfunc ) {
// factor in the reaction time
if ( AICast_EntityVisible( cs, other->s.number, qfalse ) ) {
cs->sightfunc( ent, other, lastSight );
}
}
if ( other->aiName && other->health <= 0 ) {
// they died since we last saw them
if ( ocs->deathTime > lastSight ) {
if ( !AICast_SameTeam( cs, other->s.number ) ) {
AICast_ScriptEvent( cs, "enemysightcorpse", other->aiName );
} else if ( !( cs->castScriptStatus.scriptFlags & SFL_FRIENDLYSIGHTCORPSE_TRIGGERED ) ) {
cs->castScriptStatus.scriptFlags |= SFL_FRIENDLYSIGHTCORPSE_TRIGGERED;
AICast_ScriptEvent( cs, "friendlysightcorpse", "" );
}
}
// if this is the first time, call the sight script event
} else if ( !lastSight && other->aiName ) {
if ( !AICast_SameTeam( cs, other->s.number ) ) {
// disabled.. triggered when entering combat mode
//AICast_ScriptEvent( cs, "enemysight", other->aiName );
} else {
AICast_ScriptEvent( cs, "sight", other->aiName );
}
}
}
/*
============
AICast_Pain
============
*/
void AICast_Pain( gentity_t *targ, gentity_t *attacker, int damage, vec3_t point ) {
cast_state_t *cs;
cs = AICast_GetCastState( targ->s.number );
// print debugging message
if ( aicast_debug.integer == 2 && attacker->s.number == 0 ) {
G_Printf( "hit %s %i\n", targ->aiName, targ->health );
}
// if we are below alert mode, then go there immediately
if ( cs->aiState < AISTATE_ALERT ) {
AICast_StateChange( cs, AISTATE_ALERT );
}
if ( cs->aiFlags & AIFL_NOPAIN ) {
return;
}
// process the event (turn to face the attacking direction? go into hide/retreat state?)
// need to weigh up the situation, but foremost, an inactive AI cast should always react in some way to being hurt
cs->lastPain = level.time;
// record the sighting (FIXME: silent weapons shouldn't do this, but the AI should react in some way)
if ( attacker->client ) {
AICast_UpdateVisibility( targ, attacker, qtrue, qtrue );
}
// if either of us are neutral, then we are now enemies
if ( targ->aiTeam == AITEAM_NEUTRAL || attacker->aiTeam == AITEAM_NEUTRAL ) {
cs->vislist[attacker->s.number].flags |= AIVIS_ENEMY;
}
AICast_ScriptEvent( cs, "pain", va( "%d %d", targ->health, targ->health + damage ) );
if ( cs->aiFlags & AIFL_DENYACTION ) {
// dont play any sounds
return;
}
//
// call the painfunc for this cast, so we can play associated sounds, or do any character-specific things
//
if ( cs->painfunc ) {
cs->painfunc( targ, attacker, damage, point );
}
}
/*
============
AICast_Die
============
*/
void AICast_Die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath ) {
int contents;
int killer;
cast_state_t *cs;
qboolean nogib = qtrue;
// print debugging message
if ( aicast_debug.integer == 2 && attacker->s.number == 0 ) {
G_Printf( "killed %s\n", self->aiName );
}
cs = AICast_GetCastState( self->s.number );
if ( attacker ) {
killer = attacker->s.number;
} else {
killer = ENTITYNUM_WORLD;
}
// record the sighting (FIXME: silent weapons shouldn't do this, but the AI should react in some way)
if ( attacker && attacker->client ) {
AICast_UpdateVisibility( self, attacker, qtrue, qtrue );
}
// the zombie should show special effect instead of gibbing
if ( self->aiCharacter == AICHAR_ZOMBIE && cs->secondDeadTime ) {
if ( cs->secondDeadTime > 1 ) {
// we are already totally dead
self->health += damage; // don't drop below gib_health if we weren't already below it
return;
}
/*
if (!cs->rebirthTime)
{
self->health = -999;
damage = 999;
} else if ( self->health >= GIB_HEALTH ) {
// while waiting for rebirth, we only "die" if we drop below gib health
return;
}
*/
// always gib
self->health = -999;
damage = 999;
}
// Zombies are very fragile against highly explosives
if ( self->aiCharacter == AICHAR_ZOMBIE && damage > 20 && inflictor != attacker ) {
self->health = -999;
damage = 999;
}
// process the event
if ( self->client->ps.pm_type == PM_DEAD ) {
// already dead
if ( self->health < GIB_HEALTH ) {
if ( self->aiCharacter == AICHAR_ZOMBIE ) {
// RF, changed this so Zombies always gib now
GibEntity( self, killer );
nogib = qfalse;
self->takedamage = qfalse;
self->r.contents = 0;
cs->secondDeadTime = 2;
cs->rebirthTime = 0;
cs->revivingTime = 0;
} else {
body_die( self, inflictor, attacker, damage, meansOfDeath );
return;
}
}
} else { // this is our first death, so set everything up
if ( level.intermissiontime ) {
return;
}
self->client->ps.pm_type = PM_DEAD;
self->enemy = attacker;
// drop a weapon?
// if client is in a nodrop area, don't drop anything
contents = trap_PointContents( self->r.currentOrigin, -1 );
if ( !( contents & CONTENTS_NODROP ) ) {
TossClientItems( self );
}
// make sure the client doesn't forget about this entity until it's set to "dead" frame
// otherwise it might replay it's death animation if it goes out and into client view
self->r.svFlags |= SVF_BROADCAST;
self->takedamage = qtrue; // can still be gibbed
self->s.weapon = WP_NONE;
self->s.powerups = 0;
self->r.contents = CONTENTS_CORPSE;
self->s.angles[0] = 0;
self->s.angles[1] = self->client->ps.viewangles[1];
self->s.angles[2] = 0;
VectorCopy( self->s.angles, self->client->ps.viewangles );
self->s.loopSound = 0;
self->r.maxs[2] = -8;
self->client->ps.maxs[2] = self->r.maxs[2];
// remove powerups
memset( self->client->ps.powerups, 0, sizeof( self->client->ps.powerups ) );
//cs->rebirthTime = 0;
// never gib in a nodrop
if ( self->health <= GIB_HEALTH ) {
if ( self->aiCharacter == AICHAR_ZOMBIE ) {
// RF, changed this so Zombies always gib now
GibEntity( self, killer );
nogib = qfalse;
} else if ( !( contents & CONTENTS_NODROP ) ) {
body_die( self, inflictor, attacker, damage, meansOfDeath );
//GibEntity( self, killer );
nogib = qfalse;
}
}
// if we are a zombie, and lying down during our first death, then we should just die
if ( !( self->aiCharacter == AICHAR_ZOMBIE && cs->secondDeadTime && cs->rebirthTime ) ) {
// set enemy weapon
BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_WEAPON, 0, qfalse );
if ( attacker && attacker->client ) {
BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_WEAPON, inflictor->s.weapon, qtrue );
} else {
BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_WEAPON, 0, qfalse );
}
// set enemy location
BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_POSITION, 0, qfalse );
if ( infront( self, inflictor ) ) {
BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_POSITION, POSITION_INFRONT, qtrue );
} else {
BG_UpdateConditionValue( self->s.number, ANIM_COND_ENEMY_POSITION, POSITION_BEHIND, qtrue );
}
// play the animation
BG_AnimScriptEvent( &self->client->ps, ANIM_ET_DEATH, qfalse, qtrue );
// set this flag so no other anims override us
self->client->ps.eFlags |= EF_DEAD;
self->s.eFlags |= EF_DEAD;
}
}
if ( nogib ) {
// set for rebirth
if ( self->aiCharacter == AICHAR_ZOMBIE ) {
if ( !cs->secondDeadTime ) {
cs->rebirthTime = level.time + 5000 + rand() % 2000;
cs->secondDeadTime = qtrue;
cs->revivingTime = 0;
} else if ( cs->secondDeadTime > 1 ) {
cs->rebirthTime = 0;
cs->revivingTime = 0;
cs->deathTime = level.time;
}
} else {
// the body can still be gibbed
self->die = body_die;
}
}
trap_LinkEntity( self );
// mark the time of death
cs->deathTime = level.time;
// dying ai's can trigger a target
if ( !cs->rebirthTime ) {
G_UseTargets( self, self );
// really dead now, so call the script
AICast_ScriptEvent( cs, "death", "" );
// call the deathfunc for this cast, so we can play associated sounds, or do any character-specific things
if ( !( cs->aiFlags & AIFL_DENYACTION ) && cs->deathfunc ) {
cs->deathfunc( self, attacker, damage, meansOfDeath ); //----(SA) added mod
}
} else {
// really dead now, so call the script
AICast_ScriptEvent( cs, "fakedeath", "" );
// call the deathfunc for this cast, so we can play associated sounds, or do any character-specific things
if ( !( cs->aiFlags & AIFL_DENYACTION ) && cs->deathfunc ) {
cs->deathfunc( self, attacker, damage, meansOfDeath ); //----(SA) added mod
}
}
}
/*
===============
AICast_EndChase
===============
*/
void AICast_EndChase( cast_state_t *cs ) {
// anything?
}
/*
===============
AICast_AIDoor_Touch
===============
*/
void AICast_AIDoor_Touch( gentity_t *ent, gentity_t *aidoor_trigger, gentity_t *door ) {
cast_state_t *cs, *ocs;
gentity_t *trav;
int i;
trace_t tr;
vec3_t mins, pos, dir;
cs = AICast_GetCastState( ent->s.number );
if ( !cs->bs ) {
return;
}
// does the aidoor have ai_marker's?
if ( !aidoor_trigger->targetname ) {
G_Printf( "trigger_aidoor has no ai_marker's at %s\n", vtos( ent->r.currentOrigin ) );
return;
}
// are we heading for an ai_marker?
if ( cs->aifunc == AIFunc_DoorMarker ) {
return;
}
// if they are moving away from the door, ignore them
if ( VectorLength( cs->bs->velocity ) > 1 ) {
VectorAdd( door->r.absmin, door->r.absmax, pos );
VectorScale( pos, 0.5, pos );
VectorSubtract( pos, cs->bs->origin, dir );
if ( DotProduct( cs->bs->velocity, dir ) < 0 ) {
return;
}
}
for ( trav = NULL; ( trav = G_Find( trav, FOFS( target ), aidoor_trigger->targetname ) ); ) {
// make sure the marker is vacant
trap_Trace( &tr, trav->r.currentOrigin, ent->r.mins, ent->r.maxs, trav->r.currentOrigin, ent->s.number, ent->clipmask );
if ( tr.startsolid ) {
continue;
}
// search all other AI's, to see if they are heading for this marker
for ( i = 0, ocs = AICast_GetCastState( 0 ); i < aicast_maxclients; i++, ocs++ ) {
if ( !ocs->bs ) {
continue;
}
if ( ocs->aifunc != AIFunc_DoorMarker ) {
continue;
}
if ( ocs->doorMarker != trav->s.number ) {
continue;
}
// found a match
break;
}
if ( i < aicast_maxclients ) {
continue;
}
// make sure there is a clear path
VectorCopy( ent->r.mins, mins );
mins[2] += 16; // step height
trap_Trace( &tr, ent->r.currentOrigin, mins, ent->r.maxs, trav->r.currentOrigin, ent->s.number, ent->clipmask );
if ( tr.fraction < 1.0 ) {
continue;
}
// the marker is vacant and available
cs->doorMarkerTime = level.time;
cs->doorMarkerNum = trav->s.number;
cs->doorMarkerDoor = door->s.number;
break;
}
}
/*
============
AICast_ProcessActivate
============
*/
void AICast_ProcessActivate( int entNum, int activatorNum ) {
cast_state_t *cs;
gentity_t *newent, *ent;
cs = AICast_GetCastState( entNum );
ent = &g_entities[entNum];
if ( !AICast_SameTeam( cs, activatorNum ) ) {
if ( ent->aiTeam == AITEAM_NEUTRAL ) {
AICast_ScriptEvent( cs, "activate", g_entities[activatorNum].aiName );
}
return;
}
// try running the activate event, if it denies us the request, then abort
cs->aiFlags &= ~AIFL_DENYACTION;
AICast_ScriptEvent( cs, "activate", g_entities[activatorNum].aiName );
if ( cs->aiFlags & AIFL_DENYACTION ) {
return;
}
// if we are doing something else
if ( cs->castScriptStatus.castScriptEventIndex >= 0 ) {
if ( ent->eventTime != level.time ) {
G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].ordersDenySoundScript ) );
}
return;
}
// if we are already following them, stop following
if ( cs->leaderNum == activatorNum ) {
if ( ent->eventTime != level.time ) {
G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].staySoundScript ) );
}
cs->leaderNum = -1;
// create a goal at this position
newent = G_Spawn();
newent->classname = "AI_wait_goal";
newent->r.ownerNum = entNum;
G_SetOrigin( newent, cs->bs->origin );
AIFunc_ChaseGoalStart( cs, newent->s.number, 128, qtrue );
//AIFunc_IdleStart( cs );
} else { // start following
int count, i;
cast_state_t *tcs;
// if they already have enough followers, deny
for ( count = 0, i = 0, tcs = caststates; i < level.maxclients; i++, tcs++ ) {
if ( tcs->bs && tcs != cs && tcs->entityNum != activatorNum && g_entities[tcs->entityNum].health > 0 && tcs->leaderNum == activatorNum ) {
count++;
}
}
if ( count >= 3 ) {
if ( ent->eventTime != level.time ) {
G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].ordersDenySoundScript ) );
}
return;
}
if ( ent->eventTime != level.time ) {
G_AddEvent( &g_entities[entNum], EV_GENERAL_SOUND, G_SoundIndex( aiDefaults[cs->aiCharacter].followSoundScript ) );
}
// if they have a wait goal, free it
if ( cs->followEntity >= MAX_CLIENTS && g_entities[cs->followEntity].classname && !strcmp( g_entities[cs->followEntity].classname, "AI_wait_goal" ) ) {
G_FreeEntity( &g_entities[cs->followEntity] );
}
cs->followEntity = -1;
cs->leaderNum = activatorNum;
}
}
/*
================
AICast_RecordScriptSound
================
*/
void AICast_RecordScriptSound( int client ) {
cast_state_t *cs;
cs = AICast_GetCastState( client );
cs->lastScriptSound = level.time;
}
|