]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/AFEntity.h
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / d3xp / AFEntity.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_AFENTITY_H__
30 #define __GAME_AFENTITY_H__
31
32
33 /*
34 ===============================================================================
35
36 idMultiModelAF
37
38 Entity using multiple separate visual models animated with a single
39 articulated figure. Only used for debugging!
40
41 ===============================================================================
42 */
43 const int GIB_DELAY = 200;  // only gib this often to keep performace hits when blowing up several mobs
44
45 class idMultiModelAF : public idEntity {
46 public:
47         CLASS_PROTOTYPE( idMultiModelAF );
48
49         void                                    Spawn( void );
50                                                         ~idMultiModelAF( void );
51
52         virtual void                    Think( void );
53         virtual void                    Present( void );
54
55 protected:
56         idPhysics_AF                    physicsObj;
57
58         void                                    SetModelForId( int id, const idStr &modelName );
59
60 private:
61         idList<idRenderModel *> modelHandles;
62         idList<int>                             modelDefHandles;
63 };
64
65
66 /*
67 ===============================================================================
68
69 idChain
70
71 Chain hanging down from the ceiling. Only used for debugging!
72
73 ===============================================================================
74 */
75
76 class idChain : public idMultiModelAF {
77 public:
78         CLASS_PROTOTYPE( idChain );
79
80         void                                    Spawn( void );
81
82 protected:
83         void                                    BuildChain( const idStr &name, const idVec3 &origin, float linkLength, float linkWidth, float density, int numLinks, bool bindToWorld = true );
84 };
85
86
87 /*
88 ===============================================================================
89
90 idAFAttachment
91
92 ===============================================================================
93 */
94
95 class idAFAttachment : public idAnimatedEntity {
96 public:
97         CLASS_PROTOTYPE( idAFAttachment );
98
99                                                         idAFAttachment( void );
100         virtual                                 ~idAFAttachment( void );
101
102         void                                    Spawn( void );
103
104         void                                    Save( idSaveGame *savefile ) const;
105         void                                    Restore( idRestoreGame *savefile );
106
107         void                                    SetBody( idEntity *bodyEnt, const char *headModel, jointHandle_t attachJoint );
108         void                                    ClearBody( void );
109         idEntity *                              GetBody( void ) const;
110
111         virtual void                    Think( void );
112
113         virtual void                    Hide( void );
114         virtual void                    Show( void );
115
116         void                                    PlayIdleAnim( int blendTime );
117
118         virtual void                    GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
119         virtual void                    ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
120         virtual void                    AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
121
122         virtual void                    Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
123         virtual void                    AddDamageEffect( const trace_t &collision, const idVec3 &velocity, const char *damageDefName );
124
125         void                                    SetCombatModel( void );
126         idClipModel *                   GetCombatModel( void ) const;
127         virtual void                    LinkCombat( void );
128         virtual void                    UnlinkCombat( void );
129
130 protected:
131         idEntity *                              body;
132         idClipModel *                   combatModel;    // render model for hit detection of head
133         int                                             idleAnim;
134         jointHandle_t                   attachJoint;
135 };
136
137
138 /*
139 ===============================================================================
140
141 idAFEntity_Base
142
143 ===============================================================================
144 */
145
146 class idAFEntity_Base : public idAnimatedEntity {
147 public:
148         CLASS_PROTOTYPE( idAFEntity_Base );
149
150                                                         idAFEntity_Base( void );
151         virtual                                 ~idAFEntity_Base( void );
152
153         void                                    Spawn( void );
154
155         void                                    Save( idSaveGame *savefile ) const;
156         void                                    Restore( idRestoreGame *savefile );
157
158         virtual void                    Think( void );
159         virtual void                    GetImpactInfo( idEntity *ent, int id, const idVec3 &point, impactInfo_t *info );
160         virtual void                    ApplyImpulse( idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse );
161         virtual void                    AddForce( idEntity *ent, int id, const idVec3 &point, const idVec3 &force );
162         virtual bool                    Collide( const trace_t &collision, const idVec3 &velocity );
163         virtual bool                    GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
164         virtual bool                    UpdateAnimationControllers( void );
165         virtual void                    FreeModelDef( void );
166
167         virtual bool                    LoadAF( void );
168         bool                                    IsActiveAF( void ) const { return af.IsActive(); }
169         const char *                    GetAFName( void ) const { return af.GetName(); }
170         idPhysics_AF *                  GetAFPhysics( void ) { return af.GetPhysics(); }
171
172         void                                    SetCombatModel( void );
173         idClipModel *                   GetCombatModel( void ) const;
174                                                         // contents of combatModel can be set to 0 or re-enabled (mp)
175         void                                    SetCombatContents( bool enable );
176         virtual void                    LinkCombat( void );
177         virtual void                    UnlinkCombat( void );
178
179         int                                             BodyForClipModelId( int id ) const;
180
181         void                                    SaveState( idDict &args ) const;
182         void                                    LoadState( const idDict &args );
183
184         void                                    AddBindConstraints( void );
185         void                                    RemoveBindConstraints( void );
186
187         virtual void                    ShowEditingDialog( void );
188
189         static void                             DropAFs( idEntity *ent, const char *type, idList<idEntity *> *list );
190
191 protected:
192         idAF                                    af;                             // articulated figure
193         idClipModel *                   combatModel;    // render model for hit detection
194         int                                             combatModelContents;
195         idVec3                                  spawnOrigin;    // spawn origin
196         idMat3                                  spawnAxis;              // rotation axis used when spawned
197         int                                             nextSoundTime;  // next time this can make a sound
198
199         void                                    Event_SetConstraintPosition( const char *name, const idVec3 &pos );
200 };
201
202 /*
203 ===============================================================================
204
205 idAFEntity_Gibbable
206
207 ===============================================================================
208 */
209
210 extern const idEventDef         EV_Gib;
211 extern const idEventDef         EV_Gibbed;
212
213 class idAFEntity_Gibbable : public idAFEntity_Base {
214 public:
215         CLASS_PROTOTYPE( idAFEntity_Gibbable );
216
217                                                         idAFEntity_Gibbable( void );
218                                                         ~idAFEntity_Gibbable( void );
219
220         void                                    Spawn( void );
221         void                                    Save( idSaveGame *savefile ) const;
222         void                                    Restore( idRestoreGame *savefile );
223         virtual void                    Present( void );
224         virtual void                    Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, const char *damageDefName, const float damageScale, const int location );
225 #ifdef _D3XP
226         void                                    SetThrown( bool isThrown );
227         virtual bool                    Collide( const trace_t &collision, const idVec3 &velocity );
228 #endif
229         virtual void                    SpawnGibs( const idVec3 &dir, const char *damageDefName );
230
231 #ifdef _D3XP
232         bool                                    IsGibbed() { return gibbed; };
233 #endif
234
235 protected:
236         idRenderModel *                 skeletonModel;
237         int                                             skeletonModelDefHandle;
238         bool                                    gibbed;
239
240 #ifdef _D3XP
241         bool                                    wasThrown;
242 #endif
243
244         virtual void                    Gib( const idVec3 &dir, const char *damageDefName );
245         void                                    InitSkeletonModel( void );
246
247         void                                    Event_Gib( const char *damageDefName );
248 };
249
250 /*
251 ===============================================================================
252
253         idAFEntity_Generic
254
255 ===============================================================================
256 */
257
258 class idAFEntity_Generic : public idAFEntity_Gibbable {
259 public:
260         CLASS_PROTOTYPE( idAFEntity_Generic );
261
262                                                         idAFEntity_Generic( void );
263                                                         ~idAFEntity_Generic( void );
264
265         void                                    Spawn( void );
266
267         void                                    Save( idSaveGame *savefile ) const;
268         void                                    Restore( idRestoreGame *savefile );
269
270         virtual void                    Think( void );
271         void                                    KeepRunningPhysics( void ) { keepRunningPhysics = true; }
272
273 private:
274         void                                    Event_Activate( idEntity *activator );
275
276         bool                                    keepRunningPhysics;
277 };
278
279
280 /*
281 ===============================================================================
282
283 idAFEntity_WithAttachedHead
284
285 ===============================================================================
286 */
287
288 class idAFEntity_WithAttachedHead : public idAFEntity_Gibbable {
289 public:
290         CLASS_PROTOTYPE( idAFEntity_WithAttachedHead );
291
292                                                         idAFEntity_WithAttachedHead();
293                                                         ~idAFEntity_WithAttachedHead();
294
295         void                                    Spawn( void );
296
297         void                                    Save( idSaveGame *savefile ) const;
298         void                                    Restore( idRestoreGame *savefile );
299
300         void                                    SetupHead( void );
301
302         virtual void                    Think( void );
303
304         virtual void                    Hide( void );
305         virtual void                    Show( void );
306         virtual void                    ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
307
308         virtual void                    LinkCombat( void );
309         virtual void                    UnlinkCombat( void );
310
311 protected:
312         virtual void                    Gib( const idVec3 &dir, const char *damageDefName );
313
314 #ifndef _D3XP
315 private:
316 #else
317 public:
318 #endif
319         idEntityPtr<idAFAttachment>     head;
320
321         void                                    Event_Gib( const char *damageDefName );
322         void                                    Event_Activate( idEntity *activator );
323 };
324
325
326 /*
327 ===============================================================================
328
329 idAFEntity_Vehicle
330
331 ===============================================================================
332 */
333
334 class idAFEntity_Vehicle : public idAFEntity_Base {
335 public:
336         CLASS_PROTOTYPE( idAFEntity_Vehicle );
337
338                                                         idAFEntity_Vehicle( void );
339
340         void                                    Spawn( void );
341         void                                    Use( idPlayer *player );
342
343 protected:
344         idPlayer *                              player;
345         jointHandle_t                   eyesJoint;
346         jointHandle_t                   steeringWheelJoint;
347         float                                   wheelRadius;
348         float                                   steerAngle;
349         float                                   steerSpeed;
350         const idDeclParticle *  dustSmoke;
351
352         float                                   GetSteerAngle( void );
353 };
354
355
356 /*
357 ===============================================================================
358
359 idAFEntity_VehicleSimple
360
361 ===============================================================================
362 */
363
364 class idAFEntity_VehicleSimple : public idAFEntity_Vehicle {
365 public:
366         CLASS_PROTOTYPE( idAFEntity_VehicleSimple );
367
368                                                         idAFEntity_VehicleSimple( void );
369                                                         ~idAFEntity_VehicleSimple( void );
370
371         void                                    Spawn( void );
372         virtual void                    Think( void );
373
374 protected:
375         idClipModel *                   wheelModel;
376         idAFConstraint_Suspension *     suspension[4];
377         jointHandle_t                   wheelJoints[4];
378         float                                   wheelAngles[4];
379 };
380
381
382 /*
383 ===============================================================================
384
385 idAFEntity_VehicleFourWheels
386
387 ===============================================================================
388 */
389
390 class idAFEntity_VehicleFourWheels : public idAFEntity_Vehicle {
391 public:
392         CLASS_PROTOTYPE( idAFEntity_VehicleFourWheels );
393
394                                                         idAFEntity_VehicleFourWheels( void );
395
396         void                                    Spawn( void );
397         virtual void                    Think( void );
398
399 protected:
400         idAFBody *                              wheels[4];
401         idAFConstraint_Hinge *  steering[2];
402         jointHandle_t                   wheelJoints[4];
403         float                                   wheelAngles[4];
404 };
405
406
407 /*
408 ===============================================================================
409
410 idAFEntity_VehicleSixWheels
411
412 ===============================================================================
413 */
414
415 class idAFEntity_VehicleSixWheels : public idAFEntity_Vehicle {
416 public:
417         CLASS_PROTOTYPE( idAFEntity_VehicleSixWheels );
418
419                                                         idAFEntity_VehicleSixWheels( void );
420
421         void                                    Spawn( void );
422         virtual void                    Think( void );
423
424 #ifdef _D3XP
425         float                                   force;
426         float                                   velocity;
427         float                                   steerAngle;
428 #endif
429
430 private:
431         idAFBody *                              wheels[6];
432         idAFConstraint_Hinge *  steering[4];
433         jointHandle_t                   wheelJoints[6];
434         float                                   wheelAngles[6];
435 };
436
437 #ifdef _D3XP
438 /*
439 ===============================================================================
440
441 idAFEntity_VehicleAutomated
442
443 ===============================================================================
444 */
445
446 class idAFEntity_VehicleAutomated : public idAFEntity_VehicleSixWheels {
447 public:
448         CLASS_PROTOTYPE( idAFEntity_VehicleAutomated );
449
450         void                                    Spawn( void );
451         void                                    PostSpawn( void );
452         virtual void                    Think( void );
453
454 private:
455
456         idEntity        *waypoint;
457         float           steeringSpeed;
458         float           currentSteering;
459         float           idealSteering;
460         float           originHeight;
461
462         void            Event_SetVelocity( float _velocity );
463         void            Event_SetTorque( float _torque );
464         void            Event_SetSteeringSpeed( float _steeringSpeed );
465         void            Event_SetWayPoint( idEntity *_waypoint );
466 };
467 #endif
468
469 /*
470 ===============================================================================
471
472 idAFEntity_SteamPipe
473
474 ===============================================================================
475 */
476
477 class idAFEntity_SteamPipe : public idAFEntity_Base {
478 public:
479         CLASS_PROTOTYPE( idAFEntity_SteamPipe );
480
481                                                         idAFEntity_SteamPipe( void );
482                                                         ~idAFEntity_SteamPipe( void );
483
484         void                                    Spawn( void );
485         void                                    Save( idSaveGame *savefile ) const;
486         void                                    Restore( idRestoreGame *savefile );
487
488         virtual void                    Think( void );
489
490 private:
491         int                                             steamBody;
492         float                                   steamForce;
493         float                                   steamUpForce;
494         idForce_Constant                force;
495         renderEntity_t                  steamRenderEntity;
496         qhandle_t                               steamModelDefHandle;
497
498         void                                    InitSteamRenderEntity( void );
499 };
500
501
502 /*
503 ===============================================================================
504
505 idAFEntity_ClawFourFingers
506
507 ===============================================================================
508 */
509
510 class idAFEntity_ClawFourFingers : public idAFEntity_Base {
511 public:
512         CLASS_PROTOTYPE( idAFEntity_ClawFourFingers );
513
514                                                         idAFEntity_ClawFourFingers( void );
515
516         void                                    Spawn( void );
517         void                                    Save( idSaveGame *savefile ) const;
518         void                                    Restore( idRestoreGame *savefile );
519
520 private:
521         idAFConstraint_Hinge *  fingers[4];
522
523         void                                    Event_SetFingerAngle( float angle );
524         void                                    Event_StopFingers( void );
525 };
526
527 #ifdef _D3XP
528
529 /** 
530 * idHarvestable contains all of the code required to turn an entity into a harvestable
531 * entity. The entity must create an instance of this class and call the appropriate
532 * interface methods at the correct time.
533 */
534 class idHarvestable : public idEntity {
535 public:
536         CLASS_PROTOTYPE( idHarvestable );
537
538         idHarvestable();
539         ~idHarvestable();
540
541         void                            Spawn();
542         void                            Init(idEntity* parent);
543         void                            Save( idSaveGame *savefile ) const;
544         void                            Restore( idRestoreGame *savefile );
545
546         void                            SetParent(idEntity* parent);
547
548         void                            Think();
549         void                            Gib();
550
551 protected:
552         idEntityPtr<idEntity>   parentEnt;
553         float                                   triggersize;
554         idClipModel *                   trigger;
555         float                                   giveDelay;
556         float                                   removeDelay;
557         bool                                    given;
558
559         idEntityPtr<idPlayer>   player;
560         int                                             startTime;
561
562         bool                                    fxFollowPlayer;
563         idEntityPtr<idEntityFx> fx;
564         idStr                                   fxOrient;
565
566 protected:
567         void                                    BeginBurn();
568         void                                    BeginFX();
569         void                                    CalcTriggerBounds( float size, idBounds &bounds );
570
571         bool                                    GetFxOrientationAxis(idMat3& mat);
572
573         void                                    Event_SpawnHarvestTrigger( void );
574         void                                    Event_Touch( idEntity *other, trace_t *trace );
575 } ;
576
577
578 /*
579 ===============================================================================
580
581 idAFEntity_Harvest
582
583 ===============================================================================
584 */
585
586
587
588 class idAFEntity_Harvest : public idAFEntity_WithAttachedHead {
589 public:
590         CLASS_PROTOTYPE( idAFEntity_Harvest );
591
592         idAFEntity_Harvest();
593         ~idAFEntity_Harvest();
594
595         void                                    Spawn( void );
596
597         void                                    Save( idSaveGame *savefile ) const;
598         void                                    Restore( idRestoreGame *savefile );
599
600         virtual void                    Think( void );
601
602         virtual void                    Gib( const idVec3 &dir, const char *damageDefName );
603
604 protected:
605         idEntityPtr<idHarvestable>      harvestEnt;
606 protected:
607         void                                    Event_SpawnHarvestEntity( void );
608
609 };
610 #endif
611
612 #endif /* !__GAME_AFENTITY_H__ */