sentry.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. // sentry.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 06/02/97 BRH Created this sentry gun from gunner.h
  23. //
  24. // 06/30/97 JMI Added override for EditRect() and EditHotSpot().
  25. // Also, added UpdatePosition().
  26. //
  27. // 07/01/97 BRH Added angular velocity for Sentry gun.
  28. //
  29. // 08/11/97 JMI Added transform for base, m_transBase.
  30. // Also, added initialization of m_panimCurBase to NULL.
  31. //
  32. // 08/16/97 BRH Added weapon bits to pass to ShootWeapon.
  33. //
  34. ////////////////////////////////////////////////////////////////////////////////
  35. #ifndef SENTRY_H
  36. #define SENTRY_H
  37. #include "RSPiX.h"
  38. #include "realm.h"
  39. #include "doofus.h"
  40. // CSentry is the class for the enemy guys
  41. class CSentry : public CDoofus
  42. {
  43. //---------------------------------------------------------------------------
  44. // Types, enums, etc.
  45. //---------------------------------------------------------------------------
  46. protected:
  47. //---------------------------------------------------------------------------
  48. // Variables
  49. //---------------------------------------------------------------------------
  50. public:
  51. CSprite3 m_spriteBase; // Base of gun that is stationary
  52. CAnim3D* m_panimCurBase; // current animation for the base
  53. double m_dXBase; // Position of base
  54. double m_dYBase; // Position of base
  55. double m_dZBase; // Position of base
  56. RTransform m_transBase; // Base's rotation/scaling/translation.
  57. protected:
  58. CAnim3D m_animBaseStand; // animation for the base of the gun
  59. CAnim3D m_animBaseDie; // animation for the base of the gun
  60. CBulletFest m_bullets; // Generic bullet interface.
  61. long m_lLastBulletTime; // Last time a bullet was fired.
  62. short m_sNumRounds; // Number of rounds remaining in the gun
  63. short m_sRoundsPerShot; // How many bullets does it fire at once
  64. long m_lSqDistRange; // Range in pixels squared.
  65. long m_lShootDelay; // Time to wait between shots
  66. double m_dAngularVelocity; // Amount it can turn in degrees/second
  67. // Tracks file counter so we know when to load/save "common" data
  68. static short ms_sFileCount;
  69. // "Constant" values that we want to be able to tune using the editor
  70. static double ms_dTooCloseDistance; // Close enough to hit CDude
  71. static double ms_dLongRange; // Out of range to notice or care
  72. static double ms_dInRangeLow; // Within weapon range
  73. static double ms_dInRangeHigh; // within weapon range
  74. static double ms_dGravity; // Gravity for falling
  75. static double ms_dBlowupVelocity; // Initial blast velocity
  76. static long ms_lRandomAvoidTime; // Time to wander before looking again
  77. static long ms_lReseekTime; // Time to wait before doing the next 'find'
  78. static long ms_lWatchWaitTime; // Watch your shot go
  79. static long ms_lPatrolTime; // Wait this long before shooting
  80. static long ms_lDeathTimeout; // Wait around after dying
  81. static long ms_lBurningRunTime; // Run this time before turning
  82. static short ms_sHitLimit; // Number of starting hit points
  83. static short ms_sBurntBrightness; // Brightness level when burnt
  84. static long ms_lMaxShootTime; // Maximum in ms of continuous shooting.
  85. static long ms_lReselectDudeTime; // Time before looking for a closer dude.
  86. static U32 ms_u32WeaponIncludeBits; // Weapons shot from sentry can hit this
  87. static U32 ms_u32WeaponDontcareBits;// Weapons shot from sentry ignore these bits
  88. static U32 ms_u32WeaponExcludeBits; // Weapons shot from sentry do not hit this
  89. //---------------------------------------------------------------------------
  90. // Constructor(s) / destructor
  91. //---------------------------------------------------------------------------
  92. protected:
  93. // Constructor
  94. CSentry(CRealm* pRealm)
  95. : CDoofus(pRealm, CSentryID)
  96. {
  97. m_sSuspend = 0;
  98. m_dRot = 0;
  99. m_dX = m_dY = m_dZ = m_dVel = m_dAcc = 0;
  100. m_panimCur = m_panimPrev = NULL;
  101. m_panimCurBase = NULL;
  102. m_sprite.m_pthing = this;
  103. m_sNumRounds = 0;
  104. m_sRoundsPerShot = 0;
  105. m_lSqDistRange = 0;
  106. m_lShootDelay = 0;
  107. m_dAngularVelocity = 360.0;
  108. }
  109. public:
  110. // Destructor
  111. ~CSentry()
  112. {
  113. // Remove sprite from scene (this is safe even if it was already removed!)
  114. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  115. m_pRealm->m_scene.RemoveSprite(&m_spriteBase);
  116. m_pRealm->m_smashatorium.Remove(&m_smash);
  117. // Free resources
  118. FreeResources();
  119. }
  120. //---------------------------------------------------------------------------
  121. // Required static functions
  122. //---------------------------------------------------------------------------
  123. public:
  124. // Construct object
  125. static short Construct( // Returns 0 if successfull, non-zero otherwise
  126. CRealm* pRealm, // In: Pointer to realm this object belongs to
  127. CThing** ppNew) // Out: Pointer to new object
  128. {
  129. short sResult = 0;
  130. *ppNew = new CSentry(pRealm);
  131. if (*ppNew == 0)
  132. {
  133. sResult = -1;
  134. TRACE("CSentry::Construct(): Couldn't construct CSentry (that's a bad thing)\n");
  135. }
  136. return sResult;
  137. }
  138. //---------------------------------------------------------------------------
  139. // Required virtual functions (implimenting them as inlines doesn't pay!)
  140. //---------------------------------------------------------------------------
  141. public:
  142. // Load object (should call base class version!)
  143. short Load( // Returns 0 if successfull, non-zero otherwise
  144. RFile* pFile, // In: File to load from
  145. bool bEditMode, // In: True for edit mode, false otherwise
  146. short sFileCount, // In: File count (unique per file, never 0)
  147. ULONG ulFileVersion); // In: Version of file format to load.
  148. // Save object (should call base class version!)
  149. short Save( // Returns 0 if successfull, non-zero otherwise
  150. RFile* pFile, // In: File to save to
  151. short sFileCount); // In: File count (unique per file, never 0)
  152. // Startup object
  153. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  154. // Shutdown object
  155. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  156. // Suspend object
  157. void Suspend(void);
  158. // Resume object
  159. void Resume(void);
  160. // Render override
  161. void Render(void);
  162. // Update object
  163. void Update(void);
  164. // Find angle to a CDude
  165. short FindDirection(void);
  166. // Find the squared distance to the CDude (to avoid sqrt)
  167. double SQDistanceToDude(void);
  168. // Called by editor to init new object at specified position
  169. short EditNew( // Returns 0 if successfull, non-zero otherwise
  170. short sX, // In: New x coord
  171. short sY, // In: New y coord
  172. short sZ); // In: New z coord
  173. // Called by editor to modify object
  174. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  175. // Called by editor to move object to specified position
  176. short EditMove( // Returns 0 if successfull, non-zero otherwise
  177. short sX, // In: New x coord
  178. short sY, // In: New y coord
  179. short sZ); // In: New z coord
  180. // Give Edit a rectangle around this object
  181. void EditRect(RRect* pRect);
  182. // Called by editor to get the hotspot of an object in 2D.
  183. // (virtual (Overridden here)).
  184. void EditHotSpot( // Returns nothiing.
  185. short* psX, // Out: X coord of 2D hotspot relative to
  186. // EditRect() pos.
  187. short* psY); // Out: Y coord of 2D hotspot relative to
  188. // EditRect() pos.
  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. // Initialize states, positions etc.
  198. short Init(void);
  199. // Update the animation radius based on the current frame
  200. void UpdateRadius(void);
  201. // Position the base and turret based on m_dX, Y, & Z.
  202. void UpdatePosition(void);
  203. // Message handling functions ////////////////////////////////////////////
  204. // Handles a Shot_Message.
  205. virtual // Override to implement additional functionality.
  206. // Call base class to get default functionality.
  207. void OnShotMsg( // Returns nothing.
  208. Shot_Message* pshotmsg); // In: Message to handle.
  209. // Handles an Explosion_Message.
  210. virtual // Override to implement additional functionality.
  211. // Call base class to get default functionality.
  212. void OnExplosionMsg( // Returns nothing.
  213. Explosion_Message* pexplosionmsg); // In: Message to handle.
  214. // Handles a Burn_Message.
  215. virtual // Override to implement additional functionality.
  216. // Call base class to get default functionality.
  217. void OnBurnMsg( // Returns nothing.
  218. Burn_Message* pburnmsg); // In: Message to handle.
  219. };
  220. #endif //SENTRY_H
  221. ////////////////////////////////////////////////////////////////////////////////
  222. // EOF
  223. ////////////////////////////////////////////////////////////////////////////////