Skip to content

Minor improvements to bot code #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions source/src/bot/ac_bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ weaponinfo_s WeaponInfoTable[NUMGUNS] =
};

// Code of CACBot - Start

long lastSwitchMillis = 0;
bool CACBot::ChoosePreferredWeapon()
{
if(lastmillis < m_iChangeWeaponDelay) return false;
Expand All @@ -52,6 +52,7 @@ bool CACBot::ChoosePreferredWeapon()
loopi(NUMGUNS) bestWeap[i] = 0;
// Choose a weapon
for(int i=0; i<NUMGUNS; i++)

{
sWeaponScore = primary_weap(i) ? 5 : 0; // Primary are usually better

Expand Down Expand Up @@ -131,7 +132,14 @@ bool CACBot::ChoosePreferredWeapon()
}
else bestWeapon = GUN_KNIFE;

return SelectGun(bestWeapon);
//Dont switch weapons every time
if((lastmillis -lastSwitchMillis) > 100) {
lastSwitchMillis = lastmillis;
return SelectGun(bestWeapon);
} else {
return 0;
}

};

void CACBot::Reload(int Gun)
Expand Down
24 changes: 13 additions & 11 deletions source/src/bot/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//
//
// Author: <[email protected]>
//
//


// Code of CBot - Start
Expand All @@ -18,7 +18,8 @@ extern weaponinfo_s WeaponInfoTable[NUMGUNS];
vec CBot::GetEnemyPos(playerent *d)
{
// Aim offset idea by botman
vec o = m_pMyEnt->weaponsel->type == GUN_SNIPER && d->head.x >= 0 ? d->head : d->o, offset;
// For ACR: Try to aim at the head with auto, too - rXn
vec o = (m_pMyEnt->weaponsel->type == GUN_SNIPER || m_pMyEnt->weaponsel->type == TYPE_AUTO) && d->head.x >= 0 ? d->head : d->o, offset;
float flDist = GetDistance(o), flScale;

if (WeaponInfoTable[m_pMyEnt->gunselect].eWeaponType == TYPE_ROCKET)
Expand Down Expand Up @@ -77,9 +78,9 @@ vec CBot::GetEnemyPos(playerent *d)
break;
case 1:
// GOOD, offset a little for x, y, and z
offset.x = RandomFloat(-3, 3) * flScale;
offset.y = RandomFloat(-3, 3) * flScale;
offset.z = RandomFloat(-6, 6) * flScale;
offset.x = RandomFloat(-2, 2) * flScale;
offset.y = RandomFloat(-2, 2) * flScale;
offset.z = RandomFloat(-4, 4) * flScale;
break;
case 2:
// FAIR, offset somewhat for x, y, and z
Expand Down Expand Up @@ -711,7 +712,7 @@ void CBot::ShootEnemy()
float yawtoturn = fabs(WrapYZAngle(m_pMyEnt->yaw - m_pMyEnt->targetyaw));
float pitchtoturn = fabs(WrapYZAngle(m_pMyEnt->pitch - m_pMyEnt->targetpitch));

if ((yawtoturn > 5) || (pitchtoturn > 15)) // UNDONE: Should be skill based
if ((yawtoturn > 3) || (pitchtoturn > 10)) // UNDONE: Should be skill based
return;
}

Expand Down Expand Up @@ -1337,11 +1338,12 @@ bool CBot::CheckStuck()
m_iStuckTime = 0;

// stuck in geometry?
if(!collide(m_pMyEnt))
{
StuckLastResort();
return true;
}
// Produces random suicides where bots have simply run against a wall -- rXn
// if(!collide(m_pMyEnt))
// {
// StuckLastResort();
// return true;
// }

// Crap bot is stuck, lets just try some random things

Expand Down