DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Projectile.h (10633B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition 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 BFG Edition 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();
     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();
     57 
     58 	idEntity *				GetOwner() const;
     59 	void					CatchProjectile( idEntity* o, const char* reflectName );
     60 	int						GetProjectileState();
     61 	void					Event_CreateProjectile( idEntity *owner, const idVec3 &start, const idVec3 &dir );
     62 	void					Event_LaunchProjectile( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity );
     63 	void					Event_SetGravity( float gravity );
     64 
     65 	virtual void			Think();
     66 	virtual void			Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
     67 	virtual bool			Collide( const trace_t &collision, const idVec3 &velocity );
     68 	virtual void			Explode( const trace_t &collision, idEntity *ignore );
     69 	void					Fizzle();
     70 
     71 	static idVec3			GetVelocity( const idDict *projectile );
     72 	static idVec3			GetGravity( const idDict *projectile );
     73 
     74 	enum {
     75 		EVENT_DAMAGE_EFFECT = idEntity::EVENT_MAXEVENTS,
     76 		EVENT_MAXEVENTS
     77 	};
     78 
     79 	void					SetLaunchedFromGrabber( bool bl ) { launchedFromGrabber = bl; }
     80 	bool					GetLaunchedFromGrabber() { return launchedFromGrabber; }
     81 
     82 	static void				DefaultDamageEffect( idEntity *soundEnt, const idDict &projectileDef, const trace_t &collision, const idVec3 &velocity );
     83 	static bool				ClientPredictionCollide( idEntity *soundEnt, const idDict &projectileDef, const trace_t &collision, const idVec3 &velocity, bool addDamageEffect );
     84 	virtual void			ClientPredictionThink();
     85 	virtual void			ClientThink( const int curTime, const float fraction, const bool predict );
     86 	virtual void			WriteToSnapshot( idBitMsg &msg ) const;
     87 	virtual void			ReadFromSnapshot( const idBitMsg &msg );
     88 	virtual bool			ClientReceiveEvent( int event, int time, const idBitMsg &msg );
     89 
     90 	void					QueueToSimulate( int startTime );
     91 	virtual void			SimulateProjectileFrame( int msec, int endTime );
     92 	virtual void			PostSimulate( int endTime );
     93 
     94 	struct simulatedProjectile_t {
     95 		simulatedProjectile_t(): projectile( NULL ), startTime( 0 ) {}
     96 		idProjectile* projectile;
     97 		int	startTime;
     98 	};
     99 
    100 	static const int		MAX_SIMULATED_PROJECTILES = 64;
    101 
    102 	// This list is used to "catch up" client projectiles to the current time on the server
    103 	static idArray< simulatedProjectile_t, MAX_SIMULATED_PROJECTILES >	projectilesToSimulate;
    104 
    105 protected:
    106 	idEntityPtr<idEntity>	owner;
    107 
    108 	struct projectileFlags_s {
    109 		bool				detonate_on_world			: 1;
    110 		bool				detonate_on_actor			: 1;
    111 		bool				randomShaderSpin			: 1;
    112 		bool				isTracer					: 1;
    113 		bool				noSplashDamage				: 1;
    114 	} projectileFlags;
    115 
    116 	bool					launchedFromGrabber;
    117 
    118 	float					thrust;
    119 	int						thrust_end;
    120 	float					damagePower;
    121 
    122 	renderLight_t			renderLight;
    123 	qhandle_t				lightDefHandle;				// handle to renderer light def
    124 	idVec3					lightOffset;
    125 	int						lightStartTime;
    126 	int						lightEndTime;
    127 	idVec3					lightColor;
    128 
    129 	idForce_Constant		thruster;
    130 	idPhysics_RigidBody		physicsObj;
    131 
    132 	const idDeclParticle *	smokeFly;
    133 	int						smokeFlyTime;
    134 	bool					mNoExplodeDisappear;
    135 	bool					mTouchTriggers;
    136 
    137 	int						originalTimeGroup;
    138 
    139 	typedef enum {
    140 		// must update these in script/doom_defs.script if changed
    141 		SPAWNED = 0,
    142 		CREATED = 1,
    143 		LAUNCHED = 2,
    144 		FIZZLED = 3,
    145 		EXPLODED = 4
    146 	} projectileState_t;
    147 	
    148 	projectileState_t		state;
    149 
    150 private:
    151 
    152 	idVec3					launchOrigin;
    153 	idMat3					launchAxis;
    154 
    155 	void					AddDefaultDamageEffect( const trace_t &collision, const idVec3 &velocity );
    156 	void					AddParticlesAndLight();
    157 
    158 	void					Event_Explode();
    159 	void					Event_Fizzle();
    160 	void					Event_RadiusDamage( idEntity *ignore );
    161 	void					Event_Touch( idEntity *other, trace_t *trace );
    162 	void					Event_GetProjectileState();
    163 };
    164 
    165 class idGuidedProjectile : public idProjectile {
    166 public :
    167 	CLASS_PROTOTYPE( idGuidedProjectile );
    168 
    169 							idGuidedProjectile();
    170 							~idGuidedProjectile();
    171 
    172 	void					Save( idSaveGame *savefile ) const;
    173 	void					Restore( idRestoreGame *savefile );
    174 
    175 	void					Spawn();
    176 	virtual void			Think();
    177 	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 );
    178 	void					SetEnemy( idEntity *ent );
    179 	void					Event_SetEnemy(idEntity *ent);
    180 
    181 protected:
    182 	float					speed;
    183 	idEntityPtr<idEntity>	enemy;
    184 	virtual void			GetSeekPos( idVec3 &out );
    185 
    186 private:
    187 	idAngles				rndScale;
    188 	idAngles				rndAng;
    189 	idAngles				angles;
    190 	int						rndUpdateTime;
    191 	float					turn_max;
    192 	float					clamp_dist;
    193 	bool					burstMode;
    194 	bool					unGuided;
    195 	float					burstDist;
    196 	float					burstVelocity;
    197 };
    198 
    199 class idSoulCubeMissile : public idGuidedProjectile {
    200 public:
    201 	CLASS_PROTOTYPE ( idSoulCubeMissile );
    202 	~idSoulCubeMissile();
    203 	void					Save( idSaveGame *savefile ) const;
    204 	void					Restore( idRestoreGame *savefile );
    205 
    206 	void					Spawn();
    207 	virtual void			Think();
    208 	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 );
    209 
    210 protected:
    211 	virtual void			GetSeekPos( idVec3 &out );
    212 	void					ReturnToOwner();
    213 	void					KillTarget( const idVec3 &dir );
    214 
    215 private:
    216 	idVec3					startingVelocity;
    217 	idVec3					endingVelocity;
    218 	float					accelTime;
    219 	int						launchTime;
    220 	bool					killPhase;
    221 	bool					returnPhase;
    222 	idVec3					destOrg;
    223 	idVec3					orbitOrg;
    224 	int						orbitTime;
    225 	int						smokeKillTime;
    226 	const idDeclParticle *	smokeKill;
    227 };
    228 
    229 struct beamTarget_t {
    230 	idEntityPtr<idEntity>	target;
    231 	renderEntity_t			renderEntity;
    232 	qhandle_t				modelDefHandle;
    233 };
    234 
    235 class idBFGProjectile : public idProjectile {
    236 public :
    237 	CLASS_PROTOTYPE( idBFGProjectile );
    238 
    239 							idBFGProjectile();
    240 							~idBFGProjectile();
    241 
    242 	void					Save( idSaveGame *savefile ) const;
    243 	void					Restore( idRestoreGame *savefile );
    244 
    245 	void					Spawn();
    246 	virtual void			Think();
    247 	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 );
    248 	virtual void			Explode( const trace_t &collision, idEntity *ignore );
    249 
    250 private:
    251 	idList<beamTarget_t, TAG_PROJECTILE>	beamTargets;
    252 	renderEntity_t			secondModel;
    253 	qhandle_t				secondModelDefHandle;
    254 	int						nextDamageTime;
    255 	idStr					damageFreq;
    256 
    257 	void					FreeBeams();
    258 	void					Event_RemoveBeams();
    259 	void					ApplyDamage();
    260 };
    261 
    262 class idHomingProjectile : public idProjectile {
    263 public :
    264 	CLASS_PROTOTYPE( idHomingProjectile );
    265 
    266 	idHomingProjectile();
    267 	~idHomingProjectile();
    268 
    269 	void					Save( idSaveGame *savefile ) const;
    270 	void					Restore( idRestoreGame *savefile );
    271 
    272 	void					Spawn();
    273 	virtual void			Think();
    274 	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 );
    275 	void					SetEnemy( idEntity *ent );
    276 	void					SetSeekPos( idVec3 pos );
    277 	void					Event_SetEnemy(idEntity *ent);
    278 
    279 protected:
    280 	float					speed;
    281 	idEntityPtr<idEntity>	enemy;
    282 	idVec3					seekPos;
    283 
    284 private:
    285 	idAngles				rndScale;
    286 	idAngles				rndAng;
    287 	idAngles				angles;
    288 	float					turn_max;
    289 	float					clamp_dist;
    290 	bool					burstMode;
    291 	bool					unGuided;
    292 	float					burstDist;
    293 	float					burstVelocity;
    294 };
    295 
    296 
    297 /*
    298 ===============================================================================
    299 
    300   idDebris
    301 	
    302 ===============================================================================
    303 */
    304 
    305 class idDebris : public idEntity {
    306 public :
    307 	CLASS_PROTOTYPE( idDebris );
    308 
    309 							idDebris();
    310 							~idDebris();
    311 
    312 	// save games
    313 	void					Save( idSaveGame *savefile ) const;					// archives object for save game file
    314 	void					Restore( idRestoreGame *savefile );					// unarchives object from save game file
    315 
    316 	void					Spawn();
    317 
    318 	void					Create( idEntity *owner, const idVec3 &start, const idMat3 &axis );
    319 	void					Launch();
    320 	void					Think();
    321 	void					Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
    322 	void					Explode();
    323 	void					Fizzle();
    324 	virtual bool			Collide( const trace_t &collision, const idVec3 &velocity );
    325 
    326 
    327 private:
    328 	idEntityPtr<idEntity>	owner;
    329 	idPhysics_RigidBody		physicsObj;
    330 	const idDeclParticle *	smokeFly;
    331 	int						smokeFlyTime;
    332 	const idSoundShader *	sndBounce;
    333 
    334 
    335 	void					Event_Explode();
    336 	void					Event_Fizzle();
    337 };
    338 
    339 #endif /* !__GAME_PROJECTILE_H__ */