View Single Post
an idea of selecting weapons to buy
Old
  (#1)
Whistler
Summoner
 
Whistler's Avatar
 
Status: Offline
Posts: 1,499
Join Date: Feb 2004
Location: Mist Village
Default an idea of selecting weapons to buy - 26-12-2004

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 iEmotionint iMoneyint iTeamint iType)
{
   
int iPersonality 1// personality: 0 - defensive, 1 - normal, 2 - aggressive

   
int iRandom RandomLong(0100); // 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)
         
= &defensive_t;
      else if (
iPersonality == 1)
         
= &normal_t;
      else
         
= &aggressive_t;
   } else {
      if (
iPersonality == 0)
         
= &defensive_ct;
      else if (
iPersonality == 1)
         
= &normal_ct;
      else
         
= &aggressive_ct;
   }

   
int iSize p->size();
   
std::vector<intchosen// weapons which has been chosen

   
for (int i 0iSizei++) {
      
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(100200))
         continue; 
// skip this weapon if not

      
if ((iType == && (UtilCS::WeaponIsPrimary(iId) || iId == CS_WEAPON_SHIELDGUN)) ||
         (
iType == && 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(1pow(10flFactor)));
   return 
chosen[(int)((float)(chosen.size() - 1) * flFactor 0.5)];

  
Reply With Quote