]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/Actor.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / d3xp / 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 #ifdef _D3XP
57 extern const idEventDef AI_SetState;
58 #endif
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 #ifdef _D3XP
213         idEntity*                               GetHeadEntity() { return head.GetEntity(); };
214 #endif
215
216 protected:
217         friend class                    idAnimState;
218
219         float                                   fovDot;                         // cos( fovDegrees )
220         idVec3                                  eyeOffset;                      // offset of eye relative to physics origin
221         idVec3                                  modelOffset;            // offset of visual model relative to the physics origin
222
223         idAngles                                deltaViewAngles;        // delta angles relative to view input angles
224
225         int                                             pain_debounce_time;     // next time the actor can show pain
226         int                                             pain_delay;                     // time between playing pain sound
227         int                                             pain_threshold;         // how much damage monster can take at any one time before playing pain animation
228
229         idStrList                               damageGroups;           // body damage groups
230         idList<float>                   damageScale;            // damage scale per damage gruop
231
232         bool                                            use_combat_bbox;        // whether to use the bounding box for combat collision
233         idEntityPtr<idAFAttachment>     head;
234         idList<copyJoints_t>            copyJoints;                     // copied from the body animation to the head model
235
236         // state variables
237         const function_t                *state;
238         const function_t                *idealState;
239
240         // joint handles
241         jointHandle_t                   leftEyeJoint;
242         jointHandle_t                   rightEyeJoint;
243         jointHandle_t                   soundJoint;
244
245         idIK_Walk                               walkIK;
246
247         idStr                                   animPrefix;
248         idStr                                   painAnim;
249
250         // blinking
251         int                                             blink_anim;
252         int                                             blink_time;
253         int                                             blink_min;
254         int                                             blink_max;
255
256         // script variables
257         idThread *                              scriptThread;
258         idStr                                   waitState;
259         idAnimState                             headAnim;
260         idAnimState                             torsoAnim;
261         idAnimState                             legsAnim;
262
263         bool                                    allowPain;
264         bool                                    allowEyeFocus;
265         bool                                    finalBoss;
266
267         int                                             painTime;
268
269         idList<idAttachInfo>    attachments;
270
271 #ifdef _D3XP
272         int                                             damageCap;
273 #endif
274
275         virtual void                    Gib( const idVec3 &dir, const char *damageDefName );
276
277                                                         // removes attachments with "remove" set for when character dies
278         void                                    RemoveAttachments( void );
279
280                                                         // copies animation from body to head joints
281         void                                    CopyJointsFromBodyToHead( void );
282
283 private:
284         void                                    SyncAnimChannels( int channel, int syncToChannel, int blendFrames );
285         void                                    FinishSetup( void );
286         void                                    SetupHead( void );
287         void                                    PlayFootStepSound( void );
288
289         void                                    Event_EnableEyeFocus( void );
290         void                                    Event_DisableEyeFocus( void );
291         void                                    Event_Footstep( void );
292         void                                    Event_EnableWalkIK( void );
293         void                                    Event_DisableWalkIK( void );
294         void                                    Event_EnableLegIK( int num );
295         void                                    Event_DisableLegIK( int num );
296         void                                    Event_SetAnimPrefix( const char *name );
297         void                                    Event_LookAtEntity( idEntity *ent, float duration );
298         void                                    Event_PreventPain( float duration );
299         void                                    Event_DisablePain( void );
300         void                                    Event_EnablePain( void );
301         void                                    Event_GetPainAnim( void );
302         void                                    Event_StopAnim( int channel, int frames );
303         void                                    Event_PlayAnim( int channel, const char *name );
304         void                                    Event_PlayCycle( int channel, const char *name );
305         void                                    Event_IdleAnim( int channel, const char *name );
306         void                                    Event_SetSyncedAnimWeight( int channel, int anim, float weight );
307         void                                    Event_OverrideAnim( int channel );
308         void                                    Event_EnableAnim( int channel, int blendFrames );
309         void                                    Event_SetBlendFrames( int channel, int blendFrames );
310         void                                    Event_GetBlendFrames( int channel );
311         void                                    Event_AnimState( int channel, const char *name, int blendFrames );
312         void                                    Event_GetAnimState( int channel );
313         void                                    Event_InAnimState( int channel, const char *name );
314         void                                    Event_FinishAction( const char *name );
315         void                                    Event_AnimDone( int channel, int blendFrames );
316         void                                    Event_HasAnim( int channel, const char *name );
317         void                                    Event_CheckAnim( int channel, const char *animname );
318         void                                    Event_ChooseAnim( int channel, const char *animname );
319         void                                    Event_AnimLength( int channel, const char *animname );
320         void                                    Event_AnimDistance( int channel, const char *animname );
321         void                                    Event_HasEnemies( void );
322         void                                    Event_NextEnemy( idEntity *ent );
323         void                                    Event_ClosestEnemyToPoint( const idVec3 &pos );
324         void                                    Event_StopSound( int channel, int netsync );
325         void                                    Event_SetNextState( const char *name );
326         void                                    Event_SetState( const char *name );
327         void                                    Event_GetState( void );
328         void                                    Event_GetHead( void );
329 #ifdef _D3XP
330         void                                    Event_SetDamageGroupScale( const char* groupName, float scale);
331         void                                    Event_SetDamageGroupScaleAll( float scale );
332         void                                    Event_GetDamageGroupScale( const char* groupName );
333         void                                    Event_SetDamageCap( float _damageCap );
334         void                                    Event_SetWaitState( const char* waitState);
335         void                                    Event_GetWaitState();
336         
337 #endif
338 };
339
340 #endif /* !__GAME_ACTOR_H__ */