grenade.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. // grenade.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 01/17/97 BRH Started this weapon object.
  23. //
  24. // 02/11/97 JMI Stripped 2D. Added 3D and a concept of having a parent.
  25. //
  26. // 02/21/97 JMI Made static constants public.
  27. //
  28. // 02/26/97 JMI Now sets m_sprite.m_pthing = this on construction.
  29. //
  30. // 02/28/97 BRH Derived this from the CWeapon base class and moved
  31. // many members and some functions to the base class.
  32. //
  33. // 03/03/97 BRH Moved 3D sprite to CWeapon base class.
  34. //
  35. // 03/03/97 JMI Commented out dHorizVelocity and dVertVelocity parameters
  36. // to Setup() so that this version would be a virtual over-
  37. // ride of CWeapon's.
  38. //
  39. // 03/13/97 JMI Load now takes a version number.
  40. //
  41. // 04/29/97 JMI Now defines m_sprite (as a CSprite3), which was previously
  42. // defined in the base class CWeapon.
  43. // Also, added GetSprite() virtual override to provide access
  44. // to the sprite from a lower level.
  45. //
  46. // 05/09/97 BRH Added SetRangeToTarget function to vary the velocity
  47. // of the weapon before it is shot in order to hit
  48. // your target.
  49. //
  50. // 06/03/97 BRH Tuned the SetRangeToTarget function now that the drag
  51. // has changed for the grenade.
  52. //
  53. // 06/17/97 BRH Increased Min distance in SetRangeToTarget so that enemies
  54. // won't blow themselves up. Fixed a bug in the SetRange
  55. // function as well.
  56. //
  57. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  58. // as a parameter.
  59. //
  60. // 08/08/97 JMI Added Style so this can be visually represented in multiple
  61. // ways.
  62. //
  63. // 08/08/97 JMI Added variables for rotating the weapon.
  64. //
  65. // 08/28/97 BRH Tuned distance for dynamite.
  66. //
  67. ////////////////////////////////////////////////////////////////////////////////
  68. #ifndef GRENADE_H
  69. #define GRENADE_H
  70. #include "RSPiX.h"
  71. #include "realm.h"
  72. #include "weapon.h"
  73. // CGrenade is an unguided missile weapon class
  74. class CGrenade : public CWeapon
  75. {
  76. //---------------------------------------------------------------------------
  77. // Types, enums, etc.
  78. //---------------------------------------------------------------------------
  79. public:
  80. typedef enum
  81. {
  82. Grenade,
  83. Dynamite,
  84. NumStyles
  85. } Style;
  86. //---------------------------------------------------------------------------
  87. // Variables
  88. //---------------------------------------------------------------------------
  89. public:
  90. protected:
  91. short m_sPrevHeight; // Previous height
  92. CAnim3D m_anim; // 3D animation. One should be enough, I think.
  93. RTransform m_trans; // Transform.
  94. CSprite3 m_sprite; // 3D sprite to render this thing.
  95. Style m_style; // Style of thrown weapon.
  96. double m_dAnimRotY; // Apparent rotation around Y axis.
  97. double m_dAnimRotZ; // Apparent rotation around X axis.
  98. double m_dAnimRotVelY; // Rate of apparent rotation around Y axis.
  99. double m_dAnimRotVelZ; // Rate of apparent rotation around X axis.
  100. long m_lNextSmokeTime; // Time of dispersion of next smoke.
  101. // Tracks file counter so we know when to load/save "common" data
  102. static short ms_sFileCount;
  103. public:
  104. // "Constant" values that we want to be able to tune using the editor
  105. static double ms_dAccUser; // Acceleration due to user
  106. static double ms_dAccDrag; // Acceleration due to drag (always towards 0)
  107. static double ms_dMaxVelFore; // Maximum forward velocity
  108. static double ms_dMaxVelBack; // Maximum backward velocity
  109. static double ms_dDegPerSec; // Degrees of rotation per second
  110. static double ms_dCloseDistance; // Close enough to hit CDude
  111. static long ms_lRandomAvoidTime; // Time to wander before looking again
  112. static long ms_lReseekTime; // Time to wait before doing the next 'find'
  113. static long ms_lGrenadeFuseTime; // Time from throw to blow
  114. static long ms_lSmokeInterval; // Time between smokes.
  115. static double ms_dGravity; // Acceleration due to gravity
  116. static double ms_dThrowVertVel; // Throw up at this velocity
  117. static double ms_dThrowHorizVel; // Throw out at this velocity
  118. static double ms_dMinBounceVel; // Will bounce up if velocity is this high
  119. static double ms_dBounceTransferFract; // Amount of velocity transferred in bounce
  120. static double ms_adGroundDimisher[NumStyles]; // Dimishes velocities once it hits the ground.
  121. static double ms_adBounceDimisher[NumStyles]; // Dimishes velocities when bouncing.
  122. static char* ms_apszResNames[NumStyles]; // Res names indexed Style.
  123. //---------------------------------------------------------------------------
  124. // Constructor(s) / destructor
  125. //---------------------------------------------------------------------------
  126. protected:
  127. // Constructor
  128. CGrenade(CRealm* pRealm)
  129. : CWeapon(pRealm, CGrenadeID)
  130. {
  131. m_sprite.m_pthing = this;
  132. m_style = Grenade;
  133. m_dAnimRotY = 0.0;
  134. m_dAnimRotZ = 0.0;
  135. m_dAnimRotVelY = 0.0;
  136. m_dAnimRotVelZ = 0.0;
  137. m_lNextSmokeTime = 0;
  138. }
  139. public:
  140. // Destructor
  141. ~CGrenade()
  142. {
  143. // Remove sprite from scene (this is safe even if it was already removed!)
  144. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  145. // Free resources
  146. FreeResources();
  147. }
  148. //---------------------------------------------------------------------------
  149. // Required static functions
  150. //---------------------------------------------------------------------------
  151. public:
  152. // Construct object
  153. static short Construct( // Returns 0 if successfull, non-zero otherwise
  154. CRealm* pRealm, // In: Pointer to realm this object belongs to
  155. CThing** ppNew) // Out: Pointer to new object
  156. {
  157. short sResult = 0;
  158. *ppNew = new CGrenade(pRealm);
  159. if (*ppNew == 0)
  160. {
  161. sResult = -1;
  162. TRACE("CGrenade::Construct(): Couldn't construct CGrenade (that's a bad thing)\n");
  163. }
  164. return sResult;
  165. }
  166. // Construct object as dynamite.
  167. static short ConstructDynamite( // Returns 0 if successfull, non-zero otherwise
  168. CRealm* pRealm, // In: Pointer to realm this object belongs to
  169. CThing** ppNew) // Out: Pointer to new object
  170. {
  171. short sRes = Construct(pRealm, ppNew);
  172. if (sRes == 0)
  173. {
  174. ( (CGrenade*)(*ppNew) )->m_style = Dynamite;
  175. }
  176. return sRes;
  177. }
  178. //---------------------------------------------------------------------------
  179. // Optional static functions
  180. //---------------------------------------------------------------------------
  181. // Called before play begins to cache resources for this object.
  182. static short Preload(
  183. CRealm* prealm); // In: Calling realm.
  184. //---------------------------------------------------------------------------
  185. // Required virtual functions (implimenting them as inlines doesn't pay!)
  186. //---------------------------------------------------------------------------
  187. public:
  188. // Load object (should call base class version!)
  189. short Load( // Returns 0 if successfull, non-zero otherwise
  190. RFile* pFile, // In: File to load from
  191. bool bEditMode, // In: True for edit mode, false otherwise
  192. short sFileCount, // In: File count (unique per file, never 0)
  193. ULONG ulFileVersion); // In: Version of file format to load.
  194. // Save object (should call base class version!)
  195. short Save( // Returns 0 if successfull, non-zero otherwise
  196. RFile* pFile, // In: File to save to
  197. short sFileCount); // In: File count (unique per file, never 0)
  198. // Update object
  199. void Update(void);
  200. // Render object
  201. void Render(void);
  202. // Called by the object that is creating this weapon
  203. short Setup(
  204. short sX, // In: New x coord
  205. short sY, // In: New y coord
  206. short sZ/*, // In: New z coord
  207. double dHorizVelocity = ms_dThrowHorizVel, // In: Starting horiz velocity with default
  208. double dVertVelocity = ms_dThrowVertVel*/); // In: Starting vert velocity with default
  209. // Get this class's sprite. Note that the type will vary.
  210. // This is a pure virtual functionin the base class.
  211. virtual // Overriden here.
  212. CSprite* GetSprite(void) // Returns this weapon's sprite.
  213. {
  214. return &m_sprite;
  215. }
  216. // Function to modify the velocity for a requested range
  217. virtual short SetRangeToTarget(short sRequestedRange)
  218. {
  219. short sSetRange;
  220. // Must go at least 40 or at most 400 pixels
  221. sSetRange = MAX(sRequestedRange, (short) 40);
  222. sSetRange = MIN(sSetRange, (short) 400);
  223. if (m_style == Grenade)
  224. m_dHorizVel = (double) sSetRange / 0.8476; //0.6855;
  225. else
  226. m_dHorizVel = (double) sSetRange / 1.010;
  227. return sSetRange;
  228. }
  229. // Smoke, if correct time.
  230. void Smoke(void);
  231. //---------------------------------------------------------------------------
  232. // Internal functions
  233. //---------------------------------------------------------------------------
  234. protected:
  235. // Get all required resources
  236. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  237. // Free all resources
  238. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  239. // Process Message queue
  240. void ProcessMessages(void);
  241. };
  242. #endif // GRENADE_H
  243. ////////////////////////////////////////////////////////////////////////////////
  244. // EOF
  245. ////////////////////////////////////////////////////////////////////////////////