Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
6.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "passtime_game_events.h"
  9. #include "igameevents.h"
  10. #include "tier0/memdbgon.h"
  11. //-----------------------------------------------------------------------------
  12. using namespace PasstimeGameEvents;
  13. //-----------------------------------------------------------------------------
  14. namespace
  15. {
  16. //-----------------------------------------------------------------------------
  17. template<class T>
  18. IGameEvent* CreateEvent()
  19. {
  20. IGameEvent *pEvent = gameeventmanager->CreateEvent( T::s_eventName );
  21. Assert( pEvent );
  22. return pEvent;
  23. }
  24. //-----------------------------------------------------------------------------
  25. template<class T>
  26. bool IsType( IGameEvent *pEvent )
  27. {
  28. return FStrEq( pEvent->GetName(), T::s_eventName );
  29. }
  30. }
  31. //-----------------------------------------------------------------------------
  32. const char *const BallGet::s_eventName = "pass_get";
  33. const char *const BallGet::s_keyOwnerIndex = "owner";
  34. BallGet::BallGet( IGameEvent *pEvent )
  35. : ownerIndex( pEvent->GetInt( s_keyOwnerIndex ) )
  36. {
  37. Assert( IsType<BallGet>( pEvent ) );
  38. }
  39. BallGet::BallGet( int ownerIndex_ )
  40. : ownerIndex( ownerIndex_ )
  41. {
  42. }
  43. void BallGet::Fire()
  44. {
  45. if ( IGameEvent *pEvent = CreateEvent<BallGet>() )
  46. {
  47. pEvent->SetInt( s_keyOwnerIndex, ownerIndex );
  48. gameeventmanager->FireEvent(pEvent);
  49. }
  50. }
  51. //-----------------------------------------------------------------------------
  52. const char *const Score::s_eventName = "pass_score";
  53. const char *const Score::s_keyScorerIndex = "scorer";
  54. const char *const Score::s_keyAssisterIndex = "assister";
  55. const char *const Score::s_keyNumPoints = "points";
  56. Score::Score( IGameEvent *pEvent )
  57. : scorerIndex( pEvent->GetInt( s_keyScorerIndex ) )
  58. , assisterIndex( pEvent->GetInt( s_keyAssisterIndex ) )
  59. , numPoints( pEvent->GetInt( s_keyNumPoints ) )
  60. {
  61. Assert( IsType<Score>( pEvent ) );
  62. }
  63. Score::Score( int scorerIndex_, int assisterIndex_, int numPoints_ )
  64. : scorerIndex( scorerIndex_ )
  65. , assisterIndex( assisterIndex_ )
  66. , numPoints( numPoints_ )
  67. {
  68. }
  69. Score::Score( int scorerIndex_, int numPoints_ )
  70. : scorerIndex( scorerIndex_ )
  71. , assisterIndex( -1 )
  72. , numPoints( numPoints_ )
  73. {
  74. }
  75. void Score::Fire()
  76. {
  77. if ( IGameEvent *pEvent = CreateEvent<Score>() )
  78. {
  79. pEvent->SetInt( s_keyScorerIndex, scorerIndex );
  80. pEvent->SetInt( s_keyAssisterIndex, assisterIndex );
  81. pEvent->SetInt( s_keyNumPoints, numPoints );
  82. gameeventmanager->FireEvent( pEvent );
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. const char *const BallFree::s_eventName = "pass_free";
  87. const char *const BallFree::s_keyOwnerIndex = "owner";
  88. const char *const BallFree::s_keyAttackerIndex = "attacker";
  89. BallFree::BallFree( IGameEvent *pEvent )
  90. : ownerIndex( pEvent->GetInt( s_keyOwnerIndex ) )
  91. , attackerIndex( pEvent->GetInt( s_keyAttackerIndex ) )
  92. {
  93. Assert( IsType<BallFree>( pEvent ) );
  94. }
  95. BallFree::BallFree()
  96. : ownerIndex( -1 )
  97. , attackerIndex( -1 )
  98. {
  99. }
  100. BallFree::BallFree( int ownerIndex_ )
  101. : ownerIndex( ownerIndex_ )
  102. , attackerIndex( -1 )
  103. {
  104. }
  105. BallFree::BallFree( int ownerIndex_, int attackerIndex_ )
  106. : ownerIndex( ownerIndex_ )
  107. , attackerIndex( attackerIndex_ )
  108. {
  109. }
  110. void BallFree::Fire()
  111. {
  112. if ( IGameEvent *pEvent = CreateEvent<BallFree>() )
  113. {
  114. pEvent->SetInt( s_keyOwnerIndex, ownerIndex );
  115. pEvent->SetInt( s_keyAttackerIndex, attackerIndex );
  116. gameeventmanager->FireEvent( pEvent );
  117. }
  118. }
  119. //-----------------------------------------------------------------------------
  120. const char *const PassCaught::s_eventName = "pass_pass_caught";
  121. const char *const PassCaught::s_keyPasserIndex = "passer";
  122. const char *const PassCaught::s_keyCatcherIndex = "catcher";
  123. const char *const PassCaught::s_keyDist = "dist";
  124. const char *const PassCaught::s_keyDuration = "duration";
  125. PassCaught::PassCaught( IGameEvent *pEvent )
  126. : passerIndex( pEvent->GetInt( s_keyPasserIndex ) )
  127. , catcherIndex( pEvent->GetInt( s_keyCatcherIndex ) )
  128. , dist( pEvent->GetFloat( s_keyDist ) )
  129. , duration( pEvent->GetFloat( s_keyDuration ) )
  130. {
  131. Assert( IsType<PassCaught>( pEvent ) );
  132. }
  133. PassCaught::PassCaught()
  134. : passerIndex( -1 )
  135. , catcherIndex( -1 )
  136. , dist( 0 )
  137. , duration( 0 )
  138. {
  139. }
  140. PassCaught::PassCaught( int passerIndex_, int catcherIndex_, float dist_, float duration_ )
  141. : passerIndex( passerIndex_ )
  142. , catcherIndex( catcherIndex_ )
  143. , dist( dist_ )
  144. , duration( duration_ )
  145. {
  146. }
  147. void PassCaught::Fire()
  148. {
  149. if ( IGameEvent *pEvent = CreateEvent<PassCaught>() )
  150. {
  151. pEvent->SetInt( s_keyPasserIndex, passerIndex );
  152. pEvent->SetInt( s_keyCatcherIndex, catcherIndex );
  153. pEvent->SetFloat( s_keyDist, dist );
  154. pEvent->SetFloat( s_keyDuration, duration );
  155. gameeventmanager->FireEvent( pEvent );
  156. }
  157. }
  158. //-----------------------------------------------------------------------------
  159. const char *const BallStolen::s_eventName = "pass_ball_stolen";
  160. const char *const BallStolen::s_keyVictimIndex = "victim";
  161. const char *const BallStolen::s_keyAttackerIndex = "attacker";
  162. BallStolen::BallStolen( IGameEvent *pEvent )
  163. : victimIndex( pEvent->GetInt( s_keyVictimIndex ) )
  164. , attackerIndex( pEvent->GetInt( s_keyAttackerIndex ) )
  165. {
  166. Assert( IsType<BallStolen>( pEvent ) );
  167. }
  168. BallStolen::BallStolen()
  169. : victimIndex( -1 )
  170. , attackerIndex( -1 )
  171. {
  172. }
  173. BallStolen::BallStolen( int victimIndex_, int attackerIndex_ )
  174. : victimIndex( victimIndex_ )
  175. , attackerIndex( attackerIndex_ )
  176. {
  177. }
  178. void BallStolen::Fire()
  179. {
  180. if ( IGameEvent *pEvent = CreateEvent<BallStolen>() )
  181. {
  182. pEvent->SetInt( s_keyVictimIndex, victimIndex );
  183. pEvent->SetInt( s_keyAttackerIndex, attackerIndex );
  184. gameeventmanager->FireEvent( pEvent );
  185. }
  186. }
  187. //-----------------------------------------------------------------------------
  188. const char *const BallBlocked::s_eventName = "pass_ball_blocked";
  189. const char *const BallBlocked::s_keyOwnerIndex = "owner";
  190. const char *const BallBlocked::s_keyBlockerIndex = "blocker";
  191. BallBlocked::BallBlocked( IGameEvent *pEvent )
  192. : ownerIndex( pEvent->GetInt( s_keyOwnerIndex ) )
  193. , blockerIndex( pEvent->GetInt( s_keyBlockerIndex ) )
  194. {
  195. Assert( IsType<BallBlocked>( pEvent ) );
  196. }
  197. BallBlocked::BallBlocked()
  198. : ownerIndex( -1 )
  199. , blockerIndex( -1 )
  200. {
  201. }
  202. BallBlocked::BallBlocked( int ownerIndex_, int blockerIndex_ )
  203. : ownerIndex( ownerIndex_ )
  204. , blockerIndex( blockerIndex_ )
  205. {
  206. }
  207. void BallBlocked::Fire()
  208. {
  209. if ( IGameEvent *pEvent = CreateEvent<BallBlocked>() )
  210. {
  211. pEvent->SetInt( s_keyOwnerIndex, ownerIndex );
  212. pEvent->SetInt( s_keyBlockerIndex, blockerIndex );
  213. gameeventmanager->FireEvent( pEvent );
  214. }
  215. }