bulletFest.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. // bulletFest.H
  19. // Project: Nostril (aka Postal)
  20. //
  21. // History:
  22. // 02/18/97 JMI Started.
  23. //
  24. // 02/19/97 JMI Now Fire() and FireDeluxe() take all 3 CSmash masks.
  25. //
  26. // 03/10/97 JMI Added m_u16IdTarget (last known target's ID).
  27. //
  28. // 03/21/97 JMI Added optional tracers.
  29. //
  30. // 04/02/97 JMI Changed ms_ati to m_ati.
  31. // Also, added ms_u8TracerIndex and m_sCurTracerPos.
  32. //
  33. // 04/24/97 JMI Added smid parameter specifying type of ammo noise to
  34. // FireDeluxe() and Flare().
  35. // Also, added vertical bullet angle to FireDeluxe() and
  36. // Fire().
  37. //
  38. // 06/11/97 JMI Added Preload() for loading assets used during play.
  39. //
  40. // 07/09/97 JMI Changed Preload() to take a pointer to the calling realm
  41. // as a parameter.
  42. //
  43. // 09/18/97 JMI UpdateTracerColor() now takes a realm ptr.
  44. //
  45. //////////////////////////////////////////////////////////////////////////////
  46. //
  47. // bulletFest handles launching of bullets. Currently it doesn't seem like
  48. // much more than a function call, but eventually it will need to keep track
  49. // of some per instance data.
  50. //
  51. //////////////////////////////////////////////////////////////////////////////
  52. #ifndef BULLETFEST_H
  53. #define BULLETFEST_H
  54. //////////////////////////////////////////////////////////////////////////////
  55. // C Headers -- Must be included before RSPiX.h b/c RSPiX utilizes SHMalloc.
  56. //////////////////////////////////////////////////////////////////////////////
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // RSPiX Headers.
  59. // If PATHS_IN_INCLUDES macro is defined, we can utilize relative
  60. // paths to a header file. In this case we generally go off of our
  61. // RSPiX root directory. System.h MUST be included before this macro
  62. // is evaluated. System.h is the header that, based on the current
  63. // platform (or more so in this case on the compiler), defines
  64. // PATHS_IN_INCLUDES. Blue.h includes system.h so you can include that
  65. // instead.
  66. ///////////////////////////////////////////////////////////////////////////////
  67. #include "System.h"
  68. #ifdef PATHS_IN_INCLUDES
  69. #else
  70. #endif
  71. //////////////////////////////////////////////////////////////////////////////
  72. // Postal headers.
  73. //////////////////////////////////////////////////////////////////////////////
  74. #include "realm.h"
  75. #include "SampleMaster.h"
  76. //////////////////////////////////////////////////////////////////////////////
  77. // Macros.
  78. //////////////////////////////////////////////////////////////////////////////
  79. //////////////////////////////////////////////////////////////////////////////
  80. // Protos.
  81. //////////////////////////////////////////////////////////////////////////////
  82. //////////////////////////////////////////////////////////////////////////////
  83. // Typedefs.
  84. //////////////////////////////////////////////////////////////////////////////
  85. class CBulletFest
  86. {
  87. ///////////////////////////////////////////////////////////////////////////
  88. // Typedefs/enums.
  89. ///////////////////////////////////////////////////////////////////////////
  90. public:
  91. // Macros.
  92. enum
  93. {
  94. TargetHistoryTotalPeriod = 1000, // Target history duration in ms.
  95. TargetHistoryUpdatePeriod = 100, // Duration between history
  96. // updates.
  97. TargetUpdatesPerPeriod = TargetHistoryTotalPeriod / TargetHistoryUpdatePeriod
  98. };
  99. // History info.
  100. typedef struct
  101. {
  102. bool bDirChange; // true, if a direction change (relative to
  103. // source) occured at this point; false,
  104. // otherwise.
  105. long lSqrDistance; // Squared distance traveled (relative to
  106. // source) at this point in time.
  107. } TargetInfo;
  108. ///////////////////////////////////////////////////////////////////////////
  109. // Con/Destruction.
  110. ///////////////////////////////////////////////////////////////////////////
  111. public:
  112. CBulletFest()
  113. {
  114. m_u16IdTarget = CIdBank::IdNil;
  115. m_sCurTracerPos = 0;
  116. }
  117. ~CBulletFest()
  118. {
  119. }
  120. ///////////////////////////////////////////////////////////////////////////
  121. // Methods.
  122. ///////////////////////////////////////////////////////////////////////////
  123. public:
  124. // Update current targeting information. This will function will
  125. // continually track the position of a target in order to determine
  126. // how much it is moving. The idea being that targets that move
  127. // irratically(sp?) and more often are harder to hit.
  128. void UpdateTarget( // Returns nothing.
  129. short sAngle, // In: Angle of aim in degrees (on X/Z plane).
  130. short sX, // In: Aim position.
  131. short sY, // In: Aim position.
  132. short sZ, // In: Aim position.
  133. CRealm* pRealm); // In: Realm in which to target.
  134. // Launch a bullet, create a muzzle flare at the src (sX, sY, sZ), and,
  135. // if no CThing hit, create a ricochet or impact where the bullet
  136. // contacted terrain (*psX, *psY, *psZ).
  137. // This same process can be done in pieces with more control to the user
  138. // by calling Fire(), Flare(), Ricochet(), and Impact().
  139. bool FireDeluxe( // Returns what and as Fire() would.
  140. short sAngleY, // In: Angle of launch in degrees (on X/Z plane).
  141. short sAngleZ, // In: Angle of launch in degrees (on X/Y plane).
  142. short sX, // In: Launch position.
  143. short sY, // In: Launch position.
  144. short sZ, // In: Launch position.
  145. short sRange, // In: Maximum distance.
  146. CRealm* pRealm, // In: Realm in which to fire.
  147. CSmash::Bits bitsInclude, // In: Mask of CSmash masks that this bullet can hit.
  148. CSmash::Bits bitsDontCare, // In: Mask of CSmash masks that this bullet does not care to hit.
  149. CSmash::Bits bitsExclude, // In: Mask of CSmash masks that this bullet cannot hit.
  150. short sMaxRicochetAngle, // In: Maximum angle with terrain that can cause
  151. // a ricochet (on X/Z plane).
  152. short sMaxRicochets, // In: The maximum number of ricochets.
  153. short* psX, // Out: Hit position.
  154. short* psY, // Out: Hit position.
  155. short* psZ, // Out: Hit position.
  156. CThing** ppthing, // Out: Ptr to thing hit or NULL.
  157. bool bTracer = true, // In: Draw a tracer at random point along path.
  158. SampleMasterID smid = g_smidBulletFire); // In: Use ammo sample.
  159. // Launch a bullet.
  160. bool Fire( // Returns true if a hit, false otherwise.
  161. short sAngleY, // In: Angle of launch in degrees (on X/Z plane).
  162. short sAngleZ, // In: Angle of launch in degrees (on X/Y plane).
  163. short sX, // In: Launch position.
  164. short sY, // In: Launch position.
  165. short sZ, // In: Launch position.
  166. short sRange, // In: Maximum distance.
  167. CRealm* pRealm, // In: Realm in which to fire.
  168. CSmash::Bits bitsInclude, // In: Mask of CSmash masks that this bullet can hit.
  169. CSmash::Bits bitsDontCare, // In: Mask of CSmash masks that this bullet does not care to hit.
  170. CSmash::Bits bitsExclude, // In: Mask of CSmash masks that this bullet cannot hit.
  171. short* psX, // Out: Hit position.
  172. short* psY, // Out: Hit position.
  173. short* psZ, // Out: Hit position.
  174. CThing** ppthing, // Out: Ptr to thing hit or NULL.
  175. bool bTracer = true); // In: Draw a tracer at random point along path.
  176. // Create a muzzle flare effect.
  177. void Flare( // Returns nothing.
  178. short sAngle, // In: Angle of launch in degrees (on X/Z plane).
  179. short sX, // In: Launch position.
  180. short sY, // In: Launch position.
  181. short sZ, // In: Launch position.
  182. CRealm* pRealm, // In: Realm in which to fire.
  183. SampleMasterID smid = g_smidBulletFire); // In: Use ammo sample.
  184. // Create a impact effect.
  185. void Impact( // Returns nothing.
  186. short sAngle, // In: Angle of launch in degrees (on X/Z plane).
  187. short sX, // In: Launch position.
  188. short sY, // In: Launch position.
  189. short sZ, // In: Launch position.
  190. CRealm* pRealm); // In: Realm in which to fire.
  191. // Create a ricochet effect.
  192. void Ricochet( // Returns nothing.
  193. short sAngle, // In: Angle of launch in degrees (on X/Z plane).
  194. short sX, // In: Launch position.
  195. short sY, // In: Launch position.
  196. short sZ, // In: Launch position.
  197. CRealm* pRealm); // In: Realm in which to fire.
  198. // Updates the static tracer color.
  199. static void UpdateTracerColor(
  200. CRealm* prealm); // In: Calling realm.
  201. // Preload any assets that may be used.
  202. static short Preload(
  203. CRealm* prealm); // In: Calling realm.
  204. ///////////////////////////////////////////////////////////////////////////
  205. // Querries.
  206. ///////////////////////////////////////////////////////////////////////////
  207. public:
  208. ///////////////////////////////////////////////////////////////////////////
  209. // Instantiable data.
  210. ///////////////////////////////////////////////////////////////////////////
  211. public:
  212. short m_sCurTracerPos; // Cummulative tracer position to give the look
  213. // of 'forward' movement.
  214. // Target info. ***NYI***
  215. U16 m_u16IdTarget; // Last known target or IdNil.
  216. short m_sDirChanges; // Direction changes (relative to source) over
  217. // last targeting duration.
  218. long m_lSqrDistance; // Squared distance traveled (relative to
  219. // source) over last targeting duration.
  220. RQueue<TargetInfo, TargetUpdatesPerPeriod> m_qtiHistory;
  221. TargetInfo m_ati; // Array of target info used for history queue.
  222. ///////////////////////////////////////////////////////////////////////////
  223. // Static data.
  224. ///////////////////////////////////////////////////////////////////////////
  225. static U8 ms_u8TracerIndex; // The color index to use for tracers.
  226. // This value is gotten only once per
  227. // execution of this program.
  228. public:
  229. };
  230. #endif // BULLETFEST_H
  231. //////////////////////////////////////////////////////////////////////////////
  232. // EOF
  233. //////////////////////////////////////////////////////////////////////////////