fixes bad buying for heavy weapons & shotguns
replaced some magic numbers in code to be readable
This commit is contained in:
parent
27019f76b6
commit
9ae9ecb76a
4 changed files with 61 additions and 33 deletions
|
|
@ -63,7 +63,7 @@ enum GameFlags
|
||||||
GAME_CZERO = (1 << 2), // Counter-Strike: Condition Zero
|
GAME_CZERO = (1 << 2), // Counter-Strike: Condition Zero
|
||||||
GAME_LEGACY = (1 << 3), // Counter-Strike 1.3-1.5 with/without Steam
|
GAME_LEGACY = (1 << 3), // Counter-Strike 1.3-1.5 with/without Steam
|
||||||
GAME_MOBILITY = (1 << 4), // additional flag that bot is running on android (additional flag)
|
GAME_MOBILITY = (1 << 4), // additional flag that bot is running on android (additional flag)
|
||||||
GAME_OFFICIAL_CSBOT = (1 << 5) // additional flag that indicates offficial cs bots are ingame
|
GAME_OFFICIAL_CSBOT = (1 << 5) // additional flag that indicates official cs bots are in game
|
||||||
};
|
};
|
||||||
|
|
||||||
// log levels
|
// log levels
|
||||||
|
|
@ -74,7 +74,6 @@ enum LogLevel
|
||||||
LL_ERROR = 3, // error log message
|
LL_ERROR = 3, // error log message
|
||||||
LL_IGNORE = 4, // additional flag
|
LL_IGNORE = 4, // additional flag
|
||||||
LL_FATAL = 5 // fatal error log message (terminate the game!)
|
LL_FATAL = 5 // fatal error log message (terminate the game!)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// chat types id's
|
// chat types id's
|
||||||
|
|
@ -284,6 +283,34 @@ enum Weapon
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// buy counts
|
||||||
|
enum BuyState
|
||||||
|
{
|
||||||
|
BUYSTATE_PRIMARY_WEAPON = 0,
|
||||||
|
BUYSTATE_ARMOR_VESTHELM,
|
||||||
|
BUYSTATE_SECONDARY_WEAPON,
|
||||||
|
BUYSTATE_GRENADES,
|
||||||
|
BUYSTATE_DEFUSER,
|
||||||
|
BUYSTATE_AMMO,
|
||||||
|
BUYSTATE_FINISHED
|
||||||
|
};
|
||||||
|
|
||||||
|
// economics limits
|
||||||
|
enum EconomyLimit
|
||||||
|
{
|
||||||
|
ECO_PRIMARY_GT = 0,
|
||||||
|
ECO_SMG_GT_CT,
|
||||||
|
ECO_SMG_GT_TE,
|
||||||
|
ECO_SHOTGUN_GT,
|
||||||
|
ECO_SHOTGUN_LT,
|
||||||
|
ECO_HEAVY_GT,
|
||||||
|
ECO_HEAVY_LT,
|
||||||
|
ECO_PROSTOCK_NORMAL,
|
||||||
|
ECO_PROSTOCK_RUSHER,
|
||||||
|
ECO_PROSTOCK_CAREFUL,
|
||||||
|
ECO_SHIELDGUN_GT
|
||||||
|
};
|
||||||
|
|
||||||
// defines for pickup items
|
// defines for pickup items
|
||||||
enum PickupType
|
enum PickupType
|
||||||
{
|
{
|
||||||
|
|
@ -1153,7 +1180,7 @@ public:
|
||||||
|
|
||||||
void DisplayDebugOverlay (void);
|
void DisplayDebugOverlay (void);
|
||||||
void NewRound (void);
|
void NewRound (void);
|
||||||
void EquipInBuyzone (int buyCount);
|
void EquipInBuyzone (int buyState);
|
||||||
void PushMessageQueue (int message);
|
void PushMessageQueue (int message);
|
||||||
void PrepareChatMessage (char *text);
|
void PrepareChatMessage (char *text);
|
||||||
bool FindWaypoint (void);
|
bool FindWaypoint (void);
|
||||||
|
|
|
||||||
|
|
@ -1104,12 +1104,12 @@ void Bot::CheckMessageQueue (void)
|
||||||
|
|
||||||
// if bot buying is off then no need to buy
|
// if bot buying is off then no need to buy
|
||||||
if (!yb_botbuy.GetBool ())
|
if (!yb_botbuy.GetBool ())
|
||||||
m_buyState = 6;
|
m_buyState = BUYSTATE_FINISHED;
|
||||||
|
|
||||||
// if fun-mode no need to buy
|
// if fun-mode no need to buy
|
||||||
if (yb_jasonmode.GetBool ())
|
if (yb_jasonmode.GetBool ())
|
||||||
{
|
{
|
||||||
m_buyState = 6;
|
m_buyState = BUYSTATE_FINISHED;
|
||||||
SelectWeaponByName ("weapon_knife");
|
SelectWeaponByName ("weapon_knife");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1117,7 +1117,7 @@ void Bot::CheckMessageQueue (void)
|
||||||
if (IsPlayerVIP (GetEntity ()))
|
if (IsPlayerVIP (GetEntity ()))
|
||||||
{
|
{
|
||||||
m_isVIP = true;
|
m_isVIP = true;
|
||||||
m_buyState = 6;
|
m_buyState = BUYSTATE_FINISHED;
|
||||||
m_pathType = 0;
|
m_pathType = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1128,13 +1128,13 @@ void Bot::CheckMessageQueue (void)
|
||||||
// prevent teams from buying on fun maps
|
// prevent teams from buying on fun maps
|
||||||
if (g_mapType & (MAP_KA | MAP_FY))
|
if (g_mapType & (MAP_KA | MAP_FY))
|
||||||
{
|
{
|
||||||
m_buyState = 6;
|
m_buyState = BUYSTATE_FINISHED;
|
||||||
|
|
||||||
if (g_mapType & MAP_KA)
|
if (g_mapType & MAP_KA)
|
||||||
yb_jasonmode.SetInt (1);
|
yb_jasonmode.SetInt (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_buyState > 5)
|
if (m_buyState > BUYSTATE_FINISHED - 1)
|
||||||
{
|
{
|
||||||
m_buyingFinished = true;
|
m_buyingFinished = true;
|
||||||
return;
|
return;
|
||||||
|
|
@ -1410,13 +1410,12 @@ void Bot::PurchaseWeapons (void)
|
||||||
bool isPistolMode = g_weaponSelect[25].teamStandard == -1 && g_weaponSelect[3].teamStandard == 2;
|
bool isPistolMode = g_weaponSelect[25].teamStandard == -1 && g_weaponSelect[3].teamStandard == 2;
|
||||||
bool teamEcoValid = bots.EconomicsValid (m_team);
|
bool teamEcoValid = bots.EconomicsValid (m_team);
|
||||||
|
|
||||||
|
|
||||||
// do this, because xash engine is not capable to run all the features goldsrc, but we have cs 1.6 on it, so buy table must be the same
|
// do this, because xash engine is not capable to run all the features goldsrc, but we have cs 1.6 on it, so buy table must be the same
|
||||||
bool isOldGame = (g_gameFlags & GAME_LEGACY) && !(g_gameFlags & GAME_XASH);
|
bool isOldGame = (g_gameFlags & GAME_LEGACY) && !(g_gameFlags & GAME_XASH);
|
||||||
|
|
||||||
switch (m_buyState)
|
switch (m_buyState)
|
||||||
{
|
{
|
||||||
case 0: // if no primary weapon and bot has some money, buy a primary weapon
|
case BUYSTATE_PRIMARY_WEAPON: // if no primary weapon and bot has some money, buy a primary weapon
|
||||||
if ((!HasShield () && !HasPrimaryWeapon () && teamEcoValid) || (teamEcoValid && IsMorePowerfulWeaponCanBeBought ()))
|
if ((!HasShield () && !HasPrimaryWeapon () && teamEcoValid) || (teamEcoValid && IsMorePowerfulWeaponCanBeBought ()))
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
|
|
@ -1450,21 +1449,22 @@ void Bot::PurchaseWeapons (void)
|
||||||
if (IsRestricted (selectedWeapon->id))
|
if (IsRestricted (selectedWeapon->id))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int economicsPrice = 0;
|
int *limit = g_botBuyEconomyTable;
|
||||||
|
int prostock = 0;
|
||||||
|
|
||||||
// filter out weapons with bot economics (thanks for idea to nicebot project)
|
// filter out weapons with bot economics
|
||||||
switch (m_personality)
|
switch (m_personality)
|
||||||
{
|
{
|
||||||
case PERSONALITY_RUSHER:
|
case PERSONALITY_RUSHER:
|
||||||
economicsPrice = g_botBuyEconomyTable[8];
|
prostock = limit[ECO_PROSTOCK_RUSHER];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PERSONALITY_CAREFUL:
|
case PERSONALITY_CAREFUL:
|
||||||
economicsPrice = g_botBuyEconomyTable[7];
|
prostock = limit[ECO_PROSTOCK_CAREFUL];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PERSONALITY_NORMAL:
|
case PERSONALITY_NORMAL:
|
||||||
economicsPrice = g_botBuyEconomyTable[9];
|
prostock = limit[ECO_PROSTOCK_NORMAL];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1476,12 +1476,12 @@ void Bot::PurchaseWeapons (void)
|
||||||
case WEAPON_UMP45:
|
case WEAPON_UMP45:
|
||||||
case WEAPON_P90:
|
case WEAPON_P90:
|
||||||
case WEAPON_MP5:
|
case WEAPON_MP5:
|
||||||
if (m_moneyAmount > g_botBuyEconomyTable[1] + economicsPrice)
|
if (m_moneyAmount > limit[ECO_SMG_GT_CT] + prostock)
|
||||||
ignoreWeapon = true;
|
ignoreWeapon = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedWeapon->id == WEAPON_SHIELD && m_moneyAmount > g_botBuyEconomyTable[10])
|
if (selectedWeapon->id == WEAPON_SHIELD && m_moneyAmount > limit[ECO_SHIELDGUN_GT])
|
||||||
ignoreWeapon = true;
|
ignoreWeapon = true;
|
||||||
}
|
}
|
||||||
else if (m_team == TERRORIST)
|
else if (m_team == TERRORIST)
|
||||||
|
|
@ -1493,7 +1493,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
case WEAPON_P90:
|
case WEAPON_P90:
|
||||||
case WEAPON_MP5:
|
case WEAPON_MP5:
|
||||||
case WEAPON_SCOUT:
|
case WEAPON_SCOUT:
|
||||||
if (m_moneyAmount > g_botBuyEconomyTable[2] + economicsPrice)
|
if (m_moneyAmount > limit[ECO_SMG_GT_TE] + prostock)
|
||||||
ignoreWeapon = true;
|
ignoreWeapon = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1503,7 +1503,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
{
|
{
|
||||||
case WEAPON_XM1014:
|
case WEAPON_XM1014:
|
||||||
case WEAPON_M3:
|
case WEAPON_M3:
|
||||||
if (m_moneyAmount < g_botBuyEconomyTable[3] || m_moneyAmount > g_botBuyEconomyTable[4])
|
if (m_moneyAmount >= limit[ECO_SHOTGUN_GT] || m_moneyAmount <= limit[ECO_SHOTGUN_LT])
|
||||||
ignoreWeapon = true;
|
ignoreWeapon = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1514,7 +1514,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
case WEAPON_G3SG1:
|
case WEAPON_G3SG1:
|
||||||
case WEAPON_AWP:
|
case WEAPON_AWP:
|
||||||
case WEAPON_M249:
|
case WEAPON_M249:
|
||||||
if (m_moneyAmount < g_botBuyEconomyTable[5] || m_moneyAmount > g_botBuyEconomyTable[6])
|
if (m_moneyAmount >= limit[ECO_HEAVY_GT] || m_moneyAmount <= limit[ECO_HEAVY_LT])
|
||||||
ignoreWeapon = true;
|
ignoreWeapon = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1522,7 +1522,8 @@ void Bot::PurchaseWeapons (void)
|
||||||
if (ignoreWeapon && g_weaponSelect[25].teamStandard == 1 && yb_economics_rounds.GetBool ())
|
if (ignoreWeapon && g_weaponSelect[25].teamStandard == 1 && yb_economics_rounds.GetBool ())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int moneySave = Random.Long (900, 1100);
|
// save money for grenade for example?
|
||||||
|
int moneySave = Random.Long (300, 600);
|
||||||
|
|
||||||
if (bots.GetLastWinner () == m_team)
|
if (bots.GetLastWinner () == m_team)
|
||||||
moneySave = 0;
|
moneySave = 0;
|
||||||
|
|
@ -1574,7 +1575,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1: // if armor is damaged and bot has some money, buy some armor
|
case BUYSTATE_ARMOR_VESTHELM: // if armor is damaged and bot has some money, buy some armor
|
||||||
if (pev->armorvalue < Random.Long (50, 80) && (isPistolMode || (teamEcoValid && HasPrimaryWeapon ())))
|
if (pev->armorvalue < Random.Long (50, 80) && (isPistolMode || (teamEcoValid && HasPrimaryWeapon ())))
|
||||||
{
|
{
|
||||||
// if bot is rich, buy kevlar + helmet, else buy a single kevlar
|
// if bot is rich, buy kevlar + helmet, else buy a single kevlar
|
||||||
|
|
@ -1585,7 +1586,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: // if bot has still some money, buy a better secondary weapon
|
case BUYSTATE_SECONDARY_WEAPON: // if bot has still some money, buy a better secondary weapon
|
||||||
if (isPistolMode || (HasPrimaryWeapon () && (pev->weapons & ((1 << WEAPON_USP) | (1 << WEAPON_GLOCK))) && m_moneyAmount > Random.Long (7500, 9000)))
|
if (isPistolMode || (HasPrimaryWeapon () && (pev->weapons & ((1 << WEAPON_USP) | (1 << WEAPON_GLOCK))) && m_moneyAmount > Random.Long (7500, 9000)))
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
|
|
@ -1654,7 +1655,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3: // if bot has still some money, choose if bot should buy a grenade or not
|
case BUYSTATE_GRENADES: // if bot has still some money, choose if bot should buy a grenade or not
|
||||||
if (Random.Long (1, 100) < g_grenadeBuyPrecent[0] && m_moneyAmount >= 400 && !IsRestricted (WEAPON_EXPLOSIVE))
|
if (Random.Long (1, 100) < g_grenadeBuyPrecent[0] && m_moneyAmount >= 400 && !IsRestricted (WEAPON_EXPLOSIVE))
|
||||||
{
|
{
|
||||||
// buy a he grenade
|
// buy a he grenade
|
||||||
|
|
@ -1677,7 +1678,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4: // if bot is CT and we're on a bomb map, randomly buy the defuse kit
|
case BUYSTATE_DEFUSER: // if bot is CT and we're on a bomb map, randomly buy the defuse kit
|
||||||
if ((g_mapType & MAP_DE) && m_team == CT && Random.Long (1, 100) < 80 && m_moneyAmount > 200 && !IsRestricted (WEAPON_DEFUSER))
|
if ((g_mapType & MAP_DE) && m_team == CT && Random.Long (1, 100) < 80 && m_moneyAmount > 200 && !IsRestricted (WEAPON_DEFUSER))
|
||||||
{
|
{
|
||||||
if (isOldGame)
|
if (isOldGame)
|
||||||
|
|
@ -1687,7 +1688,7 @@ void Bot::PurchaseWeapons (void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5: // buy enough primary & secondary ammo (do not check for money here)
|
case BUYSTATE_AMMO: // buy enough primary & secondary ammo (do not check for money here)
|
||||||
for (int i = 0; i <= 5; i++)
|
for (int i = 0; i <= 5; i++)
|
||||||
FakeClientCommand (GetEntity (), "buyammo%d", Random.Long (1, 2)); // simulate human
|
FakeClientCommand (GetEntity (), "buyammo%d", Random.Long (1, 2)); // simulate human
|
||||||
|
|
||||||
|
|
@ -4481,7 +4482,7 @@ void Bot::RunTask_PickupItem ()
|
||||||
if (HasShield ()) // If we have the shield...
|
if (HasShield ()) // If we have the shield...
|
||||||
FakeClientCommand (GetEntity (), "drop"); // discard both shield and pistol
|
FakeClientCommand (GetEntity (), "drop"); // discard both shield and pistol
|
||||||
}
|
}
|
||||||
EquipInBuyzone (0);
|
EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -4493,7 +4494,7 @@ void Bot::RunTask_PickupItem ()
|
||||||
SelectWeaponbyNumber (weaponID);
|
SelectWeaponbyNumber (weaponID);
|
||||||
FakeClientCommand (GetEntity (), "drop");
|
FakeClientCommand (GetEntity (), "drop");
|
||||||
}
|
}
|
||||||
EquipInBuyzone (0);
|
EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON);
|
||||||
}
|
}
|
||||||
CheckSilencer (); // check the silencer
|
CheckSilencer (); // check the silencer
|
||||||
}
|
}
|
||||||
|
|
@ -5566,7 +5567,7 @@ void Bot::DiscardWeaponForUser (edict_t *user, bool discardC4)
|
||||||
if (m_inBuyZone)
|
if (m_inBuyZone)
|
||||||
{
|
{
|
||||||
m_buyingFinished = false;
|
m_buyingFinished = false;
|
||||||
m_buyState = 0;
|
m_buyState = BUYSTATE_PRIMARY_WEAPON;
|
||||||
|
|
||||||
PushMessageQueue (GSM_BUY_STUFF);
|
PushMessageQueue (GSM_BUY_STUFF);
|
||||||
m_nextBuyTime = GetWorldTime ();
|
m_nextBuyTime = GetWorldTime ();
|
||||||
|
|
@ -6023,7 +6024,7 @@ bool Bot::IsShootableBreakable (edict_t *ent)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bot::EquipInBuyzone (int buyCount)
|
void Bot::EquipInBuyzone (int buyState)
|
||||||
{
|
{
|
||||||
// this function is gets called when bot enters a buyzone, to allow bot to buy some stuff
|
// this function is gets called when bot enters a buyzone, to allow bot to buy some stuff
|
||||||
|
|
||||||
|
|
@ -6036,7 +6037,7 @@ void Bot::EquipInBuyzone (int buyCount)
|
||||||
if (m_seeEnemyTime + 5.0f < GetWorldTime () && m_lastEquipTime + 15.0f < GetWorldTime () && m_inBuyZone && checkBuyTime && !g_bombPlanted && m_moneyAmount > g_botBuyEconomyTable[0])
|
if (m_seeEnemyTime + 5.0f < GetWorldTime () && m_lastEquipTime + 15.0f < GetWorldTime () && m_inBuyZone && checkBuyTime && !g_bombPlanted && m_moneyAmount > g_botBuyEconomyTable[0])
|
||||||
{
|
{
|
||||||
m_buyingFinished = false;
|
m_buyingFinished = false;
|
||||||
m_buyState = buyCount;
|
m_buyState = buyState;
|
||||||
|
|
||||||
// push buy message
|
// push buy message
|
||||||
PushMessageQueue (GSM_BUY_STUFF);
|
PushMessageQueue (GSM_BUY_STUFF);
|
||||||
|
|
|
||||||
|
|
@ -1190,7 +1190,7 @@ void Bot::NewRound (void)
|
||||||
m_sayTextBuffer.entityIndex = -1;
|
m_sayTextBuffer.entityIndex = -1;
|
||||||
m_sayTextBuffer.sayText[0] = 0x0;
|
m_sayTextBuffer.sayText[0] = 0x0;
|
||||||
|
|
||||||
m_buyState = 0;
|
m_buyState = BUYSTATE_PRIMARY_WEAPON;
|
||||||
m_lastEquipTime = 0.0f;
|
m_lastEquipTime = 0.0f;
|
||||||
|
|
||||||
if (!m_notKilled) // if bot died, clear all weapon stuff and force buying again
|
if (!m_notKilled) // if bot died, clear all weapon stuff and force buying again
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ void NetworkMsg::Execute (void *p)
|
||||||
m_bot->m_inBuyZone = (enabled != 0);
|
m_bot->m_inBuyZone = (enabled != 0);
|
||||||
|
|
||||||
// try to equip in buyzone
|
// try to equip in buyzone
|
||||||
m_bot->EquipInBuyzone (0);
|
m_bot->EquipInBuyzone (BUYSTATE_PRIMARY_WEAPON);
|
||||||
}
|
}
|
||||||
else if (strcmp (PTR_TO_STR (p), "vipsafety") == 0)
|
else if (strcmp (PTR_TO_STR (p), "vipsafety") == 0)
|
||||||
m_bot->m_inVIPZone = (enabled != 0);
|
m_bot->m_inVIPZone = (enabled != 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue