fire.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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. // fire.h
  19. // Project: Postal
  20. //
  21. // History:
  22. // 01/17/97 BRH Started this weapon object.
  23. //
  24. // 02/24/97 JMI Changed declaration of m_sprite from CAlphaSprite2 to
  25. // CSprite2.
  26. //
  27. // 03/13/97 JMI Load now takes a version number.
  28. //
  29. // 04/24/97 BRH Added a static variable for wind direction that will
  30. // be changed slightly every time a smoke is created, but
  31. // will generally cause them all to drift in the same
  32. // direction.
  33. //
  34. // 05/02/97 JMI Added GetTimeLeftToLive() which returns the amount of
  35. // time left before the fire goes out or the smoke thins
  36. // out.
  37. //
  38. // 06/11/97 BRH Added m_u16ShooterID to store the shooter ID which
  39. // will get passed along in the Burn Message.
  40. //
  41. // 06/17/97 JMI Converted all occurrences of rand() to GetRand() and
  42. // srand() to SeedRand().
  43. //
  44. // 07/01/97 BRH Added Small smoke animation.
  45. //
  46. // 07/04/97 BRH Added starting time used to calculate the alpha
  47. // level based on time to live.
  48. //
  49. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  50. // as a parameter.
  51. //
  52. // 07/13/97 BRH Added some variables and changed others for the new
  53. // method of using 1 alpha mask and setting the level
  54. // in the code.
  55. //
  56. // 07/23/97 BRH Changed the limits on the wind velocity so it can
  57. // be higher.
  58. //
  59. // 09/02/97 JMI Added m_u16FireStarterID. This is used for a special case
  60. // when the starter of the fire is not the thing using the
  61. // fire as a weapon (e.g., when a guy catches fire he can
  62. // use the fire on other people by running into them causing
  63. // them to catch on fire; however, if his own fire kills him
  64. // it is to the creator of the fire's credit that he dies).
  65. //
  66. //////////////////////////////////////////////////////////////////////////////
  67. //
  68. // Fire.
  69. //
  70. //////////////////////////////////////////////////////////////////////////////
  71. #ifndef FIRE_H
  72. #define FIRE_H
  73. #include "RSPiX.h"
  74. #include "realm.h"
  75. #include "AlphaAnimType.h"
  76. #include "smash.h"
  77. // CFire is a burning flame weapon class
  78. class CFire : public CThing
  79. {
  80. //---------------------------------------------------------------------------
  81. // Types, enums, etc.
  82. //---------------------------------------------------------------------------
  83. public:
  84. typedef enum
  85. {
  86. State_Idle,
  87. State_Fire,
  88. State_Find,
  89. State_Chase,
  90. State_Explode,
  91. State_Deleted
  92. } CFireState;
  93. typedef unsigned char FireAnim;
  94. typedef enum
  95. {
  96. LargeFire,
  97. SmallFire,
  98. Smoke,
  99. SmallSmoke
  100. };
  101. typedef RChannel<CAlphaAnim> ChannelAA;
  102. //---------------------------------------------------------------------------
  103. // Variables
  104. //---------------------------------------------------------------------------
  105. public:
  106. double m_dX;
  107. double m_dY;
  108. double m_dZ;
  109. short m_sRot;
  110. bool m_bTurnRight; // A Random number will determine if the
  111. // smoke will curl left or right when it hits an
  112. // obstacle.
  113. bool m_bIsBurningDude;
  114. U16 m_u16ShooterID; // Store the shooter ID to pass along in the burn message
  115. U16 m_u16FireStarterID; // Fire's creator. The ID of the thing that
  116. // caused this fire to be created. Generally
  117. // used by a thing3d when creating an internal
  118. // fire in response to Burn messages.
  119. protected:
  120. long m_lTimer; // General purpose timer
  121. long m_lCollisionTimer; // Check for collisions when this expires
  122. long m_lBurnUntil; // Burn until this time.
  123. long m_lCurrentAlphaTimeout; // Use current Alpha until this time, then switch
  124. long m_lBrightAlphaInterval; // Show each alpha for this amount of time
  125. long m_lDimAlphaInterval; // Show dim alpha level for this amount of time
  126. long m_lTimeToLive; // Total time to show this animation
  127. long m_lAlphaBreakPoint; // Time to switch from Bright to Dim
  128. long m_lStartTime; // Starting time used to calc the Alpha %
  129. short m_sCurrentAlphaLevel; // Use this Alpha level
  130. short m_sTotalAlphaChannels;
  131. U32 m_u32CollideIncludeBits; // bits to use for collision checking
  132. U32 m_u32CollideDontcareBits; // bits to use for collision checking
  133. U32 m_u32CollideExcludeBits; // bits to use for collision checking
  134. bool m_bSendMessages; // Whether or not to send messages to other
  135. // objects telling them to burn or not.
  136. FireAnim m_eFireAnim; // Which animation to use for the fire
  137. long m_lPrevTime; // Previous update time
  138. CSprite2 m_sprite; // Sprite (replace with CSprite3, soon)
  139. ChannelAA* m_pAnimChannel; // Alpha animation stored as a channel.
  140. short m_sSuspend; // Suspend flag
  141. CSmash m_smash; // Collision class
  142. // Tracks file counter so we know when to load/save "common" data
  143. static short ms_sFileCount;
  144. static short ms_sLargeRadius;
  145. static short ms_sSmallRadius;
  146. static long ms_lCollisionTime; // Check for collisions this often
  147. static long ms_lSmokeTime; // Time to let smoke run
  148. static short ms_sWindDirection; // Direction the wind is blowing, will
  149. // get changed slightly by each new smoke.
  150. static double ms_dWindVelocity; // Smoke drift velocity
  151. // "Constant" values that we want to be able to tune using the editor
  152. //---------------------------------------------------------------------------
  153. // Constructor(s) / destructor
  154. //---------------------------------------------------------------------------
  155. public:
  156. // Constructor
  157. CFire(CRealm* pRealm)
  158. : CThing(pRealm, CFireID)
  159. {
  160. m_bIsBurningDude = false;
  161. m_sSuspend = 0;
  162. m_lPrevTime = 0;
  163. m_bSendMessages = true;
  164. m_u32CollideIncludeBits = 0;
  165. m_u32CollideDontcareBits = 0;
  166. m_u32CollideExcludeBits = 0;
  167. m_sTotalAlphaChannels = 0;
  168. m_smash.m_pThing = NULL;
  169. m_smash.m_bits = 0;
  170. m_lStartTime = 0;
  171. m_u16FireStarterID = CIdBank::IdNil;
  172. }
  173. public:
  174. // Destructor
  175. ~CFire()
  176. {
  177. // Remove sprite from scene (this is safe even if it was already removed!)
  178. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  179. // Remove yourself from the collision list if it was in use
  180. // (switching to smoke removes it from the smashatorium and sets
  181. // the m_pThing field to NULL)
  182. if (m_smash.m_pThing)
  183. m_pRealm->m_smashatorium.Remove(&m_smash);
  184. // Free resources
  185. FreeResources();
  186. }
  187. //---------------------------------------------------------------------------
  188. // Required static functions
  189. //---------------------------------------------------------------------------
  190. public:
  191. // Construct object
  192. static short Construct( // Returns 0 if successfull, non-zero otherwise
  193. CRealm* pRealm, // In: Pointer to realm this object belongs to
  194. CThing** ppNew) // Out: Pointer to new object
  195. {
  196. short sResult = 0;
  197. *ppNew = new CFire(pRealm);
  198. if (*ppNew == 0)
  199. {
  200. sResult = -1;
  201. TRACE("CFire::Construct(): Couldn't construct CFire (that's a bad thing)\n");
  202. }
  203. return sResult;
  204. }
  205. //---------------------------------------------------------------------------
  206. // Optional static functions
  207. //---------------------------------------------------------------------------
  208. // Function for this class that is called before play begins to make
  209. // the resource manager cache the resources for this object.
  210. static short Preload(
  211. CRealm* prealm); // In: Calling realm.
  212. //---------------------------------------------------------------------------
  213. // Required virtual functions (implimenting them as inlines doesn't pay!)
  214. //---------------------------------------------------------------------------
  215. public:
  216. // Load object (should call base class version!)
  217. short Load( // Returns 0 if successfull, non-zero otherwise
  218. RFile* pFile, // In: File to load from
  219. bool bEditMode, // In: True for edit mode, false otherwise
  220. short sFileCount, // In: File count (unique per file, never 0)
  221. ULONG ulFileVersion); // In: Version of file format to load.
  222. // Save object (should call base class version!)
  223. short Save( // Returns 0 if successfull, non-zero otherwise
  224. RFile* pFile, // In: File to save to
  225. short sFileCount); // In: File count (unique per file, never 0)
  226. // Startup object
  227. short Startup(void); // Returns 0 if successfull, non-zero otherwise
  228. // Shutdown object
  229. short Shutdown(void); // Returns 0 if successfull, non-zero otherwise
  230. // Suspend object
  231. void Suspend(void);
  232. // Resume object
  233. void Resume(void);
  234. // Update object
  235. void Update(void);
  236. // Render object
  237. void Render(void);
  238. short Setup( // Returns 0 on success.
  239. short sX, // In: New x coord
  240. short sY, // In: New y coord
  241. short sZ, // In: New z coord
  242. long lTimeToLive = 1000, // In: Milliseconds to burn
  243. bool bThick = true, // In: Use thick fire (more opaque)
  244. FireAnim eFireAnim = LargeFire); // In: Which anim to use
  245. // Called by editor to init new object at specified position
  246. short EditNew( // Returns 0 if successfull, non-zero otherwise
  247. short sX, // In: New x coord
  248. short sY, // In: New y coord
  249. short sZ); // In: New z coord
  250. // Called by editor to modify object
  251. short EditModify(void); // Returns 0 if successfull, non-zero otherwise
  252. // Called by editor to move object to specified position
  253. short EditMove( // Returns 0 if successfull, non-zero otherwise
  254. short sX, // In: New x coord
  255. short sY, // In: New y coord
  256. short sZ); // In: New z coord
  257. // Called by editor to update object
  258. void EditUpdate(void);
  259. // Called by editor to render object
  260. void EditRender(void);
  261. // Allows whoever creates the fire to control what gets burned by it
  262. // the defaults are set initially to Characters
  263. void SetCollideBits(U32 u32Include, U32 u32Dontcare, U32 u32Exclude)
  264. {
  265. m_u32CollideIncludeBits = u32Include;
  266. m_u32CollideDontcareBits = u32Dontcare;
  267. m_u32CollideExcludeBits = u32Exclude;
  268. };
  269. // Turns messages on which will send burn messages to things the fire
  270. // is touching.
  271. void MessagesOn(void)
  272. {
  273. m_bSendMessages = true;
  274. }
  275. // Turns messages off which allows for fire that is just a visual effect
  276. void MessagesOff(void)
  277. {
  278. m_bSendMessages = false;
  279. }
  280. inline short IsBurning(void)
  281. {
  282. return m_eFireAnim != Smoke && m_eFireAnim != SmallSmoke;
  283. }
  284. // Get the time left to live.
  285. // Check IsBurning() to determine whether this applies to the fire or
  286. // the smoke.
  287. long GetTimeLeftToLive(void)
  288. {
  289. return m_lBurnUntil - m_pRealm->m_time.GetGameTime();
  290. }
  291. //---------------------------------------------------------------------------
  292. // Internal functions
  293. //---------------------------------------------------------------------------
  294. protected:
  295. // Get all required resources
  296. short GetResources(void); // Returns 0 if successfull, non-zero otherwise
  297. // Free all resources
  298. short FreeResources(void); // Returns 0 if successfull, non-zero otherwise
  299. // Process Game Messages
  300. CFire::CFireState ProcessMessages(void);
  301. // Initialize the fire for large or small objects
  302. short Init(void);
  303. // Fire it out, let the smoke start. This funciton will change animations,
  304. // remove from the smash so it won't collide with anything, reset the timers, etc.
  305. short Smokeout(void);
  306. inline void WindDirectionUpdate(void)
  307. {
  308. ms_sWindDirection = rspMod360(ms_sWindDirection -2 + (GetRand() % 4)); // Biased 1 direction
  309. ms_dWindVelocity = ms_dWindVelocity - 0.1 + ((GetRand() % 3) / 10.0);
  310. if (ms_dWindVelocity < 10.0)
  311. ms_dWindVelocity = 11.0;
  312. if (ms_dWindVelocity > 40.0)
  313. ms_dWindVelocity = 39.0;
  314. }
  315. };
  316. #endif //DOOFUS_H
  317. ////////////////////////////////////////////////////////////////////////////////
  318. // EOF
  319. ////////////////////////////////////////////////////////////////////////////////