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