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.

904 lines
23 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #ifdef CLIENT_DLL
  8. #include "achievementmgr.h"
  9. #include "baseachievement.h"
  10. #include "c_dod_player.h"
  11. #include "dod_shareddefs.h"
  12. #include "c_dod_objective_resource.h"
  13. #include "dod_gamerules.h"
  14. CAchievementMgr g_AchievementMgrDOD; // global achievement mgr for DOD
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Query if the gamerules allows achievement progress at this time
  17. //-----------------------------------------------------------------------------
  18. bool GameRulesAllowsAchievements( void )
  19. {
  20. return ( DODGameRules()->State_Get() == STATE_RND_RUNNING );
  21. }
  22. class CAchievementDODThrowBackGren : public CBaseAchievement
  23. {
  24. void Init()
  25. {
  26. // listen for player kill enemy events, base class will increment count each time that happens
  27. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL );
  28. SetGoal( 1 );
  29. }
  30. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  31. {
  32. if ( !GameRulesAllowsAchievements() )
  33. return;
  34. C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();
  35. if ( pAttacker == pLocalPlayer && pVictim->GetTeamNumber() != pAttacker->GetTeamNumber() )
  36. {
  37. // if we are allies and killed with a german grenade
  38. // or if we are axis and killed with a us grenade
  39. const char *killedwith = event->GetString( "weapon" );
  40. int iLocalTeam = pLocalPlayer->GetTeamNumber();
  41. if ( ( iLocalTeam == TEAM_ALLIES && ( FStrEq( killedwith, "frag_ger" ) || FStrEq( killedwith, "riflegren_ger" ) ) ) ||
  42. ( iLocalTeam == TEAM_AXIS && ( FStrEq( killedwith, "frag_us" ) || FStrEq( killedwith, "riflegren_us" ) ) ) )
  43. {
  44. // This kill was made with an enemy grenade.
  45. IncrementCount();
  46. }
  47. }
  48. }
  49. };
  50. DECLARE_ACHIEVEMENT( CAchievementDODThrowBackGren, ACHIEVEMENT_DOD_THROW_BACK_GREN, "DOD_THROW_BACK_GREN", 1 );
  51. class CAchievementDODConsecutiveHeadshots : public CBaseAchievement
  52. {
  53. void Init()
  54. {
  55. SetFlags( ACH_SAVE_GLOBAL );
  56. SetGoal( 1 );
  57. // Handled on server
  58. }
  59. };
  60. DECLARE_ACHIEVEMENT( CAchievementDODConsecutiveHeadshots, ACHIEVEMENT_DOD_CONSECUTIVE_HEADSHOTS, "DOD_CONSECUTIVE_HEADSHOTS", 1 );
  61. class CAchievementDODMGPositionStreak : public CBaseAchievement
  62. {
  63. void Init()
  64. {
  65. SetFlags( ACH_SAVE_GLOBAL );
  66. SetGoal( 1 );
  67. // Handled on server
  68. }
  69. };
  70. DECLARE_ACHIEVEMENT( CAchievementDODMGPositionStreak, ACHIEVEMENT_DOD_MG_POSITION_STREAK, "DOD_MG_POSITION_STREAK", 1 );
  71. class CAchievementDODWinKnifeFight : public CBaseAchievement
  72. {
  73. void Init()
  74. {
  75. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL );
  76. SetGoal( 1 );
  77. }
  78. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  79. {
  80. if ( !GameRulesAllowsAchievements() )
  81. return;
  82. C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();
  83. if ( pAttacker == pLocalPlayer && pVictim->GetTeamNumber() != pAttacker->GetTeamNumber() )
  84. {
  85. const char *killedwith = event->GetString( "weapon" );
  86. if ( FStrEq( killedwith, "amerknife" ) || FStrEq( killedwith, "spade" ) )
  87. {
  88. C_DODPlayer *pDodVictim = ToDODPlayer( pVictim );
  89. if ( pDodVictim )
  90. {
  91. CWeaponDODBase *pWpn = pDodVictim->GetActiveDODWeapon();
  92. if ( pWpn && pWpn->GetDODWpnData().m_WeaponType == WPN_TYPE_MELEE )
  93. {
  94. // Kill was made with a melee weapon, killer had melee weapon out
  95. IncrementCount();
  96. }
  97. }
  98. }
  99. }
  100. }
  101. };
  102. DECLARE_ACHIEVEMENT( CAchievementDODWinKnifeFight, ACHIEVEMENT_DOD_WIN_KNIFE_FIGHT, "DOD_WIN_KNIFE_FIGHT", 1 );
  103. const char *pszOfficialMaps[] =
  104. {
  105. "dod_anzio",
  106. "dod_avalanche",
  107. "dod_argentan",
  108. "dod_colmar",
  109. "dod_donner",
  110. "dod_flash",
  111. "dod_jagd",
  112. "dod_kalt",
  113. "dod_palermo"
  114. };
  115. class CAchievementDODCustomMaps : public CBaseAchievement
  116. {
  117. // Requires a player to kill at least one player on 5 different non-official maps
  118. void Init()
  119. {
  120. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL );
  121. SetGoal( 5 );
  122. SetStoreProgressInSteam( true );
  123. m_bCheckedCurrentMap = false;
  124. }
  125. virtual void ListenForEvents()
  126. {
  127. // hax, this is called from LevelInitPreEntity, init per-level here
  128. m_bCheckedCurrentMap = false;
  129. }
  130. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  131. {
  132. if ( m_bCheckedCurrentMap )
  133. return;
  134. // don't store the map name if we're not going to give achievement progress
  135. if ( m_pAchievementMgr->WereCheatsEverOn() )
  136. return;
  137. C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();
  138. if ( pAttacker == pLocalPlayer && pVictim->GetTeamNumber() != pAttacker->GetTeamNumber() )
  139. {
  140. char szMap[MAX_PATH];
  141. Q_FileBase( engine->GetLevelName(), szMap, ARRAYSIZE( szMap ) );
  142. if ( !IsOfficialMap( szMap ) && !HasPlayedThisCustomMap() )
  143. {
  144. IncrementCount();
  145. UTIL_IncrementMapKey( "killed_a_player" );
  146. }
  147. // stop listening
  148. m_bCheckedCurrentMap = true;
  149. }
  150. }
  151. bool HasPlayedThisCustomMap( void )
  152. {
  153. return ( UTIL_GetMapKeyCount( "killed_a_player" ) > 0 );
  154. }
  155. bool IsOfficialMap( const char *pszMapName )
  156. {
  157. bool bFound = false;
  158. for ( int i=0;i<ARRAYSIZE(pszOfficialMaps);i++ )
  159. {
  160. if ( FStrEq( pszMapName, pszOfficialMaps[i] ) )
  161. {
  162. bFound = true;
  163. break;
  164. }
  165. }
  166. return bFound;
  167. }
  168. bool m_bCheckedCurrentMap;
  169. };
  170. DECLARE_ACHIEVEMENT( CAchievementDODCustomMaps, ACHIEVEMENT_DOD_PLAY_CUSTOM_MAPS, "DOD_PLAY_CUSTOM_MAPS", 1 );
  171. class CAchievementDODKillsWithGrenade : public CBaseAchievement
  172. {
  173. void Init()
  174. {
  175. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL );
  176. SetGoal( 1 );
  177. }
  178. virtual void ListenForEvents()
  179. {
  180. // hax, this is called from LevelInitPreEntity, init per-level here
  181. m_flLastKillTime = 0;
  182. m_iKillCount = 0;
  183. }
  184. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  185. {
  186. if ( !GameRulesAllowsAchievements() )
  187. return;
  188. C_DODPlayer *pLocalPlayer = C_DODPlayer::GetLocalDODPlayer();
  189. if ( pAttacker == pLocalPlayer )
  190. {
  191. // reject non-grenade/non-rocket inflictors
  192. const char *killedwith = event->GetString( "weapon" );
  193. if ( Q_strncmp( killedwith, "frag_", 5 ) &&
  194. Q_strncmp( killedwith, "riflegren_", 10 ) &&
  195. !FStrEq( killedwith, "pschreck" ) &&
  196. !FStrEq( killedwith, "bazooka" ) )
  197. {
  198. m_flLastKillTime = 0;
  199. return;
  200. }
  201. if ( ( gpGlobals->curtime - m_flLastKillTime ) > 0.25 )
  202. {
  203. m_iKillCount = 0;
  204. }
  205. m_iKillCount++;
  206. m_flLastKillTime = gpGlobals->curtime;
  207. if ( m_iKillCount == 4 )
  208. {
  209. IncrementCount();
  210. }
  211. }
  212. }
  213. private:
  214. float m_flLastKillTime;
  215. int m_iKillCount;
  216. };
  217. DECLARE_ACHIEVEMENT( CAchievementDODKillsWithGrenade, ACHIEVEMENT_DOD_KILLS_WITH_GRENADE, "DOD_KILLS_WITH_GRENADE", 1 );
  218. class CAchievementDODLongRangeRocket : public CBaseAchievement
  219. {
  220. void Init()
  221. {
  222. SetFlags( ACH_SAVE_GLOBAL );
  223. SetGoal( 1 );
  224. // Handled on server
  225. }
  226. };
  227. DECLARE_ACHIEVEMENT( CAchievementDODLongRangeRocket, ACHIEVEMENT_DOD_LONG_RANGE_ROCKET, "DOD_LONG_RANGE_ROCKET", 1 );
  228. class CAchievementDODEndRoundKills : public CBaseAchievement
  229. {
  230. void Init()
  231. {
  232. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL );
  233. SetGoal( 1 );
  234. m_iKillCount = 0;
  235. }
  236. virtual void ListenForEvents()
  237. {
  238. ListenForGameEvent( "player_spawn" );
  239. }
  240. // Reset the count when we spawn
  241. void FireGameEvent_Internal( IGameEvent *event )
  242. {
  243. if ( m_iKillCount > 0 && 0 == Q_strcmp( event->GetName(), "player_spawn" ) && C_BasePlayer::GetLocalPlayer() )
  244. {
  245. int iUserID = event->GetInt("userid");
  246. if ( iUserID == C_BasePlayer::GetLocalPlayer()->GetUserID() )
  247. {
  248. m_iKillCount = 0;
  249. }
  250. }
  251. }
  252. // count kills in endround. No requirement that your team must have won the round - grenades count
  253. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  254. {
  255. DODRoundState state = DODGameRules()->State_Get();
  256. if ( state == STATE_ALLIES_WIN || state == STATE_AXIS_WIN )
  257. {
  258. Assert( pAttacker == C_BasePlayer::GetLocalPlayer() );
  259. if ( pVictim->GetTeamNumber() != pAttacker->GetTeamNumber() )
  260. {
  261. m_iKillCount++;
  262. if ( m_iKillCount > 3 )
  263. {
  264. IncrementCount();
  265. }
  266. }
  267. }
  268. }
  269. int m_iKillCount;
  270. };
  271. DECLARE_ACHIEVEMENT( CAchievementDODEndRoundKills, ACHIEVEMENT_DOD_END_ROUND_KILLS, "DOD_END_ROUND_KILLS", 1 );
  272. class CAchievementDODCapLastFlag : public CBaseAchievement
  273. {
  274. void Init()
  275. {
  276. SetFlags( ACH_SAVE_GLOBAL );
  277. SetGoal( 1 );
  278. // handled on server
  279. }
  280. };
  281. DECLARE_ACHIEVEMENT( CAchievementDODCapLastFlag, ACHIEVEMENT_DOD_CAP_LAST_FLAG, "DOD_CAP_LAST_FLAG", 1 );
  282. class CAchievementDODUseEnemyWeapons : public CBaseAchievement
  283. {
  284. void Init()
  285. {
  286. SetFlags( ACH_SAVE_GLOBAL );
  287. SetGoal( 1 );
  288. }
  289. // Handled on server
  290. };
  291. DECLARE_ACHIEVEMENT( CAchievementDODUseEnemyWeapons, ACHIEVEMENT_DOD_USE_ENEMY_WEAPONS, "DOD_USE_ENEMY_WEAPONS", 1 );
  292. class CAchievementDODKillDominatingMG : public CBaseAchievement
  293. {
  294. void Init()
  295. {
  296. SetFlags( ACH_SAVE_GLOBAL );
  297. SetGoal( 1 );
  298. // Handled on server
  299. }
  300. };
  301. DECLARE_ACHIEVEMENT( CAchievementDODKillDominatingMG, ACHIEVEMENT_DOD_KILL_DOMINATING_MG, "DOD_KILL_DOMINATING_MG", 1 );
  302. class CAchievementDODColmarDefense : public CBaseAchievement
  303. {
  304. void Init()
  305. {
  306. SetFlags( ACH_SAVE_GLOBAL );
  307. SetGoal( 1 );
  308. // Handled on server
  309. }
  310. };
  311. DECLARE_ACHIEVEMENT( CAchievementDODColmarDefense, ACHIEVEMENT_DOD_COLMAR_DEFENSE, "DOD_COLMAR_DEFENSE", 1 );
  312. class CAchievementDODJagdOvertimeCap : public CBaseAchievement
  313. {
  314. void Init()
  315. {
  316. SetFlags( ACH_SAVE_GLOBAL );
  317. SetGoal( 1 );
  318. // Handled on server
  319. }
  320. };
  321. DECLARE_ACHIEVEMENT( CAchievementDODJagdOvertimeCap, ACHIEVEMENT_DOD_JAGD_OVERTIME_CAP, "DOD_JAGD_OVERTIME_CAP", 1 );
  322. class CAchievementDODWeaponMastery : public CBaseAchievement
  323. {
  324. void Init()
  325. {
  326. SetFlags( ACH_SAVE_GLOBAL );
  327. SetGoal( 1 );
  328. // Handled on server
  329. }
  330. };
  331. DECLARE_ACHIEVEMENT( CAchievementDODWeaponMastery, ACHIEVEMENT_DOD_WEAPON_MASTERY, "DOD_WEAPON_MASTERY", 1 );
  332. class CAchievementDODBlockCaptures : public CBaseAchievement
  333. {
  334. void Init()
  335. {
  336. SetFlags( ACH_SAVE_GLOBAL );
  337. SetGoal( 1 );
  338. }
  339. virtual void ListenForEvents()
  340. {
  341. ListenForGameEvent( "dod_capture_blocked" );
  342. }
  343. // New achievement rule - block a capture that would have lost the game for your team
  344. void FireGameEvent_Internal( IGameEvent *event )
  345. {
  346. if ( !GameRulesAllowsAchievements() )
  347. return;
  348. Assert( FStrEq( event->GetName(), "dod_capture_blocked" ) );
  349. // was a blocked defuse or plant, don't count
  350. if ( event->GetBool("bomb") )
  351. return;
  352. if ( !g_pObjectiveResource )
  353. return;
  354. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  355. if ( pPlayer && pPlayer->entindex() == event->GetInt("blocker") )
  356. {
  357. int iCP = event->GetInt( "cp" );
  358. bool bIsLastOwnedPoint = true;
  359. int iPlayerTeam = pPlayer->GetTeamNumber();
  360. for( int i=0;i<g_pObjectiveResource->GetNumControlPoints();i++ )
  361. {
  362. // assume we own the one we blocked
  363. if ( i == iCP )
  364. continue;
  365. // if we find any other points owned by us that aren't hidden, this wasn't the last point
  366. if( !g_pObjectiveResource->IsCPVisible(i) )
  367. continue;
  368. if ( g_pObjectiveResource->GetOwningTeam(i) == iPlayerTeam )
  369. {
  370. bIsLastOwnedPoint = false;
  371. break;
  372. }
  373. }
  374. if ( bIsLastOwnedPoint )
  375. {
  376. IncrementCount();
  377. }
  378. }
  379. }
  380. };
  381. DECLARE_ACHIEVEMENT( CAchievementDODBlockCaptures, ACHIEVEMENT_DOD_BLOCK_CAPTURES, "DOD_BLOCK_CAPTURES", 1 );
  382. // achievements part deux
  383. // kills as allies
  384. // kills as axis
  385. class CBaseAchievementKillsOnTeam : public CBaseAchievement
  386. {
  387. void Init()
  388. {
  389. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL );
  390. SetGoal( 5000 );
  391. SetStoreProgressInSteam( true );
  392. }
  393. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  394. {
  395. Assert( pAttacker == C_BasePlayer::GetLocalPlayer() );
  396. if ( pVictim->GetTeamNumber() != pAttacker->GetTeamNumber() )
  397. {
  398. if ( pAttacker->GetTeamNumber() == GetTeam() )
  399. {
  400. IncrementCount();
  401. }
  402. }
  403. }
  404. virtual int GetTeam( void ) = 0;
  405. };
  406. class CAchievementKillsAsAllies : public CBaseAchievementKillsOnTeam
  407. {
  408. virtual int GetTeam( void ) { return TEAM_ALLIES; }
  409. };
  410. DECLARE_ACHIEVEMENT( CAchievementKillsAsAllies, ACHIEVEMENT_DOD_KILLS_AS_ALLIES, "DOD_KILLS_AS_ALLIES", 1 );
  411. class CAchievementKillsAsAxis : public CBaseAchievementKillsOnTeam
  412. {
  413. virtual int GetTeam( void ) { return TEAM_AXIS; }
  414. };
  415. DECLARE_ACHIEVEMENT( CAchievementKillsAsAxis, ACHIEVEMENT_DOD_KILLS_AS_AXIS, "DOD_KILLS_AS_AXIS", 1 );
  416. // rifleman
  417. // assault
  418. // support
  419. // sniper
  420. // mg
  421. // bazooka
  422. class CBaseAchievementKillsAsClass : public CBaseAchievement
  423. {
  424. void Init()
  425. {
  426. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL );
  427. SetGoal( 1000 );
  428. SetStoreProgressInSteam( true );
  429. }
  430. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  431. {
  432. Assert( pAttacker == C_BasePlayer::GetLocalPlayer() );
  433. if ( pVictim->GetTeamNumber() != pAttacker->GetTeamNumber() )
  434. {
  435. C_DODPlayer *pDODAttacker = ToDODPlayer( pAttacker );
  436. if ( pDODAttacker->m_Shared.PlayerClass() == GetClass() )
  437. {
  438. IncrementCount();
  439. }
  440. }
  441. }
  442. virtual int GetClass( void ) = 0;
  443. };
  444. #define DECLARE_KILLS_AS_CLASS_ACHIEVEMENT( classIndex, achievementID ) \
  445. class CAchievement_##achievementID : public CBaseAchievementKillsAsClass \
  446. { \
  447. virtual int GetClass( void ) { return classIndex; } \
  448. }; \
  449. DECLARE_ACHIEVEMENT( CAchievement_##achievementID, ACHIEVEMENT_##achievementID, #achievementID, 1 ) \
  450. DECLARE_KILLS_AS_CLASS_ACHIEVEMENT( 0, DOD_KILLS_AS_RIFLEMAN );
  451. DECLARE_KILLS_AS_CLASS_ACHIEVEMENT( 1, DOD_KILLS_AS_ASSAULT );
  452. DECLARE_KILLS_AS_CLASS_ACHIEVEMENT( 2, DOD_KILLS_AS_SUPPORT );
  453. DECLARE_KILLS_AS_CLASS_ACHIEVEMENT( 3, DOD_KILLS_AS_SNIPER );
  454. DECLARE_KILLS_AS_CLASS_ACHIEVEMENT( 4, DOD_KILLS_AS_MG );
  455. DECLARE_KILLS_AS_CLASS_ACHIEVEMENT( 5, DOD_KILLS_AS_BAZOOKAGUY );
  456. // per weapon
  457. class CBaseAchievementKillsWithWeapon : public CBaseAchievement
  458. {
  459. virtual void Event_EntityKilled( CBaseEntity *pVictim, CBaseEntity *pAttacker, CBaseEntity *pInflictor, IGameEvent *event )
  460. {
  461. Assert( pAttacker == C_BasePlayer::GetLocalPlayer() );
  462. if ( pVictim->GetTeamNumber() != pAttacker->GetTeamNumber() && event != NULL )
  463. {
  464. if ( FStrEq( event->GetString( "weapon", "" ), GetWeaponName() ) )
  465. {
  466. IncrementCount();
  467. }
  468. }
  469. }
  470. virtual const char *GetWeaponName( void ) = 0;
  471. };
  472. #define DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( weaponName, goalKills, achievementID ) \
  473. class CAchievement_##achievementID : public CBaseAchievementKillsWithWeapon \
  474. { \
  475. void Init() \
  476. { \
  477. SetFlags( ACH_LISTEN_PLAYER_KILL_ENEMY_EVENTS | ACH_SAVE_GLOBAL ); \
  478. SetGoal( goalKills ); \
  479. SetStoreProgressInSteam( true ); \
  480. } \
  481. \
  482. virtual const char *GetWeaponName( void ) { return weaponName; } \
  483. }; \
  484. DECLARE_ACHIEVEMENT( CAchievement_##achievementID, ACHIEVEMENT_##achievementID, #achievementID, 1 ) \
  485. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "garand", 500, DOD_KILLS_WITH_GARAND );
  486. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "thompson", 500, DOD_KILLS_WITH_THOMPSON );
  487. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "bar", 500, DOD_KILLS_WITH_BAR );
  488. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "spring", 500, DOD_KILLS_WITH_SPRING );
  489. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "30cal", 500, DOD_KILLS_WITH_30CAL );
  490. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "bazooka", 500, DOD_KILLS_WITH_BAZOOKA );
  491. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "k98", 500, DOD_KILLS_WITH_K98 );
  492. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "mp40", 500, DOD_KILLS_WITH_MP40 );
  493. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "mp44", 500, DOD_KILLS_WITH_MP44 );
  494. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "k98_scoped", 500, DOD_KILLS_WITH_K98SCOPED );
  495. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "mg42", 500, DOD_KILLS_WITH_MG42 );
  496. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "pschreck", 500, DOD_KILLS_WITH_PSCHRECK );
  497. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "colt", 150, DOD_KILLS_WITH_COLT );
  498. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "p38", 150, DOD_KILLS_WITH_P38 );
  499. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "c96", 150, DOD_KILLS_WITH_C96 );
  500. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "m1carbine", 150, DOD_KILLS_WITH_M1CARBINE );
  501. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "amerknife", 150, DOD_KILLS_WITH_AMERKNIFE );
  502. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "spade", 150, DOD_KILLS_WITH_SPADE );
  503. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "punch", 150, DOD_KILLS_WITH_PUNCH );
  504. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "frag_us", 250, DOD_KILLS_WITH_FRAG_US );
  505. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "frag_ger", 250, DOD_KILLS_WITH_FRAG_GER );
  506. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "riflegren_us", 250, DOD_KILLS_WITH_RIFLEGREN_US );
  507. DECLARE_KILLS_WITH_WEAPON_ACHIEVEMENT( "riflegren_ger", 250, DOD_KILLS_WITH_RIFLEGREN_GER );
  508. // flag captures
  509. class CAchievementDODFlagCaptureGrind : public CBaseAchievement
  510. {
  511. void Init()
  512. {
  513. SetFlags( ACH_SAVE_GLOBAL );
  514. SetGoal( 100 );
  515. SetStoreProgressInSteam( true );
  516. }
  517. virtual void ListenForEvents()
  518. {
  519. ListenForGameEvent( "dod_point_captured" );
  520. }
  521. void FireGameEvent_Internal( IGameEvent *event )
  522. {
  523. Assert( FStrEq( event->GetName(), "dod_point_captured" ) );
  524. if ( event->GetBool( "bomb" ) == true )
  525. return;
  526. if ( !GameRulesAllowsAchievements() )
  527. return;
  528. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  529. if ( !pPlayer )
  530. return;
  531. int iLocalPlayerIndex = pPlayer->entindex();
  532. const char *cappers = event->GetString("cappers");
  533. int len = Q_strlen(cappers);
  534. for( int i=0;i<len;i++ )
  535. {
  536. if ( iLocalPlayerIndex == (int)cappers[i] )
  537. {
  538. IncrementCount();
  539. break;
  540. }
  541. }
  542. }
  543. };
  544. DECLARE_ACHIEVEMENT( CAchievementDODFlagCaptureGrind, ACHIEVEMENT_DOD_CAPTURE_GRIND, "DOD_CAPTURE_GRIND", 1 );
  545. class CAchievementDODBlockCapturesGrind : public CBaseAchievement
  546. {
  547. void Init()
  548. {
  549. SetFlags( ACH_SAVE_GLOBAL );
  550. SetGoal( 100 );
  551. SetStoreProgressInSteam( true );
  552. }
  553. virtual void ListenForEvents()
  554. {
  555. ListenForGameEvent( "dod_capture_blocked" );
  556. }
  557. void FireGameEvent_Internal( IGameEvent *event )
  558. {
  559. if ( !GameRulesAllowsAchievements() )
  560. return;
  561. Assert( FStrEq( event->GetName(), "dod_capture_blocked" ) );
  562. if ( event->GetBool( "bomb" ) )
  563. return;
  564. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  565. if ( pPlayer && pPlayer->entindex() == event->GetInt( "blocker" ) )
  566. {
  567. IncrementCount();
  568. }
  569. }
  570. };
  571. DECLARE_ACHIEVEMENT( CAchievementDODBlockCapturesGrind, ACHIEVEMENT_DOD_BLOCK_CAPTURES_GRIND, "DOD_BLOCK_CAPTURES_GRIND", 1 );
  572. class CAchievementDODRoundsWonGrind : public CBaseAchievement
  573. {
  574. void Init()
  575. {
  576. SetFlags( ACH_SAVE_GLOBAL );
  577. SetGoal( 100 );
  578. SetStoreProgressInSteam( true );
  579. }
  580. virtual void ListenForEvents()
  581. {
  582. ListenForGameEvent( "dod_round_win" );
  583. }
  584. void FireGameEvent_Internal( IGameEvent *event )
  585. {
  586. if ( !GameRulesAllowsAchievements() )
  587. return;
  588. Assert( FStrEq( event->GetName(), "dod_round_win" ) );
  589. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  590. if ( !pPlayer )
  591. return;
  592. if ( event->GetInt( "team" ) == pPlayer->GetTeamNumber() )
  593. {
  594. IncrementCount();
  595. }
  596. }
  597. };
  598. DECLARE_ACHIEVEMENT( CAchievementDODRoundsWonGrind, ACHIEVEMENT_DOD_ROUNDS_WON_GRIND, "DOD_ROUNDS_WON_GRIND", 1 );
  599. class CAchievementDODBombsPlantedGrind : public CBaseAchievement
  600. {
  601. void Init()
  602. {
  603. SetFlags( ACH_SAVE_GLOBAL );
  604. SetGoal( 100 );
  605. SetStoreProgressInSteam( true );
  606. }
  607. virtual void ListenForEvents()
  608. {
  609. ListenForGameEvent( "dod_bomb_planted" );
  610. }
  611. void FireGameEvent_Internal( IGameEvent *event )
  612. {
  613. Assert( FStrEq( event->GetName(), "dod_bomb_planted" ) );
  614. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  615. if ( pPlayer && pPlayer->GetUserID() == event->GetInt("userid" ) )
  616. {
  617. IncrementCount();
  618. }
  619. }
  620. };
  621. DECLARE_ACHIEVEMENT( CAchievementDODBombsPlantedGrind, ACHIEVEMENT_DOD_BOMBS_PLANTED_GRIND, "DOD_BOMBS_PLANTED_GRIND", 1 );
  622. class CAchievementDODBombsDefusedGrind : public CBaseAchievement
  623. {
  624. void Init()
  625. {
  626. SetFlags( ACH_SAVE_GLOBAL );
  627. SetGoal( 100 );
  628. SetStoreProgressInSteam( true );
  629. }
  630. virtual void ListenForEvents()
  631. {
  632. ListenForGameEvent( "dod_bomb_defused" );
  633. }
  634. void FireGameEvent_Internal( IGameEvent *event )
  635. {
  636. Assert( FStrEq( event->GetName(), "dod_bomb_defused" ) );
  637. if ( event->GetInt("userid") == C_BasePlayer::GetLocalPlayer()->GetUserID() )
  638. {
  639. IncrementCount();
  640. }
  641. }
  642. };
  643. DECLARE_ACHIEVEMENT( CAchievementDODBombsDefusedGrind, ACHIEVEMENT_DOD_BOMBS_DEFUSED_GRIND, "DOD_BOMBS_DEFUSED_GRIND", 1 );
  644. //----------------------------------------------------------------------------------------------------------------
  645. class CAchievementDOD_All_Pack_1 : public CAchievement_AchievedCount
  646. {
  647. public:
  648. DECLARE_CLASS( CAchievementDOD_All_Pack_1, CAchievement_AchievedCount );
  649. void Init()
  650. {
  651. BaseClass::Init();
  652. SetAchievementsRequired( 51, 0, 51 );
  653. }
  654. // Complete all dod achievements
  655. };
  656. DECLARE_ACHIEVEMENT( CAchievementDOD_All_Pack_1, ACHIEVEMENT_DOD_ALL_PACK_1, "DOD_ALL_PACK_1", 5 );
  657. // 2011 Summer sale achievement
  658. // Win a round on each of the winter themed maps, dod_kalt and dod_colmar
  659. // player is not required to have been present at the start of the round
  660. class CAchievementDODBeatTheHeat : public CBaseAchievement
  661. {
  662. public:
  663. DECLARE_CLASS( CAchievementDODBeatTheHeat, CBaseAchievement );
  664. void Init()
  665. {
  666. SetFlags( ACH_SAVE_GLOBAL | ACH_HAS_COMPONENTS );
  667. static const char *szComponents[] =
  668. {
  669. "dod_kalt", "dod_colmar"
  670. };
  671. m_pszComponentNames = szComponents;
  672. m_iNumComponents = ARRAYSIZE( szComponents );
  673. SetGoal( m_iNumComponents );
  674. BaseClass::Init();
  675. }
  676. virtual void ListenForEvents()
  677. {
  678. ListenForGameEvent( "dod_round_win" );
  679. }
  680. void FireGameEvent_Internal( IGameEvent *event )
  681. {
  682. if ( !GameRulesAllowsAchievements() )
  683. return;
  684. Assert( FStrEq( event->GetName(), "dod_round_win" ) );
  685. C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
  686. if ( !pPlayer )
  687. return;
  688. if ( event->GetInt( "team" ) == pPlayer->GetTeamNumber() )
  689. {
  690. OnComponentEvent( m_pAchievementMgr->GetMapName() );
  691. }
  692. }
  693. };
  694. DECLARE_ACHIEVEMENT( CAchievementDODBeatTheHeat, ACHIEVEMENT_DOD_BEAT_THE_HEAT, "DOD_BEAT_THE_HEAT", 1 );
  695. // Winter 2011
  696. class CAchievementDODCollectHolidayGifts : public CBaseAchievement
  697. {
  698. void Init()
  699. {
  700. SetFlags( ACH_SAVE_GLOBAL );
  701. SetGoal( 3 );
  702. SetStoreProgressInSteam( true );
  703. }
  704. virtual void ListenForEvents()
  705. {
  706. ListenForGameEvent( "christmas_gift_grab" );
  707. }
  708. void FireGameEvent_Internal( IGameEvent *event )
  709. {
  710. // if ( !UTIL_IsHolidayActive( kHoliday_Christmas ) )
  711. // return;
  712. if ( Q_strcmp( event->GetName(), "christmas_gift_grab" ) == 0 )
  713. {
  714. int iPlayer = engine->GetPlayerForUserID( event->GetInt( "userid" ) );
  715. CBaseEntity *pPlayer = UTIL_PlayerByIndex( iPlayer );
  716. if ( pPlayer && pPlayer == C_DODPlayer::GetLocalDODPlayer() )
  717. {
  718. IncrementCount();
  719. }
  720. }
  721. }
  722. };
  723. DECLARE_ACHIEVEMENT( CAchievementDODCollectHolidayGifts, ACHIEVEMENT_DOD_COLLECT_HOLIDAY_GIFTS, "DOD_COLLECT_HOLIDAY_GIFTS", 5 );
  724. #endif // CLIENT_DLL