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_ITEM_H__
30 #define __GAME_ITEM_H__
31 
32 #include "physics/Physics_RigidBody.h"
33 #include "Entity.h"
34 
35 /*
36 ===============================================================================
37 
38   Items the player can pick up or use.
39 
40 ===============================================================================
41 */
42 
43 class idItem : public idEntity {
44 public:
45 	CLASS_PROTOTYPE( idItem );
46 
47 							idItem();
48 	virtual					~idItem();
49 
50 	void					Save( idSaveGame *savefile ) const;
51 	void					Restore( idRestoreGame *savefile );
52 
53 	void					Spawn( void );
54 	void					GetAttributes( idDict &attributes );
55 	virtual bool			GiveToPlayer( idPlayer *player );
56 	virtual bool			Pickup( idPlayer *player );
57 	virtual void			Think( void );
58 	virtual void			Present();
59 
60 	enum {
61 		EVENT_PICKUP = idEntity::EVENT_MAXEVENTS,
62 		EVENT_RESPAWN,
63 		EVENT_RESPAWNFX,
64 		EVENT_MAXEVENTS
65 	};
66 
67 	virtual void			ClientPredictionThink( void );
68 	virtual bool			ClientReceiveEvent( int event, int time, const idBitMsg &msg );
69 
70 	// networking
71 	virtual void			WriteToSnapshot( idBitMsgDelta &msg ) const;
72 	virtual void			ReadFromSnapshot( const idBitMsgDelta &msg );
73 
74 private:
75 	idVec3					orgOrigin;
76 	bool					spin;
77 	bool					pulse;
78 	bool					canPickUp;
79 
80 	// for item pulse effect
81 	int						itemShellHandle;
82 	const idMaterial *		shellMaterial;
83 
84 	// used to update the item pulse effect
85 	mutable bool			inView;
86 	mutable int				inViewTime;
87 	mutable int				lastCycle;
88 	mutable int				lastRenderViewTime;
89 
90 	bool					UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
91 	static bool				ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
92 
93 	void					Event_DropToFloor( void );
94 	void					Event_Touch( idEntity *other, trace_t *trace );
95 	void					Event_Trigger( idEntity *activator );
96 	void					Event_Respawn( void );
97 	void					Event_RespawnFx( void );
98 };
99 
100 class idItemPowerup : public idItem {
101 public:
102 	CLASS_PROTOTYPE( idItemPowerup );
103 
104 							idItemPowerup();
105 
106 	void					Save( idSaveGame *savefile ) const;
107 	void					Restore( idRestoreGame *savefile );
108 
109 	void					Spawn();
110 	virtual bool			GiveToPlayer( idPlayer *player );
111 
112 private:
113 	int						time;
114 	int						type;
115 };
116 
117 class idObjective : public idItem {
118 public:
119 	CLASS_PROTOTYPE( idObjective );
120 
121 							idObjective();
122 
123 	void					Save( idSaveGame *savefile ) const;
124 	void					Restore( idRestoreGame *savefile );
125 
126 	void					Spawn();
127 
128 private:
129 	idVec3					playerPos;
130 
131 	void					Event_Trigger( idEntity *activator );
132 	void					Event_HideObjective( idEntity *e );
133 	void					Event_GetPlayerPos();
134 	void					Event_CamShot();
135 };
136 
137 class idVideoCDItem : public idItem {
138 public:
139 	CLASS_PROTOTYPE( idVideoCDItem );
140 
141 	void					Spawn();
142 	virtual bool			GiveToPlayer( idPlayer *player );
143 };
144 
145 class idPDAItem : public idItem {
146 public:
147 	CLASS_PROTOTYPE( idPDAItem );
148 
149 	virtual bool			GiveToPlayer( idPlayer *player );
150 };
151 
152 class idMoveableItem : public idItem {
153 public:
154 	CLASS_PROTOTYPE( idMoveableItem );
155 
156 							idMoveableItem();
157 	virtual					~idMoveableItem();
158 
159 	void					Save( idSaveGame *savefile ) const;
160 	void					Restore( idRestoreGame *savefile );
161 
162 	void					Spawn( void );
163 	virtual void			Think( void );
164 	virtual bool			Pickup( idPlayer *player );
165 
166 	static void				DropItems( idAnimatedEntity *ent, const char *type, idList<idEntity *> *list );
167 	static idEntity	*		DropItem( const char *classname, const idVec3 &origin, const idMat3 &axis, const idVec3 &velocity, int activateDelay, int removeDelay );
168 
169 	virtual void			WriteToSnapshot( idBitMsgDelta &msg ) const;
170 	virtual void			ReadFromSnapshot( const idBitMsgDelta &msg );
171 
172 private:
173 	idPhysics_RigidBody		physicsObj;
174 	idClipModel *			trigger;
175 	const idDeclParticle *	smoke;
176 	int						smokeTime;
177 
178 	void					Gib( const idVec3 &dir, const char *damageDefName );
179 
180 	void					Event_DropToFloor( void );
181 	void					Event_Gib( const char *damageDefName );
182 };
183 
184 class idMoveablePDAItem : public idMoveableItem {
185 public:
186 	CLASS_PROTOTYPE( idMoveablePDAItem );
187 
188 	virtual bool			GiveToPlayer( idPlayer *player );
189 };
190 
191 /*
192 ===============================================================================
193 
194   Item removers.
195 
196 ===============================================================================
197 */
198 
199 class idItemRemover : public idEntity {
200 public:
201 	CLASS_PROTOTYPE( idItemRemover );
202 
203 	void					Spawn();
204 	void					RemoveItem( idPlayer *player );
205 
206 private:
207 	void					Event_Trigger( idEntity *activator );
208 };
209 
210 class idObjectiveComplete : public idItemRemover {
211 public:
212 	CLASS_PROTOTYPE( idObjectiveComplete );
213 
214 							idObjectiveComplete();
215 
216 	void					Save( idSaveGame *savefile ) const;
217 	void					Restore( idRestoreGame *savefile );
218 
219 	void					Spawn();
220 
221 private:
222 	idVec3					playerPos;
223 
224 	void					Event_Trigger( idEntity *activator );
225 	void					Event_HideObjective( idEntity *e );
226 	void					Event_GetPlayerPos();
227 };
228 
229 #endif /* !__GAME_ITEM_H__ */
230