rocket.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. // rocket.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 01/17/97 BRH Started this weapon object.
  23. //
  24. // 02/26/97 JMI Now sets m_sprite.m_pthing = this on construction.
  25. //
  26. // 03/03/97 BRH Derived this from the CWeapon base class
  27. //
  28. // 03/03/97 BRH Moved the 3D sprite to the CWeapon base class.
  29. //
  30. // 03/13/97 JMI Load now takes a version number.
  31. //
  32. // 04/29/97 BRH Added an off screen distance at which the rocket will self
  33. // destruct.
  34. //
  35. // 04/29/97 JMI Now defines m_sprite (as a CSprite3), which was previously
  36. // defined in the base class CWeapon.
  37. // Also, added GetSprite() virtual override to provide access
  38. // to the sprite from a lower level.
  39. //
  40. // 07/01/97 BRH Added smoke timer for creating a trail of smoke.
  41. //
  42. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  43. // as a parameter.
  44. //
  45. // 07/18/97 JMI Added m_siThrust to track our thrust play instance so we
  46. // can loop it and then terminate the looping when we explode.
  47. //
  48. // 08/14/97 BRH Added SetCollideBits function so that the Dude and Doofus
  49. // could set the collision bits differently.
  50. //
  51. // 08/23/97 JMI Added CSmash::AlmostDead to exclude bits.
  52. //
  53. ////////////////////////////////////////////////////////////////////////////////
  54. #ifndef ROCKET_H
  55. #define ROCKET_H
  56. #include "weapon.h"
  57. // CRocket is an unguided missile weapon class
  58. class CRocket : public CWeapon
  59. {
  60. //---------------------------------------------------------------------------
  61. // Types, enums, etc.
  62. //---------------------------------------------------------------------------
  63. public:
  64. //---------------------------------------------------------------------------
  65. // Variables
  66. //---------------------------------------------------------------------------
  67. public:
  68. // Collision bits
  69. U32 m_u32CollideIncludeBits;
  70. U32 m_u32CollideDontcareBits;
  71. U32 m_u32CollideExcludeBits;
  72. protected:
  73. CAnim3D m_anim; // 3D animation
  74. RTransform m_trans; // Transform
  75. CSmash m_smash;
  76. bool m_bArmed; // Initially missile is not armed so it doesn't
  77. // collide with the person who shot it.
  78. CSprite3 m_sprite; // 3D sprite to render this thing.
  79. long m_lSmokeTimer; // Time between emitting smoke puffs
  80. SampleMaster::SoundInstance m_siThrust; // Looping thrust play instance.
  81. // Tracks file counter so we know when to load/save "common" data
  82. static short ms_sFileCount;
  83. // "Constant" values that we want to be able to tune using the editor
  84. static double ms_dAccUser; // Acceleration due to user
  85. static double ms_dMaxVelFore; // Maximum forward velocity
  86. static double ms_dMaxVelBack; // Maximum backward velocity
  87. static double ms_dCloseDistance; // Close enough to hit CDude
  88. static long ms_lArmingTime; // Time before weapons arms.
  89. static short ms_sOffScreenDist; // Distance off screen before self destructing
  90. static long ms_lSmokeTrailInterval;// Time between creating puffs of smoke
  91. static long ms_lSmokeTimeToLive; // Time for smoke to stick around.
  92. //---------------------------------------------------------------------------
  93. // Constructor(s) / destructor
  94. //---------------------------------------------------------------------------
  95. public:
  96. // Constructor
  97. CRocket(CRealm* pRealm)
  98. : CWeapon(pRealm, CRocketID)
  99. {
  100. m_sprite.m_pthing = this;
  101. m_lSmokeTimer = 0;
  102. m_siThrust = 0;
  103. }
  104. public:
  105. // Destructor
  106. ~CRocket()
  107. {
  108. // Stop sound, if any.
  109. StopLoopingSample(m_siThrust);
  110. // Remove sprite from scene (this is safe even if it was already removed!)
  111. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  112. m_pRealm->m_smashatorium.Remove(&m_smash);
  113. // Free resources
  114. FreeResources();
  115. }
  116. //---------------------------------------------------------------------------
  117. // Required static functions
  118. //---------------------------------------------------------------------------
  119. public:
  120. // Construct object
  121. static short Construct( // Returns 0 if successfull, non-zero otherwise
  122. CRealm* pRealm, // In: Pointer to realm this object belongs to
  123. CThing** ppNew) // Out: Pointer to new object
  124. {
  125. short sResult = 0;
  126. *ppNew = new CRocket(pRealm);
  127. if (*ppNew == 0)
  128. {
  129. sResult = -1;
  130. TRACE("CRocket::Construct(): Couldn't construct CRocket (that's a bad thing)\n");
  131. }
  132. return sResult;
  133. }
  134. //---------------------------------------------------------------------------
  135. // Optional static functions
  136. //---------------------------------------------------------------------------
  137. // Called before play begins to cache resources for this object
  138. static short Preload(
  139. CRealm* prealm); // In: Calling realm.
  140. public:
  141. void SetTransform(RTransform* pTransform)
  142. {
  143. m_sprite.m_ptrans = pTransform;
  144. };
  145. //---------------------------------------------------------------------------
  146. // Optional virtual functions
  147. //---------------------------------------------------------------------------
  148. public:
  149. virtual
  150. void SetCollideBits( // Returns nothing
  151. U32 u32CollideBitsInclude, // Bits considered in collision
  152. U32 u32CollideBitsDontCare, // Bits ignored for collisions
  153. U32 u32CollideBitsExclude) // Bits that invalidate a collision
  154. {
  155. m_u32CollideIncludeBits = u32CollideBitsInclude;
  156. m_u32CollideDontcareBits = u32CollideBitsDontCare;
  157. m_u32CollideExcludeBits = u32CollideBitsExclude | CSmash::Ducking | CSmash::AlmostDead;
  158. }
  159. //---------------------------------------------------------------------------
  160. // Required virtual functions (implimenting them as inlines doesn't pay!)
  161. //---------------------------------------------------------------------------
  162. public:
  163. // Load object (should call base class version!)
  164. short Load( // Returns 0 if successfull, non-zero otherwise
  165. RFile* pFile, // In: File to load from
  166. bool bEditMode, // In: True for edit mode, false otherwise
  167. short sFileCount, // In: File count (unique per file, never 0)
  168. ULONG ulFileVersion); // In: Version of file format to load.
  169. // Save object (should call base class version!)
  170. short Save( // Returns 0 if successfull, non-zero otherwise
  171. RFile* pFile, // In: File to save to
  172. short sFileCount); // In: File count (unique per file, never 0)
  173. // Update object
  174. void Update(void);
  175. // Render object
  176. void Render(void);
  177. // Called by another object to set start a new rocket
  178. short Setup(
  179. short sX,
  180. short sY,
  181. short sZ);
  182. // Get this class's sprite. Note that the type will vary.
  183. // This is a pure virtual functionin the base class.
  184. virtual // Overriden here.
  185. CSprite* GetSprite(void) // Returns this weapon's sprite.
  186. {
  187. return &m_sprite;
  188. }
  189. //---------------------------------------------------------------------------
  190. // Internal functions
  191. //---------------------------------------------------------------------------
  192. protected:
  193. // Get all required resources
  194. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  195. // Free all resources
  196. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  197. // Process messages in the message queue.
  198. void ProcessMessages(void);
  199. };
  200. #endif //DOOFUS_H
  201. ////////////////////////////////////////////////////////////////////////////////
  202. // EOF
  203. ////////////////////////////////////////////////////////////////////////////////