Counter Strike : Global Offensive Source Code
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.

257 lines
7.9 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #ifdef GAME_DLL
  8. // this gets compiled in for HL2 + Ep(X) only
  9. #if ( defined( HL2_DLL ) || defined( HL2_EPISODIC ) ) && ( !defined ( PORTAL ) )
  10. #include "matchmaking/imatchframework.h"
  11. #include "baseachievement.h"
  12. #include "prop_combine_ball.h"
  13. #include "combine_mine.h"
  14. #include "basegrenade_shared.h"
  15. #include "basehlcombatweapon_shared.h"
  16. #include "ammodef.h"
  17. // NOTE: This has to be the last file included!
  18. #include "tier0/memdbgon.h"
  19. class CAchievementHLXKillWithPhysicsObjects : public CBaseAchievement
  20. {
  21. void Init()
  22. {
  23. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  24. SetInflictorFilter( "prop_physics" );
  25. SetGoal( 30 );
  26. if ( IsPC() )
  27. {
  28. // only in Ep2 for PC. (Shared across HLX for X360.)
  29. SetGameDirFilter( "ep2" );
  30. }
  31. }
  32. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  33. {
  34. int iDamageBits = event->GetInt( "damagebits" );
  35. // was victim killed with crushing damage?
  36. if ( iDamageBits & DMG_CRUSH )
  37. {
  38. IncrementCount();
  39. }
  40. }
  41. };
  42. DECLARE_ACHIEVEMENT( CAchievementHLXKillWithPhysicsObjects, ACHIEVEMENT_HLX_KILL_ENEMIES_WITHPHYSICS, "HLX_KILL_ENEMIES_WITHPHYSICS", 5 );
  43. class CAchievementHLXKillWithHopper : public CBaseAchievement
  44. {
  45. void Init()
  46. {
  47. SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  48. SetAttackerFilter( "combine_mine" );
  49. SetGoal( 1 );
  50. if ( IsPC() )
  51. {
  52. // only in Ep2 for PC. (Shared across HLX for X360.)
  53. SetGameDirFilter( "ep2" );
  54. }
  55. }
  56. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  57. {
  58. // If we get here, a combine mine has killed a player enemy. Now check and see if the player planted it
  59. CBounceBomb *pBounceBomb = dynamic_cast<CBounceBomb *>( pAttacker );
  60. if ( pBounceBomb && pBounceBomb->IsPlayerPlaced() )
  61. {
  62. IncrementCount();
  63. }
  64. }
  65. };
  66. DECLARE_ACHIEVEMENT( CAchievementHLXKillWithHopper, ACHIEVEMENT_HLX_KILL_ENEMY_WITHHOPPERMINE, "HLX_KILL_ENEMY_WITHHOPPERMINE", 5 );
  67. class CAchievementHLXKillWithManhack : public CBaseAchievement
  68. {
  69. void Init()
  70. {
  71. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  72. SetInflictorFilter( "npc_manhack" );
  73. SetGoal( 5 );
  74. if ( IsPC() )
  75. {
  76. // only in HL2 for PC. (Shared across HLX for X360.)
  77. SetGameDirFilter( "hl2" );
  78. }
  79. }
  80. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  81. {
  82. // We've already filtered to only get called when a player enemy gets killed with a manhack. Now just check for the
  83. // case of player smashing manhack into something, in which case the manhack is both the victim and inflictor.
  84. // If that's not the case, this is a player kill w/manhack.
  85. if ( pVictim != pInflictor )
  86. {
  87. IncrementCount();
  88. }
  89. }
  90. };
  91. DECLARE_ACHIEVEMENT( CAchievementHLXKillWithManhack, ACHIEVEMENT_HLX_KILL_ENEMIES_WITHMANHACK, "HLX_KILL_ENEMIES_WITHMANHACK", 5 );
  92. class CAchievementHLXKillSoldierWithOwnGrenade : public CBaseAchievement
  93. {
  94. protected:
  95. void Init()
  96. {
  97. SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  98. SetInflictorFilter( "npc_grenade_frag" );
  99. SetVictimFilter( "npc_combine_s" );
  100. SetGoal( 1 );
  101. if ( IsPC() )
  102. {
  103. // only in Ep2 for PC. (Shared across HLX for X360.)
  104. SetGameDirFilter( "ep2" );
  105. }
  106. }
  107. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  108. {
  109. CBaseGrenade *pGrenade = dynamic_cast<CBaseGrenade *>( pInflictor );
  110. if ( pGrenade )
  111. {
  112. CBaseEntity *pThrower = pGrenade->GetThrower();
  113. CBaseEntity *pOriginalThrower = pGrenade->GetOriginalThrower();
  114. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  115. // check if player was most recent thrower, but the victim was the original thrower
  116. if ( ( pPlayer == pThrower ) && ( pOriginalThrower == pVictim ) )
  117. {
  118. IncrementCount();
  119. }
  120. }
  121. }
  122. };
  123. DECLARE_ACHIEVEMENT( CAchievementHLXKillSoldierWithOwnGrenade, ACHIEVEMENT_HLX_KILL_SOLDIER_WITHHISGRENADE, "HLX_KILL_SOLDIER_WITHHISGRENADE", 10 );
  124. class CAchievementHLXKillWithOneEnergyBall : public CBaseAchievement
  125. {
  126. protected:
  127. virtual void Init()
  128. {
  129. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  130. SetInflictorFilter( "prop_combine_ball" );
  131. SetGoal( 1 );
  132. m_pLastInflictor = NULL;
  133. m_iLocalCount = 0;
  134. if ( IsPC() )
  135. {
  136. // only in Ep1 for PC. (Shared across HLX for X360.)
  137. SetGameDirFilter( "episodic" );
  138. }
  139. }
  140. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  141. {
  142. // to count # of kills with same energy ball, keep track of previous inflictor
  143. if ( m_pLastInflictor != NULL && pInflictor != m_pLastInflictor )
  144. {
  145. // new inflictor, start the count over at 1
  146. m_iLocalCount = 1;
  147. }
  148. else
  149. {
  150. // same inflictor, keep counting
  151. m_iLocalCount++;
  152. if ( 5 == m_iLocalCount )
  153. {
  154. IncrementCount();
  155. }
  156. }
  157. // keep track of last inflictor
  158. m_pLastInflictor = pInflictor;
  159. }
  160. CBaseEntity *m_pLastInflictor;
  161. int m_iLocalCount;
  162. };
  163. DECLARE_ACHIEVEMENT( CAchievementHLXKillWithOneEnergyBall, ACHIEVEMENT_HLX_KILL_ENEMIES_WITHONEENERGYBALL, "HLX_KILL_ENEMIES_WITHONEENERGYBALL", 5 );
  164. class CAchievementHLXKillEliteSoldierWithOwnEnergyBall : public CBaseAchievement
  165. {
  166. protected:
  167. virtual void Init()
  168. {
  169. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  170. SetInflictorFilter( "prop_combine_ball" );
  171. SetVictimFilter( "npc_combine_s" );
  172. SetGoal( 1 );
  173. if ( IsPC() )
  174. {
  175. // only in Ep2 for PC. (Shared across HLX for X360.)
  176. SetGameDirFilter( "episodic" );
  177. }
  178. }
  179. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  180. {
  181. CPropCombineBall *pBall = dynamic_cast<CPropCombineBall *>( pInflictor );
  182. if ( pBall )
  183. {
  184. // determine original owner of this ball
  185. CBaseEntity *pOriginalOwner = pBall->GetOriginalOwner();
  186. // see if original owner is the victim
  187. if ( pOriginalOwner && ( pOriginalOwner == pVictim ) )
  188. {
  189. IncrementCount();
  190. }
  191. }
  192. }
  193. };
  194. DECLARE_ACHIEVEMENT( CAchievementHLXKillEliteSoldierWithOwnEnergyBall, ACHIEVEMENT_HLX_KILL_ELITESOLDIER_WITHHISENERGYBALL, "HLX_KILL_ELITESOLDIER_WITHHISENERGYBALL", 10 );
  195. //-----------------------------------------------------------------------------
  196. // Purpose: Counts the accumulated # of primary and secondary attacks from all
  197. // weapons (except grav gun). If bBulletOnly is true, only counts
  198. // attacks with ammo that does bullet damage.
  199. //-----------------------------------------------------------------------------
  200. int CalcPlayerAttacks( bool bBulletOnly )
  201. {
  202. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  203. CAmmoDef *pAmmoDef = GetAmmoDef();
  204. if ( !pPlayer || !pAmmoDef )
  205. return 0;
  206. int iTotalAttacks = 0;
  207. int iWeapons = pPlayer->WeaponCount();
  208. for ( int i = 0; i < iWeapons; i++ )
  209. {
  210. CBaseHLCombatWeapon *pWeapon = dynamic_cast<CBaseHLCombatWeapon *>( pPlayer->GetWeapon( i ) );
  211. if ( pWeapon )
  212. {
  213. // add primary attacks if we were asked for all attacks, or only if it uses bullet ammo if we were asked to count bullet attacks
  214. if ( !bBulletOnly || ( pAmmoDef->m_AmmoType[pWeapon->GetPrimaryAmmoType()].nDamageType == DMG_BULLET ) )
  215. {
  216. iTotalAttacks += pWeapon->m_iPrimaryAttacks;
  217. }
  218. // add secondary attacks if we were asked for all attacks, or only if it uses bullet ammo if we were asked to count bullet attacks
  219. if ( !bBulletOnly || ( pAmmoDef->m_AmmoType[pWeapon->GetSecondaryAmmoType()].nDamageType == DMG_BULLET ) )
  220. {
  221. iTotalAttacks += pWeapon->m_iSecondaryAttacks;
  222. }
  223. }
  224. }
  225. return iTotalAttacks;
  226. }
  227. #endif // ( defined( HL2_DLL ) || defined( HL2_EPISODIC ) ) && ( !defined ( PORTAL ) )
  228. #endif // GAME_DLL