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.

270 lines
10 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #if GAME_DLL
  8. #include "achievementmgr.h"
  9. #include "baseachievement.h"
  10. CAchievementMgr g_AchievementMgrHL2; // global achievement mgr for HL2
  11. class CAchievementHL2KillBarnaclesWithOneBarrel : public CBaseAchievement
  12. {
  13. protected:
  14. virtual void Init()
  15. {
  16. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  17. SetInflictorFilter( "prop_physics" );
  18. SetVictimFilter( "npc_barnacle" );
  19. SetGoal( 1 );
  20. m_pLastInflictor = NULL;
  21. m_iBarnacleCount = 0;
  22. }
  23. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  24. {
  25. int iDamageBits = event->GetInt( "damagebits" );
  26. // only interested blast damage. (Barrels or other explosive phys objects are all OK)
  27. if ( !( iDamageBits & DMG_BLAST ) )
  28. return;
  29. if ( m_pLastInflictor != NULL && pInflictor != m_pLastInflictor )
  30. {
  31. m_iBarnacleCount = 1;
  32. }
  33. else
  34. {
  35. m_iBarnacleCount++;
  36. if ( 5 == m_iBarnacleCount )
  37. {
  38. IncrementCount();
  39. }
  40. }
  41. m_pLastInflictor = pInflictor;
  42. }
  43. CBaseEntity *m_pLastInflictor;
  44. int m_iBarnacleCount;
  45. };
  46. DECLARE_ACHIEVEMENT( CAchievementHL2KillBarnaclesWithOneBarrel, ACHIEVEMENT_HL2_KILL_BARNACLESWITHBARREL, "HL2_KILL_BARNACLESWITHBARREL", 5 );
  47. extern int CalcPlayerAttacks( bool bBulletOnly );
  48. class CAchievementHL2BeatRavenholmNoWeapons : public CFailableAchievement
  49. {
  50. DECLARE_CLASS( CAchievementHL2BeatRavenholmNoWeapons, CFailableAchievement );
  51. void Init()
  52. {
  53. SetFlags( ACH_LISTEN_MAP_EVENTS | ACH_SAVE_WITH_GAME );
  54. SetGoal( 1 );
  55. m_iInitialAttackCount = 0;
  56. }
  57. // map event where achievement is activated
  58. virtual const char *GetActivationEventName() { return "HL2_BEAT_RAVENHOLM_NOWEAPONS_START"; }
  59. // map event where achievement is evaluated for success
  60. virtual const char *GetEvaluationEventName() { return "HL2_BEAT_RAVENHOLM_NOWEAPONS_END"; }
  61. virtual void PreRestoreSavedGame()
  62. {
  63. m_iInitialAttackCount = 0;
  64. BaseClass::PreRestoreSavedGame();
  65. }
  66. virtual void OnActivationEvent()
  67. {
  68. // get current # of attacks by player w/all weapons (except grav gun) and store that
  69. m_iInitialAttackCount = CalcPlayerAttacks( false );
  70. BaseClass::OnActivationEvent();
  71. }
  72. virtual void OnEvaluationEvent()
  73. {
  74. // get current # of attacks by player w/all weapons (except grav gun)
  75. int iCurAttackCount = CalcPlayerAttacks( false );
  76. // compare to # of attacks when we started
  77. if ( iCurAttackCount > m_iInitialAttackCount )
  78. {
  79. // if there have been any more weapon attacks, achievement fails
  80. SetFailed();
  81. }
  82. BaseClass::OnEvaluationEvent();
  83. }
  84. // additional status for debugging
  85. virtual void PrintAdditionalStatus()
  86. {
  87. if ( m_bActivated )
  88. {
  89. Msg( "Starting wpn attacks: %d Current wpn attacks: %d\n", m_iInitialAttackCount, CalcPlayerAttacks( false ) );
  90. }
  91. }
  92. int m_iInitialAttackCount;
  93. public:
  94. DECLARE_DATADESC()
  95. };
  96. DECLARE_ACHIEVEMENT( CAchievementHL2BeatRavenholmNoWeapons, ACHIEVEMENT_HL2_BEAT_RAVENHOLM_NOWEAPONS, "HL2_BEAT_RAVENHOLM_NOWEAPONS", 25 );
  97. BEGIN_DATADESC( CAchievementHL2BeatRavenholmNoWeapons )
  98. DEFINE_FIELD( m_iInitialAttackCount, FIELD_INTEGER ),
  99. END_DATADESC()
  100. class CAchievementHL2KillGunships : public CBaseAchievement
  101. {
  102. void Init()
  103. {
  104. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  105. SetVictimFilter( "npc_combinegunship" );
  106. SetGoal( 6 ); // note: goal is really six, although #define is "THREEGUNSHIPS"
  107. }
  108. };
  109. DECLARE_ACHIEVEMENT( CAchievementHL2KillGunships, ACHIEVEMENT_HL2_KILL_THREEGUNSHIPS, "HL2_KILL_THREEGUNSHIPS", 5 );
  110. class CAchievementHL2KillEnemiesWithAntlions : public CBaseAchievement
  111. {
  112. void Init()
  113. {
  114. SetFlags( ACH_LISTEN_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  115. SetInflictorFilter( "npc_antlion" );
  116. SetGoal( 50 );
  117. }
  118. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  119. {
  120. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  121. if ( pPlayer )
  122. {
  123. // Only count antlion kills once player owns bugbait.
  124. if ( pPlayer->Weapon_OwnsThisType( "weapon_bugbait" ) )
  125. {
  126. IncrementCount();
  127. }
  128. }
  129. }
  130. };
  131. DECLARE_ACHIEVEMENT( CAchievementHL2KillEnemiesWithAntlions, ACHIEVEMENT_HL2_KILL_ENEMIES_WITHANTLIONS, "HL2_KILL_ENEMIES_WITHANTLIONS", 10 );
  132. class CAchievementHL2KillEnemyWithToilet : public CBaseAchievement
  133. {
  134. void Init()
  135. {
  136. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_WITH_GAME );
  137. SetInflictorFilter( "prop_physics" );
  138. SetGoal( 1 );
  139. }
  140. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  141. {
  142. const char *pszName = GetModelName( pInflictor );
  143. // skip past any directories and get just the file name
  144. pszName = V_UnqualifiedFileName( pszName );
  145. // if model name matches one of the toilets, this counts
  146. if ( ( 0 == Q_stricmp( pszName, "FurnitureToilet001a.mdl" ) ) || ( 0 == Q_stricmp( pszName, "prison_toilet01.mdl" ) ) )
  147. {
  148. IncrementCount();
  149. }
  150. }
  151. };
  152. DECLARE_ACHIEVEMENT( CAchievementHL2KillEnemyWithToilet, ACHIEVEMENT_HL2_KILL_ENEMY_WITHTOILET, "HL2_KILL_ENEMY_WITHTOILET", 5 );
  153. class CAchievementHL2DisintegrateSoldiersInField : public CBaseAchievement
  154. {
  155. void Init()
  156. {
  157. SetFlags( ACH_SAVE_WITH_GAME );
  158. SetGoal( 15 );
  159. }
  160. virtual void ListenForEvents()
  161. {
  162. ListenForGameEvent( "ragdoll_dissolved" );
  163. }
  164. void FireGameEvent_Internal( IGameEvent *event )
  165. {
  166. if ( 0 == Q_strcmp( event->GetName(), "ragdoll_dissolved" ) )
  167. {
  168. CBaseEntity *pRagdoll = UTIL_EntityByIndex( event->GetInt( "entindex", 0 ) );
  169. if ( pRagdoll )
  170. {
  171. const char *pszName = GetModelName( pRagdoll );
  172. // skip past any directories and get just the file name
  173. pszName = V_UnqualifiedFileName( pszName );
  174. if ( ( 0 == Q_stricmp( pszName, "combine_soldier.mdl" ) ) ||
  175. ( 0 == Q_stricmp( pszName, "combine_super_soldier.mdl" ) ) )
  176. {
  177. IncrementCount();
  178. }
  179. }
  180. }
  181. }
  182. };
  183. DECLARE_ACHIEVEMENT( CAchievementHL2DisintegrateSoldiersInField, ACHIEVEMENT_HL2_DISINTEGRATE_SOLDIERSINFIELD, "HL2_DISINTEGRATE_SOLDIERSINFIELD", 10 );
  184. class CAchievementHL2FindAllLambdas : public CBaseAchievement
  185. {
  186. virtual void Init()
  187. {
  188. static const char *szComponents[] =
  189. {
  190. "HL2_LAMDACACHE_KLEINERSLAB", "HL2_LAMDACACHE_CANALSSTATION", "HL2_LAMDACACHE_VENTCRAWL", "HL2_LAMDACACHE_CANALSTUNNEL",
  191. "HL2_LAMDACACHE_SEWERGRATE", "HL2_LAMDACACHE_STEAMPIPE", "HL2_LAMDACACHE_CURVEDROOM", "HL2_LAMDACACHE_SHANTYTOWN",
  192. "HL2_LAMDACACHE_TUNNELLADDER", "HL2_LAMDACACHE_REDBARN", "HL2_LAMDACACHE_ZOMBIEAMBUSH", "HL2_LAMDACACHE_BELOWAPCS",
  193. "HL2_LAMDACACHE_COUNTERWEIGHT", "HL2_LAMDACACHE_RAILWAYBRIDGE", "HL2_LAMDACACHE_TUNNELPLATFORMS", "HL2_LAMDACACHE_BANKEDCANAL",
  194. "HL2_LAMDACACHE_CANALWALL", "HL2_LAMDACACHE_CHANNELSPLIT", "HL2_LAMDACACHE_BMEDOCK", "HL2_LAMDACACHE_GENERATORS",
  195. "HL2_LAMDACACHE_CARCRUSHERARENA", "HL2_LAMDACACHE_RAVENHOLMATTIC", "HL2_LAMDACACHE_MINETUNNELEXIT",
  196. "HL2_LAMDACACHE_COASTSHACK", "HL2_LAMDACACHE_POISONSHACK", "HL2_LAMDACACHE_GUNSHIPVAN", "HL2_LAMDACACHE_SUICIDECITIZEN",
  197. "HL2_LAMDACACHE_RAILROADSHACK", "HL2_LAMDACACHE_COASTABOVEBATTERY", "HL2_LAMDACACHE_SANDSHACK", "HL2_LAMDACACHE_GMANCACHE",
  198. "HL2_LAMDACACHE_CELLCACHE", "HL2_LAMDACACHE_POISONLAUNDRY", "HL2_LAMDACACHE_SODAMACHINE",
  199. "HL2_LAMDACACHE_STREETWARDOGWALL", "HL2_LAMDACACHE_STREETWARSHACK", "HL2_LAMDACACHE_STREETWARFENCE", "HL2_LAMDACACHE_FREEWAYTUNNEL", "HL2_LAMDACACHE_DRAWBRIDGE",
  200. "HL2_LAMDACACHE_PLAZAFENCE", "HL2_LAMDACACHE_SEWERSCATWALKS", "HL2_LAMDACACHE_POISONZOMBIEALCOVE", "HL2_LAMDACACHE_PIPEHOPTUNNEL",
  201. "HL2_LAMDACACHE_ENDOFC1712B", "HL2_LAMDACACHE_EXITCATWALK"
  202. };
  203. SetFlags( ACH_HAS_COMPONENTS | ACH_LISTEN_COMPONENT_EVENTS | ACH_SAVE_GLOBAL );
  204. m_pszComponentNames = szComponents;
  205. m_iNumComponents = ARRAYSIZE( szComponents );
  206. SetComponentPrefix( "HL2_LAMDACACHE" );
  207. SetGoal( m_iNumComponents );
  208. }
  209. };
  210. DECLARE_ACHIEVEMENT( CAchievementHL2FindAllLambdas, ACHIEVEMENT_HL2_FIND_ALLLAMBDAS, "HL2_FIND_ALLLAMBDAS", 15 );
  211. // achievements which are won by a map event firing once
  212. DECLARE_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_HL2_HIT_CANCOP_WITHCAN, "HL2_HIT_CANCOP_WITHCAN", 5 );
  213. DECLARE_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_HL2_PUT_CANINTRASH, "HL2_PUT_CANINTRASH", 5 );
  214. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_ESCAPE_APARTMENTRAID, "HL2_ESCAPE_APARTMENTRAID", 5 );
  215. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_BREAK_MINITELEPORTER, "HL2_BREAK_MINITELEPORTER", 5 );
  216. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_GET_CROWBAR, "HL2_GET_CROWBAR", 5 );
  217. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_GET_AIRBOAT, "HL2_GET_AIRBOAT", 5 );
  218. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_GET_AIRBOATGUN, "HL2_GET_AIRBOATGUN", 5 );
  219. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_FIND_VORTIGAUNTCAVE, "HL2_FIND_VORTIGAUNTCAVE", 13 );
  220. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_KILL_CHOPPER, "HL2_KILL_CHOPPER", 10 );
  221. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_FIND_HEVFACEPLATE, "HL2_FIND_HEVFACEPLATE", 10 );
  222. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_GET_GRAVITYGUN, "HL2_GET_GRAVITYGUN", 5 );
  223. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_MAKEABASKET, "HL2_MAKEABASKET", 2 );
  224. DECLARE_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_HL2_BEAT_CEMETERY, "HL2_BEAT_CEMETERY", 5 );
  225. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_KILL_ENEMIES_WITHCRANE, "HL2_KILL_ENEMIES_WITHCRANE", 5 );
  226. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_PIN_SOLDIER_TOBILLBOARD, "HL2_PIN_SOLDIER_TOBILLBOARD", 5 );
  227. DECLARE_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_HL2_KILL_ODESSAGUNSHIP, "HL2_KILL_ODESSAGUNSHIP", 5 );
  228. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_BEAT_DONTTOUCHSAND, "HL2_BEAT_DONTTOUCHSAND", 20 );
  229. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_BEAT_TURRETSTANDOFF2, "HL2_BEAT_TURRETSTANDOFF2", 10 );
  230. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_FOLLOW_FREEMAN, "HL2_FOLLOWFREEMAN", 10 );
  231. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_BEAT_TOXICTUNNEL, "HL2_BEAT_TOXICTUNNEL", 5 );
  232. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_BEAT_PLAZASTANDOFF, "HL2_BEAT_PLAZASTANDOFF", 10 );
  233. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_KILL_ALLC1709SNIPERS, "HL2_KILL_ALLC1709SNIPERS", 5 );
  234. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_BEAT_SUPRESSIONDEVICE, "HL2_BEAT_SUPRESSIONDEVICE", 10 );
  235. DECLARE_MAP_EVENT_ACHIEVEMENT( ACHIEVEMENT_HL2_BEAT_C1713STRIDERSTANDOFF, "HL2_BEAT_C1713STRIDERSTANDOFF", 10 );
  236. DECLARE_MAP_EVENT_ACHIEVEMENT_HIDDEN( ACHIEVEMENT_HL2_BEAT_GAME, "HL2_BEAT_GAME", 25 );
  237. #endif // GAME_DLL