demon.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. // Demon.H
  19. // Project: Postal
  20. //
  21. // History:
  22. // 06/09/97 BRH Started this file from SoundThing.h
  23. //
  24. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  25. // as a parameter.
  26. //
  27. // 07/17/97 JMI Changed m_psndChannel to m_siLastPlayInstance.
  28. // Now uses new SampleMaster interface for volume and play
  29. // instance reference.
  30. // Then, removed m_psndChannel b/c this class really didn't
  31. // use it.
  32. //
  33. // 07/21/97 JMI Added GetX(), GetY(), and GetZ().
  34. //
  35. // 08/01/97 JMI Demon would set his position (m_dX, Y, Z) when first
  36. // created but, since he never Save()d or Load()ed it, he
  37. // was in an unitialized position when loaded into a level.
  38. //
  39. // 09/24/97 JMI Now initializes bFemalePain member of m_id. This member
  40. // indicates whether the sample is of a female in pain which
  41. // some countries (so far just UK) don't want in the game.
  42. //
  43. // 10/07/97 JMI Changed bFemalePain to usDescFlags.
  44. //
  45. // 12/02/97 JMI Added new m_sSoundBank member to index new static arrays
  46. // of sound banks for groups of sounds (ms_apsmidExplosion,
  47. // ms_apsmidBurn, ms_apsmidSuicide, ms_apsmidWrithing,
  48. // ms_apsmidKillSeries).
  49. // Also, removed unused vars:
  50. // m_lNextStartTime, m_lLastStartTime, m_sWhichTime,
  51. // m_bEnabled, m_bRepeats, m_bInitiallyEnabled,
  52. // m_bInitiallyRepeats, m_lMinTime[], m_lRndTime[],
  53. // m_szResName, and m_id.
  54. // Also, now saves position and defaults to position on the
  55. // the screen (that way older levels that didn't save the
  56. // position will have the demon on the screen).
  57. //
  58. //////////////////////////////////////////////////////////////////////////////
  59. //
  60. // This CThing-derived class will get messages from other things in the game
  61. // and decide what comment to make about it.
  62. //
  63. //////////////////////////////////////////////////////////////////////////////
  64. #ifndef DEMON_H
  65. #define DEMON_H
  66. #include "RSPiX.h"
  67. #include "realm.h"
  68. #include "SampleMaster.h"
  69. class CDemon : public CThing
  70. {
  71. //---------------------------------------------------------------------------
  72. // Types, enums, etc.
  73. //---------------------------------------------------------------------------
  74. public:
  75. typedef enum
  76. {
  77. State_Happy, // La, la, la.
  78. State_Delete // Delete self next chance.
  79. } State;
  80. typedef enum
  81. {
  82. NumSoundBanks = 5, // Number of sound banks.
  83. NumExplosionComments = 8, // Number of explosion comments per bank.
  84. NumBurnComments = 4, // Number of burn comments per bank.
  85. NumSuicideComments = 1, // Number of suicide comments per bank.
  86. NumWrithingComments = 5, // Number of writhing comments per bank.
  87. NumKillSeriesComments = 7 // Number of kill series comments per bank.
  88. } Macros;
  89. //---------------------------------------------------------------------------
  90. // Variables
  91. //---------------------------------------------------------------------------
  92. public:
  93. long m_lIdleTime; // Time without saying something
  94. long m_lKillTimer; // Bonus kill timer
  95. short m_sRecentKills; // Number of recent kills
  96. short m_sCommentCount; // Number of comments that could have
  97. // been made, but were withheld.
  98. RImage* m_pImage; // Pointer to only image (for editor only)
  99. CSprite2 m_sprite; // Sprite (for editor only)
  100. double m_dX; // x coord (for editor only)
  101. double m_dY; // y coord (for editor only)
  102. double m_dZ; // z coord (for editor only)
  103. short m_sSuspend; // Suspend flag
  104. State m_state; // Current state.
  105. short m_sSoundBank; // Sound bank index.
  106. protected:
  107. static long ms_lMinIdleTime; // Min time before playing next sample
  108. static long ms_lBonusKillTime; // Kill an amount within this time and get a bonus comment
  109. // Sound banks of explosion comments indexed by m_sSoundBank.
  110. static SampleMasterID* ms_apsmidExplosion[NumSoundBanks][NumExplosionComments];
  111. // Sound banks of burn comments indexed by m_sSoundBank.
  112. static SampleMasterID* ms_apsmidBurn[NumSoundBanks][NumBurnComments];
  113. // Sound banks of suicide comments indexed by m_sSoundBank.
  114. static SampleMasterID* ms_apsmidSuicide[NumSoundBanks][NumSuicideComments];
  115. // Sound banks of writhing comments indexed by m_sSoundBank.
  116. static SampleMasterID* ms_apsmidWrithing[NumSoundBanks][NumWrithingComments];
  117. // Sound banks of kill series comments indexed by m_sSoundBank.
  118. static SampleMasterID* ms_apsmidKillSeries[NumSoundBanks][NumKillSeriesComments];
  119. //---------------------------------------------------------------------------
  120. // Constructor(s) / destructor
  121. //---------------------------------------------------------------------------
  122. public:
  123. // Constructor
  124. CDemon(CRealm* pRealm)
  125. : CThing(pRealm, CDemonID)
  126. {
  127. m_lIdleTime = 0;
  128. m_lKillTimer = 0;
  129. m_sRecentKills = 0;
  130. m_sCommentCount = 0;
  131. m_pImage = 0;
  132. m_sSuspend = 0;
  133. m_state = State_Happy;
  134. // Default to position on the screen for old .rlms that did not
  135. // save their demon's position.
  136. m_dX = 100.0;
  137. m_dY = 0.0;
  138. m_dZ = 50.0;
  139. m_sSoundBank = 0;
  140. }
  141. public:
  142. // Destructor
  143. ~CDemon()
  144. {
  145. Kill();
  146. }
  147. //---------------------------------------------------------------------------
  148. // Required static functions
  149. //---------------------------------------------------------------------------
  150. public:
  151. // Construct object
  152. static short Construct( // Returns 0 if successfull, non-zero otherwise
  153. CRealm* pRealm, // In: Pointer to realm this object belongs to
  154. CThing** ppNew) // Out: Pointer to new object
  155. {
  156. short sResult = 0;
  157. *ppNew = new CDemon(pRealm);
  158. if (*ppNew == 0)
  159. {
  160. sResult = -1;
  161. TRACE("CExplode::Construct(): Couldn't construct CDemon (that's a bad thing)\n");
  162. }
  163. return sResult;
  164. }
  165. //---------------------------------------------------------------------------
  166. // Required virtual functions (implimenting them as inlines doesn't pay!)
  167. //---------------------------------------------------------------------------
  168. public:
  169. // Load object (should call base class version!)
  170. short Load( // Returns 0 if successfull, non-zero otherwise
  171. RFile* pFile, // In: File to load from
  172. bool bEditMode, // In: True for edit mode, false otherwise
  173. short sFileCount, // In: File count (unique per file, never 0)
  174. ULONG ulFileVersion); // In: Version of file format to load.
  175. // Save object (should call base class version!)
  176. short Save( // Returns 0 if successfull, non-zero otherwise
  177. RFile* pFile, // In: File to save to
  178. short sFileCount); // In: File count (unique per file, never 0)
  179. // Startup object
  180. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  181. // Shutdown object
  182. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  183. // Suspend object
  184. void Suspend(void);
  185. // Resume object
  186. void Resume(void);
  187. // Update object
  188. void Update(void);
  189. // Render object
  190. void Render(void);
  191. short Setup( // Returns 0 on success.
  192. short sX, // In: New x coord
  193. short sY, // In: New y coord
  194. short sZ); // In: New z coord
  195. // Called by editor to init new object at specified position
  196. short EditNew( // Returns 0 if successfull, non-zero otherwise
  197. short sX, // In: New x coord
  198. short sY, // In: New y coord
  199. short sZ); // In: New z coord
  200. // Called by editor to modify object
  201. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  202. // Called by editor to move object to specified position
  203. short EditMove( // Returns 0 if successfull, non-zero otherwise
  204. short sX, // In: New x coord
  205. short sY, // In: New y coord
  206. short sZ); // In: New z coord
  207. // Called by editor to get the clickable pos/area of an object in 2D.
  208. virtual // Overridden here.
  209. void EditRect( // Returns nothiing.
  210. RRect* prc); // Out: Clickable pos/area of object.
  211. // Called by editor to get the hotspot of an object in 2D.
  212. virtual // Overridden here.
  213. void EditHotSpot( // Returns nothiing.
  214. short* psX, // Out: X coord of 2D hotspot relative to
  215. // EditRect() pos.
  216. short* psY); // Out: Y coord of 2D hotspot relative to
  217. // EditRect() pos.
  218. // Called by editor to update object
  219. void EditUpdate(void);
  220. // Called by editor to render object
  221. void EditRender(void);
  222. // Get the coordinates of this thing.
  223. virtual // Overriden here.
  224. double GetX(void) { return m_dX; }
  225. virtual // Overriden here.
  226. double GetY(void) { return m_dY; }
  227. virtual // Overriden here.
  228. double GetZ(void) { return m_dZ; }
  229. //---------------------------------------------------------------------------
  230. // Optional Static functions
  231. //---------------------------------------------------------------------------
  232. // Preload the sound samples that might be used.
  233. static short Preload(
  234. CRealm* prealm); // In: Calling realm.
  235. //---------------------------------------------------------------------------
  236. // Internal functions
  237. //---------------------------------------------------------------------------
  238. protected:
  239. // Init object
  240. short Init(void); // Returns 0 if successfull, non-zero otherwise
  241. // Kill object
  242. short Kill(void); // Returns 0 if successfull, non-zero otherwise
  243. // Process our message queue.
  244. void ProcessMessages(void);
  245. };
  246. #endif // DEMON_H
  247. ////////////////////////////////////////////////////////////////////////////////
  248. // EOF
  249. ////////////////////////////////////////////////////////////////////////////////