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