summaryrefslogtreecommitdiff
path: root/game/shared/cstrike/cs_blackmarket.cpp
blob: f68e98826bc13cb8e189c3cf07b38477e76316c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//

#include "cbase.h"
#include "cs_gamerules.h"
#include "cs_blackmarket.h"
#include "weapon_csbase.h"
#include "filesystem.h"
#include <KeyValues.h>
#include "cs_gamestats.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

extern int g_iRoundCount;

#ifndef CLIENT_DLL
inline void CBlackMarketElement::NetworkStateChanged()
{
}


inline void CBlackMarketElement::NetworkStateChanged( void *pVar )
{
}

blackmarket_items_t blackmarket_items[] =
{
	{ "kevlar",	KEVLAR_PRICE },
	{ "assaultsuit",	ASSAULTSUIT_PRICE },
	{ "nightvision", NVG_PRICE },
};


CUtlVector<CBlackMarketElement> g_BlackMarket_WeaponsBought;

void TrackAutoBuyPurchases( const char *pWeaponName, CCSPlayer *pBuyer )
{
	if ( pBuyer->IsInAutoBuy() == false )
		return;

	if ( pBuyer->IsInAutoBuy() == true )
	{
		if ( Q_stristr( pWeaponName, "m4a1" ) )
		{
			g_iAutoBuyM4A1Purchases++;
		}
		else if ( Q_stristr( pWeaponName, "ak47" ) )
		{
			g_iAutoBuyAK47Purchases++;
		}
		else if ( Q_stristr( pWeaponName, "famas" ) )
		{
			g_iAutoBuyFamasPurchases++;
		}
		else if ( Q_stristr( pWeaponName, "galil" ) )
		{
			g_iAutoBuyGalilPurchases++;
		}
		else if ( Q_stristr( pWeaponName, "assault" ) )
		{
			g_iAutoBuyVestHelmPurchases++;
		}
		else if ( Q_stristr( pWeaponName, "kevlar" ) )
		{
			g_iAutoBuyVestPurchases++;
		}
	}
}

void BlackMarketAddWeapon( const char *pWeaponName, CCSPlayer *pBuyer )
{
	//Ignore bot purchases.
	if ( pBuyer && pBuyer->IsBot() )
		return;

	CSWeaponID iWeaponID = AliasToWeaponID( pWeaponName );

	TrackAutoBuyPurchases( pWeaponName, pBuyer );

	if ( g_BlackMarket_WeaponsBought.Count() > 0 )
	{
		for ( int i = 0; i < g_BlackMarket_WeaponsBought.Count(); i++ )
		{
			if ( g_BlackMarket_WeaponsBought[i].m_iWeaponID == iWeaponID )
			{
				g_BlackMarket_WeaponsBought[i].m_iTimesBought++;
				g_iWeaponPurchases[g_BlackMarket_WeaponsBought[i].m_iWeaponID]++;
				return;
			}
		}
	}

	CBlackMarketElement newweapon;

	newweapon.m_iWeaponID = iWeaponID;
	newweapon.m_iTimesBought = 1;
	newweapon.m_iPrice = 0;
	g_iWeaponPurchases[newweapon.m_iWeaponID] = 1;

	g_BlackMarket_WeaponsBought.AddToTail( newweapon );
}

int GetPistolCount( void )
{
	int iNumPistol = 0;

	for ( int j = 1; j < WEAPON_MAX; j++ )
	{
		CCSWeaponInfo *pWeaponInfo = GetWeaponInfo( (CSWeaponID)j );

		if ( pWeaponInfo )
		{
			if ( pWeaponInfo->m_WeaponType == WEAPONTYPE_PISTOL )
			{
				iNumPistol++;
			}
		}
	}

	return iNumPistol;
}

int GetRifleCount( void )
{
	int iNumRifle = 0;

	for ( int j = 1; j < WEAPON_MAX; j++ )
	{
		CCSWeaponInfo *pWeaponInfo = GetWeaponInfo( (CSWeaponID)j );

		if ( pWeaponInfo )
		{
			if ( pWeaponInfo->m_WeaponType != WEAPONTYPE_PISTOL )
			{
				iNumRifle++;
			}
		}
	}

	return iNumRifle + ARRAYSIZE( blackmarket_items );
}

#endif