Projectile.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition 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 BFG Edition 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 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  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();
  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();
  39. idEntity * GetOwner() const;
  40. void CatchProjectile( idEntity* o, const char* reflectName );
  41. int GetProjectileState();
  42. void Event_CreateProjectile( idEntity *owner, const idVec3 &start, const idVec3 &dir );
  43. void Event_LaunchProjectile( const idVec3 &start, const idVec3 &dir, const idVec3 &pushVelocity );
  44. void Event_SetGravity( float gravity );
  45. virtual void Think();
  46. virtual void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  47. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  48. virtual void Explode( const trace_t &collision, idEntity *ignore );
  49. void Fizzle();
  50. static idVec3 GetVelocity( const idDict *projectile );
  51. static idVec3 GetGravity( const idDict *projectile );
  52. enum {
  53. EVENT_DAMAGE_EFFECT = idEntity::EVENT_MAXEVENTS,
  54. EVENT_MAXEVENTS
  55. };
  56. void SetLaunchedFromGrabber( bool bl ) { launchedFromGrabber = bl; }
  57. bool GetLaunchedFromGrabber() { return launchedFromGrabber; }
  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();
  61. virtual void ClientThink( const int curTime, const float fraction, const bool predict );
  62. virtual void WriteToSnapshot( idBitMsg &msg ) const;
  63. virtual void ReadFromSnapshot( const idBitMsg &msg );
  64. virtual bool ClientReceiveEvent( int event, int time, const idBitMsg &msg );
  65. void QueueToSimulate( int startTime );
  66. virtual void SimulateProjectileFrame( int msec, int endTime );
  67. virtual void PostSimulate( int endTime );
  68. struct simulatedProjectile_t {
  69. simulatedProjectile_t(): projectile( NULL ), startTime( 0 ) {}
  70. idProjectile* projectile;
  71. int startTime;
  72. };
  73. static const int MAX_SIMULATED_PROJECTILES = 64;
  74. // This list is used to "catch up" client projectiles to the current time on the server
  75. static idArray< simulatedProjectile_t, MAX_SIMULATED_PROJECTILES > projectilesToSimulate;
  76. protected:
  77. idEntityPtr<idEntity> owner;
  78. struct projectileFlags_s {
  79. bool detonate_on_world : 1;
  80. bool detonate_on_actor : 1;
  81. bool randomShaderSpin : 1;
  82. bool isTracer : 1;
  83. bool noSplashDamage : 1;
  84. } projectileFlags;
  85. bool launchedFromGrabber;
  86. float thrust;
  87. int thrust_end;
  88. float damagePower;
  89. renderLight_t renderLight;
  90. qhandle_t lightDefHandle; // handle to renderer light def
  91. idVec3 lightOffset;
  92. int lightStartTime;
  93. int lightEndTime;
  94. idVec3 lightColor;
  95. idForce_Constant thruster;
  96. idPhysics_RigidBody physicsObj;
  97. const idDeclParticle * smokeFly;
  98. int smokeFlyTime;
  99. bool mNoExplodeDisappear;
  100. bool mTouchTriggers;
  101. int originalTimeGroup;
  102. typedef enum {
  103. // must update these in script/doom_defs.script if changed
  104. SPAWNED = 0,
  105. CREATED = 1,
  106. LAUNCHED = 2,
  107. FIZZLED = 3,
  108. EXPLODED = 4
  109. } projectileState_t;
  110. projectileState_t state;
  111. private:
  112. idVec3 launchOrigin;
  113. idMat3 launchAxis;
  114. void AddDefaultDamageEffect( const trace_t &collision, const idVec3 &velocity );
  115. void AddParticlesAndLight();
  116. void Event_Explode();
  117. void Event_Fizzle();
  118. void Event_RadiusDamage( idEntity *ignore );
  119. void Event_Touch( idEntity *other, trace_t *trace );
  120. void Event_GetProjectileState();
  121. };
  122. class idGuidedProjectile : public idProjectile {
  123. public :
  124. CLASS_PROTOTYPE( idGuidedProjectile );
  125. idGuidedProjectile();
  126. ~idGuidedProjectile();
  127. void Save( idSaveGame *savefile ) const;
  128. void Restore( idRestoreGame *savefile );
  129. void Spawn();
  130. virtual void Think();
  131. 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 );
  132. void SetEnemy( idEntity *ent );
  133. void Event_SetEnemy(idEntity *ent);
  134. protected:
  135. float speed;
  136. idEntityPtr<idEntity> enemy;
  137. virtual void GetSeekPos( idVec3 &out );
  138. private:
  139. idAngles rndScale;
  140. idAngles rndAng;
  141. idAngles angles;
  142. int rndUpdateTime;
  143. float turn_max;
  144. float clamp_dist;
  145. bool burstMode;
  146. bool unGuided;
  147. float burstDist;
  148. float burstVelocity;
  149. };
  150. class idSoulCubeMissile : public idGuidedProjectile {
  151. public:
  152. CLASS_PROTOTYPE ( idSoulCubeMissile );
  153. ~idSoulCubeMissile();
  154. void Save( idSaveGame *savefile ) const;
  155. void Restore( idRestoreGame *savefile );
  156. void Spawn();
  157. virtual void Think();
  158. 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 );
  159. protected:
  160. virtual void GetSeekPos( idVec3 &out );
  161. void ReturnToOwner();
  162. void KillTarget( const idVec3 &dir );
  163. private:
  164. idVec3 startingVelocity;
  165. idVec3 endingVelocity;
  166. float accelTime;
  167. int launchTime;
  168. bool killPhase;
  169. bool returnPhase;
  170. idVec3 destOrg;
  171. idVec3 orbitOrg;
  172. int orbitTime;
  173. int smokeKillTime;
  174. const idDeclParticle * smokeKill;
  175. };
  176. struct beamTarget_t {
  177. idEntityPtr<idEntity> target;
  178. renderEntity_t renderEntity;
  179. qhandle_t modelDefHandle;
  180. };
  181. class idBFGProjectile : public idProjectile {
  182. public :
  183. CLASS_PROTOTYPE( idBFGProjectile );
  184. idBFGProjectile();
  185. ~idBFGProjectile();
  186. void Save( idSaveGame *savefile ) const;
  187. void Restore( idRestoreGame *savefile );
  188. void Spawn();
  189. virtual void Think();
  190. 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 );
  191. virtual void Explode( const trace_t &collision, idEntity *ignore );
  192. private:
  193. idList<beamTarget_t, TAG_PROJECTILE> beamTargets;
  194. renderEntity_t secondModel;
  195. qhandle_t secondModelDefHandle;
  196. int nextDamageTime;
  197. idStr damageFreq;
  198. void FreeBeams();
  199. void Event_RemoveBeams();
  200. void ApplyDamage();
  201. };
  202. class idHomingProjectile : public idProjectile {
  203. public :
  204. CLASS_PROTOTYPE( idHomingProjectile );
  205. idHomingProjectile();
  206. ~idHomingProjectile();
  207. void Save( idSaveGame *savefile ) const;
  208. void Restore( idRestoreGame *savefile );
  209. void Spawn();
  210. virtual void Think();
  211. 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 );
  212. void SetEnemy( idEntity *ent );
  213. void SetSeekPos( idVec3 pos );
  214. void Event_SetEnemy(idEntity *ent);
  215. protected:
  216. float speed;
  217. idEntityPtr<idEntity> enemy;
  218. idVec3 seekPos;
  219. private:
  220. idAngles rndScale;
  221. idAngles rndAng;
  222. idAngles angles;
  223. float turn_max;
  224. float clamp_dist;
  225. bool burstMode;
  226. bool unGuided;
  227. float burstDist;
  228. float burstVelocity;
  229. };
  230. /*
  231. ===============================================================================
  232. idDebris
  233. ===============================================================================
  234. */
  235. class idDebris : public idEntity {
  236. public :
  237. CLASS_PROTOTYPE( idDebris );
  238. idDebris();
  239. ~idDebris();
  240. // save games
  241. void Save( idSaveGame *savefile ) const; // archives object for save game file
  242. void Restore( idRestoreGame *savefile ); // unarchives object from save game file
  243. void Spawn();
  244. void Create( idEntity *owner, const idVec3 &start, const idMat3 &axis );
  245. void Launch();
  246. void Think();
  247. void Killed( idEntity *inflictor, idEntity *attacker, int damage, const idVec3 &dir, int location );
  248. void Explode();
  249. void Fizzle();
  250. virtual bool Collide( const trace_t &collision, const idVec3 &velocity );
  251. private:
  252. idEntityPtr<idEntity> owner;
  253. idPhysics_RigidBody physicsObj;
  254. const idDeclParticle * smokeFly;
  255. int smokeFlyTime;
  256. const idSoundShader * sndBounce;
  257. void Event_Explode();
  258. void Event_Fizzle();
  259. };
  260. #endif /* !__GAME_PROJECTILE_H__ */