DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Moveable.h (7668B)


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