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

  1. // RAVEN BEGIN
  2. // bdube: note that this file is no longer merged with Doom3 updates
  3. //
  4. // MERGE_DATE 09/30/2004
  5.  
  6. #ifndef __GAME_ACTOR_H__
  7. #define __GAME_ACTOR_H__
  8.  
  9. /*
  10. ===============================================================================
  11.  
  12.     idActor
  13.  
  14. ===============================================================================
  15. */
  16.  
  17. extern const idEventDef AI_EnableEyeFocus;
  18. extern const idEventDef AI_DisableEyeFocus;
  19. extern const idEventDef EV_Footstep;
  20. extern const idEventDef EV_FootstepLeft;
  21. extern const idEventDef EV_FootstepRight;
  22. extern const idEventDef EV_EnableWalkIK;
  23. extern const idEventDef EV_DisableWalkIK;
  24. extern const idEventDef EV_EnableLegIK;
  25. extern const idEventDef EV_DisableLegIK;
  26. extern const idEventDef AI_SetAnimPrefix;
  27. extern const idEventDef AI_PlayAnim;
  28. extern const idEventDef AI_PlayCycle;
  29. extern const idEventDef AI_AnimDone;
  30. extern const idEventDef AI_SetBlendFrames;
  31. extern const idEventDef AI_GetBlendFrames;
  32. extern const idEventDef AI_ScriptedMove;
  33. extern const idEventDef AI_ScriptedDone;
  34. extern const idEventDef AI_ScriptedStop;
  35.  
  36. // RAVEN BEGIN
  37. // bdube: added flashlight
  38. // class idDeclParticle;
  39. extern const idEventDef AI_Flashlight;
  40. extern const idEventDef AI_EnterVehicle;
  41. extern const idEventDef AI_ExitVehicle;
  42. // nmckenzie:
  43. extern const idEventDef AI_OverrideAnim;
  44. extern const idEventDef AI_IdleAnim;
  45. extern const idEventDef AI_SetState;
  46. // jshepard: adjust animation speed
  47. extern const idEventDef AI_SetAnimRate;
  48. //MCG: damage over time
  49. extern const idEventDef EV_DamageOverTime;
  50. extern const idEventDef EV_DamageOverTimeEffect;
  51. //MCG: script-callable joint crawl effect
  52. extern const idEventDef EV_JointCrawlEffect;
  53.  
  54. // abahr:
  55. extern const idEventDef AI_LookAt;
  56. extern const idEventDef AI_FaceEnemy;
  57. extern const idEventDef AI_FaceEntity;
  58. extern const idEventDef    AI_JumpDown;
  59. extern const idEventDef AI_SetLeader;
  60. // RAVEN END
  61.  
  62. class idAnimState {
  63. public:
  64.  
  65.     bool                    idleAnim;
  66.     int                        animBlendFrames;
  67.     int                        lastAnimBlendFrames;        // allows override anims to blend based on the last transition time
  68.  
  69. public:
  70.                             idAnimState();
  71.                             ~idAnimState();
  72.  
  73.     void                    Save( idSaveGame *savefile ) const;
  74.     void                    Restore( idRestoreGame *savefile );
  75.  
  76.     void                    Init( idEntity *owner, idAnimator *_animator, int animchannel );
  77.     void                    Shutdown( void );
  78.     void                    SetState        ( const char *name, int blendFrames, int flags = 0 );
  79.     void                    PostState        ( const char* name, int blendFrames = 0, int delay = 0, int flags = 0 );
  80.     void                    StopAnim( int frames );
  81.     void                    PlayAnim( int anim );
  82.     void                    CycleAnim( int anim );
  83.     void                    BecomeIdle( void );
  84.     bool                    UpdateState( void );
  85.     bool                    Disabled( void ) const;
  86.     void                    Enable( int blendFrames );
  87.     void                    Disable( void );
  88.     bool                    AnimDone( int blendFrames ) const;
  89.     bool                    IsIdle( void ) const;
  90.     animFlags_t                GetAnimFlags( void ) const;
  91.  
  92.     rvStateThread&            GetStateThread    ( void );
  93.  
  94.     idAnimator *            GetAnimator( void ) const {return animator;};
  95. private:
  96. // RAVEN BEGIN
  97. // bdube: converted self to entity ptr so any entity can use it
  98.     idEntity *                self;
  99. // RAVEN END
  100.     idAnimator *            animator;
  101.     int                        channel;
  102.     bool                    disabled;
  103.     
  104.     rvStateThread            stateThread;
  105. };
  106.  
  107. ID_INLINE rvStateThread& idAnimState::GetStateThread ( void ) {
  108.     return stateThread;
  109. }
  110.  
  111. class idAttachInfo {
  112. public:
  113.     idEntityPtr<idEntity>    ent;
  114.     int                        channel;
  115. };
  116.  
  117. class idActor : public idAFEntity_Gibbable {
  118. public:
  119.     CLASS_PROTOTYPE( idActor );
  120.  
  121.     int                        team;
  122.     idLinkList<idActor>        teamNode;
  123.     int                        rank;                // monsters don't fight back if the attacker's rank is higher
  124.     idMat3                    viewAxis;            // view axis of the actor
  125.  
  126.     idLinkList<idActor>        enemyNode;            // node linked into an entity's enemy list for quick lookups of who is attacking him
  127.     idLinkList<idActor>        enemyList;            // list of characters that have targeted the player as their enemy
  128.  
  129. public:
  130.                             idActor( void );
  131.     virtual                    ~idActor( void );
  132.  
  133.     void                    Spawn( void );
  134.     virtual void            Restart( void );
  135.  
  136.     void                    Save( idSaveGame *savefile ) const;
  137.     void                    Restore( idRestoreGame *savefile );
  138.  
  139.     virtual void            Hide( void );
  140.     virtual void            Show( void );
  141.     virtual int                GetDefaultSurfaceType( void ) const;
  142.     virtual void            ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  143.  
  144.     virtual bool            LoadAF( const char* keyname = NULL, bool purgeAF = false );
  145.     void                    SetupBody( void );
  146.  
  147.     virtual void            CheckBlink( void );
  148.  
  149.     virtual bool            GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  150.     virtual bool            GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis );
  151.  
  152.                             // script state management
  153.     void                    ShutdownThreads        ( void );
  154.     void                    UpdateState            ( void );
  155.     
  156.     virtual void            OnStateThreadClear ( const char *statename, int flags = 0 );
  157.     void                    SetState        ( const char *statename, int flags = 0 );
  158.     void                    PostState        ( const char* statename, int delay = 0, int flags = 0 );
  159.     void                    InterruptState    ( const char* statename, int delay = 0, int flags = 0 );
  160.  
  161.                             // vision testing
  162.     void                    SetEyeHeight( float height );
  163.     void                    SetChestHeight ( float height );
  164.     float                    EyeHeight( void ) const;
  165.  
  166.     virtual idVec3            GetEyePosition( void ) const;
  167.     virtual idVec3            GetChestPosition ( void ) const;
  168.     idEntity*                GetGroundEntity ( void ) const;
  169.     virtual idEntity*        GetGroundElevator( idEntity* testElevator=NULL ) const;
  170.  
  171.     void                    Present( void );
  172.  
  173.     virtual void            GetViewPos    ( idVec3 &origin, idMat3 &axis ) const;
  174.     void                    SetFOV        ( float fov, float fovClose );
  175.     bool                    CheckFOV    ( const idVec3 &pos, float ang = -1.0f ) const;
  176.     virtual bool            HasFOV        ( idEntity *ent );
  177.     virtual    bool            CanSee        ( const idEntity *ent, bool useFOV ) const;
  178.     virtual    bool            CanSeeFrom    ( const idVec3& from, const idEntity *ent, bool useFOV ) const;
  179.     virtual    bool            CanSeeFrom    ( const idVec3& from, const idVec3& toPos, bool useFOV ) const;
  180.  
  181.                             // damage
  182.     void                    SetupDamageGroups( void );
  183.  
  184.     virtual    void            Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  185. // RAVEN BEGIN
  186. // nmckenzie: a final hook in the middle of the damage function
  187.     virtual void            AdjustHealthByDamage ( int inDamage ){health -= inDamage;}
  188. // RAVEN END
  189.  
  190.     virtual int                GetDamageForLocation( int damage, int location );
  191.     const char *            GetDamageGroup( int location );
  192.     void                    ClearPain( void );
  193.     virtual bool            Pain( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  194.     virtual void            AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName, idEntity* inflictor );
  195.  
  196.                             // model/combat model/ragdoll
  197.     void                    SetCombatModel( void );
  198.     idClipModel *            GetCombatModel( void ) const;
  199.     virtual void            LinkCombat( void );
  200.     virtual void            UnlinkCombat( void );
  201.     bool                    StartRagdoll( void );
  202.     void                    StopRagdoll( void );
  203.     virtual bool            UpdateAnimationControllers( void );
  204.  
  205.                             // delta view angles to allow movers to rotate the view of the actor
  206.     const idAngles &        GetDeltaViewAngles( void ) const;
  207.     void                    SetDeltaViewAngles( const idAngles &delta );
  208.  
  209.     bool                    HasEnemies( void ) const;
  210.     idActor *                ClosestEnemyToPoint( const idVec3 &pos, float maxRange=0.0f, bool returnFirst=false, bool checkPVS=false );
  211.     idActor *                EnemyWithMostHealth();
  212.  
  213.     virtual bool            OnLadder            ( void ) const;
  214.     virtual void            OnStateChange        ( int channel );
  215.     virtual void            OnFriendlyFire        ( idActor* attacker );
  216.  
  217.     virtual void            GetAASLocation( idAAS *aas, idVec3 &pos, int &areaNum ) const;
  218.  
  219.     void                    Attach( idEntity *ent );
  220.     idEntity*                FindAttachment( const char* attachmentName );
  221.     void                    HideAttachment( const char* attachmentName );
  222.     void                    ShowAttachment( const char* attachmentName );
  223.     idEntity*                GetHead() { return head; }
  224.  
  225.     virtual void            Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
  226.  
  227.     virtual    renderView_t *    GetRenderView();    
  228.  
  229.     // Animation
  230.     int                        PlayAnim                ( int channel, const char *name, int blendFrames );
  231.     bool                    PlayCycle                ( int channel, const char *name, int blendFrames );
  232.     void                    IdleAnim                ( int channel, const char *name, int blendFrames );
  233.     void                    OverrideAnim            ( int channel );
  234.     bool                    HasAnim                    ( int channel, const char *name, bool forcePrefix = false );
  235.     int                        GetAnim                    ( int channel, const char *name, bool forcePrefix = false );
  236.     bool                    AnimDone                ( int channel, int blendFrames );
  237.     
  238.     // animation state control
  239.     void                    UpdateAnimState            ( void );
  240.     void                    SetAnimState            ( int channel, const char *name, int blendFrames = 0, int flags = 0 );
  241.     void                    PostAnimState            ( int channel, const char *name, int blendFrames = 0, int delay = 0, int flags = 0 );
  242.     void                    StopAnimState            ( int channel );
  243.     bool                    InAnimState                ( int channel, const char *name );
  244.     
  245.     virtual void            SpawnGibs( const idVec3 &dir, const char *damageDefName );
  246.  
  247. // RAVEN BEGIN
  248. // bdube: added for vehicle
  249.     bool                    IsInVehicle ( void ) const;
  250.     rvVehicleController&    GetVehicleController ( void );
  251.     virtual void            GuidedProjectileIncoming( idGuidedProjectile * projectile );
  252.  
  253.     bool                    DebugFilter    (const idCVar& test) const;
  254. // RAVEN END
  255.     virtual bool            IsCrouching                ( void ) const {return false;};
  256.  
  257.     virtual bool            SkipImpulse( idEntity* ent, int id );
  258.  
  259.     int                        lightningNextTime;
  260.     int                        lightningEffects;
  261.  
  262. protected:
  263.     friend class            idAnimState;
  264.  
  265.     float                    fovDot;                // cos( fovDegrees )
  266.     float                    fovCloseDot;        // cos( fovDegreesClose )
  267.     float                    fovCloseRange;        // range within to use fovCloseDot
  268.     idVec3                    eyeOffset;            // offset of eye relative to physics origin
  269.     idVec3                    chestOffset;        // offset of chest relative to physics origin
  270.     idVec3                    modelOffset;        // offset of visual model relative to the physics origin
  271.  
  272.     idAngles                deltaViewAngles;    // delta angles relative to view input angles
  273.  
  274.     int                        pain_debounce_time;    // next time the actor can show pain
  275.     int                        pain_delay;            // time between playing pain sound
  276.  
  277.     idStrList                damageGroups;        // body damage groups
  278.     idList<float>            damageScale;        // damage scale per damage gruop
  279.     bool                    inDamageEvent;        // hacky-ass bool to prevent us from starting a new EV_DamageOverTime in our ::Damage
  280.  
  281.     bool                    use_combat_bbox;    // whether to use the bounding box for combat collision
  282.     
  283.     // joint handles
  284.     jointHandle_t            leftEyeJoint;
  285.     jointHandle_t            rightEyeJoint;
  286.     jointHandle_t            soundJoint;
  287.     jointHandle_t            eyeOffsetJoint;
  288.     jointHandle_t            chestOffsetJoint;
  289.     jointHandle_t            neckJoint;
  290.     jointHandle_t            headJoint;
  291.  
  292.     idIK_Walk                walkIK;
  293.  
  294.     idStr                    animPrefix;
  295.     idStr                    painType;
  296.     idStr                    painAnim;
  297.  
  298.     // blinking
  299.     int                        blink_anim;
  300.     int                        blink_time;
  301.     int                        blink_min;
  302.     int                        blink_max;
  303.  
  304.     idAnimState                headAnim;
  305.     idAnimState                torsoAnim;
  306.     idAnimState                legsAnim;
  307.     
  308.     rvStateThread            stateThread;
  309.  
  310.     idEntityPtr<idAFAttachment>    head;                // safe pointer to attached head
  311.  
  312.     bool                    disablePain;
  313.     bool                    allowEyeFocus;
  314.     bool                    finalBoss;
  315.  
  316.     int                        painTime;
  317.  
  318.     idList<idAttachInfo>    attachments;
  319.  
  320.     virtual void            Gib( const idVec3 &dir, const char *damageDefName );
  321.     void                    CheckDeathObjectives( void );
  322.  
  323. // RAVEN BEGIN
  324. // bdube: vehicles
  325.     virtual bool            EnterVehicle ( idEntity* vehicle );
  326.     virtual bool            ExitVehicle     ( bool force = false );
  327. // RAVEN END
  328.  
  329.                             // removes attachments with "remove" set for when character dies
  330.     void                    RemoveAttachments( void );
  331.     
  332. // RAVEN BEGIN
  333. // bdube: vehicles
  334.     rvVehicleController        vehicleController;
  335. // bdube: flashlights
  336.     renderLight_t            flashlight;
  337.     int                        flashlightHandle;
  338.     jointHandle_t            flashlightJoint;
  339.     idVec3                    flashlightOffset;
  340.  
  341. // bdube: death force
  342.     int                        deathPushTime;
  343.     idVec3                    deathPushForce;
  344.     jointHandle_t            deathPushJoint;
  345.  
  346.     void                    FlashlightUpdate    ( bool forceOn = false );
  347.     void                    InitDeathPush        ( const idVec3& dir, int location, const idDict* damageDict, float pushScale = 1.0f );
  348.     void                    DeathPush            ( void );
  349.  
  350.     // Add some dynamic externals for debugging
  351.     virtual void            GetDebugInfo        ( debugInfoProc_t proc, void* userData );
  352. // RAVEN END    
  353.  
  354. protected:
  355.  
  356.     virtual void            FootStep            ( void );
  357.     virtual void            SetupHead( const char* headDefName = "", idVec3 headOffset = idVec3(0, 0, 0) );
  358.  
  359. private:
  360.     void                    SyncAnimChannels( int channel, int syncToChannel, int blendFrames );
  361.     void                    FinishSetup( void );
  362.     
  363.     void                    Event_EnableEyeFocus( void );
  364.     void                    Event_DisableEyeFocus( void );
  365.     void                    Event_EnableBlink( void );
  366.     void                    Event_DisableBlink( void );
  367.     void                    Event_Footstep( void );
  368.     void                    Event_EnableWalkIK( void );
  369.     void                    Event_DisableWalkIK( void );
  370.     void                    Event_EnableLegIK( int num );
  371.     void                    Event_DisableLegIK( int num );
  372.     void                    Event_SetAnimPrefix( const char *name );
  373.     void                    Event_LookAtEntity( idEntity *ent, float duration );
  374.     void                    Event_PreventPain( float duration );
  375.     void                    Event_DisablePain( void );
  376.     void                    Event_EnablePain( void );
  377.     void                    Event_StopAnim( int channel, int frames );
  378.     void                    Event_PlayAnim( int channel, const char *name );
  379.     void                    Event_PlayCycle( int channel, const char *name );
  380.     void                    Event_IdleAnim( int channel, const char *name );
  381.     void                    Event_SetSyncedAnimWeight( int channel, int anim, float weight );
  382.     void                    Event_OverrideAnim( int channel );
  383.     void                    Event_EnableAnim( int channel, int blendFrames );
  384.     void                    Event_SetBlendFrames( int channel, int blendFrames );
  385.     void                    Event_GetBlendFrames( int channel );
  386.     void                    Event_HasEnemies( void );
  387.     void                    Event_NextEnemy( idEntity *ent );
  388.     void                    Event_ClosestEnemyToPoint( const idVec3 &pos );
  389.     void                    Event_StopSound( int channel, int netsync );
  390.     void                    Event_GetHead( void );
  391.  
  392.     void                    Event_Teleport        ( idVec3 &newPos, idVec3 &newAngles );
  393.     void                    Event_Flashlight    ( bool enable );
  394.     void                    Event_EnterVehicle    ( idEntity* vehicle );
  395.     void                    Event_ExitVehicle    ( bool force );
  396.     void                    Event_PreExitVehicle( bool force );
  397.  
  398.     void                    Event_SetAnimRate    ( float multiplier );
  399.     void                    Event_DamageOverTime ( int endTime, int interval, idEntity *inflictor, idEntity *attacker, idVec3 &dir, const char *damageDefName, const float damageScale, int location );
  400.     virtual void            Event_DamageOverTimeEffect    ( int endTime, int interval, const char *damageDefName );
  401.     void                    Event_JointCrawlEffect ( const char *effectKeyName, float crawlSecs );
  402.  
  403.     CLASS_STATES_PROTOTYPE ( idActor );
  404.  
  405. protected:
  406.  
  407.     // Wait states
  408.     stateResult_t            State_Wait_LegsAnim        ( const stateParms_t& parms );
  409.     stateResult_t            State_Wait_TorsoAnim    ( const stateParms_t& parms );
  410.     stateResult_t            State_Wait_Frame        ( const stateParms_t& parms );
  411.  
  412.     void                    DisableAnimState        ( int channel );
  413.     void                    EnableAnimState            ( int channel );
  414.     idAnimState&            GetAnimState            ( int channel );
  415. };
  416.  
  417. ID_INLINE bool idActor::IsInVehicle( void ) const {
  418.     return vehicleController.IsDriving();
  419. }
  420.  
  421. ID_INLINE rvVehicleController& idActor::GetVehicleController( void ) {
  422.     return vehicleController;
  423. }
  424.  
  425. #endif /* !__GAME_ACTOR_H__ */
  426.  
  427. // RAVEN END
  428.