]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/game/Moveable.h
Use the same OpenAL headers on all platforms.
[icculus/iodoom3.git] / neo / game / Moveable.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_MOVEABLE_H__
30 #define __GAME_MOVEABLE_H__
31
32 /*
33 ===============================================================================
34
35   Entity using rigid body physics.
36
37 ===============================================================================
38 */
39
40 extern const idEventDef EV_BecomeNonSolid;
41 extern const idEventDef EV_IsAtRest;
42
43 class idMoveable : public idEntity {
44 public:
45         CLASS_PROTOTYPE( idMoveable );
46
47                                                         idMoveable( void );
48                                                         ~idMoveable( void );
49
50         void                                    Spawn( void );
51
52         void                                    Save( idSaveGame *savefile ) const;
53         void                                    Restore( idRestoreGame *savefile );
54
55         virtual void                    Think( void );
56
57         virtual void                    Hide( void );
58         virtual void                    Show( void );
59
60         bool                                    AllowStep( void ) const;
61         void                                    EnableDamage( bool enable, float duration );
62         virtual bool                    Collide( const trace_t &collision, const idVec3 &velocity );
63         virtual void                    Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
64         virtual void                    WriteToSnapshot( idBitMsgDelta &msg ) const;
65         virtual void                    ReadFromSnapshot( const idBitMsgDelta &msg );
66
67 protected:
68         idPhysics_RigidBody             physicsObj;                             // physics object
69         idStr                                   brokenModel;                    // model set when health drops down to or below zero
70         idStr                                   damage;                                 // if > 0 apply damage to hit entities
71         idStr                                   fxCollide;                              // fx system to start when collides with something
72         int                                             nextCollideFxTime;              // next time it is ok to spawn collision fx
73         float                                   minDamageVelocity;              // minimum velocity before moveable applies damage
74         float                                   maxDamageVelocity;              // velocity at which the maximum damage is applied
75         idCurve_Spline<idVec3> *initialSpline;                  // initial spline path the moveable follows
76         idVec3                                  initialSplineDir;               // initial relative direction along the spline path
77         bool                                    explode;                                // entity explodes when health drops down to or below zero
78         bool                                    unbindOnDeath;                  // unbind from master when health drops down to or below zero
79         bool                                    allowStep;                              // allow monsters to step on the object
80         bool                                    canDamage;                              // only apply damage when this is set
81         int                                             nextDamageTime;                 // next time the movable can hurt the player
82         int                                             nextSoundTime;                  // next time the moveable can make a sound
83
84         const idMaterial *              GetRenderModelMaterial( void ) const;
85         void                                    BecomeNonSolid( void );
86         void                                    InitInitialSpline( int startTime );
87         bool                                    FollowInitialSplinePath( void );
88
89         void                                    Event_Activate( idEntity *activator );
90         void                                    Event_BecomeNonSolid( void );
91         void                                    Event_SetOwnerFromSpawnArgs( void );
92         void                                    Event_IsAtRest( void );
93         void                                    Event_EnableDamage( float enable );
94 };
95
96
97 /*
98 ===============================================================================
99
100   A barrel using rigid body physics. The barrel has special handling of
101   the view model orientation to make it look like it rolls instead of slides.
102
103 ===============================================================================
104 */
105
106 class idBarrel : public idMoveable {
107
108 public:
109         CLASS_PROTOTYPE( idBarrel );
110                                                         idBarrel();
111
112         void                                    Spawn( void );
113
114         void                                    Save( idSaveGame *savefile ) const;
115         void                                    Restore( idRestoreGame *savefile );
116
117         void                                    BarrelThink( void );
118         virtual void                    Think( void );
119         virtual bool                    GetPhysicsToVisualTransform( idVec3 &origin, idMat3 &axis );
120         virtual void                    ClientPredictionThink( void );
121
122 private:
123         float                                   radius;                                 // radius of barrel
124         int                                             barrelAxis;                             // one of the coordinate axes the barrel cylinder is parallel to
125         idVec3                                  lastOrigin;                             // origin of the barrel the last think frame
126         idMat3                                  lastAxis;                               // axis of the barrel the last think frame
127         float                                   additionalRotation;             // additional rotation of the barrel about it's axis
128         idMat3                                  additionalAxis;                 // additional rotation axis
129 };
130
131
132 /*
133 ===============================================================================
134
135   A barrel using rigid body physics and special handling of the view model
136   orientation to make it look like it rolls instead of slides. The barrel
137   can burn and explode when damaged.
138
139 ===============================================================================
140 */
141
142 class idExplodingBarrel : public idBarrel {
143 public:
144         CLASS_PROTOTYPE( idExplodingBarrel );
145
146                                                         idExplodingBarrel();
147                                                         ~idExplodingBarrel();
148
149         void                                    Spawn( void );
150
151         void                                    Save( idSaveGame *savefile ) const;
152         void                                    Restore( idRestoreGame *savefile );
153
154         virtual void                    Think( void );
155         virtual void                    Damage( idEntity *inflictor, idEntity *attacker, const idVec3 &dir, 
156                                                                 const char *damageDefName, const float damageScale, const int location );
157         virtual void                    Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
158
159         virtual void                    WriteToSnapshot( idBitMsgDelta &msg ) const;
160         virtual void                    ReadFromSnapshot( const idBitMsgDelta &msg );
161         virtual bool                    ClientReceiveEvent( int event, int time, const idBitMsg &msg );
162
163         enum {
164                 EVENT_EXPLODE = idEntity::EVENT_MAXEVENTS,
165                 EVENT_MAXEVENTS
166         };
167
168 private:
169         typedef enum {
170                 NORMAL = 0,
171                 BURNING,
172                 BURNEXPIRED,
173                 EXPLODING
174         } explode_state_t;
175         explode_state_t                 state;
176
177         idVec3                                  spawnOrigin;
178         idMat3                                  spawnAxis;
179         qhandle_t                               particleModelDefHandle;
180         qhandle_t                               lightDefHandle;
181         renderEntity_t                  particleRenderEntity;
182         renderLight_t                   light;
183         int                                             particleTime;
184         int                                             lightTime;
185         float                                   time;
186
187         void                                    AddParticles( const char *name, bool burn );
188         void                                    AddLight( const char *name , bool burn );
189         void                                    ExplodingEffects( void );
190
191         void                                    Event_Activate( idEntity *activator );
192         void                                    Event_Respawn();
193         void                                    Event_Explode();
194         void                                    Event_TriggerTargets();
195 };
196
197 #endif /* !__GAME_MOVEABLE_H__ */