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.

252 lines
7.7 KiB

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