PHP Code:
// choose a weapon to buy and returns the weapon ID
// emotion: 0 (defensive) - 100 (aggressive)
// type: 0 - primary, 1 - secondary
int CCSBuyManager::ChooseWeapon(int iEmotion, int iMoney, int iTeam, int iType)
{
int iPersonality = 1; // personality: 0 - defensive, 1 - normal, 2 - aggressive
int iRandom = RandomLong(0, 100); // choose a random value
int delta = iRandom - iEmotion;
if (abs(delta) > 33) {
if (delta > 0) {
iPersonality = 0; // defensive
} else {
iPersonality = 2; // aggressive
}
}
std::vector<int> *p;
if (iTeam == CS_TEAM_TERRORIST) {
if (iPersonality == 0)
p = &defensive_t;
else if (iPersonality == 1)
p = &normal_t;
else
p = &aggressive_t;
} else {
if (iPersonality == 0)
p = &defensive_ct;
else if (iPersonality == 1)
p = &normal_ct;
else
p = &aggressive_ct;
}
int iSize = p->size();
std::vector<int> chosen; // weapons which has been chosen
for (int i = 0; i < iSize; i++) {
int iId = (*p)[i];
// see if this weapon can be bought
// if we're NOT using CS 1.6 and this weapon is only for CS 1.6
if (((CServerCS *)g_pServer)->GetCSVersion() == CS_VERSION_WON &&
(iId == CS_WEAPON_GALIL || iId == CS_WEAPON_FAMAS || iId == CS_WEAPON_SHIELDGUN))
continue; // skip this weapon
// are we on an assasssination map?
if (((CServerCS *)g_pServer)->GetMapType() & MAP_AS) {
// skip certain weapons which is not available on as_* maps
if (iTeam == CS_TEAM_TERRORIST) {
if (iId == CS_WEAPON_M3 || iId == CS_WEAPON_XM1014 ||
iId == CS_WEAPON_MP5NAVY || iId == CS_WEAPON_P90 ||
iId == CS_WEAPON_M249)
continue; // skip this weapon
} else {
if (iId == CS_WEAPON_AWP)
continue; // skip this weapon
}
}
cs_weapontable_s *pWeapon = get_weapon(iId);
if (!pWeapon) // check if this weapon is in our list
continue; // skip this weapon if not
// check if we have enough money
if (iMoney < pWeapon->iPrice + RandomLong(100, 200))
continue; // skip this weapon if not
if ((iType == 1 && (UtilCS::WeaponIsPrimary(iId) || iId == CS_WEAPON_SHIELDGUN)) ||
(iType == 0 && UtilCS::WeaponIsPistol(iId)))
continue; // skip this weapon
// this is a good weapon, add it to our chosen list
chosen.push_back(iId);
}
if (chosen.empty())
return 0; // no weapon is chosen, can't buy weapon
// select the weapon to buy in the table
float flFactor = (iMoney - 3000.0) / (16000 - 3000) * 3;
if (flFactor < 1)
flFactor = 1;
float f = log10(RandomFloat(1, pow(10, flFactor)));
return chosen[(int)((float)(chosen.size() - 1) * f / flFactor + 0.5)];
}