mine.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. // mine.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 03/19/97 BRH Started this weapon object.
  23. //
  24. // 04/29/97 JMI Added GetSprite() virtual override to provide access
  25. // to m_sprite from a lower level.
  26. // Replaced Setup() with default parm eType = Proximity with
  27. // a Setup() that matches the base class virtual Setup() to
  28. // make sure it gets overriden. The functionality is the
  29. // same (the new Setup() just calls the four parm Setup()
  30. // with Proximity as the type).
  31. //
  32. // 04/30/97 JMI Changed the Setup() override of the CWeapon's Setup() to
  33. // pass the current mine type to the Setup() with eType.
  34. // Changed Construct() to take an ID as a parameter and added
  35. // ConstructProximity(), ConstructTimed(),
  36. // ConstructBouncingBetty(), and ConstructRemoteControl() to
  37. // allocate that type of mine.
  38. // Removed m_eMineType (now uses Class ID instead).
  39. // Removed Setup() that took an eType.
  40. // Fixed EditRect() and added EditHotSpot().
  41. //
  42. // 06/12/97 BRH Initialized the Shooter ID to IdNil for mines that
  43. // are placed in the level, and not placed by a CDude.
  44. //
  45. // 06/27/97 JMI Modified EditRect() to use Map3Dto2D().
  46. //
  47. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  48. // as a parameter.
  49. //
  50. // 07/21/97 JMI Now handles delete messages.
  51. //
  52. // 08/16/97 BRH Added a sound handle so that we could have a looping
  53. // arming sound that could be stopped when the mine was
  54. // armed.
  55. //
  56. // 08/17/97 JMI Destructor now stops looping the arming sound, if it is
  57. // still running.
  58. //
  59. // 08/28/97 BRH Added preload function to load the sounds and images.
  60. //
  61. ////////////////////////////////////////////////////////////////////////////////
  62. #ifndef MINE_H
  63. #define MINE_H
  64. #include "RSPiX.h"
  65. #include "realm.h"
  66. #include "weapon.h"
  67. #include "bulletFest.h"
  68. // CMine is an unguided missile weapon class
  69. class CMine : public CWeapon
  70. {
  71. //---------------------------------------------------------------------------
  72. // Types, enums, etc.
  73. //---------------------------------------------------------------------------
  74. public:
  75. typedef unsigned char MineType;
  76. typedef enum
  77. {
  78. ProximityMine = 3,
  79. TimedMine,
  80. BouncingBettyMine,
  81. RemoteControlMine,
  82. NumMineTypes
  83. };
  84. //---------------------------------------------------------------------------
  85. // Variables
  86. //---------------------------------------------------------------------------
  87. public:
  88. protected:
  89. short m_sPrevHeight; // Previous height
  90. RImage* m_pImage; // Pointer to mine image
  91. CSprite2 m_sprite; // Sprite for 2D mine
  92. CSmash m_smash; // Collision object
  93. CBulletFest m_bulletfest; // Used for bouncing betty
  94. double m_dVertVel; // Vertical velocity
  95. double m_dVertDeltaVel; // Change in vertical velocity
  96. long m_lFuseTime; // Time before timed mine goes off
  97. SampleMaster::SoundInstance m_siMineBeep;// Arming beep sound that loops
  98. // Tracks file counter so we know when to load/save "common" data
  99. static short ms_sFileCount;
  100. public:
  101. // "Constant" values that we want to be able to tune using the editor
  102. static short ms_sProximityRadius; // Distance at which mine goes off
  103. static short ms_sBettyRadius; // Distance at which mine goes off
  104. static short ms_sBettyRange; // Affected area for Bouncing Betty
  105. static long ms_lFuseTime; // Timed mine explodes after this time
  106. static long ms_lArmingTime; // Proximity mines arm after this time
  107. static long ms_lExplosionDelay; // Delay before explosion triggers mine
  108. static double ms_dInitialBounceVelocity;//Bouncing Betty popup velocity
  109. //---------------------------------------------------------------------------
  110. // Constructor(s) / destructor
  111. //---------------------------------------------------------------------------
  112. protected:
  113. // Constructor
  114. CMine(CRealm* pRealm)
  115. : CWeapon(pRealm, CProximityMineID)
  116. {
  117. Reset();
  118. }
  119. // Constructor
  120. CMine(CRealm* pRealm, ClassIDType id)
  121. : CWeapon(pRealm, id)
  122. {
  123. Reset();
  124. }
  125. public:
  126. // Destructor
  127. ~CMine()
  128. {
  129. // Stop sound, if any.
  130. StopLoopingSample(m_siMineBeep);
  131. // Remove sprite from scene (this is safe even if it was already removed!)
  132. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  133. m_pRealm->m_smashatorium.Remove(&m_smash);
  134. // Free resources
  135. FreeResources();
  136. }
  137. //---------------------------------------------------------------------------
  138. // Required static functions
  139. //---------------------------------------------------------------------------
  140. public:
  141. // Construct mine object.
  142. static short Construct( // Returns 0 if successfull, non-zero otherwise
  143. CRealm* pRealm, // In: Pointer to realm this object belongs to
  144. CThing** ppNew, // Out: Pointer to new object
  145. ClassIDType id) // In: ID of mine to construct.
  146. {
  147. short sResult = 0;
  148. *ppNew = new CMine(pRealm, id);
  149. if (*ppNew == 0)
  150. {
  151. sResult = -1;
  152. TRACE("CMine::Construct(): Couldn't construct CMine (that's a bad thing)\n");
  153. }
  154. return sResult;
  155. }
  156. // Construct proximity mine object.
  157. static short ConstructProximity( // Returns 0 if successfull, non-zero otherwise
  158. CRealm* pRealm, // In: Pointer to realm this object belongs to
  159. CThing** ppNew) // Out: Pointer to new object
  160. {
  161. return Construct(pRealm, ppNew, CProximityMineID);
  162. }
  163. // Construct timed mine object.
  164. static short ConstructTimed( // Returns 0 if successfull, non-zero otherwise
  165. CRealm* pRealm, // In: Pointer to realm this object belongs to
  166. CThing** ppNew) // Out: Pointer to new object
  167. {
  168. return Construct(pRealm, ppNew, CTimedMineID);
  169. }
  170. // Construct bouncing betty mine object.
  171. static short ConstructBouncingBetty( // Returns 0 if successfull, non-zero otherwise
  172. CRealm* pRealm, // In: Pointer to realm this object belongs to
  173. CThing** ppNew) // Out: Pointer to new object
  174. {
  175. return Construct(pRealm, ppNew, CBouncingBettyMineID);
  176. }
  177. // Construct remote control mine object.
  178. static short ConstructRemoteControl( // Returns 0 if successfull, non-zero otherwise
  179. CRealm* pRealm, // In: Pointer to realm this object belongs to
  180. CThing** ppNew) // Out: Pointer to new object
  181. {
  182. return Construct(pRealm, ppNew, CRemoteControlMineID);
  183. }
  184. //---------------------------------------------------------------------------
  185. // Internal functions
  186. //---------------------------------------------------------------------------
  187. public:
  188. // Resets members.
  189. void Reset(void)
  190. {
  191. m_pImage = NULL;
  192. m_sprite.m_pthing = this;
  193. m_lFuseTime = 0;
  194. m_u16ShooterID = CIdBank::IdNil;
  195. m_siMineBeep = 0;
  196. }
  197. // Called after load to start the object
  198. short Startup(void);
  199. // Init - common initialization code for startup, setup & edit new
  200. short Init(void);
  201. // Puts up a dialog box in the editor to select mine type
  202. short EditModify(void);
  203. // Sets up new item in the editor
  204. short EditNew(short sX, short sY, short sZ);
  205. void EditRect(RRect* pRect)
  206. {
  207. if (m_pImage)
  208. {
  209. // Map from 3d to 2d coords
  210. Map3Dto2D(
  211. (short) m_dX,
  212. (short) m_dY,
  213. (short) m_dZ,
  214. &(pRect->sX),
  215. &(pRect->sY) );
  216. // Center on image.
  217. pRect->sX -= m_pImage->m_sWidth / 2;
  218. pRect->sY -= m_pImage->m_sHeight / 2;
  219. pRect->sW = m_pImage->m_sWidth;
  220. pRect->sH = m_pImage->m_sHeight;
  221. }
  222. }
  223. void EditHotSpot( // Returns nothiing.
  224. short* psX, // Out: X coord of 2D hotspot relative to
  225. // EditRect() pos.
  226. short* psY) // Out: Y coord of 2D hotspot relative to
  227. // EditRect() pos.
  228. {
  229. if (m_pImage)
  230. {
  231. *psX = m_pImage->m_sWidth / 2;
  232. *psY = m_pImage->m_sHeight / 2;
  233. }
  234. else
  235. {
  236. CWeapon::EditHotSpot(psX, psY);
  237. }
  238. }
  239. //---------------------------------------------------------------------------
  240. // Optional static functions
  241. //---------------------------------------------------------------------------
  242. // Called before play begins to cache resources for this object.
  243. static short Preload(
  244. CRealm* prealm); // In: Calling realm.
  245. //---------------------------------------------------------------------------
  246. // Required virtual functions (implimenting them as inlines doesn't pay!)
  247. //---------------------------------------------------------------------------
  248. public:
  249. // Load object (should call base class version!)
  250. short Load( // Returns 0 if successfull, non-zero otherwise
  251. RFile* pFile, // In: File to load from
  252. bool bEditMode, // In: True for edit mode, false otherwise
  253. short sFileCount, // In: File count (unique per file, never 0)
  254. ULONG ulFileVersion); // In: Version of file format to load.
  255. // Save object (should call base class version!)
  256. short Save( // Returns 0 if successfull, non-zero otherwise
  257. RFile* pFile, // In: File to save to
  258. short sFileCount); // In: File count (unique per file, never 0)
  259. // Update object
  260. void Update(void);
  261. // Render object
  262. void Render(void);
  263. // Called by the object that is creating this weapon - this
  264. // overloaded version is for timed mines so that the fuse time
  265. // can be set
  266. short Setup(
  267. short sX, // In: New x coord
  268. short sY, // In: New y coord
  269. short sZ, // In: New z coord
  270. long lFuseTime); // In: Time in ms for fuse
  271. // Override base class Setup().
  272. virtual // Overridden here.
  273. short Setup(
  274. short sX, // In: Starting X position
  275. short sY, // In: Starting Y position
  276. short sZ); // In: Starting Z position
  277. // Get this class's sprite. Note that the type will vary.
  278. // This is a pure virtual functionin the base class.
  279. virtual // Overriden here.
  280. CSprite* GetSprite(void) // Returns this weapon's sprite.
  281. {
  282. return &m_sprite;
  283. }
  284. //---------------------------------------------------------------------------
  285. // Internal functions
  286. //---------------------------------------------------------------------------
  287. protected:
  288. // Get all required resources
  289. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  290. // Free all resources
  291. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  292. // Handle Explosion message
  293. void OnExplosionMsg(Explosion_Message* pMessage);
  294. // Handle Trigger message (for remote trigger mines)
  295. void OnTriggerMsg(Trigger_Message* pMessage);
  296. // Handles an ObjectDelete_Message.
  297. void OnDeleteMsg( // Returns nothing.
  298. ObjectDelete_Message* pdeletemsg); // In: Message to handle.
  299. };
  300. #endif // MINE_H
  301. ////////////////////////////////////////////////////////////////////////////////
  302. // EOF
  303. ////////////////////////////////////////////////////////////////////////////////