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.

81 lines
2.4 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Shared code for cs teams
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "cs_team_shared.h"
  8. #include "gametypes.h"
  9. #include "cs_gamerules.h"
  10. #if defined ( CLIENT_DLL )
  11. #include "c_cs_team.h"
  12. #define CCSTeam C_CSTeam
  13. #define CBasePlayer C_BasePlayer
  14. #else
  15. #include "cs_team.h"
  16. #endif
  17. bool IsAssassinationQuest( uint32 questID )
  18. {
  19. CEconQuestDefinition *pQuest = GetItemSchema()->GetQuestDefinition( questID );
  20. if ( pQuest && V_stristr( pQuest->GetQuestExpression(), "act_kill_target" ) )
  21. return true;
  22. return false;
  23. }
  24. // Checks basic conditions for a quest (mapgroup, mode, etc) to see if a quest is possible to complete
  25. bool Helper_CheckQuestMapAndMode( const CEconQuestDefinition *pQuest )
  26. {
  27. const char *szMapName = NULL;
  28. const char *szMapGroupName = NULL;
  29. #if defined ( CLIENT_DLL )
  30. szMapName = engine->GetLevelNameShort();
  31. szMapGroupName = engine->GetMapGroupName();
  32. #else
  33. szMapName = V_UnqualifiedFileName( STRING( gpGlobals->mapname ) );
  34. szMapGroupName = STRING( gpGlobals->mapGroupName );
  35. #endif
  36. // Wrong map
  37. if ( !StringIsEmpty( pQuest->GetMap() ) && V_strcmp( szMapName, pQuest->GetMap() ) )
  38. return false;
  39. // Unless the map group is named after our map (so queued for a single map) also confirm we're using the right map group
  40. if ( V_strcmp( szMapGroupName, CFmtStr( "mg_%s", szMapName ) ) )
  41. {
  42. if ( !StringIsEmpty( pQuest->GetMapGroup() ) && V_strcmp( szMapGroupName, pQuest->GetMapGroup() ) )
  43. {
  44. return false;
  45. }
  46. }
  47. const char *szCurrentModeAsString = g_pGameTypes->GetGameModeFromInt( g_pGameTypes->GetCurrentGameType(), g_pGameTypes->GetCurrentGameMode() );
  48. // Mode doesn't match
  49. if ( V_strcmp( pQuest->GetGameMode(), szCurrentModeAsString ) )
  50. return false;
  51. return true;
  52. }
  53. bool IsAssassinationQuestActive( const CEconQuestDefinition *pQuest )
  54. {
  55. if ( CSGameRules() && CSGameRules()->IsWarmupPeriod() )
  56. return false;
  57. // We need to have an active quest with the 'act_kill_target' requirement
  58. if ( !pQuest || !V_stristr( pQuest->GetQuestExpression(), "act_kill_target" ) )
  59. return false;
  60. // Validate target team
  61. if ( pQuest->GetTargetTeam() != TEAM_TERRORIST && pQuest->GetTargetTeam() != TEAM_CT )
  62. return false;
  63. if ( !Helper_CheckQuestMapAndMode( pQuest ) )
  64. return false;
  65. return true;
  66. }