Item.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #ifndef __GAME_ITEM_H__
  21. #define __GAME_ITEM_H__
  22. /*
  23. ===============================================================================
  24. Items the player can pick up or use.
  25. ===============================================================================
  26. */
  27. class idItem : public idEntity {
  28. public:
  29. CLASS_PROTOTYPE( idItem );
  30. idItem();
  31. virtual ~idItem();
  32. void Save( idSaveGame *savefile ) const;
  33. void Restore( idRestoreGame *savefile );
  34. void Spawn( void );
  35. void GetAttributes( idDict &attributes );
  36. virtual bool GiveToPlayer( idPlayer *player );
  37. virtual bool Pickup( idPlayer *player );
  38. virtual void Think( void );
  39. virtual void Present();
  40. enum {
  41. EVENT_PICKUP = idEntity::EVENT_MAXEVENTS,
  42. EVENT_RESPAWN,
  43. EVENT_RESPAWNFX,
  44. #ifdef CTF
  45. EVENT_TAKEFLAG,
  46. EVENT_DROPFLAG,
  47. EVENT_FLAGRETURN,
  48. EVENT_FLAGCAPTURE,
  49. #endif
  50. EVENT_MAXEVENTS
  51. };
  52. virtual void ClientPredictionThink( void );
  53. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  54. // networking
  55. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  56. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  57. private:
  58. idVec3 orgOrigin;
  59. bool spin;
  60. bool pulse;
  61. bool canPickUp;
  62. // for item pulse effect
  63. int itemShellHandle;
  64. const idMaterial * shellMaterial;
  65. // used to update the item pulse effect
  66. mutable bool inView;
  67. mutable int inViewTime;
  68. mutable int lastCycle;
  69. mutable int lastRenderViewTime;
  70. bool UpdateRenderEntity( renderEntity_s *renderEntity, const renderView_t *renderView ) const;
  71. static bool ModelCallback( renderEntity_s *renderEntity, const renderView_t *renderView );
  72. void Event_DropToFloor( void );
  73. void Event_Touch( idEntity *other, trace_t *trace );
  74. void Event_Trigger( idEntity *activator );
  75. void Event_Respawn( void );
  76. void Event_RespawnFx( void );
  77. };
  78. class idItemPowerup : public idItem {
  79. public:
  80. CLASS_PROTOTYPE( idItemPowerup );
  81. idItemPowerup();
  82. void Save( idSaveGame *savefile ) const;
  83. void Restore( idRestoreGame *savefile );
  84. void Spawn();
  85. virtual bool GiveToPlayer( idPlayer *player );
  86. private:
  87. int time;
  88. int type;
  89. };
  90. class idObjective : public idItem {
  91. public:
  92. CLASS_PROTOTYPE( idObjective );
  93. idObjective();
  94. void Save( idSaveGame *savefile ) const;
  95. void Restore( idRestoreGame *savefile );
  96. void Spawn();
  97. private:
  98. idVec3 playerPos;
  99. void Event_Trigger( idEntity *activator );
  100. void Event_HideObjective( idEntity *e );
  101. void Event_GetPlayerPos();
  102. void Event_CamShot();
  103. };
  104. class idVideoCDItem : public idItem {
  105. public:
  106. CLASS_PROTOTYPE( idVideoCDItem );
  107. void Spawn();
  108. virtual bool GiveToPlayer( idPlayer *player );
  109. };
  110. class idPDAItem : public idItem {
  111. public:
  112. CLASS_PROTOTYPE( idPDAItem );
  113. virtual bool GiveToPlayer( idPlayer *player );
  114. };
  115. class idMoveableItem : public idItem {
  116. public:
  117. CLASS_PROTOTYPE( idMoveableItem );
  118. idMoveableItem();
  119. virtual ~idMoveableItem();
  120. void Save( idSaveGame *savefile ) const;
  121. void Restore( idRestoreGame *savefile );
  122. void Spawn( void );
  123. virtual void Think( void );
  124. #ifdef _D3XP
  125. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  126. #endif
  127. virtual bool Pickup( idPlayer *player );
  128. static void DropItems( idAnimatedEntity *ent, const char *type, idList<idEntity *> *list );
  129. static idEntity * DropItem( const char *classname, const idVec3 &origin, const idMat3 &axis, const idVec3 &velocity, int activateDelay, int removeDelay );
  130. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  131. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  132. #ifdef CTF
  133. protected:
  134. #else
  135. private:
  136. #endif
  137. idPhysics_RigidBody physicsObj;
  138. idClipModel * trigger;
  139. const idDeclParticle * smoke;
  140. int smokeTime;
  141. #ifdef _D3XP
  142. int nextSoundTime;
  143. #endif
  144. #ifdef CTF
  145. bool repeatSmoke; // never stop updating the particles
  146. #endif
  147. void Gib( const idVec3 &dir, const char *damageDefName );
  148. void Event_DropToFloor( void );
  149. void Event_Gib( const char *damageDefName );
  150. };
  151. #ifdef CTF
  152. class idItemTeam : public idMoveableItem {
  153. public:
  154. CLASS_PROTOTYPE( idItemTeam );
  155. idItemTeam();
  156. virtual ~idItemTeam();
  157. void Spawn();
  158. virtual bool Pickup( idPlayer *player );
  159. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  160. virtual void Think(void );
  161. void Drop( bool death = false ); // was the drop caused by death of carrier?
  162. void Return( idPlayer * player = NULL );
  163. void Capture( void );
  164. virtual void FreeLightDef( void );
  165. virtual void Present( void );
  166. // networking
  167. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  168. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  169. public:
  170. int team;
  171. // TODO : turn this into a state :
  172. bool carried; // is it beeing carried by a player?
  173. bool dropped; // was it dropped?
  174. private:
  175. idVec3 returnOrigin;
  176. idMat3 returnAxis;
  177. int lastDrop;
  178. const idDeclSkin * skinDefault;
  179. const idDeclSkin * skinCarried;
  180. const function_t * scriptTaken;
  181. const function_t * scriptDropped;
  182. const function_t * scriptReturned;
  183. const function_t * scriptCaptured;
  184. renderLight_t itemGlow; // Used by flags when they are picked up
  185. int itemGlowHandle;
  186. int lastNuggetDrop;
  187. const char * nuggetName;
  188. private:
  189. void Event_TakeFlag( idPlayer * player );
  190. void Event_DropFlag( bool death );
  191. void Event_FlagReturn( idPlayer * player = NULL );
  192. void Event_FlagCapture( void );
  193. void PrivateReturn( void );
  194. function_t * LoadScript( char * script );
  195. void SpawnNugget( idVec3 pos );
  196. void UpdateGuis( void );
  197. };
  198. #endif
  199. class idMoveablePDAItem : public idMoveableItem {
  200. public:
  201. CLASS_PROTOTYPE( idMoveablePDAItem );
  202. virtual bool GiveToPlayer( idPlayer *player );
  203. };
  204. /*
  205. ===============================================================================
  206. Item removers.
  207. ===============================================================================
  208. */
  209. class idItemRemover : public idEntity {
  210. public:
  211. CLASS_PROTOTYPE( idItemRemover );
  212. void Spawn();
  213. void RemoveItem( idPlayer *player );
  214. private:
  215. void Event_Trigger( idEntity *activator );
  216. };
  217. class idObjectiveComplete : public idItemRemover {
  218. public:
  219. CLASS_PROTOTYPE( idObjectiveComplete );
  220. idObjectiveComplete();
  221. void Save( idSaveGame *savefile ) const;
  222. void Restore( idRestoreGame *savefile );
  223. void Spawn();
  224. private:
  225. idVec3 playerPos;
  226. void Event_Trigger( idEntity *activator );
  227. void Event_HideObjective( idEntity *e );
  228. void Event_GetPlayerPos();
  229. };
  230. #endif /* !__GAME_ITEM_H__ */