Projectile.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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_PROJECTILE_H__
  21. #define __GAME_PROJECTILE_H__
  22. /*
  23. ===============================================================================
  24. idProjectile
  25. ===============================================================================
  26. */
  27. extern const idEventDef EV_Explode;
  28. class idProjectile : public idEntity {
  29. public :
  30. CLASS_PROTOTYPE( idProjectile );
  31. idProjectile();
  32. virtual ~idProjectile();
  33. void Spawn( void );
  34. void Save( idSaveGame *savefile ) const;
  35. void Restore( idRestoreGame *savefile );
  36. void Create( idEntity *owner, const idVec3 &start, const idVec3 &dir );
  37. 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 );
  38. virtual void FreeLightDef( void );
  39. idEntity * GetOwner( void ) const;
  40. #ifdef _D3XP
  41. void CatchProjectile( idEntity* o, const char* reflectName );
  42. int GetProjectileState( void );
  43. void Event_CreateProjectile( idEntity *owner, const idVec3 &start, const idVec3 &dir );
  44. void Event_LaunchProjectile( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity );
  45. void Event_SetGravity( float gravity );
  46. #endif
  47. virtual void Think( void );
  48. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  49. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  50. virtual void Explode( const trace_t &collision, idEntity *ignore );
  51. void Fizzle( void );
  52. static idVec3 GetVelocity( const idDict *projectile );
  53. static idVec3 GetGravity( const idDict *projectile );
  54. enum {
  55. EVENT_DAMAGE_EFFECT = idEntity::EVENT_MAXEVENTS,
  56. EVENT_MAXEVENTS
  57. };
  58. static void DefaultDamageEffect( idEntity *soundEnt, const idDict &projectileDef, const trace_t &collision, const idVec3 &velocity );
  59. static bool ClientPredictionCollide( idEntity *soundEnt, const idDict &projectileDef, const trace_t &collision, const idVec3 &velocity, bool addDamageEffect );
  60. virtual void ClientPredictionThink( void );
  61. virtual void WriteToSnapshot( idBitMsgDelta &msg ) const;
  62. virtual void ReadFromSnapshot( const idBitMsgDelta &msg );
  63. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  64. protected:
  65. idEntityPtr<idEntity> owner;
  66. struct projectileFlags_s {
  67. bool detonate_on_world : 1;
  68. bool detonate_on_actor : 1;
  69. bool randomShaderSpin : 1;
  70. bool isTracer : 1;
  71. bool noSplashDamage : 1;
  72. } projectileFlags;
  73. float thrust;
  74. int thrust_end;
  75. float damagePower;
  76. renderLight_t renderLight;
  77. qhandle_t lightDefHandle; // handle to renderer light def
  78. idVec3 lightOffset;
  79. int lightStartTime;
  80. int lightEndTime;
  81. idVec3 lightColor;
  82. idForce_Constant thruster;
  83. idPhysics_RigidBody physicsObj;
  84. const idDeclParticle * smokeFly;
  85. int smokeFlyTime;
  86. #ifdef _D3XP
  87. int originalTimeGroup;
  88. #endif
  89. typedef enum {
  90. // must update these in script/doom_defs.script if changed
  91. SPAWNED = 0,
  92. CREATED = 1,
  93. LAUNCHED = 2,
  94. FIZZLED = 3,
  95. EXPLODED = 4
  96. } projectileState_t;
  97. projectileState_t state;
  98. private:
  99. bool netSyncPhysics;
  100. void AddDefaultDamageEffect( const trace_t &collision, const idVec3 &velocity );
  101. void Event_Explode( void );
  102. void Event_Fizzle( void );
  103. void Event_RadiusDamage( idEntity *ignore );
  104. void Event_Touch( idEntity *other, trace_t *trace );
  105. void Event_GetProjectileState( void );
  106. void HandleHit(const trace_t &collision);
  107. idVec3 startOrigin;
  108. //bc
  109. int stickyState;
  110. idAnimatedEntity * md5model;
  111. idVec3 facing;
  112. };
  113. class idGuidedProjectile : public idProjectile {
  114. public :
  115. CLASS_PROTOTYPE( idGuidedProjectile );
  116. idGuidedProjectile( void );
  117. ~idGuidedProjectile( void );
  118. void Save( idSaveGame *savefile ) const;
  119. void Restore( idRestoreGame *savefile );
  120. void Spawn( void );
  121. virtual void Think( void );
  122. 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 );
  123. #ifdef _D3XP
  124. void SetEnemy( idEntity *ent );
  125. void Event_SetEnemy(idEntity *ent);
  126. #endif
  127. protected:
  128. float speed;
  129. idEntityPtr<idEntity> enemy;
  130. virtual void GetSeekPos( idVec3 &out );
  131. private:
  132. idAngles rndScale;
  133. idAngles rndAng;
  134. idAngles angles;
  135. int rndUpdateTime;
  136. float turn_max;
  137. float clamp_dist;
  138. bool burstMode;
  139. bool unGuided;
  140. float burstDist;
  141. float burstVelocity;
  142. };
  143. class idSoulCubeMissile : public idGuidedProjectile {
  144. public:
  145. CLASS_PROTOTYPE ( idSoulCubeMissile );
  146. ~idSoulCubeMissile();
  147. void Save( idSaveGame *savefile ) const;
  148. void Restore( idRestoreGame *savefile );
  149. void Spawn( void );
  150. virtual void Think( void );
  151. 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 );
  152. protected:
  153. virtual void GetSeekPos( idVec3 &out );
  154. void ReturnToOwner( void );
  155. void KillTarget( const idVec3 &dir );
  156. private:
  157. idVec3 startingVelocity;
  158. idVec3 endingVelocity;
  159. float accelTime;
  160. int launchTime;
  161. bool killPhase;
  162. bool returnPhase;
  163. idVec3 destOrg;
  164. idVec3 orbitOrg;
  165. int orbitTime;
  166. int smokeKillTime;
  167. const idDeclParticle * smokeKill;
  168. };
  169. struct beamTarget_t {
  170. idEntityPtr<idEntity> target;
  171. renderEntity_t renderEntity;
  172. qhandle_t modelDefHandle;
  173. };
  174. class idBFGProjectile : public idProjectile {
  175. public :
  176. CLASS_PROTOTYPE( idBFGProjectile );
  177. idBFGProjectile();
  178. ~idBFGProjectile();
  179. void Save( idSaveGame *savefile ) const;
  180. void Restore( idRestoreGame *savefile );
  181. void Spawn( void );
  182. virtual void Think( void );
  183. 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 );
  184. virtual void Explode( const trace_t &collision, idEntity *ignore );
  185. private:
  186. idList<beamTarget_t> beamTargets;
  187. renderEntity_t secondModel;
  188. qhandle_t secondModelDefHandle;
  189. int nextDamageTime;
  190. idStr damageFreq;
  191. void FreeBeams();
  192. void Event_RemoveBeams();
  193. void ApplyDamage();
  194. };
  195. /*
  196. ===============================================================================
  197. idDebris
  198. ===============================================================================
  199. */
  200. class idDebris : public idEntity {
  201. public :
  202. CLASS_PROTOTYPE( idDebris );
  203. idDebris();
  204. ~idDebris();
  205. // save games
  206. void Save( idSaveGame *savefile ) const; // archives object for save game file
  207. void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  208. void Spawn( void );
  209. void Create( idEntity *owner, const idVec3 &start, const idMat3 &axis );
  210. void Launch( void );
  211. void Think( void );
  212. void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  213. void Explode( void );
  214. void Fizzle( void );
  215. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  216. private:
  217. idEntityPtr<idEntity> owner;
  218. idPhysics_RigidBody physicsObj;
  219. const idDeclParticle * smokeFly;
  220. int smokeFlyTime;
  221. const idSoundShader * sndBounce;
  222. void Event_Explode( void );
  223. void Event_Fizzle( void );
  224. };
  225. #endif /* !__GAME_PROJECTILE_H__ */