]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/game/AFEntity.h
hello world
[icculus/iodoom3.git] / neo / game / 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         virtual void                    SpawnGibs( const idVec3 &dir, const char *damageDefName );
226
227 protected:
228         idRenderModel *                 skeletonModel;
229         int                                             skeletonModelDefHandle;
230         bool                                    gibbed;
231
232         virtual void                    Gib( const idVec3 &dir, const char *damageDefName );
233         void                                    InitSkeletonModel( void );
234
235         void                                    Event_Gib( const char *damageDefName );
236 };
237
238 /*
239 ===============================================================================
240
241         idAFEntity_Generic
242
243 ===============================================================================
244 */
245
246 class idAFEntity_Generic : public idAFEntity_Gibbable {
247 public:
248         CLASS_PROTOTYPE( idAFEntity_Generic );
249
250                                                         idAFEntity_Generic( void );
251                                                         ~idAFEntity_Generic( void );
252
253         void                                    Spawn( void );
254
255         void                                    Save( idSaveGame *savefile ) const;
256         void                                    Restore( idRestoreGame *savefile );
257
258         virtual void                    Think( void );
259         void                                    KeepRunningPhysics( void ) { keepRunningPhysics = true; }
260
261 private:
262         void                                    Event_Activate( idEntity *activator );
263
264         bool                                    keepRunningPhysics;
265 };
266
267
268 /*
269 ===============================================================================
270
271 idAFEntity_WithAttachedHead
272
273 ===============================================================================
274 */
275
276 class idAFEntity_WithAttachedHead : public idAFEntity_Gibbable {
277 public:
278         CLASS_PROTOTYPE( idAFEntity_WithAttachedHead );
279
280                                                         idAFEntity_WithAttachedHead();
281                                                         ~idAFEntity_WithAttachedHead();
282
283         void                                    Spawn( void );
284
285         void                                    Save( idSaveGame *savefile ) const;
286         void                                    Restore( idRestoreGame *savefile );
287
288         void                                    SetupHead( void );
289
290         virtual void                    Think( void );
291
292         virtual void                    Hide( void );
293         virtual void                    Show( void );
294         virtual void                    ProjectOverlay( const idVec3 &origin, const idVec3 &dir, float size, const char *material );
295
296         virtual void                    LinkCombat( void );
297         virtual void                    UnlinkCombat( void );
298
299 protected:
300         virtual void                    Gib( const idVec3 &dir, const char *damageDefName );
301
302 private:
303         idEntityPtr<idAFAttachment>     head;
304
305         void                                    Event_Gib( const char *damageDefName );
306         void                                    Event_Activate( idEntity *activator );
307 };
308
309
310 /*
311 ===============================================================================
312
313 idAFEntity_Vehicle
314
315 ===============================================================================
316 */
317
318 class idAFEntity_Vehicle : public idAFEntity_Base {
319 public:
320         CLASS_PROTOTYPE( idAFEntity_Vehicle );
321
322                                                         idAFEntity_Vehicle( void );
323
324         void                                    Spawn( void );
325         void                                    Use( idPlayer *player );
326
327 protected:
328         idPlayer *                              player;
329         jointHandle_t                   eyesJoint;
330         jointHandle_t                   steeringWheelJoint;
331         float                                   wheelRadius;
332         float                                   steerAngle;
333         float                                   steerSpeed;
334         const idDeclParticle *  dustSmoke;
335
336         float                                   GetSteerAngle( void );
337 };
338
339
340 /*
341 ===============================================================================
342
343 idAFEntity_VehicleSimple
344
345 ===============================================================================
346 */
347
348 class idAFEntity_VehicleSimple : public idAFEntity_Vehicle {
349 public:
350         CLASS_PROTOTYPE( idAFEntity_VehicleSimple );
351
352                                                         idAFEntity_VehicleSimple( void );
353                                                         ~idAFEntity_VehicleSimple( void );
354
355         void                                    Spawn( void );
356         virtual void                    Think( void );
357
358 protected:
359         idClipModel *                   wheelModel;
360         idAFConstraint_Suspension *     suspension[4];
361         jointHandle_t                   wheelJoints[4];
362         float                                   wheelAngles[4];
363 };
364
365
366 /*
367 ===============================================================================
368
369 idAFEntity_VehicleFourWheels
370
371 ===============================================================================
372 */
373
374 class idAFEntity_VehicleFourWheels : public idAFEntity_Vehicle {
375 public:
376         CLASS_PROTOTYPE( idAFEntity_VehicleFourWheels );
377
378                                                         idAFEntity_VehicleFourWheels( void );
379
380         void                                    Spawn( void );
381         virtual void                    Think( void );
382
383 protected:
384         idAFBody *                              wheels[4];
385         idAFConstraint_Hinge *  steering[2];
386         jointHandle_t                   wheelJoints[4];
387         float                                   wheelAngles[4];
388 };
389
390
391 /*
392 ===============================================================================
393
394 idAFEntity_VehicleSixWheels
395
396 ===============================================================================
397 */
398
399 class idAFEntity_VehicleSixWheels : public idAFEntity_Vehicle {
400 public:
401         CLASS_PROTOTYPE( idAFEntity_VehicleSixWheels );
402
403                                                         idAFEntity_VehicleSixWheels( void );
404
405         void                                    Spawn( void );
406         virtual void                    Think( void );
407
408 private:
409         idAFBody *                              wheels[6];
410         idAFConstraint_Hinge *  steering[4];
411         jointHandle_t                   wheelJoints[6];
412         float                                   wheelAngles[6];
413 };
414
415
416 /*
417 ===============================================================================
418
419 idAFEntity_SteamPipe
420
421 ===============================================================================
422 */
423
424 class idAFEntity_SteamPipe : public idAFEntity_Base {
425 public:
426         CLASS_PROTOTYPE( idAFEntity_SteamPipe );
427
428                                                         idAFEntity_SteamPipe( void );
429                                                         ~idAFEntity_SteamPipe( void );
430
431         void                                    Spawn( void );
432         void                                    Save( idSaveGame *savefile ) const;
433         void                                    Restore( idRestoreGame *savefile );
434
435         virtual void                    Think( void );
436
437 private:
438         int                                             steamBody;
439         float                                   steamForce;
440         float                                   steamUpForce;
441         idForce_Constant                force;
442         renderEntity_t                  steamRenderEntity;
443         qhandle_t                               steamModelDefHandle;
444
445         void                                    InitSteamRenderEntity( void );
446 };
447
448
449 /*
450 ===============================================================================
451
452 idAFEntity_ClawFourFingers
453
454 ===============================================================================
455 */
456
457 class idAFEntity_ClawFourFingers : public idAFEntity_Base {
458 public:
459         CLASS_PROTOTYPE( idAFEntity_ClawFourFingers );
460
461                                                         idAFEntity_ClawFourFingers( void );
462
463         void                                    Spawn( void );
464         void                                    Save( idSaveGame *savefile ) const;
465         void                                    Restore( idRestoreGame *savefile );
466
467 private:
468         idAFConstraint_Hinge *  fingers[4];
469
470         void                                    Event_SetFingerAngle( float angle );
471         void                                    Event_StopFingers( void );
472 };
473
474 #endif /* !__GAME_AFENTITY_H__ */