From 958c8e91d8149dd9b78145925d5adb7e272cc3dd Mon Sep 17 00:00:00 2001 From: Lucas GAUTHERON Date: Mon, 30 May 2011 17:09:34 +0000 Subject: [PATCH] allow bots scoping & headshot git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@6478 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/bot/ac_bot_ai.cpp | 6 ++---- source/src/bot/bot.cpp | 2 +- source/src/bot/bot.h | 1 + source/src/bot/bot_ai.cpp | 29 ++++++++++++++++++++++++----- source/src/weapon.cpp | 4 ++-- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/source/src/bot/ac_bot_ai.cpp b/source/src/bot/ac_bot_ai.cpp index 2aa8645d..0cdd0d74 100644 --- a/source/src/bot/ac_bot_ai.cpp +++ b/source/src/bot/ac_bot_ai.cpp @@ -21,10 +21,10 @@ weaponinfo_s WeaponInfoTable[MAX_WEAPONS] = // ---- Type : -- minDD -- maxDD -- minFD -- maxFD -- mA { TYPE_MELEE, 0.0f, 5.0f, 0.0f, 3.5f, 0 }, // KNIFE { TYPE_NORMAL, 3.5f, 15.0f, 3.0f, 60.0f, 6 }, // PISTOL - { TYPE_SNIPER, 20.0f, 80.0f, 3.0f, 180.0f, 2 }, // CARBINE // min and max FD just guesstimates for now + { TYPE_SNIPER, 15.0f, 80.0f, 3.0f, 180.0f, 2 }, // CARBINE // min and max FD just guesstimates for now { TYPE_SHOTGUN, 0.0f, 15.0f, 0.0f, 50.0f, 3 }, // SHOTGUN { TYPE_AUTO, 0.0f, 25.0f, 3.0f, 60.0f, 10 }, // SUBGUN - { TYPE_SNIPER, 15.0f, 125.0f, 3.0f, 200.0f, 3 }, // SNIPER + { TYPE_SNIPER, 10.0f, 125.0f, 3.0f, 200.0f, 3 }, // SNIPER { TYPE_AUTO, 20.0f, 80.0f, 3.0f, 150.0f, 6 }, // ASSAULT { TYPE_AUTO, 0.0f, 0.0f, 3.0f, 0.0f, 6 }, // CPISTOL { TYPE_GRENADE, 5.0f, 30.0f, 3.0f, 50.0f, 1 }, // GRENADE @@ -50,8 +50,6 @@ bool CACBot::ChoosePreferredWeapon() if (!m_pMyEnt->mag[i] && WeaponInfoTable[i].eWeaponType != TYPE_MELEE) { continue; - // If no ammo for this weapon, skip it - if(!m_pMyEnt->ammo[i]) continue; } else { diff --git a/source/src/bot/bot.cpp b/source/src/bot/bot.cpp index 14d3df00..44841131 100644 --- a/source/src/bot/bot.cpp +++ b/source/src/bot/bot.cpp @@ -220,7 +220,7 @@ float CBot::ChangeAngle(float speed, float ideal, float current) speed = diff; // just need to turn a little bit (less than max) // check if the bot is already facing the idealpitch direction... - if (diff <= 1.0f) + if (diff <= 0.5f) return ideal; if ((current >= 180) && (ideal >= 180)) diff --git a/source/src/bot/bot.h b/source/src/bot/bot.h index 0335e37c..25c25f3a 100644 --- a/source/src/bot/bot.h +++ b/source/src/bot/bot.h @@ -247,6 +247,7 @@ public: bool FindEnemy(void); void CheckReload(void); void CheckWeaponSwitch(void); // 2011jan17:ft: fix non-shooting bots + void CheckScope(void); void ShootEnemy(void); bool CheckHunt(void); bool HuntEnemy(void); diff --git a/source/src/bot/bot_ai.cpp b/source/src/bot/bot_ai.cpp index e409fa94..b681ceda 100644 --- a/source/src/bot/bot_ai.cpp +++ b/source/src/bot/bot_ai.cpp @@ -18,8 +18,8 @@ extern weaponinfo_s WeaponInfoTable[MAX_WEAPONS]; vec CBot::GetEnemyPos(playerent *d) { // Aim offset idea by botman - vec o = d->o, offset; - float flDist = GetDistance(d->o), flScale; + vec o = m_pMyEnt->weaponsel->type == GUN_SNIPER && d->head.x >= 0 ? d->head : d->o, offset; + float flDist = GetDistance(o), flScale; if (WeaponInfoTable[m_pMyEnt->gunselect].eWeaponType == TYPE_ROCKET) { @@ -751,7 +751,7 @@ int CBot::GetShootDelay() void CBot::CheckReload() // reload gun if no enemies are around { - //if(m_pMyEnt->mag[m_pMyEnt->weaponsel->type] >= WeaponInfoTable[m_pMyEnt->weaponsel->type].sMinDesiredAmmo) return; // do not reload if mindesiredammo is satisfied + if(m_pMyEnt->mag[m_pMyEnt->weaponsel->type] >= WeaponInfoTable[m_pMyEnt->weaponsel->type].sMinDesiredAmmo) return; // do not reload if mindesiredammo is satisfied if(m_pMyEnt->enemy && m_pMyEnt->mag[m_pMyEnt->weaponsel->type]) { return; // ignore the enemy, if no ammo in mag. @@ -760,6 +760,23 @@ void CBot::CheckReload() // reload gun if no enemies are around return; } +void CBot::CheckScope() +{ +#define MINSCOPEDIST 15 +#define MINSCOPETIME 1000 + if(m_pMyEnt->weaponsel->type != GUN_SNIPER) return; + sniperrifle *sniper = (sniperrifle *)m_pMyEnt->weaponsel; + if(m_pMyEnt->enemy && m_pMyEnt->o.dist(m_pMyEnt->enemy->o) > MINSCOPEDIST) + { + sniper->setscope(true); + } + else if(m_pMyEnt->scoping && lastmillis - sniper->scoped_since < MINSCOPETIME) + { + sniper->setscope(false); + } +} + + void CBot::MainAI() { // Default bots will run forward @@ -784,6 +801,7 @@ void CBot::MainAI() if (BotManager.BotsShoot() && FindEnemy()) // Combat { CheckReload(); + CheckScope(); AddDebugText("has enemy"); // Use best weapon ChoosePreferredWeapon(); @@ -802,14 +820,15 @@ void CBot::MainAI() } else if (CheckHunt() && HuntEnemy()) { - CheckReload(); + CheckReload(); + CheckScope(); AddDebugText("Hunting to %s", m_pHuntTarget->name); m_eCurrentBotState = STATE_HUNT; } // Heading to an interesting entity(ammo, armour etc) else if (CheckItems()) { - CheckReload(); + CheckReload(); AddDebugText("has ent"); m_eCurrentBotState = STATE_ENT; } diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index 30bf5528..954ad973 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -623,7 +623,7 @@ void raydamage(vec &from, vec &to, playerent *d) switch(d->weaponsel->type) { case GUN_KNIFE: gib = true; break; - case GUN_SNIPER: if(d==player1 && hitzone==2) { dam *= 3; gib = true; }; break; + case GUN_SNIPER: if(hitzone==2) { dam *= 3; gib = true; }; break; case GUN_SUBGUN: if(flag4subgunDMGalt) dam +=1; break; default: break; } @@ -1301,7 +1301,7 @@ void sniperrifle::setscope(bool enable) if(this == owner->weaponsel && !reloading && owner->state == CS_ALIVE) { if(scoped == false && enable == true) scoped_since = lastmillis; - if(player1 == owner && enable != scoped) player1->scoping = enable; + if(enable != scoped) owner->scoping = enable; scoped = enable; } }