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