Projectile.h 8.2 KB

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