barrel.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. // barrel.h
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 03/14/97 BRH Started this exploding barrel object from the napalm
  23. // object.
  24. //
  25. // 03/17/97 BRH Restarted this object based on the new CThing3D base
  26. // class which will make it easier to do the motion for
  27. // explosions and other message processing.
  28. //
  29. // 04/02/97 JMI Removed initialization of m_pFire.
  30. //
  31. // 04/04/97 JMI Added barrel spin animation which has the origin at the
  32. // barrel's center of gravity for better spinning.
  33. //
  34. // 06/11/97 BRH Added m_u16ShooterID so it can pass along the information
  35. // for scoring purposes.
  36. //
  37. // 06/25/97 BRH Added shadow sprite and alpha animation for the shadow
  38. // along the ground to see how it looks. If it looks good,
  39. // then it will probably be moved further up into CThing3D.
  40. //
  41. // 08/15/97 BRH Added a special barrel flag so that this type of
  42. // barrel can only be destroyed by the CDude. Added an
  43. // EditModify dialog to set the option and added it to
  44. // the load and save.
  45. //
  46. ////////////////////////////////////////////////////////////////////////////////
  47. #ifndef BARREL_H
  48. #define BARREL_H
  49. #include "RSPiX.h"
  50. #include "Thing3d.h"
  51. #include "realm.h"
  52. #include "grenade.h"
  53. #include "firebomb.h"
  54. #include "doofus.h"
  55. #include "AlphaAnimType.h"
  56. // CBarrel is an exploding barrel that can react to explosions, fire and shots
  57. class CBarrel : public CThing3d
  58. {
  59. //---------------------------------------------------------------------------
  60. // Types, enums, etc.
  61. //---------------------------------------------------------------------------
  62. protected:
  63. typedef RChannel<CAlphaAnim> ChannelAA;
  64. //---------------------------------------------------------------------------
  65. // Variables
  66. //---------------------------------------------------------------------------
  67. public:
  68. U16 m_u16ShooterID; // Variable for storing the shooter ID
  69. // to pass along in the messages.
  70. protected:
  71. CCharacter::State m_ePreviousState; // State variable to remember where he was
  72. CAnim3D m_animStill; // Barrel still animation
  73. CAnim3D m_animSpin; // Barrel still but rotatable around center of gravity.
  74. CAnim3D* m_pPreviousAnim; // Previous state's animation
  75. short m_sSphereRadius; // Radius of the grenader's current frame
  76. short m_sSphereX; // Location of the grenader's sphere center
  77. short m_sSphereY; // Location of the grenader's sphere center
  78. short m_sScreenRadius; // Object's radius
  79. bool m_bSpecial; // Special dude-destroy-only barrel;
  80. // Tracks file counter so we know when to load/save "common" data
  81. static short ms_sFileCount;
  82. // "Constant" values that we want to be able to tune using the editor
  83. static long ms_lExplosionWait; // Amount of time to wait before staring fire
  84. static long ms_lExplosionDelay; // Time before explosion triggers another.
  85. static short ms_sNumFires; // Number of fires to create after explosion
  86. //---------------------------------------------------------------------------
  87. // Constructor(s) / destructor
  88. //---------------------------------------------------------------------------
  89. protected:
  90. // Constructor
  91. CBarrel(CRealm* pRealm)
  92. : CThing3d(pRealm, CBarrelID)
  93. {
  94. m_sSuspend = 0;
  95. m_dRot = 0;
  96. m_dX = m_dY = m_dZ = m_dVel = m_dAcc = 0;
  97. m_sScreenRadius = 20;
  98. m_panimCur = m_pPreviousAnim = NULL;
  99. m_sprite.m_pthing = this;
  100. m_bSpecial = false;
  101. }
  102. public:
  103. // Destructor
  104. ~CBarrel()
  105. {
  106. // Remove sprite from scene (this is safe even if it was already removed!)
  107. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  108. m_pRealm->m_scene.RemoveSprite(&m_spriteShadow);
  109. m_pRealm->m_smashatorium.Remove(&m_smash);
  110. // Free resources
  111. FreeResources();
  112. }
  113. //---------------------------------------------------------------------------
  114. // Required static functions
  115. //---------------------------------------------------------------------------
  116. public:
  117. // Construct object
  118. static short Construct( // Returns 0 if successfull, non-zero otherwise
  119. CRealm* pRealm, // In: Pointer to realm this object belongs to
  120. CThing** ppNew) // Out: Pointer to new object
  121. {
  122. short sResult = 0;
  123. *ppNew = new CBarrel(pRealm);
  124. if (*ppNew == 0)
  125. {
  126. sResult = -1;
  127. TRACE("CBarrel::Construct(): Couldn't construct CBarrel (that's a bad thing)\n");
  128. }
  129. return sResult;
  130. }
  131. //---------------------------------------------------------------------------
  132. // Required virtual functions (implimenting them as inlines doesn't pay!)
  133. //---------------------------------------------------------------------------
  134. public:
  135. // Load object (should call base class version!)
  136. short Load( // Returns 0 if successfull, non-zero otherwise
  137. RFile* pFile, // In: File to load from
  138. bool bEditMode, // In: True for edit mode, false otherwise
  139. short sFileCount, // In: File count (unique per file, never 0)
  140. ULONG ulFileVersion); // In: Version of file format to load.
  141. // Save object (should call base class version!)
  142. short Save( // Returns 0 if successfull, non-zero otherwise
  143. RFile* pFile, // In: File to save to
  144. short sFileCount); // In: File count (unique per file, never 0)
  145. // Startup object
  146. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  147. // Shutdown object
  148. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  149. // Suspend object
  150. void Suspend(void);
  151. // Resume object
  152. void Resume(void);
  153. // Update object
  154. void Update(void);
  155. // Find angle to a CDude
  156. short FindDirection(void);
  157. // Find the squared distance to the CDude (to avoid sqrt)
  158. double SQDistanceToDude(void);
  159. // Set a pointer to the guy you are tracking for other guy related
  160. // functions like FindDirection and SQDistanceToGuy
  161. short SelectDude(void);
  162. // Called by editor to init new object at specified position
  163. short EditNew( // Returns 0 if successfull, non-zero otherwise
  164. short sX, // In: New x coord
  165. short sY, // In: New y coord
  166. short sZ); // In: New z coord
  167. // Called by editor to modify object
  168. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  169. //---------------------------------------------------------------------------
  170. // Internal functions
  171. //---------------------------------------------------------------------------
  172. protected:
  173. // Get all required resources
  174. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  175. // Free all resources
  176. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  177. // Initialize states, positions etc.
  178. short Init(void);
  179. // Message handling functions ////////////////////////////////////////////
  180. // Handles a Shot_Message.
  181. virtual // Override to implement additional functionality.
  182. // Call base class to get default functionality.
  183. void OnShotMsg( // Returns nothing.
  184. Shot_Message* pshotmsg); // In: Message to handle.
  185. // Handles an Explosion_Message.
  186. virtual // Override to implement additional functionality.
  187. // Call base class to get default functionality.
  188. void OnExplosionMsg( // Returns nothing.
  189. Explosion_Message* pexplosionmsg); // In: Message to handle.
  190. // Handles a Burn_Message.
  191. virtual // Override to implement additional functionality.
  192. // Call base class to get default functionality.
  193. void OnBurnMsg( // Returns nothing.
  194. Burn_Message* pburnmsg); // In: Message to handle.
  195. // Handles an ObjectDelete_Message.
  196. virtual // Override to implement additional functionality.
  197. // Call base class to get default functionality.
  198. void OnDeleteMsg( // Returns nothing.
  199. ObjectDelete_Message* pdeletemsg); // In: Message to handle.
  200. };
  201. #endif //GRENADER_H
  202. ////////////////////////////////////////////////////////////////////////////////
  203. // EOF
  204. ////////////////////////////////////////////////////////////////////////////////