1 /*
2 ===========================================================================
3 
4 Return to Castle Wolfenstein single player GPL Source Code
5 Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Return to Castle Wolfenstein single player GPL Source Code (“RTCW SP Source Code”).
8 
9 RTCW SP Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 RTCW SP Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with RTCW SP Source Code.  If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the RTCW SP 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 SP Source Code.  If not, please request a copy in writing from id Software at the address below.
23 
24 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.
25 
26 ===========================================================================
27 */
28 
29 //===========================================================================
30 //
31 // Name:			ai_cast.h
32 // Function:		Wolfenstein AI Character Routines
33 // Programmer:		Ridah
34 // Tab Size:		4 (real tabs)
35 //===========================================================================
36 
37 #include "ai_main.h"    // just so we can use the structures
38 #include "ai_dmq3.h"    // just so we can use the structures
39 
40 #include "ai_cast_fight.h"
41 
42 //
43 // constants/defines
44 //
45 #define MAX_AIFUNCS         15      // if we go over this per frame, likely to have an infinite loop
46 //
47 #define SIGHT_PER_SEC       50      // do this many sight iterations per second
48 //
49 // Cast AI specific action flags (get translated into ucmd's
50 #define CASTACTION_WALK     1
51 //
52 #define MAX_SCRIPT_ACCUM_BUFFERS    8
53 //
54 #define AICAST_PRT_ALWAYS   0
55 #define AICAST_PRT_DEBUG    1
56 //
57 #define DEBUG_FOLLOW_DIST   96
58 //
59 #define MAX_LEADER_DIST     256
60 //
61 #define AASWORLD_STANDARD   0
62 #define AASWORLD_LARGE      1
63 //
64 // use this for returning the length of an anim
65 #define ANIMLENGTH( frames,fps )  ( ( frames * 1000 ) / fps )
66 //
67 #define AICAST_TFL_DEFAULT  TFL_DEFAULT & ~( TFL_JUMPPAD | TFL_ROCKETJUMP | TFL_BFGJUMP | TFL_GRAPPLEHOOK | TFL_DOUBLEJUMP | TFL_RAMPJUMP | TFL_STRAFEJUMP | TFL_LAVA ) //----(SA)	modified since slime is no longer deadly
68 //#define AICAST_TFL_DEFAULT	TFL_DEFAULT & ~(TFL_JUMPPAD|TFL_ROCKETJUMP|TFL_BFGJUMP|TFL_GRAPPLEHOOK|TFL_DOUBLEJUMP|TFL_RAMPJUMP|TFL_STRAFEJUMP|TFL_SLIME|TFL_LAVA)
69 //
70 // AI flags
71 #define AIFL_CATCH_GRENADE      0x1
72 #define AIFL_NO_FLAME_DAMAGE    0x2
73 #define AIFL_FIRED              0x4
74 #define AIFL_LAND_ANIM_PLAYED   0x8
75 #define AIFL_ROLL_ANIM          0x10
76 #define AIFL_FLIP_ANIM          0x20
77 #define AIFL_STAND_IDLE2        0x40
78 #define AIFL_NOAVOID            0x80    // if set, this AI will ignore requests for us to move out the way
79 #define AIFL_NOPAIN             0x100   // don't stop for pain anims
80 #define AIFL_WALKFORWARD        0x200   // only walk forward
81 #define AIFL_DENYACTION         0x400   // used by scripting to prevent dynamic code from executing certain behaviour
82 #define AIFL_VIEWLOCKED         0x800   // prevent anything outside movement routines from changing view
83 #define AIFL_CORPSESIGHTING     0x1000  // share information through friendly corpses
84 #define AIFL_WAITINGTOSPAWN     0x2000  // waiting until space is clear to spawn in to the game
85 #define AIFL_JUST_SPAWNED       0x4000
86 #define AIFL_NO_RELOAD          0x8000  // this character doesn't need to reload
87 #define AIFL_TALKING            0x10000
88 #define AIFL_NO_HEADLOOK        0x20000
89 #define AIFL_ATTACK_CROUCH      0x40000
90 #define AIFL_MISCFLAG1          0x80000     // used various bits of code, temporarily
91 #define AIFL_MISCFLAG2          0x100000    // used various bits of code, temporarily
92 #define AIFL_ZOOMING            0x200000
93 #define AIFL_NO_HEADSHOT_DMG    0x400000
94 #define AIFL_DIVE_ANIM          0x800000    // able to dive to cover
95 #define AIFL_NO_TESLA_DAMAGE    0x1000000
96 #define AIFL_EXPLICIT_ROUTING   0x2000000   // direct routing towards ai_markers, rather than using AAS
97 #define AIFL_DISMOUNTING        0x4000000
98 #define AIFL_SPECIAL_FUNC       0x8000000   // prevent external interuption of current think func
99 
100 //
101 // predict events
102 typedef enum
103 {
104 	PREDICTSTOP_NONE,
105 	PREDICTSTOP_HITENT,
106 	PREDICTSTOP_HITCLIENT
107 } predictStop_t;
108 //
109 typedef enum
110 {
111 	AITEAM_NAZI,
112 	AITEAM_ALLIES,
113 	AITEAM_MONSTER,
114 	AITEAM_SPARE1,
115 	AITEAM_SPARE2,
116 	AITEAM_SPARE3,
117 	AITEAM_SPARE4,
118 	AITEAM_NEUTRAL
119 } AITeam_t;
120 //
121 typedef enum
122 {
123 	BBOX_SMALL,
124 	BBOX_LARGE
125 } BBoxType_t;
126 //
127 // attributes
128 // !!! NOTE: any changes to this must be reflected in the attributeStrings in ai_cast.c
129 typedef enum
130 {
131 	RUNNING_SPEED,  // max = 300	(running speed)
132 	WALKING_SPEED,  // max = 300	(walking speed)
133 	CROUCHING_SPEED, // max = 300	(crouching speed)
134 	FOV,            // max = 360	(field of view)
135 	YAW_SPEED,      // max = 300	(yaw speed, so we can make zombie's turn slowly)
136 	LEADER,         // max = 1.0	(ability to lead an AI squadron)
137 	AIM_SKILL,      // max = 1.0	(skill while aiming)
138 	AIM_ACCURACY,   // max = 1.0	(accuracy of firing)
139 	ATTACK_SKILL,   // max = 1.0	(ability to attack and do other things, like retreat)
140 	REACTION_TIME,  // max = 1.0	(upon seeing enemy, wait this long before reaction)
141 	ATTACK_CROUCH,  // max = 1.0	(likely to crouch while firing)
142 	IDLE_CROUCH,    // max = 1.0	(likely to crouch while idling)
143 	AGGRESSION,     // max = 1.0	(willingness to fight till the death)
144 	TACTICAL,       // max = 1.0	(ability to use strategy to their advantage, also behaviour whilst hunting enemy, more likely to creep around)
145 	CAMPER,         // max = 1.0	(set this to make them stay in the spot they are spawned)
146 	ALERTNESS,      // max = 1.0	(ability to notice enemies at long range)
147 	STARTING_HEALTH, // MAX = 999	(starting health)
148 	HEARING_SCALE,  // max = 999	(multiply default hearing ranges by this)
149 	HEARING_SCALE_NOT_PVS,  // max = 999 (multiply hearing range by this if outside PVS)
150 	INNER_DETECTION_RADIUS, // default = 512	(enemies within this range trigger immediate combat mode
151 	PAIN_THRESHOLD_SCALE,   // default = 1.0
152 
153 	AICAST_MAX_ATTRIBUTES
154 
155 } castAttributes_t;
156 //
157 typedef enum
158 {
159 	SIGHTSOUNDSCRIPT,
160 	ATTACKSOUNDSCRIPT,
161 	ORDERSSOUNDSCRIPT,
162 	DEATHSOUNDSCRIPT,
163 	QUIETDEATHSOUNDSCRIPT,  //----(SA)	ADDED FOR SILENT DEATHS (SNIPER/KNIFE)
164 	FLAMEDEATHSOUNDSCRIPT,  //----(SA)	ADDED FOR FLAMING
165 	PAINSOUNDSCRIPT,
166 
167 	STAYSOUNDSCRIPT,
168 	FOLLOWSOUNDSCRIPT,
169 	ORDERSDENYSOUNDSCRIPT,
170 	MISC1SOUNDSCRIPT,
171 
172 	MAX_AI_EVENT_SOUNDS
173 } AIEventSounds_t;
174 //
175 typedef struct {
176 	char *name;
177 	float attributes[AICAST_MAX_ATTRIBUTES];
178 
179 	char    *soundScripts[MAX_AI_EVENT_SOUNDS];
180 
181 	int aiTeam;
182 	char *skin;
183 	int weapons[8];
184 	int bboxType;
185 	vec2_t crouchstandZ;
186 	int aiFlags;
187 
188 	char    *( *aifuncAttack1 )( struct cast_state_s *cs );     //use this battle aifunc for monster_attack1
189 	char    *( *aifuncAttack2 )( struct cast_state_s *cs );     //use this battle aifunc for monster_attack2
190 	char    *( *aifuncAttack3 )( struct cast_state_s *cs );     //use this battle aifunc for monster_attack2
191 
192 	char *loopingSound;     // play this sound constantly while alive
193 
194 	aistateEnum_t aiState;
195 } AICharacterDefaults_t;
196 
197 //
198 // script flags
199 #define SFL_NOCHANGEWEAPON          0x1
200 #define SFL_NOAIDAMAGE              0x2
201 #define SFL_FRIENDLYSIGHTCORPSE_TRIGGERED   0x4
202 #define SFL_WAITING_RESTORE         0x8
203 #define SFL_FIRST_CALL              0x10
204 //
205 // attributes strings (used for per-entity attribute definitions)
206 // NOTE: these must match the attributes above)
207 extern char *castAttributeStrings[];
208 extern AICharacterDefaults_t aiDefaults[NUM_CHARACTERS];
209 //
210 // structure defines
211 //
212 #define AIVIS_ENEMY					1
213 #define AIVIS_INSPECTED				2		// we have inspected them once already
214 #define AIVIS_INSPECT				4		// we should inspect them when we get a chance
215 #define AIVIS_PROCESS_SIGHTING		8		// so we know if we have or haven't processed the sighting since they were last seen
216 #define AIVIS_SIGHT_SCRIPT_CALLED	0x10	// set once sight script has been called.. only call once
217 //
218 // share range
219 #define AIVIS_SHARE_RANGE       384     // if we are within this range of a friendly, share their vis info
220 //
221 #define MAX_CHASE_MARKERS       3
222 #define CHASE_MARKER_INTERVAL   1000
223 //
224 #define COMBAT_TIMEOUT          8000
225 // sight info
226 typedef struct
227 {
228 	int flags;
229 	int lastcheck_timestamp;
230 	int real_visible_timestamp;
231 	int real_update_timestamp;
232 	int real_notvisible_timestamp;
233 	int visible_timestamp;          // time we last recorded a sighting
234 	vec3_t visible_pos;             // position we last knew of them being at (could be hearing, etc)
235 	vec3_t real_visible_pos;        // position we last physically saw them
236 	vec3_t visible_vel;             // velocity during last sighting
237 	int notvisible_timestamp;       // last time we didn't see the entity (used for reaction delay)
238 	vec3_t chase_marker[MAX_CHASE_MARKERS];
239 	int chase_marker_count;
240 	int lastcheck_health;
241 } cast_visibility_t;
242 //
243 // starting weapons, ammo, etc
244 typedef struct
245 {
246 	int startingWeapons[MAX_WEAPONS / ( sizeof( int ) * 8 )];
247 	int startingAmmo[MAX_WEAPONS];          // starting ammo values for each weapon (set to 999 for unlimited)
248 } cast_weapon_info_t;
249 //
250 // scripting
251 typedef struct
252 {
253 	char    *actionString;
254 	qboolean ( *actionFunc )( struct cast_state_s *cs, char *params );
255 } cast_script_stack_action_t;
256 //
257 typedef struct
258 {
259 	//
260 	// set during script parsing
261 	cast_script_stack_action_t      *action;            // points to an action to perform
262 	char                            *params;
263 } cast_script_stack_item_t;
264 //
265 #define AICAST_MAX_SCRIPT_STACK_ITEMS   64
266 //
267 typedef struct
268 {
269 	cast_script_stack_item_t items[AICAST_MAX_SCRIPT_STACK_ITEMS];
270 	int numItems;
271 } cast_script_stack_t;
272 //
273 typedef struct
274 {
275 	int eventNum;                           // index in scriptEvents[]
276 	char                *params;            // trigger targetname, etc
277 	cast_script_stack_t stack;
278 } cast_script_event_t;
279 //
280 typedef struct
281 {
282 	char        *eventStr;
283 	qboolean ( *eventMatch )( cast_script_event_t *event, char *eventParm );
284 } cast_script_event_define_t;
285 //
286 typedef struct
287 {
288 	int castScriptStackHead, castScriptStackChangeTime;
289 	int castScriptEventIndex;       // current event containing stack of actions to perform
290 	// scripting system AI variables (set by scripting system, used directly by AI)
291 	int scriptId;                   // incremented each time the script changes
292 	int scriptFlags;
293 	int scriptNoAttackTime;
294 	int scriptNoMoveTime;
295 	int playAnimViewlockTime;
296 	int scriptGotoEnt;              // just goto them, then resume normal behaviour (don't follow)
297 	int scriptGotoId;
298 	vec3_t scriptWaitPos;
299 	int scriptWaitMovetime;
300 	vec3_t scriptWaitHidePos;
301 	int scriptWaitHideTime;
302 	int scriptNoSightTime;
303 	int scriptAttackEnt;            // we should always attack this AI if they are alive
304 	vec3_t playanim_viewangles;
305 } cast_script_status_t;
306 //
307 typedef struct
308 {
309 	aistateEnum_t currentState;
310 	aistateEnum_t nextState;
311 	int nextStateTimer;             // time left until "newState" is reached
312 } aistate_t;
313 //
314 typedef enum
315 {
316 	MS_DEFAULT,
317 	MS_WALK,
318 	MS_RUN,
319 	MS_CROUCH
320 } movestate_t;
321 //
322 typedef enum
323 {
324 	MSTYPE_NONE,
325 	MSTYPE_TEMPORARY,
326 	MSTYPE_PERMANENT
327 } movestateType_t;
328 //
329 //
330 typedef struct aicast_checkattack_cache_s
331 {
332 	int enemy;
333 	qboolean allowHitWorld;
334 	int time;
335 	int weapon;
336 	qboolean result;
337 } aicast_checkattack_cache_t;
338 //
339 // --------------------------------------------------------------------------------
340 // the main cast structure
341 typedef struct cast_state_s
342 {
343 	bot_state_t     *bs;
344 	int entityNum;
345 
346 	int aasWorldIndex;              // set this according to our bounding box type
347 
348 	// Cast specific information follows. Add to this as needed, this way the bot_state_t structure
349 	// remains untouched.
350 
351 	int aiCharacter;
352 	int aiFlags;
353 	int lastThink;                  // time they last thinked, so we can vary the think times
354 	int actionFlags;                // cast AI specific movement flags
355 	int lastPain, lastPainDamage;
356 	int travelflags;
357 	int thinkFuncChangeTime;
358 
359 	aistateEnum_t aiState;
360 	movestate_t movestate;              // walk, run, crouch etc (can be specified in a script)
361 	movestateType_t movestateType;      // temporary, permanent, etc
362 
363 	float attributes[AICAST_MAX_ATTRIBUTES];
364 	// these define the abilities of each cast AI
365 
366 	// scripting system
367 	int numCastScriptEvents;
368 	cast_script_event_t     *castScriptEvents;  // contains a list of actions to perform for each event type
369 	cast_script_status_t castScriptStatus;      // current status of scripting
370 	cast_script_status_t castScriptStatusCurrent;       // scripting status to use for backups
371 	cast_script_status_t castScriptStatusBackup;    // perm backup of status of scripting, only used by backup and restore commands
372 	int scriptCallIndex;                        // inc'd each time a script is called
373 	int scriptAnimTime, scriptAnimNum;                          // last time an anim was played using scripting
374 	// the accumulation buffer
375 	int scriptAccumBuffer[MAX_SCRIPT_ACCUM_BUFFERS];
376 
377 	//
378 	cast_weapon_info_t  *weaponInfo;    // FIXME: make this a list, so they can have multiple weapons?
379 	cast_visibility_t vislist[MAX_CLIENTS];         // array of all other client entities, allocated at level start-up
380 	int weaponFireTimes[MAX_WEAPONS];
381 
382 	char    *( *aifunc )( struct cast_state_s *cs );            //current AI function
383 	char    *( *oldAifunc )( struct cast_state_s *cs );         // just so we can restore the last aiFunc if required
384 
385 	char    *( *aifuncAttack1 )( struct cast_state_s *cs );     //use this battle aifunc for monster_attack1
386 	char    *( *aifuncAttack2 )( struct cast_state_s *cs );     //use this battle aifunc for monster_attack2
387 	char    *( *aifuncAttack3 )( struct cast_state_s *cs );     //use this battle aifunc for monster_attack2
388 
389 	void ( *painfunc )( gentity_t *ent, gentity_t *attacker, int damage, vec3_t point );
390 	void ( *deathfunc )( gentity_t *ent, gentity_t *attacker, int damage, int mod ); //----(SA)	added mod
391 	void ( *sightfunc )( gentity_t *ent, gentity_t *other, int lastSight );
392 
393 	//int		(*getDeathAnim)(gentity_t *ent, gentity_t *attacker, int damage);
394 	void ( *sightEnemy )( gentity_t *ent, gentity_t *other );
395 	void ( *sightFriend )( gentity_t *ent, gentity_t *other );
396 
397 	void ( *activate )( int entNum, int activatorNum );
398 
399 	//
400 	// !!! NOTE: make sure any entityNum type variables get initialized
401 	//		to -1 in AICast_CreateCharacter(), or they'll be defaulting to
402 	//		the player (index 0)
403 	//
404 
405 	// goal/AI stuff
406 
407 	int followEntity;
408 	float followDist;
409 	qboolean followIsGoto;      // we are really just going to the entity, but should wait until scripting tells us we can stop
410 	int followTime;             // if this runs out, the scripting has probably been interupted
411 	qboolean followSlowApproach;
412 
413 	int leaderNum;              // entnum of player we are following
414 
415 	float speedScale;           // so we can vary movement speed
416 
417 	float combatGoalTime;
418 	vec3_t combatGoalOrigin;
419 
420 	int lastGetHidePos;
421 	int startAttackCount;       // incremented each time we start a standing attack
422 								// used to make sure we only find a combat spot once per attack
423 	int combatSpotAttackCount;
424 	int combatSpotDelayTime;
425 	int startBattleChaseTime;
426 
427 	int blockedTime;            // time they were last blocked by a solid entity
428 	int obstructingTime;        // time that we should move so we are not obstructing someone else
429 	vec3_t obstructingPos;
430 
431 	int blockedAvoidTime;
432 	float blockedAvoidYaw;
433 
434 	int deathTime;
435 	int rebirthTime, revivingTime;
436 
437 	// battle values
438 	int enemyHeight;
439 	int enemyDist;
440 
441 	vec3_t takeCoverPos, takeCoverEnemyPos;
442 	int takeCoverTime;
443 
444 	int attackSpotTime;
445 
446 	int triggerReleaseTime;
447 
448 	int lastWeaponFired;        // set each time a weapon is fired. used to detect when a weapon has been fired from within scripting
449 	vec3_t lastWeaponFiredPos;
450 	int lastWeaponFiredWeaponNum;
451 
452 	// idle behaviour stuff
453 	int lastEnemy, nextIdleAngleChange;
454 	float idleYawChange, idleYaw;
455 
456 	qboolean crouchHideFlag;
457 
458 	int doorMarker, doorEntNum;
459 
460 	// Rafael
461 	int attackSNDtime;
462 	int attacksnd;
463 	int painSoundTime;
464 	int firstSightTime;
465 	qboolean secondDeadTime;
466 	// done
467 
468 	int startGrenadeFlushTime;
469 	int lockViewAnglesTime;
470 	int grenadeFlushEndTime;
471 	int grenadeFlushFiring;
472 
473 	int dangerEntity;
474 	int dangerEntityValidTime;      // dangerEntity is valid until this time expires
475 	vec3_t dangerEntityPos;         // dangerEntity is predicted to end up here
476 	int dangerEntityTimestamp;      // time this danger was recorded
477 	float dangerDist;
478 
479 	int mountedEntity;              // mg42, etc that we have mounted
480 	int inspectBodyTime;
481 	vec3_t startOrigin;
482 
483 	int damageQuota;
484 	int damageQuotaTime;
485 
486 	int dangerLastGetAvoid;
487 	int lastAvoid;
488 
489 	int doorMarkerTime, doorMarkerNum, doorMarkerDoor;
490 
491 	int pauseTime;                  // absolutely don't move move while this is > level.time
492 
493 	aicast_checkattack_cache_t checkAttackCache;
494 
495 	int secretsFound;
496 
497 	int attempts;
498 
499 	qboolean grenadeGrabFlag;       // if this is set, we need to play the anim before we can grab it
500 
501 	vec3_t lastMoveToPosGoalOrg;    // if this changes, we should reset the Bot Avoid Reach
502 
503 	int noAttackTime;               // used by dynamic AI to stop attacking for set time
504 
505 	int lastRollMove;
506 	int lastFlipMove;
507 
508 	vec3_t stimFlyAttackPos;
509 
510 	int lastDodgeRoll;              // last time we rolled to get out of our enemies direct aim
511 	int battleRollTime;
512 
513 	vec3_t viewlock_viewangles;
514 	int grenadeKickWeapon;
515 
516 	int animHitCount;               // for stepping through the frames on which to inflict damage
517 
518 	int totalPlayTime, lastLoadTime;
519 
520 	int queryStartTime, queryCountValidTime, queryCount, queryAlertSightTime;
521 
522 	int lastScriptSound;
523 
524 	int inspectNum;
525 
526 	int scriptPauseTime;
527 
528 	int bulletImpactEntity;
529 	int bulletImpactTime;           // last time we heard/saw a bullet impact
530 	int bulletImpactIgnoreTime;
531 	vec3_t bulletImpactStart, bulletImpactEnd;
532 
533 	int audibleEventTime;
534 	vec3_t audibleEventOrg;
535 	int audibleEventEnt;
536 
537 	int battleChaseMarker, battleChaseMarkerDir;
538 
539 	int lastBattleHunted;           // last time an enemy decided to hunt us
540 	int battleHuntPauseTime, battleHuntViewTime;
541 
542 	int lastAttackCrouch;
543 
544 	int lastMoveThink;          // last time we ran our ClientThink()
545 
546 	int numEnemies;             // last count of enemies that are currently pursuing us
547 
548 	int noReloadTime;           // dont reload prematurely until this time has expired
549 
550 	int lastValidAreaNum[2];        // last valid area within each AAS world
551 	int lastValidAreaTime[2];       // time we last got the area
552 
553 	int weaponNum;              // our current weapon
554 	int enemyNum;               // our current enemy
555 	vec3_t ideal_viewangles, viewangles;
556 	usercmd_t lastucmd;
557 	int attackcrouch_time;
558 	int bFlags;
559 
560 	int deadSinkStartTime;
561 
562 	int lastActivate;
563 
564 	vec3_t loperLeapVel;
565 	// -------------------------------------------------------------------------------------------
566 	// if working on a post release patch, new variables should ONLY be inserted after this point
567 	// -------------------------------------------------------------------------------------------
568 
569 } cast_state_t;
570 //
571 #define CSFOFS( x ) ( (size_t)&( ( (cast_state_t *)0 )->x ) )
572 //
573 typedef struct aicast_predictmove_s
574 {
575 	vec3_t endpos;              //position at the end of movement prediction
576 	vec3_t velocity;            //velocity at the end of movement prediction
577 	int presencetype;           //presence type at end of movement prediction
578 	int stopevent;              //event that made the prediction stop
579 	float time;                 //time predicted ahead
580 	int frames;                 //number of frames predicted ahead
581 	int numtouch;
582 	int touchents[MAXTOUCH];
583 	int groundEntityNum;
584 } aicast_predictmove_t;
585 //
586 // variables/globals
587 //
588 //cast states
589 extern cast_state_t *caststates;
590 //number of characters
591 extern int numcast;
592 //
593 // minimum time between thinks (maximum is double this)
594 extern int aicast_thinktime;
595 // maximum number of character thinks at once
596 extern int aicast_maxthink;
597 // maximum clients
598 extern int aicast_maxclients;
599 // skill scale
600 extern float aicast_skillscale;
601 //
602 // cvar to enable aicast debugging, set higher for more levels of debugging
603 extern vmCvar_t aicast_debug;
604 extern vmCvar_t aicast_debugname;
605 extern vmCvar_t aicast_scripts;
606 //
607 //
608 // procedure defines
609 //
610 // ai_cast.c
611 void    AIChar_SetBBox( gentity_t *ent, cast_state_t *cs, qboolean useHeadTag );
612 void    AICast_Printf( int type, const char *fmt, ... ) __attribute__ ((format (printf, 2, 3)));
613 gentity_t *AICast_CreateCharacter( gentity_t *ent, float *attributes, cast_weapon_info_t *weaponInfo, char *castname, char *model, char *head, char *sex, char *color, char *handicap );
614 void    AICast_Init( void );
615 void    AICast_DelayedSpawnCast( gentity_t *ent, int castType );
616 qboolean AICast_SolidsInBBox( vec3_t pos, vec3_t mins, vec3_t maxs, int entnum, int mask );
617 void    AICast_CheckLevelAttributes( cast_state_t *cs, gentity_t *ent, char **ppStr );
618 //
619 // ai_cast_sight.c
620 void    AICast_SightUpdate( int numchecks );
621 qboolean AICast_VisibleFromPos( vec3_t srcpos, int srcnum,
622 								vec3_t destpos, int destnum, qboolean updateVisPos );
623 void    AICast_UpdateVisibility( gentity_t *srcent, gentity_t *destent, qboolean shareVis, qboolean directview );
624 qboolean AICast_CheckVisibility( gentity_t *srcent, gentity_t *destent );
625 //
626 // ai_cast_debug.c
627 void    AICast_DBG_InitAIFuncs( void );
628 void    AICast_DBG_AddAIFunc( cast_state_t *cs, char *funcname );
629 void    AICast_DBG_ListAIFuncs( cast_state_t *cs, int numprint );
630 void    AICast_DBG_RouteTable_f( vec3_t org, char *param );
631 int     Sys_MilliSeconds( void );
632 void    AICast_DebugFrame( cast_state_t *cs );
633 //
634 // ai_cast_funcs.c
635 void AICast_SpecialFunc( cast_state_t *cs );
636 bot_moveresult_t *AICast_MoveToPos( cast_state_t *cs, vec3_t pos, int entnum );
637 float   AICast_SpeedScaleForDistance( cast_state_t *cs, float startdist, float idealDist );
638 char    *AIFunc_DefaultStart( cast_state_t *cs );
639 char    *AIFunc_IdleStart( cast_state_t *cs );
640 char    *AIFunc_ChaseGoalIdleStart( cast_state_t *cs, int entitynum, float reachdist );
641 char    *AIFunc_ChaseGoalStart( cast_state_t *cs, int entitynum, float reachdist, qboolean slowApproach );
642 char    *AIFunc_BattleChaseStart( cast_state_t *cs );
643 char    *AIFunc_BattleStart( cast_state_t *cs );
644 char    *AIFunc_DoorMarkerStart( cast_state_t *cs, int doornum, int markernum );
645 char    *AIFunc_DoorMarker( cast_state_t *cs );
646 char    *AIFunc_BattleTakeCoverStart( cast_state_t *cs );
647 char    *AIFunc_GrenadeFlushStart( cast_state_t *cs );
648 char    *AIFunc_AvoidDangerStart( cast_state_t *cs );
649 char    *AIFunc_BattleMG42Start( cast_state_t *cs );
650 char    *AIFunc_InspectBodyStart( cast_state_t *cs );
651 char    *AIFunc_GrenadeKickStart( cast_state_t *cs );
652 char    *AIFunc_InspectFriendlyStart( cast_state_t *cs, int entnum );
653 char    *AIFunc_InspectBulletImpactStart( cast_state_t *cs );
654 char    *AIFunc_InspectAudibleEventStart( cast_state_t *cs, int entnum );
655 char    *AIFunc_BattleAmbushStart( cast_state_t *cs );
656 char    *AIFunc_BattleHuntStart( cast_state_t *cs );
657 //
658 // ai_cast_func_attack.c
659 char    *AIFunc_ZombieFlameAttackStart( cast_state_t *cs );
660 char    *AIFunc_ZombieAttack2Start( cast_state_t *cs );
661 char    *AIFunc_ZombieMeleeStart( cast_state_t *cs );
662 char    *AIFunc_LoperAttack1Start( cast_state_t *cs );
663 char    *AIFunc_LoperAttack2Start( cast_state_t *cs );
664 char    *AIFunc_LoperAttack3Start( cast_state_t *cs );
665 char    *AIFunc_StimSoldierAttack1Start( cast_state_t *cs );
666 char    *AIFunc_StimSoldierAttack2Start( cast_state_t *cs );
667 char    *AIFunc_BlackGuardAttack1Start( cast_state_t *cs );
668 char    *AIFunc_RejectAttack1Start( cast_state_t *cs ); //----(SA)
669 char    *AIFunc_WarriorZombieMeleeStart( cast_state_t *cs );
670 char    *AIFunc_WarriorZombieSightStart( cast_state_t *cs );
671 char    *AIFunc_WarriorZombieDefenseStart( cast_state_t *cs );
672 //
673 // ai_cast_func_boss1.c
674 char    *AIFunc_Helga_SpiritAttack_Start( cast_state_t *cs );
675 char    *AIFunc_Helga_MeleeStart( cast_state_t *cs );
676 char    *AIFunc_FlameZombie_PortalStart( cast_state_t *cs );
677 char    *AIFunc_Heinrich_MeleeStart( cast_state_t *cs );
678 char    *AIFunc_Heinrich_RaiseDeadStart( cast_state_t *cs );
679 char    *AIFunc_Heinrich_SpawnSpiritsStart( cast_state_t *cs );
680 void    AICast_Heinrich_SoundPrecache( void );
681 //
682 // ai_cast_fight.c
683 qboolean AICast_StateChange( cast_state_t *cs, aistateEnum_t newaistate );
684 void    AICast_WeaponSway( cast_state_t *cs, vec3_t ofs );
685 int     AICast_ScanForEnemies( cast_state_t *cs, int *enemies );
686 void    AICast_UpdateBattleInventory( cast_state_t *cs, int enemy );
687 float   AICast_Aggression( cast_state_t *cs );
688 int     AICast_WantsToChase( cast_state_t *cs );
689 int     AICast_WantsToTakeCover( cast_state_t *cs, qboolean attacking );
690 qboolean AICast_EntityVisible( cast_state_t *cs, int enemynum, qboolean directview );
691 bot_moveresult_t AICast_CombatMove( cast_state_t *cs, int tfl );
692 qboolean AICast_AimAtEnemy( cast_state_t *cs );
693 qboolean AICast_CheckAttackAtPos( int entnum, int enemy, vec3_t pos, qboolean ducking, qboolean allowHitWorld );
694 qboolean AICast_CheckAttack( cast_state_t *cs, int enemy, qboolean allowHitWorld );
695 void    AICast_ProcessAttack( cast_state_t *cs );
696 void    AICast_ChooseWeapon( cast_state_t *cs, qboolean battleFunc );
697 qboolean AICast_GetTakeCoverPos( cast_state_t *cs, int enemyNum, vec3_t enemyPos, vec3_t returnPos );
698 qboolean AICast_CanMoveWhileFiringWeapon( int weaponnum );
699 float   AICast_GetWeaponSoundRange( int weapon );
700 qboolean AICast_StopAndAttack( cast_state_t *cs );
701 qboolean AICast_WantToRetreat( cast_state_t *cs );
702 int     AICast_SafeMissileFire( gentity_t *ent, int duration, int enemyNum, vec3_t enemyPos, int selfNum, vec3_t endPos );
703 void    AIChar_AttackSound( cast_state_t *cs );
704 qboolean AICast_GotEnoughAmmoForWeapon( cast_state_t *cs, int weapon );
705 qboolean AICast_HostileEnemy( cast_state_t *cs, int enemynum );
706 qboolean AICast_QueryEnemy( cast_state_t *cs, int enemynum );
707 void AICast_AudibleEvent( int srcnum, vec3_t pos, float range );
708 qboolean AICast_WeaponUsable( cast_state_t *cs, int weaponNum );
709 float AICast_WeaponRange( cast_state_t *cs, int weaponnum );
710 
711 //
712 // ai_cast_events.c
713 void    AICast_Pain( gentity_t *targ, gentity_t *attacker, int damage, vec3_t point );
714 void    AICast_Die( gentity_t *self, gentity_t *inflictor, gentity_t *attacker, int damage, int meansOfDeath );
715 void    AICast_Sight( gentity_t *ent, gentity_t *other, int lastSight );
716 void    AICast_EndChase( cast_state_t *cs );
717 void    AICast_ProcessActivate( int entNum, int activatorNum );
718 //
719 // ai_cast_think.c
720 void AICast_Think( int client, float thinktime );
721 void AICast_UpdateInput( cast_state_t *cs, int time );
722 void AICast_InputToUserCommand( cast_state_t * cs, bot_input_t * bi, usercmd_t * ucmd, int delta_angles[3] );
723 void AICast_PredictMovement( cast_state_t *cs, int numframes, float frametime, aicast_predictmove_t *move, usercmd_t *ucmd, int checkHitEnt );
724 void AICast_Blocked( cast_state_t *cs, bot_moveresult_t *moveresult, int activate, bot_goal_t *goal );
725 qboolean AICast_RequestCrouchAttack( cast_state_t *cs, vec3_t org, float time );
726 qboolean AICast_GetAvoid( cast_state_t *cs, bot_goal_t *goal, vec3_t outpos, qboolean reverse, int blockEnt );
727 void AICast_QueryThink( cast_state_t *cs );
728 void AICast_DeadClipWalls( cast_state_t *cs );
729 void AICast_IdleReload( cast_state_t *cs );
730 //
731 // ai_cast_script.c
732 qboolean AICast_ScriptRun( cast_state_t *cs, qboolean force );
733 //
734 // ai_cast_soldier.c
735 void    AIChar_spawn( gentity_t *ent );
736 //
737 // other/external defines
738 void    BotCheckAir( bot_state_t *bs );
739 void    BotUpdateInput( bot_state_t *bs, int time );
740 float   AngleDifference( float ang1, float ang2 );
741 float   BotChangeViewAngle( float angle, float ideal_angle, float speed );
742 void BotInputToUserCommand( bot_input_t * bi, usercmd_t * ucmd, int delta_angles[3] );
743 void    GibEntity( gentity_t *self, int killer );
744 void    GibHead( gentity_t *self, int killer );
745 //
746 extern bot_state_t  *botstates[MAX_CLIENTS];
747