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.

185 lines
6.7 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #ifdef GAME_DLL
  8. #include "achievementmgr.h"
  9. #include "baseachievement.h"
  10. #include "iservervehicle.h"
  11. #include "npc_antlion.h"
  12. #include "npc_hunter.h"
  13. class CAchievementEp2KillPoisonAntlion : public CBaseAchievement
  14. {
  15. protected:
  16. virtual void Init()
  17. {
  18. SetVictimFilter( "npc_antlion" );
  19. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  20. SetGameDirFilter( "ep2" );
  21. SetGoal( 1 );
  22. }
  23. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  24. {
  25. CNPC_Antlion *pAntlion = dynamic_cast<CNPC_Antlion *>( pVictim );
  26. if ( pAntlion && pAntlion->IsWorker() )
  27. {
  28. IncrementCount();
  29. }
  30. }
  31. };
  32. DECLARE_ACHIEVEMENT( CAchievementEp2KillPoisonAntlion, ACHIEVEMENT_EP2_KILL_POISONANTLION, "EP2_KILL_POISONANTLION", 5 );
  33. class CAchievementEp2KillAllGrubs : public CBaseAchievement
  34. {
  35. protected:
  36. virtual void Init()
  37. {
  38. SetVictimFilter( "npc_antlion_grub" );
  39. SetFlags( ACH_LISTEN_KILL_EVENTS | ACH_SAVE_WITH_GAME );
  40. SetGameDirFilter( "ep2" );
  41. SetGoal( 333 );
  42. }
  43. };
  44. DECLARE_ACHIEVEMENT( CAchievementEp2KillAllGrubs, ACHIEVEMENT_EP2_KILL_ALLGRUBS, "EP2_KILL_ALLGRUBS", 20 );
  45. class CAchievementEp2KillEnemiesWithCar : public CBaseAchievement
  46. {
  47. protected:
  48. virtual void Init()
  49. {
  50. SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  51. SetInflictorFilter( "prop_vehicle_jeep" );
  52. SetGameDirFilter( "ep2" );
  53. SetGoal( 20 );
  54. }
  55. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  56. {
  57. // count this if the object is a driveable vehicle and local player is driving
  58. CBasePlayer *pLocalPlayer = UTIL_GetLocalPlayer();
  59. IDrivableVehicle *pDriveableVehicle = dynamic_cast<IDrivableVehicle *>( pInflictor );
  60. if ( pLocalPlayer && pDriveableVehicle && pDriveableVehicle->GetDriver() == pLocalPlayer )
  61. {
  62. IncrementCount();
  63. }
  64. }
  65. };
  66. DECLARE_ACHIEVEMENT( CAchievementEp2KillEnemiesWithCar, ACHIEVEMENT_EP2_KILL_ENEMIES_WITHCAR, "EP2_KILL_ENEMIES_WITHCAR", 5 );
  67. class CAchievementEp2KillHunterWithFlechette : public CBaseAchievement
  68. {
  69. protected:
  70. void Init()
  71. {
  72. SetFlags( ACH_LISTEN_KILL_EVENTS | ACH_SAVE_WITH_GAME );
  73. SetVictimFilter( "npc_hunter" );
  74. SetInflictorFilter( "hunter_flechette" );
  75. SetGameDirFilter( "ep2" );
  76. SetGoal( 1 );
  77. }
  78. };
  79. DECLARE_ACHIEVEMENT( CAchievementEp2KillHunterWithFlechette, ACHIEVEMENT_EP2_KILL_HUNTER_WITHFLECHETTES, "EP2_KILL_HUNTER_WITHFLECHETTES", 10 );
  80. class CAchievementEp2FindAllWebCaches : public CBaseAchievement
  81. {
  82. virtual void Init()
  83. {
  84. static const char *szComponents[] =
  85. {
  86. "EP2_WEBCACHE_01", "EP2_WEBCACHE_02", "EP2_WEBCACHE_03", "EP2_WEBCACHE_04",
  87. "EP2_WEBCACHE_05", "EP2_WEBCACHE_06", "EP2_WEBCACHE_07", "EP2_WEBCACHE_08", "EP2_WEBCACHE_09"
  88. };
  89. SetFlags( ACH_HAS_COMPONENTS | ACH_LISTEN_COMPONENT_EVENTS | ACH_SAVE_GLOBAL );
  90. m_pszComponentNames = szComponents;
  91. m_iNumComponents = ARRAYSIZE( szComponents );
  92. SetComponentPrefix( "EP2_WEBCACHE" );
  93. SetGameDirFilter( "ep2" );
  94. SetGoal( m_iNumComponents );
  95. }
  96. // don't show progress notifications for this achievement, it's distracting
  97. virtual bool ShouldShowProgressNotification() { return false; }
  98. };
  99. DECLARE_ACHIEVEMENT( CAchievementEp2FindAllWebCaches , ACHIEVEMENT_EP2_BREAK_ALLWEBS, "EP2_BREAK_ALLWEBS", 5 );
  100. class CAchievementEp2KillChopperNoMisses: public CFailableAchievement
  101. {
  102. protected:
  103. void Init()
  104. {
  105. SetFlags( ACH_LISTEN_MAP_EVENTS | ACH_SAVE_WITH_GAME );
  106. SetGameDirFilter( "ep2" );
  107. SetGoal( 1 );
  108. }
  109. virtual void ListenForEvents()
  110. {
  111. ListenForGameEvent( "helicopter_grenade_punt_miss" );
  112. }
  113. // map event where achievement is activated
  114. virtual const char *GetActivationEventName() { return "EP2_KILL_CHOPPER_NOMISSES_START"; }
  115. // map event where achievement is evaluated for success
  116. virtual const char *GetEvaluationEventName() { return "EP2_KILL_CHOPPER_NOMISSES_END"; }
  117. void FireGameEvent_Internal( IGameEvent *event )
  118. {
  119. if ( 0 == Q_strcmp( event->GetName(), "helicopter_grenade_punt_miss" ) )
  120. {
  121. SetFailed();
  122. }
  123. }
  124. };
  125. DECLARE_ACHIEVEMENT( CAchievementEp2KillChopperNoMisses, ACHIEVEMENT_EP2_KILL_CHOPPER_NOMISSES, "EP2_KILL_CHOPPER_NOMISSES", 15 );
  126. class CAchievementEp2FindAllRadarCaches : public CBaseAchievement
  127. {
  128. virtual void Init()
  129. {
  130. static const char *szComponents[] =
  131. {
  132. "EP2_RADARCACHE_VAN", "EP2_RADARCACHE_SHACK", "EP2_RADARCACHE_RPG", "EP2_RADARCACHE_CAVE", "EP2_RADARCACHE_HANGING"
  133. };
  134. SetFlags( ACH_HAS_COMPONENTS | ACH_LISTEN_COMPONENT_EVENTS | ACH_SAVE_GLOBAL );
  135. m_pszComponentNames = szComponents;
  136. m_iNumComponents = ARRAYSIZE( szComponents );
  137. SetComponentPrefix( "EP2_RADARCACHE" );
  138. SetGameDirFilter( "ep2" );
  139. SetGoal( m_iNumComponents );
  140. }
  141. };
  142. DECLARE_ACHIEVEMENT( CAchievementEp2FindAllRadarCaches, ACHIEVEMENT_EP2_FIND_ALLRADARCACHES, "EP2_FIND_ALLRADARCACHES", 10 );
  143. // Ep2-specific macro that sets game dir filter. We need this because Ep1/Ep2/... share a binary so we need runtime check against running game.
  144. #define DECLARE_EP2_MAP_EVENT_ACHIEVEMENT( achievementID, achievementName, iPointValue ) \
  145. DECLARE_MAP_EVENT_ACHIEVEMENT_( achievementID, achievementName, "ep2", iPointValue, false )
  146. #define DECLARE_EP2_MAP_EVENT_ACHIEVEMENT_HIDDEN( achievementID, achievementName, iPointValue ) \
  147. DECLARE_MAP_EVENT_ACHIEVEMENT_( achievementID, achievementName, "ep2", iPointValue, true )
  148. // achievements which are won by a map event firing once
  149. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_EP2_BEAT_ANTLIONINVASION, "EP2_BEAT_ANTLIONINVASION", 5 );
  150. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_EP2_BEAT_ANTLIONGUARDS, "EP2_BEAT_ANTLIONGUARDS", 5 );
  151. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_EP2_BEAT_HUNTERAMBUSH, "EP2_BEAT_HUNTERAMBUSH", 10 );
  152. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_EP2_KILL_COMBINECANNON, "EP2_KILL_COMBINECANNON", 5 );
  153. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_EP2_BEAT_RACEWITHDOG, "EP2_BEAT_RACEWITHDOG", 5 );
  154. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_EP2_BEAT_ROCKETCACHEPUZZLE, "EP2_BEAT_ROCKETCACHEPUZZLE", 5 );
  155. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_EP2_BEAT_WHITEFORESTINN, "EP2_BEAT_WHITEFORESTINN", 10 );
  156. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_EP2_PUT_ITEMINROCKET, "EP2_PUT_ITEMINROCKET", 30 );
  157. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_EP2_BEAT_MISSILESILO2, "EP2_BEAT_MISSILESILO2", 5 );
  158. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_EP2_BEAT_OUTLAND12_NOBUILDINGSDESTROYED, "EP2_BEAT_OUTLAND12_NOBUILDINGSDESTROYED", 35 );
  159. DECLARE_EP2_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_EP2_BEAT_GAME, "EP2_BEAT_GAME", 20 );
  160. #endif // GAME_DLL