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