heatseeker.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // heatseeker.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 05/13/97 BRH Started this weapon object fromt the CHeatseeker code.
  23. //
  24. // 07/01/97 BRH Added smoke timer for making smoke trails.
  25. //
  26. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  27. // as a parameter.
  28. //
  29. // 08/14/97 BRH Added SetCollideBits and the collision bit fields so that
  30. // they can be set by the Doofus or Dude when they shoot it
  31. // and they can collide differently, rather than the
  32. // standard default behavoir.
  33. //
  34. // 08/17/97 BRH Added thrust sound instance so it is like the rocket.
  35. //
  36. // 08/23/97 JMI Added CSmash::AlmostDead to exclude bits.
  37. //
  38. ////////////////////////////////////////////////////////////////////////////////
  39. #ifndef HEATSEEKER_H
  40. #define HEATSEEKER_H
  41. #include "weapon.h"
  42. // CHeatseeker is a heat seeking missile
  43. class CHeatseeker : public CWeapon
  44. {
  45. //---------------------------------------------------------------------------
  46. // Types, enums, etc.
  47. //---------------------------------------------------------------------------
  48. public:
  49. //---------------------------------------------------------------------------
  50. // Variables
  51. //---------------------------------------------------------------------------
  52. public:
  53. // Collision bits
  54. protected:
  55. CAnim3D m_anim; // 3D animation
  56. RTransform m_trans; // Transform
  57. CSmash m_smash; // Smash used for explosion collisions (small)
  58. CSmash m_smashSeeker; // Smash used to detect heat sources (larger)
  59. bool m_bArmed; // Initially missile is not armed so it doesn't
  60. // collide with the person who shot it.
  61. CSprite3 m_sprite; // 3D sprite to render this thing.
  62. long m_lSmokeTimer; // Time to wait between emitting smoke
  63. U32 m_u32CollideBitsInclude; // Bits that cause a collision
  64. U32 m_u32CollideBitsDontCare; // Bits that are ignored for collisions
  65. U32 m_u32CollideBitsExclude; // Bits that invalidate a collision
  66. U32 m_u32SeekBitsInclude; // Bits that cause a collision
  67. U32 m_u32SeekBitsDontCare; // Bits that are ignored for collisions
  68. U32 m_u32SeekBitsExclude; // bits taht invalidate a collision
  69. SampleMaster::SoundInstance m_siThrust; // Looping thrust play instance
  70. // Tracks file counter so we know when to load/save "common" data
  71. static short ms_sFileCount;
  72. // "Constant" values that we want to be able to tune using the editor
  73. static double ms_dAccUser; // Acceleration due to user
  74. static double ms_dMaxVelFore; // Maximum forward velocity
  75. static double ms_dMaxVelBack; // Maximum backward velocity
  76. static double ms_dCloseDistance; // Close enough to hit CDude
  77. static double ms_dLineCheckRate; // Pixel distance for line checking
  78. static long ms_lArmingTime; // Time before weapons arms.
  79. static long ms_lSeekRadius; // Radius of Heatseeking circle
  80. static short ms_sOffScreenDist; // Distance off screen before self destructing
  81. static short ms_sAngularVelocity;// Degrees per second that it can turn
  82. static U32 ms_u32CollideIncludeBits;
  83. static U32 ms_u32CollideDontcareBits;
  84. static U32 ms_u32CollideExcludeBits;
  85. static U32 ms_u32SeekIncludeBits;
  86. static U32 ms_u32SeekDontcareBits;
  87. static U32 ms_u32SeekExcludeBits;
  88. static long ms_lSmokeTrailInterval; // Time between smoke releases
  89. static long ms_lSmokeTimeToLive; // Time for smoke to stick around.
  90. //---------------------------------------------------------------------------
  91. // Constructor(s) / destructor
  92. //---------------------------------------------------------------------------
  93. public:
  94. // Constructor
  95. CHeatseeker(CRealm* pRealm)
  96. : CWeapon(pRealm, CHeatseekerID)
  97. {
  98. m_sprite.m_pthing = this;
  99. m_lSmokeTimer = 0;
  100. m_siThrust = 0;
  101. }
  102. public:
  103. // Destructor
  104. ~CHeatseeker()
  105. {
  106. // Stop sound if any
  107. StopLoopingSample(m_siThrust);
  108. // Remove sprite from scene (this is safe even if it was already removed!)
  109. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  110. m_pRealm->m_smashatorium.Remove(&m_smash);
  111. // Free resources
  112. FreeResources();
  113. }
  114. //---------------------------------------------------------------------------
  115. // Required static functions
  116. //---------------------------------------------------------------------------
  117. public:
  118. // Construct object
  119. static short Construct( // Returns 0 if successfull, non-zero otherwise
  120. CRealm* pRealm, // In: Pointer to realm this object belongs to
  121. CThing** ppNew) // Out: Pointer to new object
  122. {
  123. short sResult = 0;
  124. *ppNew = new CHeatseeker(pRealm);
  125. if (*ppNew == 0)
  126. {
  127. sResult = -1;
  128. TRACE("CHeatseeker::Construct(): Couldn't construct CHeatseeker (that's a bad thing)\n");
  129. }
  130. return sResult;
  131. }
  132. //---------------------------------------------------------------------------
  133. // Optional static functions
  134. //---------------------------------------------------------------------------
  135. // Called before play begins to cache resources for this object
  136. static short Preload(
  137. CRealm* prealm); // In: Calling realm.
  138. public:
  139. void SetTransform(RTransform* pTransform)
  140. {
  141. m_sprite.m_ptrans = pTransform;
  142. };
  143. //---------------------------------------------------------------------------
  144. // Optional virtual functions
  145. //---------------------------------------------------------------------------
  146. public:
  147. // Used to set the collision bit fields
  148. virtual
  149. void SetCollideBits( // Returns nothing
  150. U32 u32BitsInclude, // Bits to detect in collisions
  151. U32 u32BitsDontCare, // Bits that don't matter for collision detection
  152. U32 u32BitsExclude) // Bits that invalidate collision
  153. {
  154. m_u32CollideBitsInclude = u32BitsInclude | CSmash::Fire;
  155. m_u32CollideBitsDontCare = u32BitsDontCare;
  156. m_u32CollideBitsExclude = u32BitsExclude | CSmash::Ducking | CSmash::AlmostDead;
  157. }
  158. // Used to set the detection bit fields
  159. virtual
  160. void SetDetectionBits( // Returns nothing
  161. U32 u32BitsInclude, // Bits to detect in collisions
  162. U32 u32BitsDontcare, // Bits that don't matter for collision detection
  163. U32 u32BitsExclude) // Bits that invalidate collision
  164. {
  165. m_u32SeekBitsInclude = u32BitsInclude | CSmash::Fire;
  166. m_u32SeekBitsDontCare = u32BitsDontcare;
  167. m_u32SeekBitsExclude = u32BitsExclude | CSmash::Ducking | CSmash::AlmostDead;
  168. }
  169. //---------------------------------------------------------------------------
  170. // Required virtual functions (implimenting them as inlines doesn't pay!)
  171. //---------------------------------------------------------------------------
  172. public:
  173. // Load object (should call base class version!)
  174. short Load( // Returns 0 if successfull, non-zero otherwise
  175. RFile* pFile, // In: File to load from
  176. bool bEditMode, // In: True for edit mode, false otherwise
  177. short sFileCount, // In: File count (unique per file, never 0)
  178. ULONG ulFileVersion); // In: Version of file format to load.
  179. // Save object (should call base class version!)
  180. short Save( // Returns 0 if successfull, non-zero otherwise
  181. RFile* pFile, // In: File to save to
  182. short sFileCount); // In: File count (unique per file, never 0)
  183. // Update object
  184. void Update(void);
  185. // Render object
  186. void Render(void);
  187. // Called by another object to set start a new rocket
  188. short Setup(
  189. short sX,
  190. short sY,
  191. short sZ);
  192. // Get this class's sprite. Note that the type will vary.
  193. // This is a pure virtual functionin the base class.
  194. virtual // Overriden here.
  195. CSprite* GetSprite(void) // Returns this weapon's sprite.
  196. {
  197. return &m_sprite;
  198. }
  199. //---------------------------------------------------------------------------
  200. // Internal functions
  201. //---------------------------------------------------------------------------
  202. protected:
  203. // Get all required resources
  204. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  205. // Free all resources
  206. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  207. // Process messages in the message queue.
  208. void ProcessMessages(void);
  209. inline short FindAngleTo(double dX, double dZ)
  210. {
  211. return rspATan((m_dZ - dZ), (dX - m_dX));
  212. }
  213. };
  214. #endif //HEATSEEKER_H
  215. ////////////////////////////////////////////////////////////////////////////////
  216. // EOF
  217. ////////////////////////////////////////////////////////////////////////////////