weapon.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. // weapon.h
  19. // Project: Postal
  20. //
  21. // History:
  22. //
  23. // 02/28/97 BRH Started this base class for weapons. Will change several
  24. // of the current weapons to derive from this base class.
  25. //
  26. // 03/03/97 BRH Added a few states from the Rocket and Napalm.
  27. //
  28. // 03/03/97 BRH Added 3d sprite to the weapon to make it more universal.
  29. // A weapon that is 2d or uses no sprite will be a special
  30. // case where it will add a 2d sprite to its derived class,
  31. // or ignore the sprite entirely.
  32. //
  33. // 03/13/97 JMI Load now takes a version number.
  34. //
  35. // 03/19/97 BRH Added virtual functions for processing messages and
  36. // virtual OnMessage handler functions so that it follows
  37. // the model of the CThing3d base class object.
  38. //
  39. // 04/29/97 JMI Removed the m_sprite (was a CSprite3) so we could instead
  40. // make this data part of the descended class. Since C++ does
  41. // not support virtual data, we had to replace the base class
  42. // m_sprite with a pure virtual GetSprite() that returns the
  43. // appropriate sprite for the class.
  44. //
  45. // 05/09/97 BRH Added SetRangeToTarget function to vary the velocity
  46. // of the weapon before it is shot in order to hit
  47. // your target.
  48. //
  49. // 06/25/97 BRH Added m_spriteShadow and PrepareShadow() for shadow
  50. // support for weapons.
  51. //
  52. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  53. //
  54. // 07/31/97 BRH Added remote control state.
  55. //
  56. // 08/14/97 BRH Added a virtual function SetCollideBits so that weapons
  57. // that use collision bits can overload it to set their
  58. // bit fields. Others that don't use it won't overload it
  59. // and the call will be ignored.
  60. //
  61. // 08/17/97 JMI Changed m_pthingParent to m_idParent.
  62. // Also, changed MineSndHalfLife to 150 (was 500).
  63. //
  64. // 08/24/97 BRH Added SetDetectionBits function like the SetCollideBits
  65. // which the heatseeker will override to set its bits.
  66. //
  67. ////////////////////////////////////////////////////////////////////////////////
  68. #ifndef WEAPON_H
  69. #define WEAPON_H
  70. #include "RSPiX.h"
  71. #include "realm.h"
  72. // CWeapon is the base class for the weapons
  73. class CWeapon : public CThing
  74. {
  75. //---------------------------------------------------------------------------
  76. // Types, enums, etc.
  77. //---------------------------------------------------------------------------
  78. public:
  79. typedef unsigned char CWeaponState;
  80. typedef enum
  81. {
  82. LaunchSndHalfLife = 1000,
  83. ExplosionSndHalfLife = 1000,
  84. SideEffectSndHalfLife = 1000, // Grenade bounce or similar.
  85. FireBombSndHalfLife = 1000,
  86. NapalmSndHalfLife = 1000,
  87. MineSndHalfLife = 80
  88. } Macros;
  89. typedef enum
  90. {
  91. State_Idle,
  92. State_Fire,
  93. State_Go,
  94. State_Roll,
  95. State_Explode,
  96. State_Slide,
  97. State_Hide,
  98. State_Chase,
  99. State_Find,
  100. State_Deleted,
  101. State_Armed,
  102. State_RemoteControl
  103. };
  104. //---------------------------------------------------------------------------
  105. // Variables
  106. //---------------------------------------------------------------------------
  107. public:
  108. double m_dX; // x coord
  109. double m_dY; // y coord
  110. double m_dZ; // z coord
  111. double m_dVertVel; // Vertical Velocity
  112. double m_dHorizVel; // Horizontal Velocity
  113. double m_dRot; // Rotation (in degrees, 0 to 359.999999)
  114. CWeaponState m_eState; // State variable for run routine
  115. U16 m_idParent; // Anyone can be this item's parent.
  116. // It'd probably be a good idea to make
  117. // sure this is NULL before setting it,
  118. // though.
  119. U16 m_u16ShooterID; // Instance ID of the shooter (so that credit
  120. // for a kill can be determined)
  121. CSprite2 m_spriteShadow; // 2D sprite for shadow on the ground
  122. protected:
  123. long m_lTimer; // Timer for explosion
  124. long m_lPrevTime; // Previous update time
  125. short m_sSuspend; // Suspend flag
  126. short m_sCurRadius; // Radius of the dude's current frame.
  127. // Tracks file counter so we know when to load/save "common" data
  128. static short ms_sFileCount;
  129. public:
  130. // "Constant" values that we want to be able to tune using the editor
  131. //---------------------------------------------------------------------------
  132. // Constructor(s) / destructor
  133. //---------------------------------------------------------------------------
  134. protected:
  135. // Constructor
  136. CWeapon(CRealm* pRealm, ClassIDType id)
  137. : CThing(pRealm, id)
  138. {
  139. m_sSuspend = 0;
  140. m_dX = m_dY = m_dZ = m_dRot = m_dVertVel = m_dHorizVel = 0.0;
  141. m_eState = State_Idle;
  142. m_idParent = CIdBank::IdNil;
  143. m_spriteShadow.m_sInFlags = CSprite::InHidden;
  144. m_spriteShadow.m_pImage = NULL;
  145. m_spriteShadow.m_pthing = this;
  146. m_lPrevTime = 0; // valgrind fix. --ryan.
  147. }
  148. public:
  149. // Destructor
  150. ~CWeapon()
  151. {
  152. // Remove sprite from scene (this is safe even if it was already removed!)
  153. m_pRealm->m_scene.RemoveSprite(&m_spriteShadow);
  154. // Release the shadow resource
  155. if (m_spriteShadow.m_pImage)
  156. rspReleaseResource(&g_resmgrGame, &(m_spriteShadow.m_pImage));
  157. }
  158. //---------------------------------------------------------------------------
  159. // Required static functions
  160. //---------------------------------------------------------------------------
  161. public:
  162. // Construct object
  163. static short Construct( // Returns 0 if successfull, non-zero otherwise
  164. CRealm* pRealm, // In: Pointer to realm this object belongs to
  165. CThing** ppNew) // Out: Pointer to new object
  166. {
  167. return 0;
  168. }
  169. //---------------------------------------------------------------------------
  170. // Required virtual functions (implimenting them as inlines doesn't pay!)
  171. //---------------------------------------------------------------------------
  172. public:
  173. // Load object (should call base class version!)
  174. virtual short Load( // Returns 0 if successfull, non-zero otherwise
  175. RFile* pFile, // In: File to load from
  176. bool bEditMode, // In: True for edit mode, false otherwise
  177. short sFileCount, // In: File count (unique per file, never 0)
  178. ULONG ulFileVersion); // In: Version of file format to load.
  179. // Save object (should call base class version!)
  180. virtual short Save( // Returns 0 if successfull, non-zero otherwise
  181. RFile* pFile, // In: File to save to
  182. short sFileCount); // In: File count (unique per file, never 0)
  183. // Setup object after creating it
  184. virtual short Setup(
  185. short sX, // In: Starting X position
  186. short sY, // In: Starting Y position
  187. short sZ); // In: Starting Z position
  188. // Startup object
  189. virtual short Startup(void); // Returns 0 if successfull, non-zero otherwise
  190. // Shutdown object
  191. virtual short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  192. // Suspend object
  193. virtual void Suspend(void);
  194. // Resume object
  195. virtual void Resume(void);
  196. // Update object
  197. virtual void Update(void);
  198. // Render object
  199. virtual void Render(void);
  200. // Called by editor to init new object at specified position
  201. virtual short EditNew( // Returns 0 if successfull, non-zero otherwise
  202. short sX, // In: New x coord
  203. short sY, // In: New y coord
  204. short sZ); // In: New z coord
  205. // Called by editor to modify object
  206. virtual short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  207. // Called by editor to move object to specified position
  208. virtual short EditMove( // Returns 0 if successfull, non-zero otherwise
  209. short sX, // In: New x coord
  210. short sY, // In: New y coord
  211. short sZ); // In: New z coord
  212. // Called by editor to update object
  213. virtual void EditUpdate(void);
  214. // Called by editor to render object
  215. virtual void EditRender(void);
  216. // Give Edit a rectangle around this object
  217. virtual void EditRect(RRect* pRect)
  218. {
  219. }
  220. // Get the coordinates of this thing.
  221. virtual // Overriden here.
  222. double GetX(void) { return m_dX; }
  223. virtual // Overriden here.
  224. double GetY(void) { return m_dY; }
  225. virtual // Overriden here.
  226. double GetZ(void) { return m_dZ; }
  227. virtual short GetResources(void);
  228. virtual short FreeResources(void);
  229. virtual double BounceAngle(double dAngle);
  230. // Function to modify the velocity for a requested range
  231. // Weapons that can modify their velocity to affect the
  232. // range can do the calculation and modify their horizontal
  233. // velocity. This default one does nothing
  234. virtual short SetRangeToTarget(short sRequestedRange)
  235. {
  236. return sRequestedRange;
  237. }
  238. // Get the descended class's sprite. Note that the type will vary.
  239. // This is a pure virtual function, making this an abstract
  240. // (i.e., uninstantiable) class.
  241. virtual // A descended class must define this virtual
  242. // in order to be instantiable.
  243. CSprite* GetSprite(void) = 0; // Returns this weapon's sprite.
  244. // Process all messages currently in the message queue through
  245. // ProcessMessage().
  246. virtual // Override to implement additional functionality.
  247. void ProcessMessages(void);
  248. // Process the specified message. For most messages, this function
  249. // will call the equivalent On* function.
  250. virtual // Override to implement additional functionality.
  251. void ProcessMessage( // Returns nothing.
  252. GameMessage* pmsg); // Message to process.
  253. // This function provides a way to set the collision bits for
  254. // a specific weapon, if that weapon uses collision bits. Rocket
  255. // and Heatseeker will override this to set their collision bits,
  256. // but others like the cocktail don't use collision bits so they
  257. // will just rely on this version of the function to throw out
  258. // the request to set the bits.
  259. virtual
  260. void SetCollideBits( // Returns nothing
  261. U32 u32BitsInclude, // Bits included in a collision
  262. U32 u32BitsDontCare, // Bits that are ignored for collision
  263. U32 u32BitsExclude) // Bits that invalidate collision
  264. {
  265. // The base class does nothing - override if you want to use it, but
  266. // you don't have to if your weapon doesn't have collide bits.
  267. }
  268. // This function provides a way to set the detection bits for
  269. // a specific weapon. If that weapon uses detection bits, it
  270. // can override this function, otherwise the bits will be ignored
  271. virtual
  272. void SetDetectionBits( // Returns nothing
  273. U32 u32BitsInclude, // Bits included in a collision
  274. U32 u32BitsDontcare, // Bits that are ignored for collision
  275. U32 u32BitsExclude) // Bits that invalidate collision
  276. {
  277. // The base class does nothing - override if you want to use it, but
  278. // you don't have to if your weapon doesn't have detect bits
  279. }
  280. // Message handling functions ////////////////////////////////////////////
  281. // Handles a Shot_Message.
  282. virtual // Override to implement additional functionality.
  283. // Call base class to get default functionality.
  284. void OnShotMsg( // Returns nothing.
  285. Shot_Message* pshotmsg); // In: Message to handle.
  286. // Handles an Explosion_Message.
  287. virtual // Override to implement additional functionality.
  288. // Call base class to get default functionality.
  289. void OnExplosionMsg( // Returns nothing.
  290. Explosion_Message* pexplosionmsg); // In: Message to handle.
  291. // Handles a Burn_Message.
  292. virtual // Override to implement additional functionality.
  293. // Call base class to get default functionality.
  294. void OnBurnMsg( // Returns nothing.
  295. Burn_Message* pburnmsg); // In: Message to handle.
  296. // Handles an ObjectDelete_Message.
  297. virtual // Override to implement additional functionality.
  298. // Call base class to get default functionality.
  299. void OnDeleteMsg( // Returns nothing.
  300. ObjectDelete_Message* pdeletemsg); // In: Message to handle.
  301. // Handles Trigger_Message
  302. virtual // Overrride to implement additional functionality
  303. // Call base class to get default functionality.
  304. void OnTriggerMsg( // Returns nothing.
  305. Trigger_Message* ptriggermsg); // In: Message to handle
  306. // Load the default shadow resource unless one has already been loaded
  307. // and set the shadow to visible
  308. virtual // Override to implement additional functionality
  309. // Call base class to get default functionality
  310. short PrepareShadow(void); // Returns SUCCESS if set successfully
  311. //---------------------------------------------------------------------------
  312. // Internal functions
  313. //---------------------------------------------------------------------------
  314. protected:
  315. };
  316. #endif //WEAPON_H
  317. ////////////////////////////////////////////////////////////////////////////////
  318. // EOF
  319. ////////////////////////////////////////////////////////////////////////////////