DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

Item.h (9400B)


      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_ITEM_H__
     30 #define __GAME_ITEM_H__
     31 
     32 
     33 /*
     34 ===============================================================================
     35 
     36   Items the player can pick up or use.
     37 
     38 ===============================================================================
     39 */
     40 
     41 /*
     42 ================================================
     43 These flags are passed to the Give functions
     44 to set their behavior. We need to be able to
     45 separate the feedback from the actual
     46 state modification so that we can hide lag
     47 on MP clients.
     48 
     49 For the previous behavior of functions which
     50 take a giveFlags parameter (this is usually
     51 desired on the server too) pass
     52 ITEM_GIVE_FEEDBACK | ITEM_GIVE_UPDATE_STATE.
     53 ================================================
     54 */
     55 enum itemGiveFlags_t {
     56 	ITEM_GIVE_FEEDBACK			= BIT( 0 ),
     57 	ITEM_GIVE_UPDATE_STATE		= BIT( 1 ),
     58 	ITEM_GIVE_FROM_WEAPON		= BIT( 2 ),			// indicates this was given via a weapon's launchPowerup (for bloodstone powerups)
     59 };
     60 
     61 class idItem : public idEntity {
     62 public:
     63 	CLASS_PROTOTYPE( idItem );
     64 
     65 							idItem();
     66 	virtual					~idItem();
     67 
     68 	void					Save( idSaveGame *savefile ) const;
     69 	void					Restore( idRestoreGame *savefile );
     70 
     71 	void					Spawn();
     72 	void					GetAttributes( idDict &attributes ) const;
     73 	virtual bool			GiveToPlayer( idPlayer *player, unsigned int giveFlags );
     74 	virtual bool			Pickup( idPlayer *player );
     75 	virtual void			Think();
     76 	virtual void			Present();
     77 
     78 	enum {
     79 		EVENT_PICKUP = idEntity::EVENT_MAXEVENTS,
     80 		EVENT_RESPAWN,
     81 		EVENT_RESPAWNFX,
     82         EVENT_TAKEFLAG,
     83         EVENT_DROPFLAG,
     84         EVENT_FLAGRETURN,
     85 		EVENT_FLAGCAPTURE,
     86 		EVENT_MAXEVENTS
     87 	};
     88 
     89 	void					ClientThink( const int curTime, const float fraction, const bool predict );
     90 	virtual void			ClientPredictionThink();
     91 	virtual bool			ClientReceiveEvent( int event, int time, const idBitMsg &msg );
     92 
     93 	// networking
     94 	virtual void			WriteToSnapshot( idBitMsg &msg ) const;
     95 	virtual void			ReadFromSnapshot( const idBitMsg &msg );
     96 
     97 protected:
     98 	int						GetPredictPickupMilliseconds() const { return clientPredictPickupMilliseconds; }
     99 
    100 private:
    101 	idVec3					orgOrigin;
    102 	bool					spin;
    103 	bool					pulse;
    104 	bool					canPickUp;
    105 
    106 	// for item pulse effect
    107 	int						itemShellHandle;
    108 	const idMaterial *		shellMaterial;
    109 
    110 	// used to update the item pulse effect
    111 	mutable bool			inView;
    112 	mutable int				inViewTime;
    113 	mutable int				lastCycle;
    114 	mutable int				lastRenderViewTime;
    115 
    116 	// used for prediction in mp
    117 	int						clientPredictPickupMilliseconds;
    118 	
    119 	bool					UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
    120 	static bool				ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
    121 
    122 	void					Event_DropToFloor();
    123 	void					Event_Touch( idEntity *other, trace_t *trace );
    124 	void					Event_Trigger( idEntity *activator );
    125 	void					Event_Respawn();
    126 	void					Event_RespawnFx();
    127 };
    128 
    129 class idItemPowerup : public idItem {
    130 public:
    131 	CLASS_PROTOTYPE( idItemPowerup );
    132 
    133 							idItemPowerup();
    134 
    135 	void					Save( idSaveGame *savefile ) const;
    136 	void					Restore( idRestoreGame *savefile );
    137 
    138 	void					Spawn();
    139 	virtual bool			GiveToPlayer( idPlayer *player, unsigned int giveFlags );
    140 
    141 private:
    142 	int						time;
    143 	int						type;
    144 };
    145 
    146 class idObjective : public idItem {
    147 public:
    148 	CLASS_PROTOTYPE( idObjective );
    149 
    150 							idObjective();
    151 
    152 	void					Save( idSaveGame *savefile ) const;
    153 	void					Restore( idRestoreGame *savefile );
    154 
    155 	void					Spawn();
    156 
    157 private:
    158 	idVec3					playerPos;
    159 	const idMaterial *		screenshot;
    160 
    161 	void					Event_Trigger( idEntity *activator );
    162 	void					Event_HideObjective( idEntity *e );
    163 	void					Event_GetPlayerPos();
    164 };
    165 
    166 class idVideoCDItem : public idItem {
    167 public:
    168 	CLASS_PROTOTYPE( idVideoCDItem );
    169 
    170 	virtual bool			GiveToPlayer( idPlayer *player, unsigned int giveFlags );
    171 };
    172 
    173 class idPDAItem : public idItem {
    174 public:
    175 	CLASS_PROTOTYPE( idPDAItem );
    176 
    177 	virtual bool			GiveToPlayer( idPlayer *player, unsigned int giveFlags );
    178 };
    179 
    180 class idMoveableItem : public idItem {
    181 public:
    182 	CLASS_PROTOTYPE( idMoveableItem );
    183 
    184 							idMoveableItem();
    185 	virtual					~idMoveableItem();
    186 
    187 	void					Save( idSaveGame *savefile ) const;
    188 	void					Restore( idRestoreGame *savefile );
    189 
    190 	void					Spawn();
    191 	virtual void			Think();
    192 	void					ClientThink( const int curTime, const float fraction, const bool predict );
    193 	virtual bool			Collide( const trace_t &collision, const idVec3 &velocity );
    194 	virtual bool			Pickup( idPlayer *player );
    195 
    196 	static void				DropItems( idAnimatedEntity *ent, const char *type, idList<idEntity *> *list );
    197 	static idEntity	*		DropItem( const char *classname, const idVec3 &origin, const idMat3 &axis, const idVec3 &velocity, int activateDelay, int removeDelay );
    198 
    199 	virtual void			WriteToSnapshot( idBitMsg &msg ) const;
    200 	virtual void			ReadFromSnapshot( const idBitMsg &msg );
    201 
    202 protected:
    203 	idPhysics_RigidBody		physicsObj;
    204 	idClipModel *			trigger;
    205 	const idDeclParticle *	smoke;
    206 	int						smokeTime;
    207 
    208 	int						nextSoundTime;
    209 	bool					repeatSmoke;	// never stop updating the particles
    210 
    211 	void					Gib( const idVec3 &dir, const char *damageDefName );
    212 
    213 	void					Event_DropToFloor();
    214 	void					Event_Gib( const char *damageDefName );
    215 };
    216 
    217 class idItemTeam : public idMoveableItem {
    218 public:
    219     CLASS_PROTOTYPE( idItemTeam );
    220 
    221                             idItemTeam();
    222 	virtual					~idItemTeam();
    223 
    224     void                    Spawn();
    225 	virtual bool			Pickup( idPlayer *player );
    226 	virtual bool			ClientReceiveEvent( int event, int time, const idBitMsg &msg );    
    227 	virtual void			Think(void );
    228 
    229 	void					Drop( bool death = false );	// was the drop caused by death of carrier?
    230 	void					Return( idPlayer * player = NULL );
    231 	void					Capture();
    232 
    233 	virtual void			FreeLightDef();
    234 	virtual void			Present();
    235 
    236 	// networking
    237 	virtual void			WriteToSnapshot( idBitMsg &msg ) const;
    238 	virtual void			ReadFromSnapshot( const idBitMsg &msg );
    239 
    240 public:
    241     int                     team;
    242 	// TODO : turn this into a state : 
    243 	bool					carried;			// is it beeing carried by a player?
    244 	bool					dropped;			// was it dropped?
    245 
    246 private:
    247 	idVec3					returnOrigin;
    248 	idMat3					returnAxis;
    249 	int						lastDrop;
    250 
    251 	const idDeclSkin *		skinDefault;
    252 	const idDeclSkin *		skinCarried;
    253 
    254 	const function_t *		scriptTaken;
    255 	const function_t *		scriptDropped;
    256 	const function_t *		scriptReturned;
    257 	const function_t *		scriptCaptured;
    258 
    259     renderLight_t           itemGlow;           // Used by flags when they are picked up
    260     int                     itemGlowHandle;
    261 
    262 	int						lastNuggetDrop;
    263 	const char *			nuggetName;
    264 
    265 private:
    266 
    267 	void					Event_TakeFlag( idPlayer * player );
    268     void					Event_DropFlag( bool death );
    269 	void					Event_FlagReturn( idPlayer * player = NULL );
    270 	void					Event_FlagCapture();
    271 
    272 	void					PrivateReturn();
    273 	function_t *			LoadScript( char * script );
    274 
    275 	void					SpawnNugget( idVec3 pos );
    276     void                    UpdateGuis();
    277 };
    278 
    279 class idMoveablePDAItem : public idMoveableItem {
    280 public:
    281 	CLASS_PROTOTYPE( idMoveablePDAItem );
    282 
    283 	virtual bool			GiveToPlayer( idPlayer *player, unsigned int giveFlags );
    284 };
    285 
    286 /*
    287 ===============================================================================
    288 
    289   Item removers.
    290 
    291 ===============================================================================
    292 */
    293 
    294 class idItemRemover : public idEntity {
    295 public:
    296 	CLASS_PROTOTYPE( idItemRemover );
    297 
    298 	void					Spawn();
    299 	void					RemoveItem( idPlayer *player );
    300 
    301 private:
    302 	void					Event_Trigger( idEntity *activator );
    303 };
    304 
    305 class idObjectiveComplete : public idItemRemover {
    306 public:
    307 	CLASS_PROTOTYPE( idObjectiveComplete );
    308 
    309 							idObjectiveComplete();
    310 
    311 	void					Save( idSaveGame *savefile ) const;
    312 	void					Restore( idRestoreGame *savefile );
    313 
    314 	void					Spawn();
    315 
    316 private:
    317 	idVec3					playerPos;
    318 
    319 	void					Event_Trigger( idEntity *activator );
    320 	void					Event_HideObjective( idEntity *e );
    321 	void					Event_GetPlayerPos();
    322 };
    323 
    324 #endif /* !__GAME_ITEM_H__ */