home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / game / ai / AI.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  50KB  |  1,374 lines

  1. /*
  2. ================
  3.  
  4. AI.h
  5.  
  6. ================
  7. */
  8.  
  9. #ifndef __AI_H__
  10. #define __AI_H__
  11.  
  12. // moved all motion related code to AI_Move.h
  13. #ifndef __AI_MOVE_H__
  14.     #include "AI_Move.h"
  15. #endif
  16. #ifndef __AAS_TACTICAL_H__
  17.     #include "AAS_tactical.h"
  18. #endif    
  19.  
  20. typedef enum {
  21.     AITACTICAL_NONE,
  22.     AITACTICAL_MELEE,                    // Rush towards the enemy and perform melee attacks when within range
  23.     AITACTICAL_MOVE_FOLLOW,                // Move towards leader, stop when within range
  24.     AITACTICAL_MOVE_TETHER,                // Move within tether, stop when within tether
  25.     AITACTICAL_MOVE_PLAYERPUSH,            // Move away when the player pushes us (or another ai entity pushes us that was pushe by player)
  26.     AITACTICAL_COVER,                    // Move to cover and perform attacks from that cover position
  27.      AITACTICAL_COVER_FLANK,
  28.      AITACTICAL_COVER_ADVANCE,
  29.      AITACTICAL_COVER_RETREAT,
  30.      AITACTICAL_COVER_AMBUSH,
  31.     AITACTICAL_RANGED,                    // Move to position in which the enemy can be attacked from range, stop when there and attack enemy
  32.     AITACTICAL_TURRET,                    // Stay in current position and attack enemy
  33.     AITACTICAL_HIDE,                    // Move to a position where we cannot be seen by our enemy
  34.     AITACTICAL_PASSIVE,                    // Stay in current position with multiple idles, twitch animations, and conversations
  35.  
  36.     AITACTICAL_MAX
  37. } aiTactical_t;
  38.  
  39. typedef enum  {
  40.     AICTRESULT_OK,
  41.     AICTRESULT_SKIP,
  42.     AICTRESULT_NOMOVE,
  43. } aiCTResult_t;
  44.  
  45. const int AITACTICAL_NONE_BIT                = BIT(AITACTICAL_NONE);
  46. const int AITACTICAL_MELEE_BIT                = BIT(AITACTICAL_MELEE);
  47. const int AITACTICAL_MOVE_FOLLOW_BIT        = BIT(AITACTICAL_MOVE_FOLLOW);
  48. const int AITACTICAL_MOVE_TETHER_BIT        = BIT(AITACTICAL_MOVE_TETHER);
  49. const int AITACTICAL_MOVE_PLAYERPUSH_BIT    = BIT(AITACTICAL_MOVE_PLAYERPUSH);
  50. const int AITACTICAL_COVER_BIT                = BIT(AITACTICAL_COVER);
  51. const int AITACTICAL_COVER_FLANK_BIT        = BIT(AITACTICAL_COVER_FLANK);
  52. const int AITACTICAL_COVER_ADVANCE_BIT        = BIT(AITACTICAL_COVER_ADVANCE);
  53. const int AITACTICAL_COVER_RETREAT_BIT        = BIT(AITACTICAL_COVER_RETREAT);
  54. const int AITACTICAL_COVER_AMBUSH_BIT        = BIT(AITACTICAL_COVER_AMBUSH);
  55. const int AITACTICAL_RANGED_BIT                = BIT(AITACTICAL_RANGED);
  56. const int AITACTICAL_TURRET_BIT                = BIT(AITACTICAL_TURRET);
  57. const int AITACTICAL_HIDE_BIT                = BIT(AITACTICAL_HIDE);
  58. const int AITACTICAL_PASSIVE_BIT            = BIT(AITACTICAL_PASSIVE);
  59.  
  60. const int AITACTICAL_COVER_BITS                = (AITACTICAL_COVER_BIT|AITACTICAL_COVER_FLANK_BIT|AITACTICAL_COVER_ADVANCE_BIT|AITACTICAL_COVER_RETREAT_BIT|AITACTICAL_COVER_AMBUSH_BIT);
  61. const int AITACTICAL_RANGED_BITS            = (AITACTICAL_RANGED_BIT);
  62. const int AITACTICAL_NONMOVING_BITS            = (AITACTICAL_NONE_BIT|AITACTICAL_TURRET_BIT|AITACTICAL_PASSIVE_BIT);
  63.  
  64. typedef enum {
  65.     TALKMSG_NONE,
  66.     TALKMSG_PRIMARY,
  67.     TALKMSG_SECONDARY,
  68.     TALKMSG_LOOP,
  69. } talkMessage_t;
  70.  
  71. typedef enum {
  72.     AIFLAGOVERRIDE_DAMAGE,
  73.     AIFLAGOVERRIDE_DISABLEPAIN,
  74.     AIFLAGOVERRIDE_NOTURN,
  75.     AIFLAGOVERRIDE_NOGRAVITY
  76. } aiFlagOverride_t;
  77.  
  78. typedef enum {
  79.     TALK_NEVER,                        // Never talk to the player
  80.     TALK_DEAD,                        // Cant talk due to being dead
  81.     TALK_OK,                        // Can talk
  82.     TALK_FOLLOW,                    // Talking to will cause a follow
  83.     TALK_BUSY,                        // Cant talk right now, is busy
  84.     TALK_WAIT,                        // Wait a bit - he's probably in the middle of a conversation (this is so you can still see their names but they won't talk to you when clicked on)
  85.     NUM_TALK_STATES
  86. } talkState_t;
  87.  
  88. //chance that AI will make an announcement when they have the option (0 - 1.0f)
  89. #define AISPEAK_CHANCE 0.2f
  90.  
  91. typedef enum {
  92.     AIFOCUS_NONE,
  93.     AIFOCUS_LEADER,
  94.     AIFOCUS_TARGET,
  95.     AIFOCUS_TALK,
  96.     AIFOCUS_PLAYER,
  97.     AIFOCUS_USE_DIRECTIONAL_MOVE,
  98.     AIFOCUS_ENEMY = AIFOCUS_USE_DIRECTIONAL_MOVE,
  99.     AIFOCUS_COVER,
  100.     AIFOCUS_COVERLOOK,
  101.     AIFOCUS_HELPER,
  102.     AIFOCUS_TETHER,
  103.     AIFOCUS_MAX
  104. } aiFocus_t;
  105.  
  106. typedef enum {
  107.     AIMOVESPEED_DEFAULT,            // Choose run/walk depending on situation
  108.     AIMOVESPEED_RUN,                // Always run
  109.     AIMOVESPEED_WALK,                // alwasy walk
  110. } aiMoveSpeed_t;
  111.  
  112. typedef struct rvAIFuncs_s {
  113.     rvScriptFuncUtility        first_sight;        // script to run when an enemy is first sighted
  114.     rvScriptFuncUtility        sight;                // script to run every time an enemy is sighted
  115.     rvScriptFuncUtility        pain;                // script to run when the AI takes pain
  116.     rvScriptFuncUtility        damage;                // script to run when the AI takes damage
  117.     rvScriptFuncUtility        death;                // script to run when the AI dies
  118.     rvScriptFuncUtility        attack;                // script to run when attacking an enemy
  119.     rvScriptFuncUtility        init;                // script to run on initialization
  120.     rvScriptFuncUtility        onclick;            // script to run when a friendly AI is clicked on
  121.     rvScriptFuncUtility        launch_projectile;    // script to run when a projectile is launched
  122.     rvScriptFuncUtility        footstep;            // script to run on a footstep
  123. } rvAIFuncs_t;
  124.  
  125. typedef struct rvAICombat_s{
  126.     struct combatFlags_s {
  127.         bool        ignoreEnemies        :1;
  128.         bool        alert                :1;
  129.          bool        aware                :1;
  130.         bool        tetherNoBreak        :1;                // Set to true to prevent enemies from breaking tethers
  131.         bool        tetherAutoBreak        :1;                // Set to true to automatically break tethers when within range
  132.         bool        tetherOutOfRange    :1;                // Set to true when we are out of range of our curren tether
  133.         bool        seenEnemyDirectly    :1;                // Has directly seen an enemy (as opposed to having heard or been told about him)
  134.         bool        noChatter            :1;                // No combat announcements
  135.         bool        crouchViewClear        :1;                // Can I crouch at the position that I stopped at?
  136.     } fl;
  137.     
  138.     float                    max_chasing_turn;
  139.     float                    shotAtTime;
  140.     float                    shotAtAngle;
  141.     idVec2                    hideRange;
  142.     idVec2                    attackRange;
  143.     int                        attackSightDelay;
  144.     float                    meleeRange;
  145.     float                    aggressiveRange;            // Range to become more aggressive
  146.     float                    aggressiveScale;            // Scale to use when altering numbers due to aggression
  147.      int                        investigateTime;
  148.  
  149.     float                    visStandHeight;                // Height to check enemy visibiliy while standing
  150.     float                    visCrouchHeight;            // Height to check enemy visiblity while crouching
  151.      float                    visRange;                    // Maximum distance to check enemy visibility
  152.      float                    earRange;                    // Maximum distance to check hearing an enemy from
  153.      float                    awareRange;                    // Distance to become automatically aware of an enemy
  154.     
  155.     int                        tacticalMaskAvailable;        // Currently available tactical states
  156.     int                        tacticalMaskUpdate;            // states currently being evaluated
  157.     aiTactical_t            tacticalCurrent;            // Current tactical state    
  158.     int                        tacticalUpdateTime;            // Last time the tacitcal state was updated (for delaying updating)
  159.      int                        tacticalPainTaken;            // Amount of damage taken in the current tactical state
  160.      int                        tacticalPainThreshold;        // Threshold of pain before invalidating the current tactical state
  161.      int                        tacticalFlinches;            // Number of flinches that have occured at the current tactical state
  162.  
  163.     float                    threatBase;                    // Base amount of threat generated by AI
  164.     float                    threatCurrent;                // Current amount of threat generatd by AI based on current state
  165.  
  166.      int                        maxLostVisTime;
  167.  
  168.     int                        coverValidTime;
  169.     int                        maxInvalidCoverTime;
  170. } rvAICombat_t;
  171.  
  172. typedef struct rvAIPain_s {
  173.     float                    threshold;
  174.     float                    takenThisFrame;
  175.     int                        lastTakenTime;
  176.     int                        loopEndTime;
  177.     idStr                    loopType;
  178. } rvAIPain_t;
  179.  
  180. typedef struct rvAIEnemy_s {
  181.     struct flags_s {
  182.         bool        lockOrigin        :1;                    // Stop tracking enemy origin until state changes
  183.         bool        dead            :1;                    // Enemy is dead
  184.         bool        inFov            :1;                    // Enemy is currently in fov
  185.         bool        sighted            :1;                    // Enemy was sighted at least once
  186.         bool        visible            :1;                    // Enemy is visible?
  187.     } fl;
  188.  
  189.     idEntityPtr<idEntity>    ent;
  190.     int                        lastVisibleChangeTime;            // last time the visible state of the enemy changed
  191.     idVec3                    lastVisibleFromEyePosition;        // Origin used in last successfull visibility check
  192.     idVec3                    lastVisibleEyePosition;            // Origin of last known visible eye position
  193.     idVec3                    lastVisibleChestPosition;        // Origin of last known visible chest position
  194.     int                        lastVisibleTime;                // Time we last saw and enemy
  195.  
  196.     idVec3                    smoothedLinearVelocity;            
  197.     idVec3                    smoothedPushedVelocity;            
  198.     float                    smoothVelocityRate;
  199.  
  200.     idVec3                    lastKnownPosition;                // last place the enemy was known to be (does not mean visiblity)
  201.  
  202.     float                    range;                            // range to enemy
  203.     float                    range2d;                        // 2d range to enemy
  204.     int                        changeTime;                        // Time enemy was last changed
  205.     int                        checkTime;                        // Time we last checked for a new enemy
  206. } rvAIEnemy_t;
  207.  
  208. typedef struct rvAIPassive_s {
  209.     struct flags_s {
  210.         bool        disabled        :1;                        // No advanced passive state
  211.         bool        multipleIdles    :1;                        // Has multiple idle animations to play
  212.         bool        fidget            :1;                        // Has fidget animations
  213.     } fl;
  214.  
  215.     idStr                    animIdlePrefix;
  216.     idStr                    animFidgetPrefix;
  217.     idStr                    animTalkPrefix;
  218.     //idStr                    talkPrefix;
  219.     
  220.     idStr                    prefix;
  221.     idStr                    idleAnim;
  222.     int                        idleAnimChangeTime;
  223.     int                        fidgetTime;
  224.     int                        talkTime;
  225. } rvAIPassive_t;
  226.  
  227. typedef struct rvAIAttackAnimInfo_s {
  228.     idVec3                    attackOffset;
  229.     idVec3                    eyeOffset;
  230. } rvAIAttackAnimInfo_t;
  231.  
  232. #define AIACTIONF_ATTACK    BIT(0)
  233. #define AIACTIONF_MELEE        BIT(1)
  234.  
  235. class rvAIActionTimer {
  236. public:
  237.  
  238.     rvAIActionTimer ( void );
  239.  
  240.     bool    Init            ( const idDict& args, const char* name );
  241.                 
  242.     void    Save            ( idSaveGame *savefile ) const;
  243.     void    Restore            ( idRestoreGame *savefile );
  244.                 
  245.     void    Clear            ( int currentTime );
  246.     void    Reset            ( int currentTime, float diversity = 0.0f, float scale = 1.0f );
  247.     void    Add                ( int _time, float diversity = 0.0f );
  248.  
  249.     bool    IsDone            ( int currentTime ) const;
  250.  
  251.     int        GetTime            ( void ) const;
  252.     int        GetRate            ( void ) const;
  253.         
  254. protected:
  255.  
  256.     int            time;
  257.     int            rate;
  258. };
  259.  
  260. ID_INLINE bool rvAIActionTimer::IsDone ( int currentTime ) const {
  261.     return currentTime >= time;
  262. }
  263.  
  264. ID_INLINE int rvAIActionTimer::GetTime ( void ) const {
  265.     return time;
  266. }
  267.  
  268. ID_INLINE int rvAIActionTimer::GetRate ( void ) const {
  269.     return rate;
  270. }
  271. class rvAIAction {
  272. public:
  273.  
  274.     rvAIAction ( void );
  275.     
  276.     bool    Init            ( const idDict& args, const char* name, const char* defaultState, int flags );
  277.  
  278.     void    Save            ( idSaveGame *savefile ) const;
  279.     void    Restore            ( idRestoreGame *savefile );
  280.     
  281.     enum EStatus {
  282.         STATUS_UNUSED,
  283.         STATUS_OK,                                // action was performed
  284.         STATUS_FAIL_DISABLED,                    // action is current disabled
  285.         STATUS_FAIL_TIMER,                        // actions timer has not finished
  286.         STATUS_FAIL_EXTERNALTIMER,                // external timer passed in to PerformAction has not finished
  287.         STATUS_FAIL_MINRANGE,                    // enemy is not within minimum range
  288.         STATUS_FAIL_MAXRANGE,                    // enemy is out of maximum range
  289.         STATUS_FAIL_CHANCE,                        // action chance check failed
  290.         STATUS_FAIL_ANIM,                        // bad animation
  291.         STATUS_FAIL_CONDITION,                    // condition given to PerformAction failed
  292.         STATUS_FAIL_NOENEMY,                    // enemy cant be attacked
  293.         STATUS_MAX
  294.     };
  295.     
  296.     struct flags_s {
  297.         bool        disabled            :1;        // action disabled?
  298.         bool        noPain                :1;        // no pain during action
  299.         bool        noTurn                :1;        // no turning during action
  300.         bool        isAttack            :1;        // attack?
  301.         bool        isMelee                :1;        // melee?
  302.         bool        overrideLegs        :1;        // override legs on this action?
  303.         bool        noSimpleThink        :1;        // dont use simple think logic for this action
  304.     } fl;
  305.     
  306.     
  307.     idStrList            anims;
  308.     idStr                state;
  309.  
  310.     rvAIActionTimer        timer;
  311.     
  312.     int                    blendFrames;
  313.     int                    failRate;
  314.     
  315.     float                minRange;
  316.     float                maxRange;
  317.     float                minRange2d;
  318.     float                maxRange2d;
  319.     
  320.     float                chance;
  321.     float                diversity;
  322.     
  323.     EStatus                status;
  324. };
  325.  
  326. typedef bool (idAI::*checkAction_t)(rvAIAction*,int);
  327.  
  328. class rvPlaybackDriver
  329. {
  330. public:
  331.                             rvPlaybackDriver( void ) { mPlaybackDecl = NULL; mOldPlaybackDecl = NULL; }
  332.  
  333.     bool                    Start( const char *playback, idEntity *owner, int flags, int numFrames );
  334.     bool                    UpdateFrame( idEntity *ent, rvDeclPlaybackData &out );
  335.     void                    EndFrame( void );
  336.     bool                    IsActive( void ) { return( !!mPlaybackDecl || !!mOldPlaybackDecl ); }
  337.  
  338.     const char                *GetDestination( void );
  339.  
  340. // cnicholson: Begin  Added save/restore functionality
  341.     void                    Save            ( idSaveGame *savefile ) const;
  342.     void                    Restore            ( idRestoreGame *savefile );
  343. // cnicholson: End  Added save/restore functionality
  344.  
  345. private:
  346.     int                        mLastTime;
  347.     int                        mTransitionTime;
  348.  
  349.     int                        mStartTime;
  350.     int                        mFlags;
  351.     const rvDeclPlayback    *mPlaybackDecl;
  352.     idVec3                    mOffset;
  353.  
  354.     int                        mOldStartTime;
  355.     int                        mOldFlags;
  356.     const rvDeclPlayback    *mOldPlaybackDecl;
  357.     idVec3                    mOldOffset;
  358. };
  359.  
  360. /*
  361. ===============================================================================
  362.  
  363.     idAI
  364.  
  365. ===============================================================================
  366. */
  367.  
  368. const float    AI_TURN_SCALE                = 60.0f;
  369. const float    AI_SEEK_PREDICTION            = 0.3f;
  370. const float    AI_FLY_DAMPENING            = 0.15f;
  371. const float    AI_HEARING_RANGE            = 2048.0f;
  372. const float AI_COVER_MINRANGE            = 4.0f;
  373. const float AI_PAIN_LOOP_DELAY            = 200;
  374. const int    DEFAULT_FLY_OFFSET            = 68.0f;
  375.  
  376. #define ATTACK_IGNORE                    0
  377. #define ATTACK_ON_DAMAGE                BIT(0)
  378. #define ATTACK_ON_ACTIVATE                BIT(1)
  379. #define ATTACK_ON_SIGHT                    BIT(2)
  380.  
  381. // defined in script/ai_base.script.  please keep them up to date.
  382.  
  383. #define    DI_NODIR    -1
  384.  
  385.  
  386. //
  387. // events
  388. //
  389. extern const idEventDef AI_DirectDamage;
  390. extern const idEventDef AI_JumpFrame;
  391. extern const idEventDef AI_EnableClip;
  392. extern const idEventDef AI_DisableClip;
  393. extern const idEventDef AI_EnableGravity;
  394. extern const idEventDef AI_DisableGravity;
  395. extern const idEventDef AI_EnablePain;
  396. extern const idEventDef AI_DisablePain;
  397. extern const idEventDef AI_EnableTarget;
  398. extern const idEventDef AI_DisableTarget;
  399. extern const idEventDef AI_EnableMovement;
  400. extern const idEventDef AI_DisableMovement;
  401. extern const idEventDef AI_Vagary_ChooseObjectToThrow;
  402. extern const idEventDef AI_Speak;
  403. extern const idEventDef AI_SpeakRandom;
  404. extern const idEventDef AI_Attack;
  405. extern const idEventDef AI_AttackMelee;
  406. extern const idEventDef AI_WaitMove;
  407. extern const idEventDef AI_EnableDamage;
  408. extern const idEventDef AI_DisableDamage;
  409. extern const idEventDef AI_LockEnemyOrigin;
  410. extern const idEventDef AI_SetEnemy;
  411. extern const idEventDef AI_ScriptedAnim;
  412. extern const idEventDef AI_ScriptedDone;
  413. extern const idEventDef AI_ScriptedStop;
  414. extern const idEventDef AI_SetScript;
  415. extern const idEventDef AI_BecomeSolid;
  416. extern const idEventDef AI_BecomePassive;
  417. extern const idEventDef AI_BecomeAggressive;
  418. extern const idEventDef AI_SetHealth;
  419. extern const idEventDef AI_TakeDamage;
  420. extern const idEventDef AI_EnableBlink;
  421. extern const idEventDef AI_DisableBlink;
  422. extern const idEventDef AI_EnableAutoBlink;
  423. extern const idEventDef AI_DisableAutoBlink;
  424.  
  425. class idPathCorner;
  426. class idProjectile;
  427. class rvSpawner;
  428. class rvAIHelper;
  429. class rvAITether;
  430.  
  431. class idAI : public idActor {
  432. friend class rvAIManager;
  433. friend class idAASFindAttackPosition;
  434. public:
  435.     CLASS_PROTOTYPE( idAI );
  436.  
  437.                             idAI();
  438.                             ~idAI();
  439.  
  440.     void                    Save                            ( idSaveGame *savefile ) const;
  441.     void                    Restore                            ( idRestoreGame *savefile );
  442.  
  443.     void                    Spawn                            ( void );
  444.     virtual void            TalkTo                            ( idActor *actor );
  445.  
  446.     idEntity*                GetEnemy                        ( void ) const;
  447.      idEntity*                GetGoalEntity                    ( void ) const;
  448.     talkState_t                GetTalkState                    ( void ) const;
  449.     const idVec2&            GetAttackRange                    ( void ) const;
  450.     const idVec2&            GetFollowRange                    ( void ) const;
  451.     int                        GetTravelFlags                    ( void ) const;
  452.  
  453.     void                    TouchedByFlashlight                ( idActor *flashlight_owner );
  454.  
  455.      idEntity *                FindEnemy                        ( bool inFov, bool forceNearest, float maxDistSqr = 0.0f );
  456.     void                    SetSpawner                        ( rvSpawner* _spawner );
  457.     rvSpawner*                GetSpawner                        ( void );
  458.  
  459.     idActor*                GetLeader                        ( void ) const;
  460.  
  461.                             // Outputs a list of all monsters to the console.
  462.     static void                List_f( const idCmdArgs &args );
  463.  
  464.  
  465.     // Add some dynamic externals for debugging
  466.     virtual void            GetDebugInfo                    ( debugInfoProc_t proc, void* userData );
  467.  
  468.  
  469.        bool                    IsEnemyVisible                    ( void ) const;
  470.       bool                    InCoverMode                        ( void ) const;
  471.       bool                    InCrouchCoverMode                ( void ) const;
  472.      bool                    LookAtCoverTall                    ( void ) const;
  473.      bool                    InLookAtCoverMode                ( void ) const;
  474.      bool                    IsBehindCover                    ( void ) const;
  475.      bool                    IsLipSyncing                    ( void ) const;
  476.      bool                    IsSpeaking                        ( void ) const;
  477.        bool                    IsFacingEnt                        ( idEntity* targetEnt );
  478.      bool                    IsCoverValid                    ( void ) const;
  479.     virtual bool            IsCrouching                        ( void ) const;
  480.  
  481.  
  482. public:
  483.  
  484.     idLinkList<idAI>        simpleThinkNode;
  485.  
  486.     // navigation
  487.     idAAS*                    aas;
  488.     idAASCallback*            aasFind;
  489.  
  490.     // movement
  491.     idMoveState                move;
  492.     idMoveState                savedMove;
  493.  
  494.     // physics
  495.     idPhysics_Monster        physicsObj;
  496.     
  497.     // weapon/attack vars
  498.     bool                    lastHitCheckResult;
  499.     int                        lastHitCheckTime;
  500.     int                        lastAttackTime;
  501.     float                    projectile_height_to_distance_ratio;    // calculates the maximum height a projectile can be thrown
  502.     idList<rvAIAttackAnimInfo_t>    attackAnimInfo;
  503.     
  504.     mutable idClipModel*    projectileClipModel;
  505.     idEntityPtr<idProjectile> projectile;
  506.  
  507.     // chatter/talking
  508.     int                        chatterTime;
  509.     int                        chatterRateCombat;
  510.     int                        chatterRateIdle;
  511.     talkState_t                talkState;
  512.     idEntityPtr<idActor>    talkTarget;
  513.     talkMessage_t            talkMessage;
  514.     int                        talkBusyCount;
  515.     int                        speakTime;
  516.  
  517.     // Focus
  518.     idEntityPtr<idEntity>    lookTarget;
  519.     aiFocus_t                focusType;    
  520.     idEntityPtr<idEntity>    focusEntity;
  521.     float                    focusRange;
  522.     int                        focusAlignTime;
  523.     int                        focusTime;
  524.     idVec3                    currentFocusPos;
  525.  
  526.     // Looking
  527.     bool                    allowJointMod;
  528.     int                        alignHeadTime;
  529.     int                        forceAlignHeadTime;
  530.     idAngles                eyeAng;
  531.     idAngles                lookAng;
  532.     idAngles                destLookAng;
  533.     idAngles                lookMin;
  534.     idAngles                lookMax;
  535.     idList<jointHandle_t>    lookJoints;
  536.     idList<idAngles>        lookJointAngles;
  537.     float                    eyeVerticalOffset;
  538.     float                    eyeHorizontalOffset;
  539.     float                    headFocusRate;
  540.     float                    eyeFocusRate;
  541.     
  542.     // joint controllers
  543.     idAngles                eyeMin;
  544.     idAngles                eyeMax;
  545.     jointHandle_t            orientationJoint;
  546.  
  547.     idEntityPtr<idEntity>    pusher;
  548.     idEntityPtr<idEntity>    scriptedActionEnt;
  549.  
  550.     // script variables
  551.     struct aiFlags_s {
  552.         bool        awake                    :1;            // set to false until state_wakeup is called.
  553.         bool        damage                    :1;
  554.         bool        pain                    :1;
  555.         bool        dead                    :1;
  556.         bool        activated                :1;
  557.         bool        jump                    :1;
  558.         bool        hitEnemy                :1;
  559.         bool        pushed                    :1;
  560.         bool        disableAttacks            :1;
  561.         bool        scriptedEndWithIdle     :1;
  562.         bool        scriptedNeverDormant    :1;            // Prevent going dormant while in scripted sequence
  563.         bool        scripted                :1;
  564.         bool        simpleThink                :1;
  565.         bool        ignoreFlashlight        :1;
  566.         bool        action                    :1;
  567.         bool        lookAtPlayer            :1;
  568.         bool        disableLook                :1;
  569.         bool        undying                    :1;
  570.         bool        tetherMover                :1;            // Currently using a dynamic tether to a mover
  571.         bool        meleeSuperhero            :1;
  572.         bool        killerGuard                :1;            // Do 100 points of damage with each hit
  573.     } aifl;
  574.     
  575.     //
  576.     // ai/ai.cpp
  577.     //
  578.     void                    SetAAS                            ( void );
  579.     virtual    void            DormantBegin                    ( void );        // called when entity becomes dormant
  580.     virtual    void            DormantEnd                        ( void );        // called when entity wakes from being dormant
  581.     virtual void            Think                            ( void );
  582.     void                    Activate                        ( idEntity *activator );
  583.     virtual void            Hide                            ( void );
  584.     virtual void            Show                            ( void );
  585.     virtual void            AdjustHealthByDamage            ( int inDamage );
  586.     void                    CalculateAttackOffsets            ( void );
  587.  
  588.     void                    InitNonPersistentSpawnArgs        ( void );    
  589.  
  590.     /*
  591.     ===============================================================================
  592.                                     Speaking & Chatter
  593.     ===============================================================================
  594.     */
  595. public:
  596.  
  597.     bool                    Speak                            ( const char *speechDecl, bool random = false );
  598.      void                    StopSpeaking                    ( bool stopAnims );
  599.     virtual void            CheckBlink                        ( void );
  600.  
  601. protected:
  602.  
  603.     virtual bool            CanPlayChatterSounds            ( void ) const;
  604.     void                    UpdateChatter                    ( void );
  605.  
  606.  
  607.     /*
  608.     ===============================================================================
  609.                                     Movement
  610.     ===============================================================================
  611.     */
  612.  
  613.     // static helper functions
  614. public:
  615.                             // Finds a path around dynamic obstacles.
  616.     static bool                FindPathAroundObstacles            ( const idPhysics *physics, const idAAS *aas, const idEntity *ignore, const idVec3 &startPos, const idVec3 &seekPos, obstaclePath_t &path );
  617.                             // Frees any nodes used for the dynamic obstacle avoidance.
  618.     static void                FreeObstacleAvoidanceNodes        ( void );
  619.                             // Predicts movement, returns true if a stop event was triggered.
  620.     static bool                PredictPath                        ( const idEntity *ent, const idAAS *aas, const idVec3 &start, const idVec3 &velocity, int totalTime, int frameTime, int stopEvent, predictedPath_t &path, const idEntity *ignore = NULL );
  621.                             // Return true if the trajectory of the clip model is collision free.
  622.     static bool                TestTrajectory                    ( const idVec3 &start, const idVec3 &end, float zVel, float gravity, float time, float max_height, const idClipModel *clip, int clipmask, const idEntity *ignore, const idEntity *targetEntity, int drawtime );
  623.                             // Finds the best collision free trajectory for a clip model.
  624.     static bool                PredictTrajectory                ( const idVec3 &firePos, const idVec3 &target, float projectileSpeed, const idVec3 &projGravity, const idClipModel *clip, int clipmask, float max_height, const idEntity *ignore, const idEntity *targetEntity, int drawtime, idVec3 &aimDir );
  625.  
  626.  
  627.     // special flying code
  628.     void                    AdjustFlyingAngles                ( void );
  629.     void                    AddFlyBob                        ( idVec3 &vel );
  630.     void                    AdjustFlyHeight                    ( idVec3 &vel, const idVec3 &goalPos );
  631.     void                    FlySeekGoal                        ( idVec3 &vel, idVec3 &goalPos );
  632.     void                    AdjustFlySpeed                    ( idVec3 &vel );
  633.     void                    FlyTurn                            ( void );
  634.  
  635.     // movement types
  636.     void                    Move                            ( void );
  637.     virtual    void            DeadMove                        ( void );
  638.     void                    AnimMove                        ( void );
  639.     void                    SlideMove                        ( void );
  640.     void                    PlaybackMove                    ( void );
  641.     void                    FlyMove                            ( void );
  642.     void                    StaticMove                        ( void );
  643.     void                    RVMasterMove                    ( void );
  644.     void                    SetMoveType                        ( moveType_t moveType );
  645.     //twhitaker: added custom move type
  646.     virtual void            CustomMove                        ( void );
  647.  
  648.     // movement actions
  649.     void                    KickObstacles                    ( const idVec3 &dir, float force, idEntity *alwaysKick );
  650.  
  651.     // steering
  652.     virtual void            ApplyImpulse                    ( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse, bool splash = false );
  653.     void                    GetAnimMoveDelta                ( const idMat3 &oldaxis, const idMat3 &axis, idVec3 &delta );
  654.     void                    CheckObstacleAvoidance            ( const idVec3 &goalPos, idVec3 &newPos, idReachability* goalReach=0  );
  655.     bool                    GetMovePos                        ( idVec3 &seekPos, idReachability** seekReach=0 );
  656.  
  657.  
  658.     // navigation
  659.     float                    TravelDistance                    ( const idVec3 &end ) const;
  660.     float                    TravelDistance                    ( const idVec3 &start, const idVec3 &end ) const;
  661.     float                    TravelDistance                    ( idEntity* ent ) const;
  662.     float                    TravelDistance                    ( idEntity* start, idEntity* end ) const;
  663.     int                        PointReachableAreaNum            ( const idVec3 &pos, const float boundsScale = 2.0f ) const;
  664.     bool                    PathToGoal                        ( aasPath_t &path, int areaNum, const idVec3 &origin, int goalAreaNum, const idVec3 &goalOrigin ) const;
  665.     void                    BlockedFailSafe                    ( void );
  666.  
  667.     // turning
  668.     void                    Turn                            ( void );
  669.     bool                    TurnToward                        ( float yaw );
  670.     bool                    TurnToward                        ( const idVec3 &pos );
  671.     bool                    TurnTowardLeader                ( bool faceLeaderByDefault=false );
  672.     bool                    FacingIdeal                        ( void );
  673.     bool                    DirectionalTurnToward            ( const idVec3 &pos );
  674.  
  675.     // movement control
  676.     bool                    FaceEnemy                        ( void );
  677.     bool                    FaceEntity                        ( idEntity *ent );
  678.       bool                    SlideToPosition                    ( const idVec3 &pos, float time );
  679.      bool                    WanderAround                    ( void );
  680.     bool                    StepDirection                    ( float dir );
  681.     bool                    NewWanderDir                    ( const idVec3 &dest );
  682.  
  683.  
  684.     /*
  685.     ===============================================================================
  686.                                     Reactions
  687.     ===============================================================================
  688.     */
  689.     void                    ReactToShotAt                    ( idEntity* attacker, const idVec3 &origOrigin, const idVec3 &origDir );
  690.     void                    ReactToPain                        ( idEntity* attacker, int damage );
  691.  
  692.     /*
  693.     ===============================================================================
  694.                                     AI helpers
  695.     ===============================================================================
  696.     */
  697.  
  698. public:
  699.  
  700.     void                    UpdateHelper                    ( void );
  701.     rvAIHelper*                GetActiveHelper                    ( void );
  702.  
  703.     /*
  704.     ===============================================================================
  705.                                     Sensory Perception
  706.     ===============================================================================
  707.     */
  708.  
  709. public:
  710.  
  711.     const idVec3&            LastKnownPosition                ( const idEntity *ent );
  712.     const idVec3&            LastKnownFacing                    ( const idEntity *ent );
  713.     idEntity *                HeardSound                        ( int ignore_team );
  714.     int                        ReactionTo                        ( const idEntity *ent );
  715.     void                    SetLastVisibleEnemyTime            ( int time=-1/* DEFAULT IS CURRENT TIME*/ );
  716.     bool                    IsEnemyRecentlyVisible            ( float maxLostVisTimeScale = 1.0f ) const;
  717.  
  718.     /*
  719.     ===============================================================================
  720.                                     Passive
  721.     ===============================================================================
  722.     */
  723.  
  724. public:
  725.  
  726.     void                    SetTalkState                    ( talkState_t state );
  727.     void                    SetPassivePrefix                ( const char* prefix );
  728.  
  729. protected:
  730.  
  731.     bool                    GetPassiveAnimPrefix            ( const char* animName, idStr& animPrefix );
  732.  
  733.     /*
  734.     ===============================================================================
  735.                                     Combat
  736.     ===============================================================================
  737.     */
  738.  
  739. public:
  740.  
  741.     // enemy managment
  742.     bool                    SetEnemy                        ( idEntity *newEnemy );
  743.     void                    ClearEnemy                        ( bool dead = false );
  744.  
  745.     void                    UpdateEnemy                        ( void );
  746.     void                    UpdateEnemyPosition                ( bool force = true );
  747.     void                    UpdateEnemyVisibility            ( void );
  748.  
  749.     // Attack direction
  750.     bool                    GetAimDir                        ( const idVec3& source, const idEntity* aimAtEnt, const idDict* projectileDict, idEntity *ignore, idVec3 &aimDir, float aimOffset, float predict ) const;
  751.     void                    GetPredictedAimDirOffset        ( const idVec3& source, const idVec3& target, float projectileSpeed, const idVec3& targetVelocity, idVec3& offset ) const;
  752.  
  753.     // damage
  754.     virtual bool            Pain                            ( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  755.     virtual void            Killed                            ( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  756.     bool                    CheckDeathCausesMissionFailure    ( void );
  757.  
  758.     // attacks
  759.     virtual bool            Attack                            ( const char* attackName, jointHandle_t joint, idEntity* target, const idVec3& pushVelocity = vec3_origin );
  760.     virtual idProjectile*    AttackRanged                    ( const char* attackName, const idDict* attackDict, jointHandle_t joint, idEntity* target, const idVec3& pushVelocity = vec3_origin );
  761.     virtual idProjectile*    AttackProjectile                ( const idDict* projectileDict, const idVec3 &org, const idAngles &ang );
  762.     virtual bool            AttackMelee                        ( const char* attackName, const idDict* meleeDict );
  763.     
  764.     void                    CreateProjectileClipModel        ( void ) const;
  765.     idProjectile*            CreateProjectile                ( const idDict* projectileDict, const idVec3 &pos, const idVec3 &dir );
  766.     void                    RemoveProjectile                ( void );
  767.     virtual void            DamageFeedback                    ( idEntity *victim, idEntity *inflictor, int &damage );
  768.     void                    DirectDamage                    ( const char *meleeDefName, idEntity *ent );
  769.     bool                    TestMelee                        ( void ) const;
  770.     void                    PushWithAF                        ( void );
  771.     bool                    IsMeleeNeeded                    ( void );
  772.  
  773.     // special effects
  774.     void                    GetMuzzle                        ( jointHandle_t joint, idVec3 &muzzle, idMat3 &axis );
  775.     void                    LerpLookAngles                    ( idAngles &curAngles, idAngles newAngles, float orientationJointYaw, float focusRate );
  776.     virtual bool            UpdateAnimationControllers        ( void );
  777.  
  778.     // AI script state management
  779.     void                    UpdateStates                    ( void );
  780.     void                    UpdateFocus                        ( const idMat3& orientationAxis );
  781.     void                    SetFocus                        ( aiFocus_t focus, int time );
  782.  
  783.     // event?
  784.     virtual void            FootStep                        ( void );
  785.  
  786.     void                    CreateMissile                    ( jointHandle_t joint  );
  787.     void                    RadiusDamageFromJoint            ( const char *jointname, const char *damageDefName );
  788.     void                    BecomeSolid                        ( void );
  789.     void                    BecomeNonSolid                    ( void );
  790.     const char *            ChooseAnim                        ( int channel, const char *animname );
  791.  
  792.     //
  793.     // ai/ai_events.cpp
  794.     //
  795. public:
  796.  
  797.  
  798.     virtual bool            CanTakeDamage                    ( void ) const;
  799.     virtual bool            CanTakePain                        ( void ) const;
  800.     virtual bool            CanTurn                            ( void ) const;
  801.     virtual bool            CanMove                            ( void ) const;
  802.     virtual bool            CanAnnounce                        ( float chance ) const;
  803.  
  804.     virtual bool            SkipCurrentDestination            ( void ) const;
  805.  
  806. // ----------------------------- Functions ------------------------------------
  807.  
  808.     virtual bool            DoDormantTests                    ( void );
  809.  
  810.     void                    OverrideFlag                    ( aiFlagOverride_t flag, bool value );
  811.     void                    RestoreFlag                        ( aiFlagOverride_t flag );
  812.  
  813.     virtual bool            SkipImpulse                        ( idEntity *ent, int id );
  814.     
  815.     virtual const char*        GetIdleAnimName                    ( void );
  816.  
  817.     bool                    RespondToFlashlight                ( void )                { return !aifl.ignoreFlashlight;}
  818.     bool                    ForceFaceEnemy                    ( void )                { return ( move.moveCommand == MOVE_TO_ENEMY ); }
  819.  
  820.     bool                    CanBecomeSolid                    ( void );
  821.     bool                    CanHitEnemyFromAnim                ( int animNum, idVec3 offset = vec3_origin );
  822.     bool                    CanHitEnemy                        ( void );
  823.     bool                    CanHitEnemyFromJoint            ( const char *jointname );
  824.  
  825.     float                    GetTurnDelta                    ( void );
  826.  
  827.     int                        TestTrajectory                    ( const idVec3 &firePos, const idVec3 &target, const char *projectileName );
  828.     bool                    TestAnimMove                    ( int animNum, idEntity *ignore = NULL, idVec3 *pMoveVec = NULL );
  829.     void                    ExecScriptFunction                ( rvScriptFuncUtility& func, idEntity* parm = NULL );
  830.     void                    SetLeader                        ( idEntity *newLeader );
  831.  
  832.     int                        CheckMelee                        ( bool disableAttack );
  833.     bool                    CheckForEnemy                    ( bool useFov, bool force = false );
  834.      bool                    CheckForCloserEnemy                ( void );
  835.      bool                    CheckForReplaceEnemy            ( idEntity* replacement );
  836.     bool                    CheckForTeammateEnemy            ( void );
  837.  
  838.      void                    DrawSuspicion                    ( void );
  839.      float                    RateSuspiciousness                ( idActor* shady, bool rateSound = false );
  840.      void                    RateSuspicionLevel                ( void );
  841.  
  842.     void                    UpdatePlayback                    ( idVec3 &goalPos, idVec3 &delta, idVec3 &oldorigin, idMat3 &oldaxis );
  843.  
  844.     void                    LookAtEntity                    ( idEntity *ent, float duration );
  845.  
  846. // ----------------------------- Variables ------------------------------------
  847.  
  848.     int                        actionAnimNum;            // Index of animation to use for the upcoming action
  849.     int                        actionTime;                // Time line for actions (time is stopped when an action is running)
  850.     int                        actionSkipTime;            // Time to use if an action is skipped by another
  851.  
  852.     int                        flagOverrides;
  853.  
  854.     float                    announceRate;            // How often (0 - 1.0f) the AI will make certain announcements.
  855.  
  856.     rvAICombat_t            combat;                    // Members related to combat state
  857.     rvAIPassive_t            passive;                // Members related to passive state
  858.     rvAIEnemy_t                enemy;                    // Members related to tracking enemies
  859.     rvAIPain_t                pain;
  860.     rvAIFuncs_t                funcs;
  861.  
  862.     rvPlaybackDriver        mPlayback;
  863.     rvPlaybackDriver        mLookPlayback;
  864.  
  865.     rvAASTacticalSensor*    aasSensor;
  866.  
  867.     idEntityPtr<rvAITether>    tether;
  868.     idEntityPtr<rvAIHelper>    helperCurrent;
  869.     idEntityPtr<rvAIHelper>    helperIdeal;
  870.     idEntityPtr<idActor>    leader;
  871.     idEntityPtr<rvSpawner>    spawner;
  872.  
  873.     bool                        ValidateCover                    ( void );
  874.  
  875.     virtual bool                UpdateRunStatus                    ( void );
  876.     bool                        UpdateTactical                    ( int delay = 0 );
  877.     void                        ForceTacticalUpdate                ( void );
  878.     bool                        UpdateTactical_r                ( void );
  879.     virtual int                    FilterTactical                    ( int availableTactical );
  880.     void                        WakeUpTargets                    ( void );
  881.  
  882.     virtual aiCTResult_t        CheckTactical                    ( aiTactical_t tactical );
  883.  
  884.     void                        Begin                            ( void );
  885.     void                        WakeUp                            ( void );
  886.  
  887.     virtual void                Prethink                        ( void );
  888.     virtual void                Postthink                        ( void );
  889.  
  890.     /*
  891.     ===============================================================================
  892.                               Threat Management
  893.     ===============================================================================
  894.     */
  895.  
  896. protected:
  897.  
  898.     virtual void            UpdateThreat                    ( void );
  899.     virtual float            CalculateEnemyThreat            ( idEntity* enemy );
  900.  
  901.     /*
  902.     ===============================================================================
  903.                                     Tethers
  904.     ===============================================================================
  905.     */
  906.  
  907. public:
  908.  
  909.     virtual bool            IsTethered                        ( void ) const;
  910.     bool                    IsWithinTether                    ( void ) const;
  911.     rvAITether*                GetTether                        ( void );
  912.     virtual void            SetTether                        ( rvAITether* newTether );
  913.  
  914.     /*
  915.     ===============================================================================
  916.                                     Scripting
  917.     ===============================================================================
  918.     */
  919.  
  920. public:
  921.  
  922.     void                    ScriptedMove                    ( idEntity* destEnt, float minDist, bool endWithIdle );
  923.     void                    ScriptedFace                    ( idEntity* faceEnt, bool endWithIdle );
  924.     void                    ScriptedAnim                    ( const char* animname, int blendFrames, bool loop, bool endWithIdle );
  925.     void                    ScriptedPlaybackMove            ( const char* playback, int flags, int numFrames );
  926.     void                    ScriptedPlaybackAim                ( const char* playback, int flags, int numFrames );
  927.     void                    ScriptedAction                    ( idEntity* actionEnt, bool endWithIdle );
  928.     void                    ScriptedStop                    ( void );
  929.  
  930.     void                    SetScript                        ( const char* scriptName, const char* funcName );
  931.  
  932. private:
  933.  
  934.     bool                    ScriptedBegin                    ( bool endWithIdle, bool allowDormant = false );
  935.     void                    ScriptedEnd                        ( void );
  936.  
  937.     /*
  938.     ===============================================================================
  939.                                     Handlers 
  940.     ===============================================================================
  941.     */
  942.  
  943. protected:
  944.  
  945.     virtual void            OnDeath                            ( void );
  946.     virtual void            OnStateChange                    ( int channel );
  947.     virtual void            OnUpdatePlayback                ( const rvDeclPlaybackData& pbd );
  948.     virtual void            OnEnemyChange                    ( idEntity* oldEnemy );
  949.     virtual void            OnLeaderChange                    ( idEntity* oldLeader );
  950.     virtual void            OnStartMoving                    ( void );
  951.     virtual void            OnStopMoving                    ( aiMoveCommand_t oldMoveCommand );
  952.     virtual void            OnTacticalChange                ( aiTactical_t oldTactical );
  953.     virtual void            OnFriendlyFire                    ( idActor* attacker );
  954.     virtual void            OnWakeUp                        ( void );
  955.     virtual void            OnTouch                            ( idEntity *other, trace_t *trace );
  956.     virtual void            OnCoverInvalidated                ( void );
  957.     virtual void            OnCoverNotFacingEnemy            ( void );
  958.     virtual void            OnEnemyVisiblityChange            ( bool oldVisible );
  959.     virtual void            OnStartAction                    ( void );
  960.     virtual void            OnStopAction                    ( void );
  961.     virtual void            OnSetKey                        ( const char* key, const char* value );
  962.  
  963.     /*
  964.     ===============================================================================
  965.                                     Movement / Turning
  966.     ===============================================================================
  967.     */
  968.     
  969. protected:
  970.  
  971.     bool                    StartMove                        ( aiMoveCommand_t command, const idVec3& goalOrigin, int goalArea, idEntity* goalEntity, aasFeature_t* feature, float range );
  972.     void                    StopMove                        ( moveStatus_t status );
  973.  
  974.     bool                    MoveTo                            ( const idVec3 &pos, float range = 0.0f );
  975.     bool                    MoveToAttack                    ( idEntity *ent, int attack_anim );
  976.     bool                    MoveToTether                    ( rvAITether* tether );
  977.     virtual bool            MoveToEnemy                        ( void );
  978.     bool                    MoveToEntity                    ( idEntity *ent, float range = 0.0f );
  979.     bool                    MoveToCover                        ( float minRange, float maxRange, aiTactical_t coverType );
  980.     bool                    MoveToHide                        ( void );
  981.  
  982.     bool                    MoveOutOfRange                    ( idEntity *entity, float range, float minRange=0.0f );
  983.  
  984.     void                    AnimTurn                        ( float angles, bool force );
  985.  
  986.     bool                    ReachedPos                        ( const idVec3 &pos, const aiMoveCommand_t moveCommand, float range = 0.0f ) const;
  987.  
  988.     /*
  989.     ===============================================================================
  990.                                     Debug
  991.     ===============================================================================
  992.     */
  993.  
  994. public:
  995.  
  996.     void                    DrawRoute                        ( void ) const;
  997.     void                    DrawTactical                    ( void );
  998.  
  999.     /*
  1000.     ===============================================================================
  1001.                                     Announcements
  1002.     ===============================================================================
  1003.     */
  1004.  
  1005. public:
  1006.  
  1007.     bool                    ActorIsBehindActor                ( idActor* ambusher, idActor* victim );
  1008.     void                    AnnounceNewEnemy                ( void );
  1009.     void                    AnnounceKill                    ( idActor *victim );
  1010.     void                    AnnounceTactical                ( aiTactical_t newTactical );
  1011.     void                    AnnounceSuppressed                ( idActor *suppressor );
  1012.     void                    AnnounceSuppressing                ( void );
  1013.     void                    AnnounceFlinch                    ( idEntity *attacker );
  1014.     void                    AnnounceInjured                    ( void );
  1015.     void                    AnnounceFriendlyFire            ( idActor* attacker );
  1016.     void                    AnnounceGrenade                    ( void );
  1017.     void                    AnnounceGrenadeThrow            ( void );
  1018.  
  1019.     /*
  1020.     ===============================================================================
  1021.                                     Actions
  1022.     ===============================================================================
  1023.     */
  1024.  
  1025. protected:
  1026.  
  1027.     rvAIActionTimer            actionTimerRangedAttack;
  1028.     rvAIActionTimer            actionTimerEvade;
  1029.     rvAIActionTimer            actionTimerSpecialAttack;
  1030.     rvAIActionTimer            actionTimerPain;
  1031.     
  1032.     rvAIAction                actionEvadeLeft;
  1033.     rvAIAction                actionEvadeRight;
  1034.     rvAIAction                actionRangedAttack;
  1035.     rvAIAction                actionMeleeAttack;
  1036.     rvAIAction                actionLeapAttack;    
  1037.     rvAIAction                actionJumpBack;
  1038.  
  1039.     bool                    UpdateAction                        ( void );
  1040.     virtual bool            CheckActions                        ( void );
  1041.     virtual bool            CheckPainActions                    ( void );
  1042.  
  1043.     bool                    PerformAction                        ( rvAIAction* action, bool (idAI::*)(rvAIAction*,int), rvAIActionTimer* timer = NULL );
  1044.     void                    PerformAction                        ( const char* stateName, int blendFrames = 0, bool noPain = false );
  1045.  
  1046.     // RAVEN BEGIN
  1047.     // twhitaker: needed this for difficulty settings
  1048.     virtual void            Event_PostSpawn                        ( void );
  1049.     // RAVEN END
  1050.  
  1051. public:
  1052.         
  1053.     virtual bool            CheckAction_EvadeLeft                ( rvAIAction* action, int animNum );
  1054.     virtual bool            CheckAction_EvadeRight                ( rvAIAction* action, int animNum );
  1055.     virtual bool            CheckAction_RangedAttack            ( rvAIAction* action, int animNum );
  1056.     virtual bool            CheckAction_MeleeAttack                ( rvAIAction* action, int animNum );
  1057.     bool                    CheckAction_LeapAttack                ( rvAIAction* action, int animNum );
  1058.     virtual bool            CheckAction_JumpBack                ( rvAIAction* action, int animNum );
  1059.  
  1060.     /*
  1061.     ===============================================================================
  1062.                                     Events
  1063.     ===============================================================================
  1064.     */
  1065.  
  1066. private:
  1067.     
  1068.     // Orphaned events
  1069.     void                    Event_ClosestReachableEnemyOfEntity    ( idEntity *team_mate );
  1070.     void                    Event_GetReachableEntityPosition    ( idEntity *ent );
  1071.     void                    Event_EntityInAttackCone            ( idEntity *ent );
  1072.     void                    Event_TestAnimMoveTowardEnemy        ( const char *animname );
  1073.     void                    Event_TestAnimMove                    ( const char *animname );
  1074.     void                    Event_TestMoveToPosition            ( const idVec3 &position );
  1075.     void                    Event_TestMeleeAttack                ( void );
  1076.     void                    Event_TestAnimAttack                ( const char *animname );
  1077.     void                    Event_SaveMove                        ( void );
  1078.     void                    Event_RestoreMove                    ( void );
  1079.     void                    Event_ThrowMoveable                    ( void );
  1080.     void                    Event_ThrowAF                        ( void );
  1081.     void                    Event_PredictEnemyPos                ( float time );
  1082.     void                    Event_FindActorsInBounds            ( const idVec3 &mins, const idVec3 &maxs );
  1083.  
  1084.     void                    Event_Activate                        ( idEntity *activator );
  1085.     void                    Event_Touch                            ( idEntity *other, trace_t *trace );
  1086.     void                    Event_LookAt                        ( idEntity* lookAt );
  1087.     
  1088.     void                    Event_SetAngles                        ( idAngles const &ang );
  1089.     void                    Event_SetEnemy                        ( idEntity *ent );
  1090.     void                    Event_SetHealth                        ( float newHealth );
  1091.     void                    Event_SetTalkTarget                    ( idEntity *target );
  1092.     void                    Event_SetTalkState                    ( int state );
  1093.     void                    Event_SetLeader                        ( idEntity *newLeader );
  1094.     void                    Event_SetScript                        ( const char* scriptName, const char* funcName );
  1095.     void                    Event_SetMoveSpeed                    ( int speed );
  1096.     void                    Event_SetPassivePrefix                ( const char* prefix );
  1097.  
  1098.     void                    Event_GetAngles                        ( void );
  1099.     void                    Event_GetEnemy                        ( void );
  1100.     void                    Event_GetLeader                        ( void );
  1101.  
  1102.     void                    Event_Attack                        ( const char* attackName, const char* jointName );
  1103.     void                    Event_AttackMelee                    ( const char *meleeDefName );
  1104.  
  1105.     void                    Event_DirectDamage                    ( idEntity *damageTarget, const char *damageDefName );
  1106.     void                    Event_RadiusDamageFromJoint            ( const char *jointname, const char *damageDefName );
  1107.     void                    Event_CanBecomeSolid                ( void );
  1108.     void                    Event_BecomeSolid                    ( void );
  1109.     void                    Event_BecomeNonSolid                ( void );
  1110.     void                    Event_BecomeRagdoll                    ( void );
  1111.     void                    Event_StopRagdoll                    ( void );
  1112.     void                    Event_FaceEnemy                        ( void );
  1113.     void                    Event_FaceEntity                    ( idEntity *ent );
  1114.     void                    Event_WaitMove                        ( void );
  1115.  
  1116.     void                    Event_BecomePassive                    ( int ignoreEnemies );
  1117.     void                    Event_BecomeAggressive                ( void );
  1118.  
  1119.     void                    Event_EnableDamage                    ( void );
  1120.     void                    Event_EnableClip                    ( void );
  1121.     void                    Event_EnableGravity                    ( void );
  1122.     void                    Event_EnableAFPush                    ( void );
  1123.     void                    Event_EnablePain                    ( void );
  1124.     void                    Event_DisableDamage                    ( void );
  1125.     void                    Event_DisableClip                    ( void );
  1126.     void                    Event_DisableGravity                ( void );
  1127.     void                    Event_DisableAFPush                    ( void );
  1128.     void                    Event_DisablePain                    ( void );
  1129.     void                    Event_EnableTarget                    ( void );
  1130.     void                    Event_DisableTarget                    ( void );
  1131.     void                    Event_TakeDamage                    ( float takeDamage );
  1132.     void                    Event_SetUndying                    ( float setUndying );
  1133.     void                    Event_EnableAutoBlink                ( void );
  1134.     void                    Event_DisableAutoBlink                ( void );
  1135.  
  1136.     void                    Event_LockEnemyOrigin                ( void );
  1137.  
  1138.     void                    Event_StopThinking                    ( void );
  1139.     void                    Event_JumpFrame                        ( void );
  1140.     void                    Event_RealKill                        ( void );
  1141.     void                    Event_Kill                            ( void );
  1142.     void                    Event_RemoveUpdateSpawner            ( void );
  1143.     void                    Event_AllowHiddenMovement            ( int enable );
  1144.     void                     Event_CanReachPosition                ( const idVec3 &pos );
  1145.     void                     Event_CanReachEntity                ( idEntity *ent );
  1146.     void                    Event_CanReachEnemy                    ( void );
  1147.  
  1148.     void                    Event_IsSpeaking                    ( void );
  1149.     void                    Event_IsTethered                    ( void );
  1150.     void                    Event_IsWithinTether                ( void );
  1151.     void                    Event_IsMoving                        ( void );
  1152.     
  1153.     void                    Event_Speak                            ( const char *speechDecl );
  1154.     void                    Event_SpeakRandom                    ( const char *speechDecl );
  1155.  
  1156.     void                    Event_ScriptedMove                    ( idEntity* destEnt, float minDist, bool endWithIdle );
  1157.     void                    Event_ScriptedFace                    ( idEntity* faceEnt, bool endWithIdle );
  1158.     void                    Event_ScriptedAnim                    ( const char* animname, int blendFrames, bool loop, bool endWithIdle );
  1159.     void                    Event_ScriptedPlaybackMove            ( const char* playback, int flags, int numFrames );
  1160.     void                    Event_ScriptedPlaybackAim            ( const char* playback, int flags, int numFrames );
  1161.     void                    Event_ScriptedAction                ( idEntity* actionEnt, bool endWithIdle );
  1162.     void                    Event_ScriptedDone                    ( void );
  1163.     void                    Event_ScriptedStop                    ( void );
  1164.     void                    Event_ScriptedJumpDown                ( float yaw );
  1165.  
  1166.     void                    Event_FindEnemy                        ( float distSquare );
  1167.     void                    Event_SetKey                        ( const char *key, const char *value );
  1168.  
  1169.     
  1170.     /*
  1171.     ===============================================================================
  1172.                                     States
  1173.     ===============================================================================
  1174.     */
  1175.  
  1176. protected:
  1177.  
  1178.     // Wait states
  1179.     stateResult_t            State_Wait_Activated                ( const stateParms_t& parms );
  1180.     stateResult_t            State_Wait_ScriptedDone                ( const stateParms_t& parms );
  1181.     stateResult_t            State_Wait_Action                    ( const stateParms_t& parms );
  1182.     stateResult_t            State_Wait_ActionNoPain                ( const stateParms_t& parms );
  1183.     
  1184.     // Global states
  1185.     stateResult_t            State_WakeUp                        ( const stateParms_t& parms );
  1186.     stateResult_t            State_TriggerAnim                    ( const stateParms_t& parms );
  1187.     stateResult_t            State_Wander                        ( const stateParms_t& parms );
  1188.     stateResult_t            State_Killed                        ( const stateParms_t& parms );
  1189.     stateResult_t            State_Dead                            ( const stateParms_t& parms );
  1190.     stateResult_t            State_LightningDeath                ( const stateParms_t& parms );
  1191.     stateResult_t            State_Burn                            ( const stateParms_t& parms );
  1192.     stateResult_t            State_Remove                        ( const stateParms_t& parms );
  1193.  
  1194.     stateResult_t            State_Passive                        ( const stateParms_t& parms );
  1195.  
  1196.     stateResult_t            State_Combat                        ( const stateParms_t& parms );
  1197.     stateResult_t            State_CombatCover                    ( const stateParms_t& parms );
  1198.     stateResult_t            State_CombatMelee                    ( const stateParms_t& parms );
  1199.     stateResult_t            State_CombatRanged                    ( const stateParms_t& parms );
  1200.     stateResult_t            State_CombatTurret                    ( const stateParms_t& parms );
  1201.     virtual stateResult_t    State_CombatHide                    ( const stateParms_t& parms );
  1202.  
  1203.     stateResult_t            State_MovePlayerPush                ( const stateParms_t& parms );
  1204.     stateResult_t            State_MoveTether                    ( const stateParms_t& parms );
  1205.     stateResult_t            State_MoveFollow                    ( const stateParms_t& parms );
  1206.  
  1207.     stateResult_t            State_ScriptedMove                    ( const stateParms_t& parms );    
  1208.     stateResult_t            State_ScriptedFace                    ( const stateParms_t& parms );    
  1209.     stateResult_t            State_ScriptedStop                    ( const stateParms_t& parms );
  1210.     stateResult_t            State_ScriptedPlaybackMove            ( const stateParms_t& parms );
  1211.     stateResult_t            State_ScriptedPlaybackAim            ( const stateParms_t& parms );
  1212.     stateResult_t            State_ScriptedJumpDown                ( const stateParms_t& parms );
  1213.  
  1214.     // Torso States
  1215.     stateResult_t            State_Torso_Idle                    ( const stateParms_t& parms );
  1216.     stateResult_t            State_Torso_Sight                    ( const stateParms_t& parms );
  1217.     stateResult_t            State_Torso_CustomCycle                ( const stateParms_t& parms );
  1218.     stateResult_t            State_Torso_Action                    ( const stateParms_t& parms );
  1219.     stateResult_t            State_Torso_FinishAction            ( const stateParms_t& parms );
  1220.     stateResult_t            State_Torso_Pain                    ( const stateParms_t& parms );
  1221.     stateResult_t            State_Torso_ScriptedAnim            ( const stateParms_t& parms );    
  1222.     stateResult_t            State_Torso_PassiveIdle                ( const stateParms_t& parms );
  1223.     stateResult_t            State_Torso_PassiveFidget            ( const stateParms_t& parms );
  1224.     
  1225.     // Leg States
  1226.     stateResult_t            State_Legs_Idle                        ( const stateParms_t& parms );
  1227.     stateResult_t            State_Legs_TurnLeft                    ( const stateParms_t& parms );
  1228.     stateResult_t            State_Legs_TurnRight                ( const stateParms_t& parms );
  1229.     stateResult_t            State_Legs_Move                        ( const stateParms_t& parms );
  1230.     stateResult_t            State_Legs_MoveThink                ( const stateParms_t& parms );
  1231.     stateResult_t            State_Legs_ChangeDirection            ( const stateParms_t& parms );
  1232.     
  1233.     // Head states    
  1234.     stateResult_t            State_Head_Idle                        ( const stateParms_t& parms );
  1235.  
  1236.     CLASS_STATES_PROTOTYPE ( idAI );
  1237. };
  1238.  
  1239. /*
  1240. ===============================================================================
  1241.  
  1242.     idAI Inlines
  1243.  
  1244. ===============================================================================
  1245. */
  1246.  
  1247. ID_INLINE int DelayTime( int min, int range ) {
  1248.     return min + gameLocal.random.RandomInt ( range + 1 );
  1249. }
  1250.  
  1251. ID_INLINE const idVec2& idAI::GetAttackRange ( void ) const {
  1252.     return combat.attackRange;
  1253. }
  1254.  
  1255. ID_INLINE const idVec2& idAI::GetFollowRange ( void ) const {
  1256.     return move.followRange;
  1257. }
  1258.  
  1259. ID_INLINE int idAI::GetTravelFlags ( void ) const {
  1260.     return move.travelFlags;
  1261. }
  1262.  
  1263. ID_INLINE bool idAI::IsEnemyVisible ( void ) const {
  1264.     return enemy.ent && enemy.fl.visible;
  1265. }
  1266.  
  1267. ID_INLINE bool idAI::IsEnemyRecentlyVisible( float maxLostVisTimeScale ) const {
  1268.     return (enemy.ent
  1269.             && combat.fl.seenEnemyDirectly 
  1270.              && (enemy.lastVisibleTime && gameLocal.time-enemy.lastVisibleTime < (combat.maxLostVisTime * maxLostVisTimeScale)));
  1271. }
  1272.  
  1273. ID_INLINE bool idAI::LookAtCoverTall( void ) const {
  1274.      return ( aasSensor->Look()
  1275.              && (aasSensor->Look()->flags&FEATURE_LOOK_OVER)
  1276.              && aasSensor->Look()->height > 40.0f );
  1277. }
  1278.  
  1279. ID_INLINE bool idAI::InLookAtCoverMode ( void ) const {
  1280.      return (!IsBehindCover() 
  1281.              && !aifl.action 
  1282.             && move.fl.moving
  1283.              && (combat.fl.alert || combat.fl.aware)
  1284.             && aasSensor->Look()
  1285.              && combat.tacticalCurrent != AITACTICAL_MELEE
  1286.              && combat.tacticalCurrent != AITACTICAL_HIDE
  1287.              && !IsEnemyRecentlyVisible(0.2f));
  1288. }
  1289.  
  1290. ID_INLINE bool idAI::InCoverMode ( void ) const {    
  1291.     return ( (1<<combat.tacticalCurrent) & AITACTICAL_COVER_BITS ) && aasSensor->Reserved ( );
  1292. }
  1293.  
  1294. ID_INLINE bool idAI::InCrouchCoverMode ( void ) const {
  1295.     return ( InCoverMode() && (aasSensor->Reserved()->flags&FEATURE_LOOK_OVER) );
  1296. }
  1297.    
  1298. ID_INLINE bool idAI::IsBehindCover ( void ) const {
  1299.     return ( InCoverMode() && move.fl.done && (aifl.action || DistanceTo2d ( aasSensor->ReservedOrigin() ) < AI_COVER_MINRANGE) );
  1300. }
  1301.  
  1302. ID_INLINE bool idAI::IsSpeaking ( void ) const {
  1303.     return speakTime && gameLocal.time < speakTime;
  1304. }
  1305.  
  1306. ID_INLINE bool idAI::IsFacingEnt ( idEntity* targetEnt ) {
  1307.     return( move.moveCommand == MOVE_FACE_ENTITY && move.goalEntity == targetEnt && FacingIdeal() );
  1308. }
  1309.  
  1310. ID_INLINE bool idAI::IsCoverValid (  ) const {
  1311.      return combat.coverValidTime && (gameLocal.time - combat.coverValidTime < combat.maxInvalidCoverTime);
  1312. }
  1313.  
  1314. ID_INLINE idActor* idAI::GetLeader ( void ) const { 
  1315.     return leader;
  1316. }
  1317.  
  1318. ID_INLINE idEntity* idAI::GetGoalEntity ( void ) const { 
  1319.     return move.goalEntity;
  1320. }
  1321.  
  1322. ID_INLINE bool idAI::CanTakeDamage( void ) const {
  1323.     return idActor::CanTakeDamage( );
  1324. }
  1325.  
  1326. ID_INLINE bool idAI::CanTakePain ( void ) const {
  1327.     return !disablePain;
  1328. }
  1329.  
  1330. ID_INLINE bool idAI::CanTurn ( void ) const {
  1331.     return move.turnRate && !move.fl.noTurn && !move.fl.disabled;
  1332. }
  1333.  
  1334. ID_INLINE bool idAI::CanMove ( void ) const {
  1335.     return !move.fl.disabled && !move.fl.blocked && gameLocal.GetTime()>move.blockTime;
  1336. }
  1337.  
  1338. ID_INLINE bool idAI::CanAnnounce ( float chance ) const {
  1339.     return !aifl.dead && !IsSpeaking ( ) && !af.IsActive ( ) && !combat.fl.noChatter && ( gameLocal.random.RandomFloat() < chance );
  1340. }
  1341.  
  1342. ID_INLINE void idAI::SetFocus ( aiFocus_t focus, int time ) {
  1343.     focusType = focus;
  1344.     focusTime = gameLocal.time + time;
  1345. }
  1346.  
  1347. ID_INLINE idEntity *idAI::GetEnemy( void ) const {
  1348.     return enemy.ent;
  1349. }
  1350.  
  1351. ID_INLINE void idAI::ForceTacticalUpdate ( void ) {
  1352.     combat.tacticalUpdateTime = 0;
  1353.     combat.tacticalMaskUpdate = 0;
  1354.     delete aasFind;
  1355.     aasFind = NULL;
  1356. }    
  1357.  
  1358. /*
  1359. ===============================================================================
  1360.  
  1361.     externs
  1362.  
  1363. ===============================================================================
  1364. */
  1365.  
  1366. extern const char* aiActionStatusString [ rvAIAction::STATUS_MAX ];
  1367. extern const char* aiTalkMessageString    [ ];
  1368. extern const char* aiTacticalString        [ AITACTICAL_MAX ];
  1369. extern const char* aiMoveCommandString    [ NUM_MOVE_COMMANDS ];
  1370. extern const char* aiFocusString        [ AIFOCUS_MAX ];
  1371.  
  1372. #endif /* !__AI_H__ */
  1373.  
  1374.