warp.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. // Warp.H
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 06/02/97 JMI Started.
  23. //
  24. // 06/07/97 JMI Added warp in options enum.
  25. // Also, constructor now initializes static ms_stockpile
  26. // to CDude defaults, if it has not yet been done.
  27. // Also, added CreateWarpFromDude().
  28. //
  29. // 06/15/97 JMI Moved initialization of ms_stockpile into warp.cpp since
  30. // the stockpile is non aggregatable.
  31. //
  32. // 07/19/97 JMI Added m_sRotY, the dude's initial rotation around the Y
  33. // axis.
  34. //
  35. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  36. //
  37. //////////////////////////////////////////////////////////////////////////////
  38. //
  39. // This CThing-derived class will represent places and settings for dudes to
  40. // 'warp' in at/with.
  41. //
  42. //////////////////////////////////////////////////////////////////////////////
  43. #ifndef WARP_H
  44. #define WARP_H
  45. #include "RSPiX.h"
  46. #include "realm.h"
  47. #include "StockPile.h"
  48. #include "dude.h"
  49. class CWarp : public CThing
  50. {
  51. //---------------------------------------------------------------------------
  52. // Types, enums, etc.
  53. //---------------------------------------------------------------------------
  54. public:
  55. enum // Warp options.
  56. {
  57. None = 0x0000,
  58. // Only one of these options may be specified per WarpIn*().
  59. CopyStockPile = 0x0001, // Copy warp stockpile to Dude's.
  60. UnionStockPile = 0x0002, // Union warp stockpile with Dude's.
  61. AddStockPile = 0x0003, // Add stockpile to dude.
  62. // Mask for stockpile options.
  63. StockPileMask = 0x000F
  64. // These options can be combined per WarpIn*() call.
  65. };
  66. //---------------------------------------------------------------------------
  67. // Variables
  68. //---------------------------------------------------------------------------
  69. public:
  70. double m_dX; // Dude's initial position.
  71. double m_dY; // Dude's initial position.
  72. double m_dZ; // Dude's initial position.
  73. short m_sRotY; // Dude's initial rotation
  74. // around the Y axis.
  75. short m_sSuspend; // Suspend flag
  76. CSprite2 m_sprite; // Sprite.
  77. protected:
  78. //---------------------------------------------------------------------------
  79. // Static Variables
  80. //---------------------------------------------------------------------------
  81. public:
  82. // The stockpile of ammo and health used by all CWarps.
  83. static CStockPile ms_stockpile;
  84. // Tracks file counter so we know when to load/save "common" data
  85. static short ms_sFileCount;
  86. //---------------------------------------------------------------------------
  87. // Constructor(s) / destructor
  88. //---------------------------------------------------------------------------
  89. public:
  90. // Constructor
  91. CWarp(CRealm* pRealm)
  92. : CThing(pRealm, CWarpID)
  93. {
  94. m_sSuspend = 0;
  95. m_sRotY = 0;
  96. m_sprite.m_pthing = this;
  97. }
  98. public:
  99. // Destructor
  100. ~CWarp()
  101. {
  102. // Remove sprite from scene (this is safe even if it was already removed!)
  103. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  104. // Free resources
  105. FreeResources();
  106. }
  107. //---------------------------------------------------------------------------
  108. // Required static functions
  109. //---------------------------------------------------------------------------
  110. public:
  111. // Construct object
  112. static short Construct( // Returns 0 if successfull, non-zero otherwise
  113. CRealm* pRealm, // In: Pointer to realm this object belongs to
  114. CThing** ppNew) // Out: Pointer to new object
  115. {
  116. short sResult = 0;
  117. *ppNew = new CWarp(pRealm);
  118. if (*ppNew == 0)
  119. {
  120. sResult = -1;
  121. TRACE("CWarp::Construct(): Couldn't construct CWarp (that's a bad thing)\n");
  122. }
  123. return sResult;
  124. }
  125. //---------------------------------------------------------------------------
  126. // Required virtual functions (implementing them as inlines doesn't pay!)
  127. //---------------------------------------------------------------------------
  128. public:
  129. // Load object (should call base class version!)
  130. short Load( // Returns 0 if successfull, non-zero otherwise
  131. RFile* pFile, // In: File to load from
  132. bool bEditMode, // In: True for edit mode, false otherwise
  133. short sFileCount, // In: File count (unique per file, never 0)
  134. ULONG ulFileVersion); // In: Version of file format to load.
  135. // Save object (should call base class version!)
  136. short Save( // Returns 0 if successfull, non-zero otherwise
  137. RFile* pFile, // In: File to save to
  138. short sFileCount); // In: File count (unique per file, never 0)
  139. // Startup object
  140. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  141. // Shutdown object
  142. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  143. // Suspend object
  144. void Suspend(void);
  145. // Resume object
  146. void Resume(void);
  147. // Update object
  148. void Update(void);
  149. // Render object
  150. void Render(void);
  151. // Called by editor to init new object at specified position
  152. short EditNew( // Returns 0 if successfull, non-zero otherwise
  153. short sX, // In: New x coord
  154. short sY, // In: New y coord
  155. short sZ); // In: New z coord
  156. // Called by editor to modify object
  157. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  158. // Called by editor to move object to specified position
  159. short EditMove( // Returns 0 if successfull, non-zero otherwise
  160. short sX, // In: New x coord
  161. short sY, // In: New y coord
  162. short sZ); // In: New z coord
  163. // Called by editor to get the clickable pos/area of an object in 2D.
  164. virtual // Overridden here.
  165. void EditRect( // Returns nothing.
  166. RRect* prc); // Out: Clickable pos/area of object.
  167. // Called by editor to get the hotspot of an object in 2D.
  168. virtual // Overridden here.
  169. void EditHotSpot( // Returns nothiing.
  170. short* psX, // Out: X coord of 2D hotspot relative to
  171. // EditRect() pos.
  172. short* psY); // Out: Y coord of 2D hotspot relative to
  173. // EditRect() pos.
  174. // Called by editor to update object
  175. void EditUpdate(void);
  176. // Called by editor to render object
  177. void EditRender(void);
  178. // Get the coordinates of this thing.
  179. virtual // Overriden here.
  180. double GetX(void) { return m_dX; }
  181. virtual // Overriden here.
  182. double GetY(void) { return m_dY; }
  183. virtual // Overriden here.
  184. double GetZ(void) { return m_dZ; }
  185. //---------------------------------------------------------------------------
  186. // Handy external functions
  187. //---------------------------------------------------------------------------
  188. public:
  189. // Stocks, rejuvenates, and places a CDude. The dude can be passed to this
  190. // function or allocated by this function.
  191. short WarpIn( // Returns 0 on success.
  192. CDude** ppdude, // In: CDude to 'warp in', *ppdude = NULL to create one.
  193. // Out: Newly created CDude, if no CDude passed in.
  194. short sOptions); // In: Options for 'warp in'.
  195. // Stocks, rejuvenates, and places a CDude at a random warp. The dude can
  196. // be passed to this function or allocated by this function.
  197. static short WarpInAnywhere( // Returns 0 on success.
  198. CRealm* prealm, // In: Realm in which to choose CWarp.
  199. CDude** ppdude, // In: CDude to 'warp in', *ppdude = NULL to create one.
  200. // Out: Newly created CDude, if no CDude passed in.
  201. short sOptions); // In: Options for 'warp in'.
  202. // Creates a warp based on a dude's settings.
  203. static short CreateWarpFromDude( // Returns 0 on success.
  204. CRealm* prealm, // In: Realm in which to choose CWarp.
  205. CDude* pdude, // In: Dude to create warp from.
  206. CWarp** ppwarp, // Out: New warp on success.
  207. bool bCopyStockPile); // In: true to copy stockpile, false otherwise.
  208. //---------------------------------------------------------------------------
  209. // Internal functions
  210. //---------------------------------------------------------------------------
  211. protected:
  212. // Get all required resources
  213. short GetResources(void); // Returns 0, if successfull, non-zero otherwise
  214. // Free all resources
  215. short FreeResources(void); // Returns 0, if successfull, non-zero otherwise
  216. // Initialize object.
  217. short Init(void); // Returns 0, on success.
  218. };
  219. #endif // WARP_H
  220. ////////////////////////////////////////////////////////////////////////////////
  221. // EOF
  222. ////////////////////////////////////////////////////////////////////////////////