Allow bots to switch to knife or pistol + less useless reloads

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6322 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lucas GAUTHERON
2011-04-24 19:11:10 +00:00
parent 3712231df3
commit 6eeafb0695
3 changed files with 25 additions and 12 deletions
+3 -3
View File
@@ -21,10 +21,10 @@ weaponinfo_s WeaponInfoTable[MAX_WEAPONS] =
// ---- Type : -- minDD -- maxDD -- minFD -- maxFD -- mA
{ TYPE_MELEE, 0.0f, 2.0f, 0.0f, 3.5f, 1 }, // KNIFE
{ TYPE_NORMAL, 0.0f, 20.0f, 0.0f, 50.0f, 6 }, // PISTOL
{ TYPE_SNIPER, 20.0f, 80.0f, 5.0f, 180.0f, 2 }, // RIFLE // min and max FD just guesstimates for now
{ TYPE_SNIPER, 20.0f, 80.0f, 2.5f, 180.0f, 2 }, // RIFLE // min and max FD just guesstimates for now
{ TYPE_SHOTGUN, 0.0f, 15.0f, 0.0f, 40.0f, 3 }, // SHOTGUN
{ TYPE_AUTO, 0.0f, 25.0f, 0.0f, 60.0f, 10 }, // SUBGUN
{ TYPE_SNIPER, 23.0f, 75.0f, 20.0f, 200.0f, 3 }, // SNIPER
{ TYPE_SNIPER, 23.0f, 75.0f, 10.0f, 200.0f, 3 }, // SNIPER
{ TYPE_AUTO, 20.0f, 80.0f, 0.0f, 150.0f, 6 }, // ASSAULT
{ TYPE_AUTO, 0.0f, 0.0f, 0.0f, 0.0f, 6 }, // CPISTOL
{ TYPE_GRENADE, 30.0f, 25.0f, 0.0f, 50.0f, 1 }, // GRENADE
@@ -59,7 +59,7 @@ bool CACBot::ChoosePreferredWeapon()
if((flDist >= WeaponInfoTable[i].flMinDesiredDistance) &&
(flDist <= WeaponInfoTable[i].flMaxDesiredDistance))
{
if(WeaponInfoTable[i].eWeaponType == TYPE_MELEE) sWeaponScore += 5;
if(WeaponInfoTable[i].eWeaponType == TYPE_MELEE) sWeaponScore += 20;
}
if ((flDist > WeaponInfoTable[i].flMinFireDistance) && // inside the range, continue to evaluate
+5 -1
View File
@@ -284,9 +284,13 @@ float CBot::GetDistance(entity *e)
bool CBot::SelectGun(int Gun)
{
if(m_pMyEnt->weaponsel->reloading) return false;
if(m_pMyEnt->weaponsel->reloading || m_pMyEnt->weaponchanging) return false;
if (m_pMyEnt->gunselect != Gun) audiomgr.playsound(S_GUNCHANGE, m_pMyEnt);
m_pMyEnt->gunselect = Gun;
if(m_pMyEnt->weaponsel->type != Gun)
{
m_pMyEnt->weaponswitch(m_pMyEnt->weapons[Gun]);
}
return true;
}
+17 -8
View File
@@ -618,19 +618,17 @@ bool CBot::HuntEnemy(void)
void CBot::CheckWeaponSwitch()
{
if(m_pMyEnt->nextweaponsel == NULL) m_pMyEnt->weaponchanging = 0;
if(!m_pMyEnt->weaponchanging) return;
int timeprogress = lastmillis-m_pMyEnt->weaponchanging;
if(timeprogress>weapon::weaponchangetime)
{
m_pMyEnt->prevweaponsel = m_pMyEnt->weaponsel;
m_pMyEnt->weaponsel = m_pMyEnt->nextweaponsel;
if(m_pMyEnt->weaponsel!=NULL) addmsg(SV_WEAPCHANGE, "ri", m_pMyEnt->weaponsel->type); // 2011jan17:ft: message possibly not needed in a local game!?!
m_pMyEnt->weaponchanging = 0;
}
else if(timeprogress>(weapon::weaponchangetime>>1) && m_pMyEnt->weaponsel != m_pMyEnt->nextweaponsel)
{
m_pMyEnt->prevweaponsel = m_pMyEnt->weaponsel;
if(m_pMyEnt->nextweaponsel==NULL) m_pMyEnt->weaponsel = m_pMyEnt->weaponsel; // just keep using this weapon - next spawn will assign a new random weapon!
else m_pMyEnt->weaponsel = m_pMyEnt->nextweaponsel;
}
}
void CBot::ShootEnemy()
@@ -717,14 +715,23 @@ bool CBot::ChoosePreferredWeapon()
{
// If no ammo for this weapon, skip it
if (m_pMyEnt->ammo[i] == 0) continue;
sWeaponScore = 5; // Minimal score for a weapon
// Minimal score for a weapon
sWeaponScore = 5;
// advantage for primary weapons
sWeaponScore += i > 1 ? 5 : 0;
if ((flDist >= WeaponInfoTable[i].flMinDesiredDistance) &&
(flDist <= WeaponInfoTable[i].flMaxDesiredDistance))
{
// In desired range for this weapon
sWeaponScore += 5; // Increase score much
if(WeaponInfoTable[i].eWeaponType == TYPE_MELEE) sWeaponScore += 20; // knife is a powerful weapon
// pistol & knife are better with sniper-like weapons as primary
if((i == GUN_PISTOL || WeaponInfoTable[i].eWeaponType == TYPE_MELEE) && WeaponInfoTable[m_pMyEnt->primary].eWeaponType == TYPE_SNIPER)
{
sWeaponScore += 5;
}
}
else if ((flDist < WeaponInfoTable[i].flMinFireDistance) ||
(flDist > WeaponInfoTable[i].flMaxFireDistance))
@@ -788,6 +795,8 @@ int CBot::GetShootDelay()
void CBot::CheckReload() // reload gun if no enemies are around
{
if(m_pMyEnt->enemy) return;
// do not try to reload if not needed
if(m_pMyEnt->mag[m_pMyEnt->primary] >= WeaponInfoTable[m_pMyEnt->primary].sMinDesiredAmmo) return;
SelectGun(m_pMyEnt->primary);
tryreload(m_pMyEnt);
return;