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.

163 lines
3.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "triggers.h"
  8. #include "cs_player.h"
  9. #include "cs_team.h"
  10. //======================================
  11. // Buy zone
  12. //
  13. //
  14. extern ConVar mp_logdetail;
  15. class CBuyZone : public CBaseTrigger
  16. {
  17. public:
  18. DECLARE_CLASS( CBuyZone, CBaseTrigger );
  19. DECLARE_DATADESC();
  20. CBuyZone();
  21. void Spawn();
  22. void EXPORT BuyZoneTouch( CBaseEntity* pOther );
  23. void InputSetTeam_TerroristOnly( inputdata_t& inputdata );
  24. void InputSetTeam_CTOnly( inputdata_t& inputdata );
  25. void InputSetTeam_AllTeams( inputdata_t& inputdata );
  26. void InputSetTeam_None( inputdata_t& inputdata );
  27. // CBaseTrigger override
  28. virtual void EndTouch( CBaseEntity *pOther ) OVERRIDE;
  29. public:
  30. int m_LegacyTeamNum;
  31. };
  32. LINK_ENTITY_TO_CLASS( func_buyzone, CBuyZone );
  33. BEGIN_DATADESC( CBuyZone )
  34. DEFINE_FUNCTION( BuyZoneTouch ),
  35. // This is here to support maps that haven't updated to using "teamnum" yet.
  36. DEFINE_INPUT( m_LegacyTeamNum, FIELD_INTEGER, "team" ),
  37. DEFINE_INPUTFUNC( FIELD_VOID, "SetTeam_TerroristOnly", InputSetTeam_TerroristOnly ),
  38. DEFINE_INPUTFUNC( FIELD_VOID, "SetTeam_CTOnly", InputSetTeam_CTOnly ),
  39. DEFINE_INPUTFUNC( FIELD_VOID, "SetTeam_AllTeams", InputSetTeam_AllTeams ),
  40. DEFINE_INPUTFUNC( FIELD_VOID, "SetTeam_None", InputSetTeam_None )
  41. END_DATADESC()
  42. CBuyZone::CBuyZone()
  43. {
  44. m_LegacyTeamNum = -1;
  45. }
  46. void CBuyZone::Spawn()
  47. {
  48. InitTrigger();
  49. SetTouch( &CBuyZone::BuyZoneTouch );
  50. // Support for legacy-style teamnums.
  51. if ( m_LegacyTeamNum == 1 )
  52. {
  53. ChangeTeam( TEAM_TERRORIST );
  54. }
  55. else if ( m_LegacyTeamNum == 2 )
  56. {
  57. ChangeTeam( TEAM_CT );
  58. }
  59. }
  60. void CBuyZone::BuyZoneTouch( CBaseEntity* pOther )
  61. {
  62. CCSPlayer *p = dynamic_cast< CCSPlayer* >( pOther );
  63. if ( p )
  64. {
  65. int nZoneTeam = GetTeamNumber();
  66. if ( nZoneTeam == -1 )
  67. {
  68. // -1 mean no team can use it
  69. return;
  70. }
  71. // compare player team with buy zone team number
  72. else if ( nZoneTeam == 0 || p->GetTeamNumber() == GetTeamNumber() )
  73. {
  74. p->m_bInBuyZone = true;
  75. p->AutoBuyAmmo();
  76. }
  77. }
  78. }
  79. void CBuyZone::InputSetTeam_TerroristOnly( inputdata_t& inputdata )
  80. {
  81. ChangeTeam( TEAM_TERRORIST );
  82. }
  83. void CBuyZone::InputSetTeam_CTOnly( inputdata_t& inputdata )
  84. {
  85. ChangeTeam( TEAM_CT );
  86. }
  87. void CBuyZone::InputSetTeam_AllTeams( inputdata_t& inputdata )
  88. {
  89. // team 0 in this case means that everyone can use it
  90. ChangeTeam( 0 );
  91. }
  92. void CBuyZone::InputSetTeam_None( inputdata_t& inputdata )
  93. {
  94. // team -1 means that no one can use it
  95. ChangeTeam( -1 );
  96. }
  97. void CBuyZone::EndTouch( CBaseEntity *pOther )
  98. {
  99. BaseClass::EndTouch( pOther );
  100. // Feature mostly for tournament organizers to aid match stat log parsing.
  101. if ( mp_logdetail.GetInt() >= 3 && pOther->IsPlayer() )
  102. {
  103. if ( CCSPlayer *pCSPlayer = ToCSPlayer( pOther ) )
  104. {
  105. CUtlString strEquipment( "[ ");
  106. for ( int i = 0; i < MAX_WEAPONS; ++i )
  107. {
  108. if ( CBaseCombatWeapon* pWeapon = pCSPlayer->GetWeapon( i ) )
  109. strEquipment.Append( CFmtStr( "%s ", pWeapon->GetEconItemView() ? pWeapon->GetEconItemView()->GetItemDefinition()->GetDefinitionName() : pWeapon->GetName() ).Get() );
  110. }
  111. if ( pCSPlayer->HasDefuser() )
  112. strEquipment.Append( "defuser " );
  113. if ( pCSPlayer->ArmorValue() > 0 )
  114. strEquipment.Append( CFmtStr( "kevlar(%d) ", pCSPlayer->ArmorValue() ).Get() );
  115. if ( pCSPlayer->m_bHasHelmet )
  116. strEquipment.Append( "helmet " );
  117. if ( pCSPlayer->HasC4() )
  118. strEquipment.Append( "C4 " );
  119. strEquipment.Append( "]" );
  120. UTIL_LogPrintf( "\"%s<%i><%s><%s>\" left buyzone with %s\n",
  121. pCSPlayer->GetPlayerName(),
  122. pCSPlayer->GetUserID(),
  123. pCSPlayer->GetNetworkIDString(),
  124. pCSPlayer->GetTeam()->GetName(),
  125. strEquipment.Get() );
  126. }
  127. }
  128. }