Actor.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. #ifdef _D3XP
  43. extern const idEventDef AI_SetState;
  44. #endif
  45. class idDeclParticle;
  46. class idAnimState {
  47. public:
  48. bool idleAnim;
  49. idStr state;
  50. int animBlendFrames;
  51. int lastAnimBlendFrames; // allows override anims to blend based on the last transition time
  52. public:
  53. idAnimState();
  54. ~idAnimState();
  55. void Save( idSaveGame *savefile ) const;
  56. void Restore( idRestoreGame *savefile );
  57. void Init( idActor *owner, idAnimator *_animator, int animchannel );
  58. void Shutdown( void );
  59. void SetState( const char *name, int blendFrames );
  60. void StopAnim( int frames );
  61. void PlayAnim( int anim );
  62. void CycleAnim( int anim );
  63. void BecomeIdle( void );
  64. bool UpdateState( void );
  65. bool Disabled( void ) const;
  66. void Enable( int blendFrames );
  67. void Disable( void );
  68. bool AnimDone( int blendFrames ) const;
  69. bool IsIdle( void ) const;
  70. animFlags_t GetAnimFlags( void ) const;
  71. private:
  72. idActor * self;
  73. idAnimator * animator;
  74. idThread * thread;
  75. int channel;
  76. bool disabled;
  77. };
  78. class idAttachInfo {
  79. public:
  80. idEntityPtr<idEntity> ent;
  81. int channel;
  82. };
  83. typedef struct {
  84. jointModTransform_t mod;
  85. jointHandle_t from;
  86. jointHandle_t to;
  87. } copyJoints_t;
  88. class idActor : public idAFEntity_Gibbable {
  89. public:
  90. CLASS_PROTOTYPE( idActor );
  91. int team;
  92. int rank; // monsters don't fight back if the attacker's rank is higher
  93. idMat3 viewAxis; // view axis of the actor
  94. idLinkList<idActor> enemyNode; // node linked into an entity's enemy list for quick lookups of who is attacking him
  95. idLinkList<idActor> enemyList; // list of characters that have targeted the player as their enemy
  96. public:
  97. idActor( void );
  98. virtual ~idActor( void );
  99. void Spawn( void );
  100. virtual void Restart( void );
  101. void Save( idSaveGame *savefile ) const;
  102. void Restore( idRestoreGame *savefile );
  103. virtual void Hide( void );
  104. virtual void Show( void );
  105. virtual int GetDefaultSurfaceType( void ) const;
  106. virtual void ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
  107. virtual bool LoadAF( void );
  108. void SetupBody( void );
  109. void CheckBlink( void );
  110. virtual bool GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
  111. virtual bool GetPhysicsToSoundTransform( idVec3 &origin, idMat3 &axis );
  112. // script state management
  113. void ShutdownThreads( void );
  114. virtual bool ShouldConstructScriptObjectAtSpawn( void ) const;
  115. virtual idThread * ConstructScriptObject( void );
  116. void UpdateScript( void );
  117. const function_t *GetScriptFunction( const char *funcname );
  118. void SetState( const function_t *newState );
  119. void SetState( const char *statename );
  120. // vision testing
  121. void SetEyeHeight( float height );
  122. float EyeHeight( void ) const;
  123. idVec3 EyeOffset( void ) const;
  124. idVec3 GetEyePosition( void ) const;
  125. virtual void GetViewPos( idVec3 &origin, idMat3 &axis ) const;
  126. void SetFOV( float fov );
  127. bool CheckFOV( const idVec3 &pos ) const;
  128. bool CanSee( idEntity *ent, bool useFOV ) const;
  129. bool PointVisible( const idVec3 &point ) const;
  130. virtual void GetAIAimTargets( const idVec3 &lastSightPos, idVec3 &headPos, idVec3 &chestPos );
  131. // damage
  132. void SetupDamageGroups( void );
  133. virtual void Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
  134. int GetDamageForLocation( int damage, int location );
  135. const char * GetDamageGroup( int location );
  136. void ClearPain( void );
  137. virtual bool Pain( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  138. // model/combat model/ragdoll
  139. void SetCombatModel( void );
  140. idClipModel * GetCombatModel( void ) const;
  141. virtual void LinkCombat( void );
  142. virtual void UnlinkCombat( void );
  143. bool StartRagdoll( void );
  144. void StopRagdoll( void );
  145. virtual bool UpdateAnimationControllers( void );
  146. // delta view angles to allow movers to rotate the view of the actor
  147. const idAngles & GetDeltaViewAngles( void ) const;
  148. void SetDeltaViewAngles( const idAngles &delta );
  149. bool HasEnemies( void ) const;
  150. idActor * ClosestEnemyToPoint( const idVec3 &pos );
  151. idActor * EnemyWithMostHealth();
  152. virtual bool OnLadder( void ) const;
  153. virtual void GetAASLocation( idAAS *aas, idVec3 &pos, int &areaNum ) const;
  154. void Attach( idEntity *ent );
  155. virtual void Teleport( const idVec3 &origin, const idAngles &angles, idEntity *destination );
  156. virtual renderView_t * GetRenderView();
  157. // animation state control
  158. int GetAnim( int channel, const char *name );
  159. void UpdateAnimState( void );
  160. void SetAnimState( int channel, const char *name, int blendFrames );
  161. const char * GetAnimState( int channel ) const;
  162. bool InAnimState( int channel, const char *name ) const;
  163. const char * WaitState( void ) const;
  164. void SetWaitState( const char *_waitstate );
  165. bool AnimDone( int channel, int blendFrames ) const;
  166. virtual void SpawnGibs( const idVec3 &dir, const char *damageDefName );
  167. #ifdef _D3XP
  168. idEntity* GetHeadEntity() { return head.GetEntity(); };
  169. #endif
  170. protected:
  171. friend class idAnimState;
  172. float fovDot; // cos( fovDegrees )
  173. idVec3 eyeOffset; // offset of eye relative to physics origin
  174. idVec3 modelOffset; // offset of visual model relative to the physics origin
  175. idAngles deltaViewAngles; // delta angles relative to view input angles
  176. int pain_debounce_time; // next time the actor can show pain
  177. int pain_delay; // time between playing pain sound
  178. int pain_threshold; // how much damage monster can take at any one time before playing pain animation
  179. idStrList damageGroups; // body damage groups
  180. idList<float> damageScale; // damage scale per damage gruop
  181. bool use_combat_bbox; // whether to use the bounding box for combat collision
  182. idEntityPtr<idAFAttachment> head;
  183. idList<copyJoints_t> copyJoints; // copied from the body animation to the head model
  184. // state variables
  185. const function_t *state;
  186. const function_t *idealState;
  187. // joint handles
  188. jointHandle_t leftEyeJoint;
  189. jointHandle_t rightEyeJoint;
  190. jointHandle_t soundJoint;
  191. idIK_Walk walkIK;
  192. idStr animPrefix;
  193. idStr painAnim;
  194. // blinking
  195. int blink_anim;
  196. int blink_time;
  197. int blink_min;
  198. int blink_max;
  199. // script variables
  200. idThread * scriptThread;
  201. idStr waitState;
  202. idAnimState headAnim;
  203. idAnimState torsoAnim;
  204. idAnimState legsAnim;
  205. bool allowPain;
  206. bool allowEyeFocus;
  207. bool finalBoss;
  208. int painTime;
  209. idList<idAttachInfo> attachments;
  210. #ifdef _D3XP
  211. int damageCap;
  212. #endif
  213. virtual void Gib( const idVec3 &dir, const char *damageDefName );
  214. // removes attachments with "remove" set for when character dies
  215. void RemoveAttachments( void );
  216. // copies animation from body to head joints
  217. void CopyJointsFromBodyToHead( void );
  218. private:
  219. void SyncAnimChannels( int channel, int syncToChannel, int blendFrames );
  220. void FinishSetup( void );
  221. void SetupHead( void );
  222. void PlayFootStepSound( void );
  223. void Event_EnableEyeFocus( void );
  224. void Event_DisableEyeFocus( void );
  225. void Event_Footstep( void );
  226. void Event_EnableWalkIK( void );
  227. void Event_DisableWalkIK( void );
  228. void Event_EnableLegIK( int num );
  229. void Event_DisableLegIK( int num );
  230. void Event_SetAnimPrefix( const char *name );
  231. void Event_LookAtEntity( idEntity *ent, float duration );
  232. void Event_PreventPain( float duration );
  233. void Event_DisablePain( void );
  234. void Event_EnablePain( void );
  235. void Event_GetPainAnim( void );
  236. void Event_StopAnim( int channel, int frames );
  237. void Event_PlayAnim( int channel, const char *name );
  238. void Event_PlayCycle( int channel, const char *name );
  239. void Event_IdleAnim( int channel, const char *name );
  240. void Event_SetSyncedAnimWeight( int channel, int anim, float weight );
  241. void Event_OverrideAnim( int channel );
  242. void Event_EnableAnim( int channel, int blendFrames );
  243. void Event_SetBlendFrames( int channel, int blendFrames );
  244. void Event_GetBlendFrames( int channel );
  245. void Event_AnimState( int channel, const char *name, int blendFrames );
  246. void Event_GetAnimState( int channel );
  247. void Event_InAnimState( int channel, const char *name );
  248. void Event_FinishAction( const char *name );
  249. void Event_AnimDone( int channel, int blendFrames );
  250. void Event_HasAnim( int channel, const char *name );
  251. void Event_CheckAnim( int channel, const char *animname );
  252. void Event_ChooseAnim( int channel, const char *animname );
  253. void Event_AnimLength( int channel, const char *animname );
  254. void Event_AnimDistance( int channel, const char *animname );
  255. void Event_HasEnemies( void );
  256. void Event_NextEnemy( idEntity *ent );
  257. void Event_ClosestEnemyToPoint( const idVec3 &pos );
  258. void Event_StopSound( int channel, int netsync );
  259. void Event_SetNextState( const char *name );
  260. void Event_SetState( const char *name );
  261. void Event_GetState( void );
  262. void Event_GetHead( void );
  263. #ifdef _D3XP
  264. void Event_SetDamageGroupScale( const char* groupName, float scale);
  265. void Event_SetDamageGroupScaleAll( float scale );
  266. void Event_GetDamageGroupScale( const char* groupName );
  267. void Event_SetDamageCap( float _damageCap );
  268. void Event_SetWaitState( const char* waitState);
  269. void Event_GetWaitState();
  270. #endif
  271. };
  272. #endif /* !__GAME_ACTOR_H__ */