Actor.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_ACTOR_H__
  21. #define __GAME_ACTOR_H__
  22. /*
  23. ===============================================================================
  24. idActor
  25. ===============================================================================
  26. */
  27. extern const idEventDef AI_EnableEyeFocus;
  28. extern const idEventDef AI_DisableEyeFocus;
  29. extern const idEventDef EV_Footstep;
  30. extern const idEventDef EV_FootstepLeft;
  31. extern const idEventDef EV_FootstepRight;
  32. extern const idEventDef EV_EnableWalkIK;
  33. extern const idEventDef EV_DisableWalkIK;
  34. extern const idEventDef EV_EnableLegIK;
  35. extern const idEventDef EV_DisableLegIK;
  36. extern const idEventDef AI_SetAnimPrefix;
  37. extern const idEventDef AI_PlayAnim;
  38. extern const idEventDef AI_PlayCycle;
  39. extern const idEventDef AI_AnimDone;
  40. extern const idEventDef AI_SetBlendFrames;
  41. extern const idEventDef AI_GetBlendFrames;
  42. class idDeclParticle;
  43. class idAnimState {
  44. public:
  45. bool idleAnim;
  46. idStr state;
  47. int animBlendFrames;
  48. int lastAnimBlendFrames; // allows override anims to blend based on the last transition time
  49. public:
  50. idAnimState();
  51. ~idAnimState();
  52. void Save( idSaveGame *savefile ) const;
  53. void Restore( idRestoreGame *savefile );
  54. void Init( idActor *owner, idAnimator *_animator, int animchannel );
  55. void Shutdown( void );
  56. void SetState( const char *name, int blendFrames );
  57. void StopAnim( int frames );
  58. void PlayAnim( int anim );
  59. void CycleAnim( int anim );
  60. void BecomeIdle( void );
  61. bool UpdateState( void );
  62. bool Disabled( void ) const;
  63. void Enable( int blendFrames );
  64. void Disable( void );
  65. bool AnimDone( int blendFrames ) const;
  66. bool IsIdle( void ) const;
  67. animFlags_t GetAnimFlags( void ) const;
  68. private:
  69. idActor * self;
  70. idAnimator * animator;
  71. idThread * thread;
  72. int channel;
  73. bool disabled;
  74. };
  75. class idAttachInfo {
  76. public:
  77. idEntityPtr<idEntity> ent;
  78. int channel;
  79. };
  80. typedef struct {
  81. jointModTransform_t mod;
  82. jointHandle_t from;
  83. jointHandle_t to;
  84. } copyJoints_t;
  85. class idActor : public idAFEntity_Gibbable {
  86. public:
  87. CLASS_PROTOTYPE( idActor );
  88. int team;
  89. int rank; // monsters don't fight back if the attacker's rank is higher
  90. idMat3 viewAxis; // view axis of the actor
  91. idLinkList<idActor> enemyNode; // node linked into an entity's enemy list for quick lookups of who is attacking him
  92. idLinkList<idActor> enemyList; // list of characters that have targeted the player as their enemy
  93. public:
  94. idActor( void );
  95. virtual ~idActor( void );
  96. void Spawn( void );
  97. virtual void Restart( void );
  98. void Save( idSaveGame *savefile ) const;
  99. void Restore( idRestoreGame *savefile );
  100. virtual void Hide( void );
  101. virtual void Show( void );
  102. virtual int GetDefaultSurfaceType( void ) const;
  103. virtual void ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  104. virtual bool LoadAF( void );
  105. void SetupBody( void );
  106. void CheckBlink( void );
  107. virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  108. virtual bool GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis );
  109. // script state management
  110. void ShutdownThreads( void );
  111. virtual bool ShouldConstructScriptObjectAtSpawn( void ) const;
  112. virtual idThread * ConstructScriptObject( void );
  113. void UpdateScript( void );
  114. const function_t *GetScriptFunction( const char *funcname );
  115. void SetState( const function_t *newState );
  116. void SetState( const char *statename );
  117. // vision testing
  118. void SetEyeHeight( float height );
  119. float EyeHeight( void ) const;
  120. idVec3 EyeOffset( void ) const;
  121. idVec3 GetEyePosition( void ) const;
  122. virtual void GetViewPos( idVec3 &origin, idMat3 &axis ) const;
  123. void SetFOV( float fov );
  124. bool CheckFOV( const idVec3 &pos ) const;
  125. bool CanSee( idEntity *ent, bool useFOV ) const;
  126. bool PointVisible( const idVec3 &point ) const;
  127. virtual void GetAIAimTargets( const idVec3 &lastSightPos, idVec3 &headPos, idVec3 &chestPos );
  128. // damage
  129. void SetupDamageGroups( void );
  130. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  131. int GetDamageForLocation( int damage, int location );
  132. const char * GetDamageGroup( int location );
  133. void ClearPain( void );
  134. virtual bool Pain( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  135. // model/combat model/ragdoll
  136. void SetCombatModel( void );
  137. idClipModel * GetCombatModel( void ) const;
  138. virtual void LinkCombat( void );
  139. virtual void UnlinkCombat( void );
  140. bool StartRagdoll( void );
  141. void StopRagdoll( void );
  142. virtual bool UpdateAnimationControllers( void );
  143. // delta view angles to allow movers to rotate the view of the actor
  144. const idAngles & GetDeltaViewAngles( void ) const;
  145. void SetDeltaViewAngles( const idAngles &delta );
  146. bool HasEnemies( void ) const;
  147. idActor * ClosestEnemyToPoint( const idVec3 &pos );
  148. idActor * EnemyWithMostHealth();
  149. virtual bool OnLadder( void ) const;
  150. virtual void GetAASLocation( idAAS *aas, idVec3 &pos, int &areaNum ) const;
  151. void Attach( idEntity *ent );
  152. virtual void Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
  153. virtual renderView_t * GetRenderView();
  154. // animation state control
  155. int GetAnim( int channel, const char *name );
  156. void UpdateAnimState( void );
  157. void SetAnimState( int channel, const char *name, int blendFrames );
  158. const char * GetAnimState( int channel ) const;
  159. bool InAnimState( int channel, const char *name ) const;
  160. const char * WaitState( void ) const;
  161. void SetWaitState( const char *_waitstate );
  162. bool AnimDone( int channel, int blendFrames ) const;
  163. virtual void SpawnGibs( const idVec3 &dir, const char *damageDefName );
  164. protected:
  165. friend class idAnimState;
  166. float fovDot; // cos( fovDegrees )
  167. idVec3 eyeOffset; // offset of eye relative to physics origin
  168. idVec3 modelOffset; // offset of visual model relative to the physics origin
  169. idAngles deltaViewAngles; // delta angles relative to view input angles
  170. int pain_debounce_time; // next time the actor can show pain
  171. int pain_delay; // time between playing pain sound
  172. int pain_threshold; // how much damage monster can take at any one time before playing pain animation
  173. idStrList damageGroups; // body damage groups
  174. idList<float> damageScale; // damage scale per damage gruop
  175. bool use_combat_bbox; // whether to use the bounding box for combat collision
  176. idEntityPtr<idAFAttachment> head;
  177. idList<copyJoints_t> copyJoints; // copied from the body animation to the head model
  178. // state variables
  179. const function_t *state;
  180. const function_t *idealState;
  181. // joint handles
  182. jointHandle_t leftEyeJoint;
  183. jointHandle_t rightEyeJoint;
  184. jointHandle_t soundJoint;
  185. idIK_Walk walkIK;
  186. idStr animPrefix;
  187. idStr painAnim;
  188. // blinking
  189. int blink_anim;
  190. int blink_time;
  191. int blink_min;
  192. int blink_max;
  193. // script variables
  194. idThread * scriptThread;
  195. idStr waitState;
  196. idAnimState headAnim;
  197. idAnimState torsoAnim;
  198. idAnimState legsAnim;
  199. bool allowPain;
  200. bool allowEyeFocus;
  201. bool finalBoss;
  202. int painTime;
  203. idList<idAttachInfo> attachments;
  204. virtual void Gib( const idVec3 &dir, const char *damageDefName );
  205. // removes attachments with "remove" set for when character dies
  206. void RemoveAttachments( void );
  207. // copies animation from body to head joints
  208. void CopyJointsFromBodyToHead( void );
  209. private:
  210. void SyncAnimChannels( int channel, int syncToChannel, int blendFrames );
  211. void FinishSetup( void );
  212. void SetupHead( void );
  213. void PlayFootStepSound( void );
  214. void Event_EnableEyeFocus( void );
  215. void Event_DisableEyeFocus( void );
  216. void Event_Footstep( void );
  217. void Event_EnableWalkIK( void );
  218. void Event_DisableWalkIK( void );
  219. void Event_EnableLegIK( int num );
  220. void Event_DisableLegIK( int num );
  221. void Event_SetAnimPrefix( const char *name );
  222. void Event_LookAtEntity( idEntity *ent, float duration );
  223. void Event_PreventPain( float duration );
  224. void Event_DisablePain( void );
  225. void Event_EnablePain( void );
  226. void Event_GetPainAnim( void );
  227. void Event_StopAnim( int channel, int frames );
  228. void Event_PlayAnim( int channel, const char *name );
  229. void Event_PlayCycle( int channel, const char *name );
  230. void Event_IdleAnim( int channel, const char *name );
  231. void Event_SetSyncedAnimWeight( int channel, int anim, float weight );
  232. void Event_OverrideAnim( int channel );
  233. void Event_EnableAnim( int channel, int blendFrames );
  234. void Event_SetBlendFrames( int channel, int blendFrames );
  235. void Event_GetBlendFrames( int channel );
  236. void Event_AnimState( int channel, const char *name, int blendFrames );
  237. void Event_GetAnimState( int channel );
  238. void Event_InAnimState( int channel, const char *name );
  239. void Event_FinishAction( const char *name );
  240. void Event_AnimDone( int channel, int blendFrames );
  241. void Event_HasAnim( int channel, const char *name );
  242. void Event_CheckAnim( int channel, const char *animname );
  243. void Event_ChooseAnim( int channel, const char *animname );
  244. void Event_AnimLength( int channel, const char *animname );
  245. void Event_AnimDistance( int channel, const char *animname );
  246. void Event_HasEnemies( void );
  247. void Event_NextEnemy( idEntity *ent );
  248. void Event_ClosestEnemyToPoint( const idVec3 &pos );
  249. void Event_StopSound( int channel, int netsync );
  250. void Event_SetNextState( const char *name );
  251. void Event_SetState( const char *name );
  252. void Event_GetState( void );
  253. void Event_GetHead( void );
  254. };
  255. #endif /* !__GAME_ACTOR_H__ */