PowerUp.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. // PowerUp.H
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 05/08/97 JMI Started.
  23. //
  24. // 05/09/97 JMI Added m_smash and Init().
  25. //
  26. // 05/14/97 JMI Added Grab() and Drop().
  27. // Also, made m_sprite public.
  28. //
  29. // 06/06/97 JMI Got rid of the whole type thing. Now uses a CStockPile
  30. // and can contain any combination of powerups w/i one
  31. // instance. Types are still used for loading old powerup
  32. // files.
  33. // Also, added GetDescription().
  34. //
  35. // 06/12/97 JMI Added support for new weapon members of CStockPile.
  36. //
  37. // 06/12/97 JMI Added sHitPointMax parameter to GetDescription().
  38. //
  39. // 06/14/97 JMI Changed to a descendant of CItem3d instead of CThing.
  40. //
  41. // 06/14/97 JMI Added KevlarVest (CStockPile::m_sArmorLayers).
  42. //
  43. // 06/15/97 JMI Added Backpack (CStockPile::m_sBackpack).
  44. //
  45. // 06/16/97 JMI Added a user (audible) feedback function, PickUpFeedback().
  46. //
  47. // 07/15/97 JMI Made GetDescription() and TypeToStockPile() static and
  48. // added stockpiles as parms so they can be used more
  49. // generically.
  50. // Also, added RepaginateNow().
  51. // Also, added IsEmpty().
  52. //
  53. // 07/15/97 JMI Added some message handling functions.
  54. // Transferred powerup index enums into CStockPile.
  55. //
  56. // 07/16/97 JMI Moved IsEmpty() from powerup to stockpile.
  57. //
  58. // 07/23/97 JMI Added separate launcher for napalm.
  59. //
  60. // 08/17/97 JMI Got rid of m_szMessages and all message related functions
  61. // and variables from CDude since we are now using the toolbar
  62. // for dude status feedback to the user. This includes:
  63. // MsgTypeInfo, m_lNextStatusUpdateTime, m_lMsgUpdateDoneTime,
  64. // m_print, m_bClearedStatus, m_szMessages[], m_sDeadMsgNum,
  65. // ms_amtfMessages[], ms_u8FontForeIndex, ms_u8FontBackIndex,
  66. // ms_u8FontShadowIndex, DrawStatus(), StatusChange(),
  67. // MessageChange(), Message(), UpdateFontColors(),
  68. // CPowerUp::ms_apszPowerUpTypeNames[],
  69. // CPowerUp::GetDescription(), and some strings and a string
  70. // array in localize.*.
  71. //
  72. //////////////////////////////////////////////////////////////////////////////
  73. //
  74. // This CItem3d-derived class will represent power ups that the player can
  75. // pick up.
  76. //
  77. //////////////////////////////////////////////////////////////////////////////
  78. #ifndef POWERUP_H
  79. #define POWERUP_H
  80. #include "RSPiX.h"
  81. #include "realm.h"
  82. #include "item3d.h"
  83. #include "StockPile.h"
  84. class CPowerUp : public CItem3d
  85. {
  86. //---------------------------------------------------------------------------
  87. // Types, enums, etc.
  88. //---------------------------------------------------------------------------
  89. public:
  90. //---------------------------------------------------------------------------
  91. // Variables
  92. //---------------------------------------------------------------------------
  93. public:
  94. protected:
  95. //---------------------------------------------------------------------------
  96. // Static Variables
  97. //---------------------------------------------------------------------------
  98. public:
  99. // Powerup anim names.
  100. static char* ms_apszPowerUpResNames[CStockPile::NumStockPileItems + 2];
  101. //---------------------------------------------------------------------------
  102. // Constructor(s) / destructor
  103. //---------------------------------------------------------------------------
  104. public:
  105. // Constructor
  106. CPowerUp(CRealm* pRealm)
  107. : CItem3d(pRealm, CPowerUpID)
  108. {
  109. m_panimCur = &m_anim;
  110. m_stockpile.m_sHitPoints = 0;
  111. m_sprite.m_pthing = this;
  112. m_smash.m_pThing = this;
  113. }
  114. public:
  115. // Destructor
  116. ~CPowerUp()
  117. {
  118. // Remove sprite from scene (this is safe even if it was already removed!)
  119. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  120. // Free resources
  121. FreeResources();
  122. // Remove collision thinger.
  123. m_pRealm->m_smashatorium.Remove(&m_smash);
  124. }
  125. //---------------------------------------------------------------------------
  126. // Required static functions
  127. //---------------------------------------------------------------------------
  128. public:
  129. // Construct object
  130. static short Construct( // Returns 0 if successfull, non-zero otherwise
  131. CRealm* pRealm, // In: Pointer to realm this object belongs to
  132. CThing** ppNew) // Out: Pointer to new object
  133. {
  134. short sResult = 0;
  135. *ppNew = new CPowerUp(pRealm);
  136. if (*ppNew == 0)
  137. {
  138. sResult = -1;
  139. TRACE("CPowerUp::Construct(): Couldn't construct CPowerUp (that's a bad thing)\n");
  140. }
  141. return sResult;
  142. }
  143. //---------------------------------------------------------------------------
  144. // Optional static functions
  145. //---------------------------------------------------------------------------
  146. // Preload assets needed during the game
  147. static short Preload(CRealm* prealm);
  148. //---------------------------------------------------------------------------
  149. // Required virtual functions (implementing them as inlines doesn't pay!)
  150. //---------------------------------------------------------------------------
  151. public:
  152. // Load object (should call base class version!)
  153. short Load( // Returns 0 if successfull, non-zero otherwise
  154. RFile* pFile, // In: File to load from
  155. bool bEditMode, // In: True for edit mode, false otherwise
  156. short sFileCount, // In: File count (unique per file, never 0)
  157. ULONG ulFileVersion); // In: Version of file format to load.
  158. // Save object (should call base class version!)
  159. short Save( // Returns 0 if successfull, non-zero otherwise
  160. RFile* pFile, // In: File to save to
  161. short sFileCount); // In: File count (unique per file, never 0)
  162. // Update object
  163. void Update(void);
  164. // Render object
  165. void Render(void);
  166. // Called by editor to init new object at specified position
  167. short EditNew( // Returns 0 if successfull, non-zero otherwise
  168. short sX, // In: New x coord
  169. short sY, // In: New y coord
  170. short sZ); // In: New z coord
  171. // Called by editor to modify object
  172. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  173. //---------------------------------------------------------------------------
  174. // Handy external functions
  175. //---------------------------------------------------------------------------
  176. public:
  177. short Setup( // Returns 0 on success.
  178. short sX, // In: New x coord
  179. short sY, // In: New y coord
  180. short sZ); // In: New z coord
  181. // Call to grab this item.
  182. short Grab( // Returns 0 on success.
  183. CSprite* psprParent); // In: Parent's sprite.
  184. // Call to release this item.
  185. void Drop( // Returns nothing.
  186. short sX, // In: Position from which to release.
  187. short sY, // In: Position from which to release.
  188. short sZ); // In: Position from which to release.
  189. // Determine if this powerup's stockpile is empty.
  190. bool IsEmpty(void) // Returns true, if the stockpile is
  191. // empty.
  192. {
  193. return m_stockpile.IsEmpty();
  194. }
  195. // Plays a sample corresponding to the type of powerup indicating it
  196. // was picked up.
  197. void PickUpFeedback(void); // Returns nothing.
  198. // If this powerup has nothing left, destroys itself. Otherwise, chooses
  199. // a new resource to represent its current contents.
  200. // NOTE: This function can cause this item to be destroyed. Don't use
  201. // a ptr to this object after calling this function.
  202. void RepaginateNow(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. // Internal functions
  221. //---------------------------------------------------------------------------
  222. protected:
  223. // Get all required resources
  224. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  225. // Free all resources
  226. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  227. // Initialize object.
  228. short Init(void); // Returns 0 on success.
  229. // Get resource name for this item.
  230. void GetResName( // Returns nothing.
  231. char* pszResName); // Out: Resource base name.
  232. };
  233. #endif // POWERUP_H
  234. ////////////////////////////////////////////////////////////////////////////////
  235. // EOF
  236. ////////////////////////////////////////////////////////////////////////////////