chunk.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. // Chunk.H
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 05/13/97 JMI Started.
  23. //
  24. // 05/22/97 JMI Can support several types of 'chunks'.
  25. //
  26. // 08/18/97 JMI Now uses its own internal GetRand() and has randomization
  27. // arguments to Setup() so the caller can still control the
  28. // the randomization.
  29. // Now Construct() will not construct a CChunk if particle
  30. // effects are disabled.
  31. //
  32. // 09/08/97 JMI Added Kevlar type for pieces of kevlar vest that get
  33. // splatter off of dudes with vest.
  34. //
  35. //////////////////////////////////////////////////////////////////////////////
  36. //
  37. // This CThing-derived class will represent pieces of bloody yee (or chunks)
  38. // that fly off a recently damaged, complex organism or something.
  39. // Also, can now support bullet casings and shells.
  40. //
  41. //////////////////////////////////////////////////////////////////////////////
  42. #ifndef CHUNK_H
  43. #define CHUNK_H
  44. #include "RSPiX.h"
  45. #include "realm.h"
  46. class CChunk : public CThing
  47. {
  48. //---------------------------------------------------------------------------
  49. // Types, enums, etc.
  50. //---------------------------------------------------------------------------
  51. public:
  52. typedef enum
  53. {
  54. Blood,
  55. BulletCasing,
  56. Shell,
  57. Kevlar,
  58. NumTypes
  59. } Type;
  60. typedef struct
  61. {
  62. U8 u8ColorIndex;
  63. short sLen;
  64. } TypeInfo;
  65. //---------------------------------------------------------------------------
  66. // Variables
  67. //---------------------------------------------------------------------------
  68. public:
  69. double m_dX;
  70. double m_dY;
  71. double m_dZ;
  72. double m_dRot;
  73. double m_dVel;
  74. double m_dVertVel;
  75. long m_lPrevTime;
  76. short m_sSuspend; // Suspend flag
  77. Type m_type;
  78. short m_sLen; // Length of item.
  79. protected:
  80. CSpriteLine2d m_sprite; // Sprite.
  81. // Note that this is never reseeded b/c this is just an 'effect'
  82. // that does not and SHOULD not affect game play as it can be
  83. // turned off.
  84. static long ms_lGetRandomSeed; // Seed for GetRand[om]().
  85. // Chunk info for each type.
  86. static TypeInfo ms_atiChunks[NumTypes];
  87. //---------------------------------------------------------------------------
  88. // Static Variables
  89. //---------------------------------------------------------------------------
  90. public:
  91. //---------------------------------------------------------------------------
  92. // Constructor(s) / destructor
  93. //---------------------------------------------------------------------------
  94. public:
  95. // Constructor
  96. CChunk(CRealm* pRealm)
  97. : CThing(pRealm, CChunkID)
  98. {
  99. m_sSuspend = 0;
  100. m_dRot = 0.0;
  101. m_dVel = 0.0;
  102. m_dVertVel = 0.0;
  103. m_sLen = 0;
  104. m_sprite.m_pthing = this;
  105. m_sprite.m_u8Color = 1;
  106. m_type = Blood;
  107. }
  108. public:
  109. // Destructor
  110. ~CChunk()
  111. {
  112. // Remove sprite from scene (this is safe even if it was already removed!)
  113. m_pRealm->m_scene.RemoveSprite(&m_sprite);
  114. }
  115. //---------------------------------------------------------------------------
  116. // Required static functions
  117. //---------------------------------------------------------------------------
  118. public:
  119. // Construct object
  120. static short Construct( // Returns 0 if successfull, non-zero otherwise
  121. CRealm* pRealm, // In: Pointer to realm this object belongs to
  122. CThing** ppNew) // Out: Pointer to new object
  123. {
  124. short sResult = 0;
  125. // Don't allow chunks when disabled . . .
  126. if (g_GameSettings.m_sParticleEffects)
  127. {
  128. *ppNew = new CChunk(pRealm);
  129. if (*ppNew == 0)
  130. {
  131. sResult = -1;
  132. TRACE("CChunk::Construct(): Couldn't construct CChunk (that's really "
  133. "not that bad a thing)\n");
  134. }
  135. }
  136. else
  137. {
  138. // Particles disabled.
  139. sResult = 1;
  140. }
  141. return sResult;
  142. }
  143. //---------------------------------------------------------------------------
  144. // Virtual functions (implementing them as inlines doesn't pay!)
  145. //---------------------------------------------------------------------------
  146. public:
  147. // Suspend object
  148. void Suspend(void);
  149. // Resume object
  150. void Resume(void);
  151. // Update object
  152. void Update(void);
  153. // Render object
  154. void Render(void);
  155. // Note that this setup accepts the amount of random sway you want to
  156. // apply to the particle so you don't have to. You should not, otherwise
  157. // you'll ruin it (the game synch that is). Seriously.
  158. short Setup( // Returns 0 on success.
  159. short sX, // In: New x coord
  160. short sY, // In: New y coord
  161. short sZ, // In: New z coord
  162. double dRot, // In: Initial direction.
  163. short sRandRotSway, // In: Random sway on rotation or zero.
  164. double dVel, // In: Initial velocity.
  165. short sRandVelSway, // In: Random sway on velocity or zero.
  166. double dVertVel, // In: Initial vertical velocity.
  167. short sRandVertVelSway, // In: Random sway on velocity or zero.
  168. Type type); // In: Type of chunk.
  169. // Get a random number that is in no way related to the game's main
  170. // GetRand().
  171. static long GetChunkRand(void)
  172. {
  173. return (((ms_lGetRandomSeed = ms_lGetRandomSeed * 214013L + 2531011L) >> 16) & 0x7fff);
  174. }
  175. //---------------------------------------------------------------------------
  176. // Internal functions
  177. //---------------------------------------------------------------------------
  178. protected:
  179. };
  180. #endif // CHUNK_H
  181. ////////////////////////////////////////////////////////////////////////////////
  182. // EOF
  183. ////////////////////////////////////////////////////////////////////////////////