firebomb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. // firebomb.h
  19. // Project: Nostril (aka 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. // 02/28/97 BRH Derived this from the CWeapon base class
  27. //
  28. // 03/03/97 BRH Moved 3D sprite to CWeapon base class.
  29. //
  30. // 03/13/97 JMI Load()s now take a version number.
  31. //
  32. // 04/29/97 JMI Now CFirebomb defines m_sprite (as a CSprite3), which was
  33. // previously defined in the base class CWeapon.
  34. // Also, added GetSprite() virtual override to CFirebomb and
  35. // CFireFrag to provide access to the sprite from a lower
  36. // level.
  37. //
  38. // 05/09/97 BRH Added SetRangeToTarget function to vary the velocity
  39. // of the weapon before it is shot in order to hit
  40. // your target.
  41. //
  42. // 05/20/97 BRH Fixed problem with SetRangeToTarget.
  43. //
  44. // 06/17/97 BRH Fixed a bug in SetRangeToTarget and adjusted the
  45. // Min range up a bit so the enemies don't set themselves
  46. // on fire.
  47. //
  48. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  49. // as a parameter.
  50. //
  51. // 08/28/97 JMI Added a explode counter so we can cap the number of
  52. // explosions a firefrag can make.
  53. //
  54. ////////////////////////////////////////////////////////////////////////////////
  55. #ifndef FIREBOMB_H
  56. #define FIREBOMB_H
  57. #include "RSPiX.h"
  58. #include "realm.h"
  59. #include "fire.h"
  60. #include "weapon.h"
  61. #include "IdBank.h"
  62. // CFirebomb is hand thrown fire grenade weapon class
  63. class CFirebomb : public CWeapon
  64. {
  65. //---------------------------------------------------------------------------
  66. // Types, enums, etc.
  67. //---------------------------------------------------------------------------
  68. public:
  69. //---------------------------------------------------------------------------
  70. // Variables
  71. //---------------------------------------------------------------------------
  72. public:
  73. protected:
  74. short m_sPrevHeight; // Previous height
  75. CAnim3D m_anim; // 3D animation
  76. RTransform m_trans; // Transform
  77. CSprite3 m_sprite; // 3D sprite to render this thing.
  78. // Tracks file counter so we know when to load/save "common" data
  79. static short ms_sFileCount;
  80. // "Constant" values that we want to be able to tune using the editor
  81. static double ms_dCloseDistance; // Close enough to hit CDude
  82. static double ms_dThrowVertVel; // Throw up at this velocity
  83. static double ms_dThrowHorizVel; // Throw out at this velocity
  84. //---------------------------------------------------------------------------
  85. // Constructor(s) / destructor
  86. //---------------------------------------------------------------------------
  87. protected:
  88. // Constructor
  89. CFirebomb(CRealm* pRealm)
  90. : CWeapon(pRealm, CFirebombID)
  91. {
  92. m_sSuspend = 0;
  93. m_sprite.m_pthing = this;
  94. }
  95. public:
  96. // Destructor
  97. ~CFirebomb()
  98. {
  99. // Remove sprite from scene (this is safe even if it was already removed!)
  100. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  101. // Free resources
  102. FreeResources();
  103. }
  104. //---------------------------------------------------------------------------
  105. // Required static functions
  106. //---------------------------------------------------------------------------
  107. public:
  108. // Construct object
  109. static short Construct( // Returns 0 if successfull, non-zero otherwise
  110. CRealm* pRealm, // In: Pointer to realm this object belongs to
  111. CThing** ppNew) // Out: Pointer to new object
  112. {
  113. short sResult = 0;
  114. *ppNew = new CFirebomb(pRealm);
  115. if (*ppNew == 0)
  116. {
  117. sResult = -1;
  118. TRACE("CFirebomb::Construct(): Couldn't construct CFirebomb (that's a bad thing)\n");
  119. }
  120. return sResult;
  121. }
  122. //---------------------------------------------------------------------------
  123. // Optional static functions
  124. //---------------------------------------------------------------------------
  125. // Called before play begins to cache the resource for this object
  126. static short Preload(
  127. CRealm* prealm); // In: Calling realm.
  128. //---------------------------------------------------------------------------
  129. // Required virtual functions (implimenting them as inlines doesn't pay!)
  130. //---------------------------------------------------------------------------
  131. public:
  132. // Load object (should call base class version!)
  133. short Load( // Returns 0 if successfull, non-zero otherwise
  134. RFile* pFile, // In: File to load from
  135. bool bEditMode, // In: True for edit mode, false otherwise
  136. short sFileCount, // In: File count (unique per file, never 0)
  137. ULONG ulFileVersion); // In: Version of file format to load.
  138. // Save object (should call base class version!)
  139. short Save( // Returns 0 if successfull, non-zero otherwise
  140. RFile* pFile, // In: File to save to
  141. short sFileCount); // In: File count (unique per file, never 0)
  142. // Update object
  143. void Update(void);
  144. // Render object
  145. void Render(void);
  146. // Called by the object that is creating this weapon
  147. short Setup(
  148. short sX, // In: New x coord
  149. short sY, // In: New y coord
  150. short sZ); // In: New z coord
  151. // Get this class's sprite. Note that the type will vary.
  152. // This is a pure virtual functionin the base class.
  153. virtual // Overriden here.
  154. CSprite* GetSprite(void) // Returns this weapon's sprite.
  155. {
  156. return &m_sprite;
  157. }
  158. // Function to modify the velocity for a requested range
  159. virtual short SetRangeToTarget(short sRequestedRange)
  160. {
  161. short sSetRange;
  162. // Must go at least 60 or at most 400 pixels
  163. sSetRange = MAX(sRequestedRange, (short) 60);
  164. sSetRange = MIN(sSetRange, (short) 400);
  165. m_dHorizVel = (double) sSetRange / 0.8986; //0.7366;
  166. return sSetRange;
  167. }
  168. //---------------------------------------------------------------------------
  169. // Internal functions
  170. //---------------------------------------------------------------------------
  171. protected:
  172. // Get all required resources
  173. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  174. // Free all resources
  175. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  176. // Process message queue
  177. void ProcessMessages(void);
  178. };
  179. // CFirefrag a fragment that comes out of the CFirebomb weapon
  180. class CFirefrag : public CWeapon
  181. {
  182. //---------------------------------------------------------------------------
  183. // Types, enums, etc.
  184. //---------------------------------------------------------------------------
  185. public:
  186. //---------------------------------------------------------------------------
  187. // Variables
  188. //---------------------------------------------------------------------------
  189. public:
  190. protected:
  191. short m_sPrevHeight; // Previous height
  192. CFire* m_pFire; // Pointer to controlled fire object
  193. U16 m_u16FireID; // ID for fire.
  194. RImage* m_pImage; // Pointer to only image (replace with 3d anim, soon)
  195. CSprite2 m_sprite; // 2D sprite to render this object.
  196. short m_sNumExplosions; // Total Number of explosions.
  197. // Tracks file counter so we know when to load/save "common" data
  198. static short ms_sFileCount;
  199. // "Constant" values that we want to be able to tune using the editor
  200. static double ms_dAccUser; // Acceleration due to user
  201. static double ms_dAccDrag; // Acceleration due to drag (always towards 0)
  202. static double ms_dGravity; // Acceleration due to gravity
  203. static double ms_dThrowVertVel; // Throw up at this velocity
  204. static double ms_dThrowHorizVel; // Throw out at this velocity
  205. static double ms_dMinBounceVel; // Minimum velocity needed to bounce up
  206. static double ms_dVelTransferFract; // Amount of velocity to bounce back up
  207. static short ms_sMaxExplosions; // Maximum explosions before death.
  208. //---------------------------------------------------------------------------
  209. // Constructor(s) / destructor
  210. //---------------------------------------------------------------------------
  211. protected:
  212. // Constructor
  213. CFirefrag(CRealm* pRealm)
  214. : CWeapon(pRealm, CFirefragID)
  215. {
  216. m_pImage = 0;
  217. m_pFire = NULL;
  218. m_u16FireID = CIdBank::IdNil;
  219. m_sNumExplosions = 0;
  220. }
  221. public:
  222. // Destructor
  223. ~CFirefrag()
  224. {
  225. // Remove sprite from scene (this is safe even if it was already removed!)
  226. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  227. // Free resources
  228. FreeResources();
  229. }
  230. //---------------------------------------------------------------------------
  231. // Required static functions
  232. //---------------------------------------------------------------------------
  233. public:
  234. // Construct object
  235. static short Construct( // Returns 0 if successfull, non-zero otherwise
  236. CRealm* pRealm, // In: Pointer to realm this object belongs to
  237. CThing** ppNew) // Out: Pointer to new object
  238. {
  239. short sResult = 0;
  240. *ppNew = new CFirefrag(pRealm);
  241. if (*ppNew == 0)
  242. {
  243. sResult = -1;
  244. TRACE("CFirefrag::Construct(): Couldn't construct CFirefrag (that's a bad thing)\n");
  245. }
  246. return sResult;
  247. }
  248. //---------------------------------------------------------------------------
  249. // Required virtual functions (implimenting them as inlines doesn't pay!)
  250. //---------------------------------------------------------------------------
  251. public:
  252. // Load object (should call base class version!)
  253. short Load( // Returns 0 if successfull, non-zero otherwise
  254. RFile* pFile, // In: File to load from
  255. bool bEditMode, // In: True for edit mode, false otherwise
  256. short sFileCount, // In: File count (unique per file, never 0)
  257. ULONG ulFileVersion); // In: Version of file format to load.
  258. // Save object (should call base class version!)
  259. short Save( // Returns 0 if successfull, non-zero otherwise
  260. RFile* pFile, // In: File to save to
  261. short sFileCount); // In: File count (unique per file, never 0)
  262. // Update object
  263. void Update(void);
  264. // Render object
  265. void Render(void);
  266. // Called by the object that is creating this weapon
  267. short Setup(
  268. short sX, // In: New x coord
  269. short sY, // In: New y coord
  270. short sZ); // In: New z coord
  271. // Get this class's sprite. Note that the type will vary.
  272. // This is a pure virtual functionin the base class.
  273. virtual // Overriden here.
  274. CSprite* GetSprite(void) // Returns this weapon's sprite.
  275. {
  276. return &m_sprite;
  277. }
  278. //---------------------------------------------------------------------------
  279. // Internal functions
  280. //---------------------------------------------------------------------------
  281. protected:
  282. // Get all required resources
  283. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  284. // Free all resources
  285. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  286. };
  287. #endif //FIREBOMB_H
  288. ////////////////////////////////////////////////////////////////////////////////
  289. // EOF
  290. ////////////////////////////////////////////////////////////////////////////////