napalm.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. // napalm.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. // 03/03/97 BRH Changed to be derived from CWeapon base class
  27. //
  28. // 03/03/97 BRH Moved the 3D sprite to the CWeapon base class.
  29. //
  30. // 03/03/97 JMI Commented out dHorizVelocity and dVertVelocity parameters
  31. // to Setup() so that this version would be a virtual over-
  32. // ride of CWeapon's.
  33. //
  34. // 03/13/97 JMI Load now takes a version number.
  35. //
  36. // 04/29/97 JMI Now defines m_sprite (as a CSprite3), which was previously
  37. // defined in the base class CWeapon.
  38. // Also, added GetSprite() virtual override to provide access
  39. // to the sprite from a lower level.
  40. //
  41. // 05/09/97 BRH Added SetRangeToTarget function to vary the velocity
  42. // of the weapon before it is shot in order to hit
  43. // your target.
  44. //
  45. // 06/17/97 BRH Fixed a bug in SetRangeToTarget where the min was not
  46. // being limited correctly.
  47. //
  48. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  49. // as a parameter.
  50. //
  51. ////////////////////////////////////////////////////////////////////////////////
  52. #ifndef NAPALM_H
  53. #define NAPALM_H
  54. #include "weapon.h"
  55. // CNapalm is a canister of napalm weapon class
  56. class CNapalm : public CWeapon
  57. {
  58. //---------------------------------------------------------------------------
  59. // Types, enums, etc.
  60. //---------------------------------------------------------------------------
  61. public:
  62. //---------------------------------------------------------------------------
  63. // Variables
  64. //---------------------------------------------------------------------------
  65. public:
  66. // CSprite3 m_sprite; // 3D Sprite
  67. protected:
  68. double m_dFireX; // Last position of fire for comparision
  69. double m_dFireZ; // Last position of fire for comparision
  70. CAnim3D m_anim; // 3D animation
  71. RTransform m_trans; // Transform
  72. CSprite3 m_sprite; // 3D sprite to render this thing.
  73. // Tracks file counter so we know when to load/save "common" data
  74. static short ms_sFileCount;
  75. // "Constant" values that we want to be able to tune using the editor
  76. static double ms_dAccDrag; // Acceleration due to drag (always towards 0)
  77. static long ms_lGrenadeFuseTime; // Time from throw to blow
  78. static double ms_dThrowVertVel; // Throw up at this velocity
  79. static double ms_dThrowHorizVel; // Throw out at this velocity
  80. static double ms_dMinFireInterval; // Lay fire down every this amount of distance
  81. //---------------------------------------------------------------------------
  82. // Constructor(s) / destructor
  83. //---------------------------------------------------------------------------
  84. protected:
  85. // Constructor
  86. CNapalm(CRealm* pRealm)
  87. : CWeapon(pRealm, CNapalmID)
  88. {
  89. m_sprite.m_pthing = this;
  90. }
  91. public:
  92. // Destructor
  93. ~CNapalm()
  94. {
  95. // Remove sprite from scene (this is safe even if it was already removed!)
  96. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  97. // Free resources
  98. FreeResources();
  99. }
  100. //---------------------------------------------------------------------------
  101. // Required static functions
  102. //---------------------------------------------------------------------------
  103. public:
  104. // Construct object
  105. static short Construct( // Returns 0 if successfull, non-zero otherwise
  106. CRealm* pRealm, // In: Pointer to realm this object belongs to
  107. CThing** ppNew) // Out: Pointer to new object
  108. {
  109. short sResult = 0;
  110. *ppNew = new CNapalm(pRealm);
  111. if (*ppNew == 0)
  112. {
  113. sResult = -1;
  114. TRACE("CNapalm::Construct(): Couldn't construct CNapalm (that's a bad thing)\n");
  115. }
  116. return sResult;
  117. }
  118. //---------------------------------------------------------------------------
  119. // Optional static functions
  120. //---------------------------------------------------------------------------
  121. // Called before play begins to cache resources for this object
  122. static short Preload(
  123. CRealm* prealm); // In: Calling realm.
  124. public:
  125. void SetTransform(RTransform* pTransform)
  126. {
  127. m_sprite.m_ptrans = pTransform;
  128. };
  129. //---------------------------------------------------------------------------
  130. // Required virtual functions (implimenting them as inlines doesn't pay!)
  131. //---------------------------------------------------------------------------
  132. public:
  133. // Load object (should call base class version!)
  134. short Load( // Returns 0 if successfull, non-zero otherwise
  135. RFile* pFile, // In: File to load from
  136. bool bEditMode, // In: True for edit mode, false otherwise
  137. short sFileCount, // In: File count (unique per file, never 0)
  138. ULONG ulFileVersion); // In: Version of file format to load.
  139. // Save object (should call base class version!)
  140. short Save( // Returns 0 if successfull, non-zero otherwise
  141. RFile* pFile, // In: File to save to
  142. short sFileCount); // In: File count (unique per file, never 0)
  143. // Update object
  144. void Update(void);
  145. // Render object
  146. void Render(void);
  147. // Called by the object that is creating this weapon
  148. short Setup(
  149. short sX, // In: New x coord
  150. short sY, // In: New y coord
  151. short sZ/*, // In: New z coord
  152. double dHorizVel = ms_dThrowHorizVel, // In: Starting horizontal velocity
  153. double dVertVel = ms_dThrowVertVel*/); // In: Starting vertical velocity
  154. // Get this class's sprite. Note that the type will vary.
  155. // This is a pure virtual functionin the base class.
  156. virtual // Overriden here.
  157. CSprite* GetSprite(void) // Returns this weapon's sprite.
  158. {
  159. return &m_sprite;
  160. }
  161. // Function to modify the velocity for a requested range
  162. virtual short SetRangeToTarget(short sRequestedRange)
  163. {
  164. short sSetRange;
  165. // Must go at least 30 or at most 400 pixels
  166. sSetRange = MAX(sRequestedRange, (short) 30);
  167. sSetRange = MIN(sSetRange, (short) 400);
  168. m_dHorizVel = (double) sSetRange / 0.8544; //0.6782;
  169. return sSetRange;
  170. }
  171. //---------------------------------------------------------------------------
  172. // Internal functions
  173. //---------------------------------------------------------------------------
  174. protected:
  175. // Get all required resources
  176. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  177. // Free all resources
  178. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  179. // Process messages in the message queue.
  180. void ProcessMessages(void);
  181. };
  182. #endif //DOOFUS_H
  183. ////////////////////////////////////////////////////////////////////////////////
  184. // EOF
  185. ////////////////////////////////////////////////////////////////////////////////