fireball.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  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. // fireball.h
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 04/25/97 BRH Started this new weapon to be used to make a
  23. // flamethrower.
  24. //
  25. // 04/29/97 JMI Added GetSprite() virtual override to provide access
  26. // to m_sprite from a lower level.
  27. // Changed back to being derived from CWeapon (instead of
  28. // CThing).
  29. // Added a Setup() that matches the base class virtual
  30. // Setup() to make sure it gets overriden. The
  31. // functionality is the same (the new Setup() just calls
  32. // the six parm Setup() with some handy defaults).
  33. // Changed name of ProcessMessages() to
  34. // ProcessFireballMessages() to avoid conflicts with
  35. // CWeapon's ProcessMessages().
  36. //
  37. // 06/30/97 BRH Added a fire stream object in this file to emit several
  38. // fireballs spaced close together to make a better stream
  39. // for the flamethrower.
  40. //
  41. // 07/04/97 BRH Changed to an auto alpha level based on the time to
  42. // live so that the flame gets more alpha-ed toward the
  43. // end where it burns out.
  44. //
  45. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  46. // as a parameter.
  47. //
  48. // 08/08/97 JMI Changed m_pFireball1, 2, & 3 to m_idFireball1, 2, & 3.
  49. //
  50. // 08/17/97 JMI Changed m_pthingParent to m_idParent.
  51. //
  52. //////////////////////////////////////////////////////////////////////////////
  53. //
  54. // Fireball.
  55. //
  56. //////////////////////////////////////////////////////////////////////////////
  57. #ifndef FIREBALL_H
  58. #define FIREBALL_H
  59. #include "RSPiX.h"
  60. #include "realm.h"
  61. #include "AlphaAnimType.h"
  62. #include "smash.h"
  63. #include "weapon.h"
  64. /////////////////////////////////////////// CFireball /////////////////////////////////////
  65. // CFireball is a burning flame weapon class
  66. class CFireball : public CWeapon
  67. {
  68. //---------------------------------------------------------------------------
  69. // Types, enums, etc.
  70. //---------------------------------------------------------------------------
  71. public:
  72. typedef enum
  73. {
  74. State_Idle,
  75. State_Fire,
  76. State_Find,
  77. State_Chase,
  78. State_Explode,
  79. State_Deleted
  80. } CFireballState;
  81. typedef RChannel<CAlphaAnim> ChannelAA;
  82. //---------------------------------------------------------------------------
  83. // Variables
  84. //---------------------------------------------------------------------------
  85. public:
  86. short m_sSpreadDir; // A Random number will determine the spread
  87. // when it hits a wall.
  88. protected:
  89. long m_lTimer; // General purpose timer
  90. long m_lCollisionTimer; // Check for collisions when this expires
  91. long m_lBurnUntil; // Burn until this time.
  92. long m_lCurrentAlphaTimeout; // Use current Alpha until this time, then switch
  93. long m_lAlphaChannelInterval; // Show each alpha for this amount of time
  94. long m_lTimeToLive; // Total time to show this animation
  95. long m_lTotalFlameTime; // Total time to show the flame (non adjusted for game time)
  96. short m_sCurrentAlphaChannel; // Use this Alpha channel
  97. short m_sTotalAlphaChannels;
  98. U32 m_u32CollideIncludeBits; // bits to use for collision checking
  99. U32 m_u32CollideDontcareBits; // bits to use for collision checking
  100. U32 m_u32CollideExcludeBits; // bits to use for collision checking
  101. U16 m_u16ShooterID; // shooter's ID so you don't hit him.
  102. bool m_bSendMessages; // Whether or not to send messages to other
  103. // objects telling them to burn or not.
  104. bool m_bMoving; // Once it hits a wall it will stop moving
  105. long m_lAnimTime; // Animation time so anims can be offset frames.
  106. long m_lPrevTime; // Previous update time
  107. CSprite2 m_sprite; // 2D sprite to render this object.
  108. ChannelAA* m_pAnimChannel; // Alpha animation stored as a channel.
  109. short m_sSuspend; // Suspend flag
  110. CSmash m_smash; // Collision class
  111. // Tracks file counter so we know when to load/save "common" data
  112. static short ms_sFileCount;
  113. static short ms_sSmallRadius;
  114. static long ms_lCollisionTime; // Check for collisions this often
  115. static double ms_dFireVelocity; // Rate of travel.
  116. // "Constant" values that we want to be able to tune using the editor
  117. //---------------------------------------------------------------------------
  118. // Constructor(s) / destructor
  119. //---------------------------------------------------------------------------
  120. public:
  121. // Constructor
  122. CFireball(CRealm* pRealm)
  123. : CWeapon(pRealm, CFireballID)
  124. {
  125. m_sSuspend = 0;
  126. m_lPrevTime = 0;
  127. m_bSendMessages = true;
  128. m_u32CollideIncludeBits = 0;
  129. m_u32CollideDontcareBits = 0;
  130. m_u32CollideExcludeBits = 0;
  131. m_sTotalAlphaChannels = 0;
  132. m_smash.m_pThing = NULL;
  133. m_smash.m_bits = 0;
  134. m_bMoving = true;
  135. m_lAnimTime = 0;
  136. m_sprite.m_pthing = this;
  137. }
  138. public:
  139. // Destructor
  140. ~CFireball()
  141. {
  142. // Remove sprite from scene (this is safe even if it was already removed!)
  143. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  144. // Remove yourself from the collision list if it was in use
  145. // (switching to smoke removes it from the smashatorium and sets
  146. // the m_pThing field to NULL)
  147. if (m_smash.m_pThing)
  148. m_pRealm->m_smashatorium.Remove(&m_smash);
  149. // Free resources
  150. FreeResources();
  151. }
  152. //---------------------------------------------------------------------------
  153. // Required static functions
  154. //---------------------------------------------------------------------------
  155. public:
  156. // Construct object
  157. static short Construct( // 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. short sResult = 0;
  162. *ppNew = new CFireball(pRealm);
  163. if (*ppNew == 0)
  164. {
  165. sResult = -1;
  166. TRACE("CFireball::Construct(): Couldn't construct CFireball (that's a bad thing)\n");
  167. }
  168. return sResult;
  169. }
  170. //---------------------------------------------------------------------------
  171. // Optional static functions
  172. //---------------------------------------------------------------------------
  173. // Function for this class that is called before play begins to make
  174. // the resource manager cache the resources for this object.
  175. static short Preload(
  176. CRealm* prealm); // In: Calling realm.
  177. //---------------------------------------------------------------------------
  178. // Required virtual functions (implimenting them as inlines doesn't pay!)
  179. //---------------------------------------------------------------------------
  180. public:
  181. // Load object (should call base class version!)
  182. short Load( // Returns 0 if successfull, non-zero otherwise
  183. RFile* pFile, // In: File to load from
  184. bool bEditMode, // In: True for edit mode, false otherwise
  185. short sFileCount, // In: File count (unique per file, never 0)
  186. ULONG ulFileVersion); // In: Version of file format to load.
  187. // Save object (should call base class version!)
  188. short Save( // Returns 0 if successfull, non-zero otherwise
  189. RFile* pFile, // In: File to save to
  190. short sFileCount); // In: File count (unique per file, never 0)
  191. // Startup object
  192. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  193. // Shutdown object
  194. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  195. // Suspend object
  196. void Suspend(void);
  197. // Resume object
  198. void Resume(void);
  199. // Update object
  200. void Update(void);
  201. // Render object
  202. void Render(void);
  203. short Setup( // Returns 0 on success.
  204. short sX, // In: New x coord
  205. short sY, // In: New y coord
  206. short sZ, // In: New z coord
  207. short sDir, // In: Direction of travel
  208. long lTimeToLive, // In: Milliseconds to burn
  209. U16 u16ShooterID); // In: Your ID (the shooter) so it doesn't hit you
  210. // Override base class Setup().
  211. virtual // Overridden here.
  212. short Setup(
  213. short sX, // In: Starting X position
  214. short sY, // In: Starting Y position
  215. short sZ) // In: Starting Z position
  216. {
  217. // Default to 500 ms to live and parent's shooter ID, if there is a parent.
  218. return Setup(
  219. sX, sY, sZ,
  220. 0,
  221. 500,
  222. m_idParent
  223. );
  224. }
  225. // Called by editor to init new object at specified position
  226. short EditNew( // Returns 0 if successfull, non-zero otherwise
  227. short sX, // In: New x coord
  228. short sY, // In: New y coord
  229. short sZ); // In: New z coord
  230. // Called by editor to modify object
  231. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  232. // Called by editor to move object to specified position
  233. short EditMove( // Returns 0 if successfull, non-zero otherwise
  234. short sX, // In: New x coord
  235. short sY, // In: New y coord
  236. short sZ); // In: New z coord
  237. // Called by editor to update object
  238. void EditUpdate(void);
  239. // Called by editor to render object
  240. void EditRender(void);
  241. // Allows whoever creates the fire to control what gets burned by it
  242. // the defaults are set initially to Characters
  243. void SetCollideBits(U32 u32Include, U32 u32Dontcare, U32 u32Exclude)
  244. {
  245. m_u32CollideIncludeBits = u32Include;
  246. m_u32CollideDontcareBits = u32Dontcare;
  247. m_u32CollideExcludeBits = u32Exclude;
  248. };
  249. // Turns messages on which will send burn messages to things the fire
  250. // is touching.
  251. void MessagesOn(void)
  252. {
  253. m_bSendMessages = true;
  254. }
  255. // Turns messages off which allows for fire that is just a visual effect
  256. void MessagesOff(void)
  257. {
  258. m_bSendMessages = false;
  259. }
  260. // Get this class's sprite. Note that the type will vary.
  261. // This is a pure virtual functionin the base class.
  262. virtual // Overriden here.
  263. CSprite* GetSprite(void) // Returns this weapon's sprite.
  264. {
  265. return &m_sprite;
  266. }
  267. //---------------------------------------------------------------------------
  268. // Internal functions
  269. //---------------------------------------------------------------------------
  270. protected:
  271. // Get all required resources
  272. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  273. // Free all resources
  274. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  275. // Process Game Messages
  276. CFireballState ProcessFireballMessages(void);
  277. // Initialize the fire for large or small objects
  278. short Init(void);
  279. };
  280. /////////////////////////////////// Firestream ////////////////////////////////
  281. // CFirestream is a burning flame weapon class
  282. class CFirestream : public CWeapon
  283. {
  284. //---------------------------------------------------------------------------
  285. // Types, enums, etc.
  286. //---------------------------------------------------------------------------
  287. public:
  288. typedef enum
  289. {
  290. State_Idle,
  291. State_Fire,
  292. State_Find,
  293. State_Chase,
  294. State_Explode,
  295. State_Deleted
  296. } CFirestreamState;
  297. typedef RChannel<CAlphaAnim> ChannelAA;
  298. //---------------------------------------------------------------------------
  299. // Variables
  300. //---------------------------------------------------------------------------
  301. public:
  302. // when it hits a wall.
  303. protected:
  304. long m_lBurnUntil; // Burn until this time.
  305. long m_lCurrentAlphaTimeout; // Use current Alpha until this time, then switch
  306. long m_lAlphaChannelInterval; // Show each alpha for this amount of time
  307. long m_lTimeToLive; // Total time to show this animation
  308. short m_sCurrentAlphaChannel; // Use this Alpha channel
  309. short m_sTotalAlphaChannels;
  310. U16 m_u16ShooterID; // shooter's ID so you don't hit him.
  311. bool m_bSendMessages; // Whether or not to send messages to other
  312. // objects telling them to burn or not.
  313. long m_lPrevTime; // Previous update time
  314. CSprite2 m_sprite; // False sprite for positioning info
  315. U16 m_idFireball1;
  316. U16 m_idFireball2;
  317. U16 m_idFireball3;
  318. short m_sSuspend; // Suspend flag
  319. // Tracks file counter so we know when to load/save "common" data
  320. static short ms_sFileCount;
  321. static short ms_sOffset1; // Offset for 2nd fireball
  322. static short ms_sOffset2; // Offset for 3rd fireball
  323. // "Constant" values that we want to be able to tune using the editor
  324. //---------------------------------------------------------------------------
  325. // Constructor(s) / destructor
  326. //---------------------------------------------------------------------------
  327. public:
  328. // Constructor
  329. CFirestream(CRealm* pRealm)
  330. : CWeapon(pRealm, CFirestreamID)
  331. {
  332. m_sSuspend = 0;
  333. m_lPrevTime = 0;
  334. m_bSendMessages = true;
  335. m_sTotalAlphaChannels = 0;
  336. m_sprite.m_pthing = this;
  337. m_idFireball1 = CIdBank::IdNil;
  338. m_idFireball2 = CIdBank::IdNil;
  339. m_idFireball3 = CIdBank::IdNil;
  340. }
  341. public:
  342. // Destructor
  343. ~CFirestream()
  344. {
  345. // Remove sprite from scene (this is safe even if it was already removed!)
  346. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  347. }
  348. //---------------------------------------------------------------------------
  349. // Required static functions
  350. //---------------------------------------------------------------------------
  351. public:
  352. // Construct object
  353. static short Construct( // Returns 0 if successfull, non-zero otherwise
  354. CRealm* pRealm, // In: Pointer to realm this object belongs to
  355. CThing** ppNew) // Out: Pointer to new object
  356. {
  357. short sResult = 0;
  358. *ppNew = new CFirestream(pRealm);
  359. if (*ppNew == 0)
  360. {
  361. sResult = -1;
  362. TRACE("CFirestream::Construct(): Couldn't construct CFirestream (that's a bad thing)\n");
  363. }
  364. return sResult;
  365. }
  366. //---------------------------------------------------------------------------
  367. // Optional static functions
  368. //---------------------------------------------------------------------------
  369. // Function for this class that is called before play begins to make
  370. // the resource manager cache the resources for this object.
  371. static short Preload(
  372. CRealm* prealm); // In: Calling realm.
  373. //---------------------------------------------------------------------------
  374. // Required virtual functions (implimenting them as inlines doesn't pay!)
  375. //---------------------------------------------------------------------------
  376. public:
  377. // Load object (should call base class version!)
  378. short Load( // Returns 0 if successfull, non-zero otherwise
  379. RFile* pFile, // In: File to load from
  380. bool bEditMode, // In: True for edit mode, false otherwise
  381. short sFileCount, // In: File count (unique per file, never 0)
  382. ULONG ulFileVersion); // In: Version of file format to load.
  383. // Save object (should call base class version!)
  384. short Save( // Returns 0 if successfull, non-zero otherwise
  385. RFile* pFile, // In: File to save to
  386. short sFileCount); // In: File count (unique per file, never 0)
  387. // Startup object
  388. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  389. // Shutdown object
  390. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  391. // Suspend object
  392. void Suspend(void);
  393. // Resume object
  394. void Resume(void);
  395. // Update object
  396. void Update(void);
  397. // Render object
  398. void Render(void);
  399. short Setup( // Returns 0 on success.
  400. short sX, // In: New x coord
  401. short sY, // In: New y coord
  402. short sZ, // In: New z coord
  403. short sDir, // In: Direction of travel
  404. long lTimeToLive, // In: Milliseconds to burn
  405. U16 u16ShooterID); // In: Your ID (the shooter) so it doesn't hit you
  406. // Override base class Setup().
  407. virtual // Overridden here.
  408. short Setup(
  409. short sX, // In: Starting X position
  410. short sY, // In: Starting Y position
  411. short sZ) // In: Starting Z position
  412. {
  413. // Default to 500 ms to live and parent's shooter ID, if there is a parent.
  414. return Setup(
  415. sX, sY, sZ,
  416. 0,
  417. 500,
  418. m_idParent
  419. );
  420. }
  421. // Called by editor to init new object at specified position
  422. short EditNew( // Returns 0 if successfull, non-zero otherwise
  423. short sX, // In: New x coord
  424. short sY, // In: New y coord
  425. short sZ); // In: New z coord
  426. // Called by editor to modify object
  427. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  428. // Called by editor to move object to specified position
  429. short EditMove( // Returns 0 if successfull, non-zero otherwise
  430. short sX, // In: New x coord
  431. short sY, // In: New y coord
  432. short sZ); // In: New z coord
  433. // Called by editor to update object
  434. void EditUpdate(void);
  435. // Called by editor to render object
  436. void EditRender(void);
  437. // Turns messages on which will send burn messages to things the fire
  438. // is touching.
  439. void MessagesOn(void)
  440. {
  441. m_bSendMessages = true;
  442. }
  443. // Turns messages off which allows for fire that is just a visual effect
  444. void MessagesOff(void)
  445. {
  446. m_bSendMessages = false;
  447. }
  448. // Get this class's sprite. Note that the type will vary.
  449. // This is a pure virtual functionin the base class.
  450. virtual // Overriden here.
  451. CSprite* GetSprite(void) // Returns this weapon's sprite.
  452. {
  453. return &m_sprite;
  454. }
  455. //---------------------------------------------------------------------------
  456. // Internal functions
  457. //---------------------------------------------------------------------------
  458. protected:
  459. // Process Game Messages
  460. CFirestreamState ProcessFireballMessages(void);
  461. // Initialize the fire for large or small objects
  462. short Init(void);
  463. };
  464. #endif //FIREBALL_H
  465. ////////////////////////////////////////////////////////////////////////////////
  466. // EOF
  467. ////////////////////////////////////////////////////////////////////////////////