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.

146 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "cs_gamerules.h"
  8. #include "cs_blackmarket.h"
  9. #include "weapon_csbase.h"
  10. #include "filesystem.h"
  11. #include <KeyValues.h>
  12. #include "cs_gamestats.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. extern int g_iRoundCount;
  16. #ifndef CLIENT_DLL
  17. inline void CBlackMarketElement::NetworkStateChanged()
  18. {
  19. }
  20. inline void CBlackMarketElement::NetworkStateChanged( void *pVar )
  21. {
  22. }
  23. blackmarket_items_t blackmarket_items[] =
  24. {
  25. { "kevlar", KEVLAR_PRICE },
  26. { "assaultsuit", ASSAULTSUIT_PRICE },
  27. { "nightvision", NVG_PRICE },
  28. };
  29. CUtlVector<CBlackMarketElement> g_BlackMarket_WeaponsBought;
  30. void TrackAutoBuyPurchases( const char *pWeaponName, CCSPlayer *pBuyer )
  31. {
  32. if ( pBuyer->IsInAutoBuy() == false )
  33. return;
  34. if ( pBuyer->IsInAutoBuy() == true )
  35. {
  36. if ( Q_stristr( pWeaponName, "m4a1" ) )
  37. {
  38. g_iAutoBuyM4A1Purchases++;
  39. }
  40. else if ( Q_stristr( pWeaponName, "ak47" ) )
  41. {
  42. g_iAutoBuyAK47Purchases++;
  43. }
  44. else if ( Q_stristr( pWeaponName, "famas" ) )
  45. {
  46. g_iAutoBuyFamasPurchases++;
  47. }
  48. else if ( Q_stristr( pWeaponName, "galil" ) )
  49. {
  50. g_iAutoBuyGalilPurchases++;
  51. }
  52. else if ( Q_stristr( pWeaponName, "assault" ) )
  53. {
  54. g_iAutoBuyVestHelmPurchases++;
  55. }
  56. else if ( Q_stristr( pWeaponName, "kevlar" ) )
  57. {
  58. g_iAutoBuyVestPurchases++;
  59. }
  60. }
  61. }
  62. void BlackMarketAddWeapon( const char *pWeaponName, CCSPlayer *pBuyer )
  63. {
  64. //Ignore bot purchases.
  65. if ( pBuyer && pBuyer->IsBot() )
  66. return;
  67. CSWeaponID iWeaponID = AliasToWeaponID( pWeaponName );
  68. TrackAutoBuyPurchases( pWeaponName, pBuyer );
  69. if ( g_BlackMarket_WeaponsBought.Count() > 0 )
  70. {
  71. for ( int i = 0; i < g_BlackMarket_WeaponsBought.Count(); i++ )
  72. {
  73. if ( g_BlackMarket_WeaponsBought[i].m_iWeaponID == iWeaponID )
  74. {
  75. g_BlackMarket_WeaponsBought[i].m_iTimesBought++;
  76. g_iWeaponPurchases[g_BlackMarket_WeaponsBought[i].m_iWeaponID]++;
  77. return;
  78. }
  79. }
  80. }
  81. CBlackMarketElement newweapon;
  82. newweapon.m_iWeaponID = iWeaponID;
  83. newweapon.m_iTimesBought = 1;
  84. newweapon.m_iPrice = 0;
  85. g_iWeaponPurchases[newweapon.m_iWeaponID] = 1;
  86. g_BlackMarket_WeaponsBought.AddToTail( newweapon );
  87. }
  88. int GetPistolCount( void )
  89. {
  90. int iNumPistol = 0;
  91. for ( int j = 1; j < WEAPON_MAX; j++ )
  92. {
  93. CCSWeaponInfo *pWeaponInfo = GetWeaponInfo( (CSWeaponID)j );
  94. if ( pWeaponInfo )
  95. {
  96. if ( pWeaponInfo->m_WeaponType == WEAPONTYPE_PISTOL )
  97. {
  98. iNumPistol++;
  99. }
  100. }
  101. }
  102. return iNumPistol;
  103. }
  104. int GetRifleCount( void )
  105. {
  106. int iNumRifle = 0;
  107. for ( int j = 1; j < WEAPON_MAX; j++ )
  108. {
  109. CCSWeaponInfo *pWeaponInfo = GetWeaponInfo( (CSWeaponID)j );
  110. if ( pWeaponInfo )
  111. {
  112. if ( pWeaponInfo->m_WeaponType != WEAPONTYPE_PISTOL )
  113. {
  114. iNumRifle++;
  115. }
  116. }
  117. }
  118. return iNumRifle + ARRAYSIZE( blackmarket_items );
  119. }
  120. #endif