]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/Projectile.h
hello world
[icculus/iodoom3.git] / neo / d3xp / Projectile.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_PROJECTILE_H__
30 #define __GAME_PROJECTILE_H__
31
32 /*
33 ===============================================================================
34
35   idProjectile
36         
37 ===============================================================================
38 */
39
40 extern const idEventDef EV_Explode;
41
42 class idProjectile : public idEntity {
43 public :
44         CLASS_PROTOTYPE( idProjectile );
45
46                                                         idProjectile();
47         virtual                                 ~idProjectile();
48
49         void                                    Spawn( void );
50
51         void                                    Save( idSaveGame *savefile ) const;
52         void                                    Restore( idRestoreGame *savefile );
53
54         void                                    Create( idEntity *owner, const idVec3 &start, const idVec3 &dir );
55         virtual void                    Launch( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity, const float timeSinceFire = 0.0f, const float launchPower = 1.0f, const float dmgPower = 1.0f );
56         virtual void                    FreeLightDef( void );
57
58         idEntity *                              GetOwner( void ) const;
59 #ifdef _D3XP
60         void                                    CatchProjectile( idEntity* o, const char* reflectName );
61         int                                             GetProjectileState( void );
62         void                                    Event_CreateProjectile( idEntity *owner, const idVec3 &start, const idVec3 &dir );
63         void                                    Event_LaunchProjectile( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity );
64         void                                    Event_SetGravity( float gravity );
65 #endif
66
67         virtual void                    Think( void );
68         virtual void                    Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
69         virtual bool                    Collide( const trace_t &collision, const idVec3 &velocity );
70         virtual void                    Explode( const trace_t &collision, idEntity *ignore );
71         void                                    Fizzle( void );
72
73         static idVec3                   GetVelocity( const idDict *projectile );
74         static idVec3                   GetGravity( const idDict *projectile );
75
76         enum {
77                 EVENT_DAMAGE_EFFECT = idEntity::EVENT_MAXEVENTS,
78                 EVENT_MAXEVENTS
79         };
80
81         static void                             DefaultDamageEffect( idEntity *soundEnt, const idDict &projectileDef, const trace_t &collision, const idVec3 &velocity );
82         static bool                             ClientPredictionCollide( idEntity *soundEnt, const idDict &projectileDef, const trace_t &collision, const idVec3 &velocity, bool addDamageEffect );
83         virtual void                    ClientPredictionThink( void );
84         virtual void                    WriteToSnapshot( idBitMsgDelta &msg ) const;
85         virtual void                    ReadFromSnapshot( const idBitMsgDelta &msg );
86         virtual bool                    ClientReceiveEvent( int event, int time, const idBitMsg &msg );
87
88 protected:
89         idEntityPtr<idEntity>   owner;
90
91         struct projectileFlags_s {
92                 bool                            detonate_on_world                       : 1;
93                 bool                            detonate_on_actor                       : 1;
94                 bool                            randomShaderSpin                        : 1;
95                 bool                            isTracer                                        : 1;
96                 bool                            noSplashDamage                          : 1;
97         } projectileFlags;
98
99         float                                   thrust;
100         int                                             thrust_end;
101         float                                   damagePower;
102
103         renderLight_t                   renderLight;
104         qhandle_t                               lightDefHandle;                         // handle to renderer light def
105         idVec3                                  lightOffset;
106         int                                             lightStartTime;
107         int                                             lightEndTime;
108         idVec3                                  lightColor;
109
110         idForce_Constant                thruster;
111         idPhysics_RigidBody             physicsObj;
112
113         const idDeclParticle *  smokeFly;
114         int                                             smokeFlyTime;
115
116 #ifdef _D3XP
117         int                                             originalTimeGroup;
118 #endif
119
120         typedef enum {
121                 // must update these in script/doom_defs.script if changed
122                 SPAWNED = 0,
123                 CREATED = 1,
124                 LAUNCHED = 2,
125                 FIZZLED = 3,
126                 EXPLODED = 4
127         } projectileState_t;
128         
129         projectileState_t               state;
130
131 private:
132         bool                                    netSyncPhysics;
133
134         void                                    AddDefaultDamageEffect( const trace_t &collision, const idVec3 &velocity );
135
136         void                                    Event_Explode( void );
137         void                                    Event_Fizzle( void );
138         void                                    Event_RadiusDamage( idEntity *ignore );
139         void                                    Event_Touch( idEntity *other, trace_t *trace );
140         void                                    Event_GetProjectileState( void );
141 };
142
143 class idGuidedProjectile : public idProjectile {
144 public :
145         CLASS_PROTOTYPE( idGuidedProjectile );
146
147                                                         idGuidedProjectile( void );
148                                                         ~idGuidedProjectile( void );
149
150         void                                    Save( idSaveGame *savefile ) const;
151         void                                    Restore( idRestoreGame *savefile );
152
153         void                                    Spawn( void );
154         virtual void                    Think( void );
155         virtual void                    Launch( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity, const float timeSinceFire = 0.0f, const float launchPower = 1.0f, const float dmgPower = 1.0f );
156 #ifdef _D3XP
157         void                                    SetEnemy( idEntity *ent );
158         void                                    Event_SetEnemy(idEntity *ent);
159 #endif
160
161 protected:
162         float                                   speed;
163         idEntityPtr<idEntity>   enemy;
164         virtual void                    GetSeekPos( idVec3 &out );
165
166 private:
167         idAngles                                rndScale;
168         idAngles                                rndAng;
169         idAngles                                angles;
170         int                                             rndUpdateTime;
171         float                                   turn_max;
172         float                                   clamp_dist;
173         bool                                    burstMode;
174         bool                                    unGuided;
175         float                                   burstDist;
176         float                                   burstVelocity;
177 };
178
179 class idSoulCubeMissile : public idGuidedProjectile {
180 public:
181         CLASS_PROTOTYPE ( idSoulCubeMissile );
182         ~idSoulCubeMissile();
183         void                                    Save( idSaveGame *savefile ) const;
184         void                                    Restore( idRestoreGame *savefile );
185
186         void                                    Spawn( void );
187         virtual void                    Think( void );
188         virtual void                    Launch( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity, const float timeSinceFire = 0.0f, const float power = 1.0f, const float dmgPower = 1.0f );
189
190 protected:
191         virtual void                    GetSeekPos( idVec3 &out );
192         void                                    ReturnToOwner( void );
193         void                                    KillTarget( const idVec3 &dir );
194
195 private:
196         idVec3                                  startingVelocity;
197         idVec3                                  endingVelocity;
198         float                                   accelTime;
199         int                                             launchTime;
200         bool                                    killPhase;
201         bool                                    returnPhase;
202         idVec3                                  destOrg;
203         idVec3                                  orbitOrg;
204         int                                             orbitTime;
205         int                                             smokeKillTime;
206         const idDeclParticle *  smokeKill;
207 };
208
209 struct beamTarget_t {
210         idEntityPtr<idEntity>   target;
211         renderEntity_t                  renderEntity;
212         qhandle_t                               modelDefHandle;
213 };
214
215 class idBFGProjectile : public idProjectile {
216 public :
217         CLASS_PROTOTYPE( idBFGProjectile );
218
219                                                         idBFGProjectile();
220                                                         ~idBFGProjectile();
221
222         void                                    Save( idSaveGame *savefile ) const;
223         void                                    Restore( idRestoreGame *savefile );
224
225         void                                    Spawn( void );
226         virtual void                    Think( void );
227         virtual void                    Launch( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity, const float timeSinceFire = 0.0f, const float launchPower = 1.0f, const float dmgPower = 1.0f );
228         virtual void                    Explode( const trace_t &collision, idEntity *ignore );
229
230 private:
231         idList<beamTarget_t>    beamTargets;
232         renderEntity_t                  secondModel;
233         qhandle_t                               secondModelDefHandle;
234         int                                             nextDamageTime;
235         idStr                                   damageFreq;
236
237         void                                    FreeBeams();
238         void                                    Event_RemoveBeams();
239         void                                    ApplyDamage();
240 };
241
242 /*
243 ===============================================================================
244
245   idDebris
246         
247 ===============================================================================
248 */
249
250 class idDebris : public idEntity {
251 public :
252         CLASS_PROTOTYPE( idDebris );
253
254                                                         idDebris();
255                                                         ~idDebris();
256
257         // save games
258         void                                    Save( idSaveGame *savefile ) const;                                     // archives object for save game file
259         void                                    Restore( idRestoreGame *savefile );                                     // unarchives object from save game file
260
261         void                                    Spawn( void );
262
263         void                                    Create( idEntity *owner, const idVec3 &start, const idMat3 &axis );
264         void                                    Launch( void );
265         void                                    Think( void );
266         void                                    Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
267         void                                    Explode( void );
268         void                                    Fizzle( void );
269         virtual bool                    Collide( const trace_t &collision, const idVec3 &velocity );
270
271
272 private:
273         idEntityPtr<idEntity>   owner;
274         idPhysics_RigidBody             physicsObj;
275         const idDeclParticle *  smokeFly;
276         int                                             smokeFlyTime;
277         const idSoundShader *   sndBounce;
278
279
280         void                                    Event_Explode( void );
281         void                                    Event_Fizzle( void );
282 };
283
284 #endif /* !__GAME_PROJECTILE_H__ */