Skip to content

Commit

Permalink
bot_fortress: changes to aiming
Browse files Browse the repository at this point in the history
Bots will now always accurately predict with all projectile based weapons

Snipers will go for consistently headshots
  • Loading branch information
pongo1231 committed Jan 1, 2025
1 parent 6117230 commit ae414d8
Showing 1 changed file with 103 additions and 93 deletions.
196 changes: 103 additions & 93 deletions utils/RCBot2_meta/bot_fortress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6948,52 +6948,107 @@ void CBotTF2 ::modAim(edict_t *pEntity, Vector &v_origin, Vector *v_desired_offs

if (pWp)
{
if (m_iClass == TF_CLASS_SNIPER)
/*if (m_iClass == TF_CLASS_SNIPER)
{
if (pWp->getID() == TF2_WEAPON_BOW)
{
if (pWp->getProjectileSpeed() > 0)
{
CClient *pClient = CClients::get(pEntity);
Vector vVelocity;
if (CClassInterface::getVelocity(pEntity, &vVelocity))
{
if (pClient && (vVelocity == Vector(0, 0, 0)))
vVelocity = pClient->getVelocity();
}
else if (pClient)
vVelocity = pClient->getVelocity();
// the arrow will arc
fTime = fDist2D / (pWp->getProjectileSpeed() * 0.707);
if (rcbot_supermode.GetBool())
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime));
else
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime) * m_pProfile->m_fAimSkill);
if (sv_gravity.IsValid())
v_desired_offset->z += ((pow(2, fTime) - 1.0f)
* (sv_gravity.GetFloat() * 0.1f)); // - (getOrigin().z - v_origin.z);
v_desired_offset->z *= 0.6f;
}
}
else if ((v_desired_offset->z < 64.0f) && !hasSomeConditions(CONDITION_SEE_ENEMY_GROUND))
{
if (rcbot_supermode.GetBool())
v_desired_offset->z += 15.0f;
else
v_desired_offset->z += randomFloat(0.0f, 16.0f);
}
}*/

CWeapon *pWepInfo = pWp->getWeaponInfo();
if (pWepInfo->isProjectile())
{
if (pWp->getID() == TF2_WEAPON_BOW)
// int iSpeed = 0;

/*switch (pWp->getID())
{
if (pWp->getProjectileSpeed() > 0)
{
CClient *pClient = CClients::get(pEntity);
Vector vVelocity;
case TF2_WEAPON_ROCKETLAUNCHER:
// fall through
case TF2_WEAPON_COWMANGLER:
case TF2_WEAPON_FLAREGUN:
case TF2_WEAPON_GRENADELAUNCHER:
{*/
CClient *pClient = CClients::get(pEntity);
Vector vVelocity;

if (CClassInterface::getVelocity(pEntity, &vVelocity))
{
if (pClient && (vVelocity == Vector(0, 0, 0)))
vVelocity = pClient->getVelocity();
}
else if (pClient)
vVelocity = pClient->getVelocity();
// if ( iSpeed == 0 )
// iSpeed = TF2_GRENADESPEED;

// the arrow will arc
fTime = fDist2D / (pWp->getProjectileSpeed() * 0.707);
// if ( pClient )
//{
if (CClassInterface ::getVelocity(pEntity, &vVelocity))
{
if (pClient && (vVelocity == Vector(0, 0, 0)))
vVelocity = pClient->getVelocity();
}
else if (pClient)
vVelocity = pClient->getVelocity();

if (rcbot_supermode.GetBool())
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime));
else
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime) * m_pProfile->m_fAimSkill);
// speed = distance/time
// .'.
// time = distance/speed

if (sv_gravity.IsValid())
v_desired_offset->z += ((pow(2, fTime) - 1.0f)
* (sv_gravity.GetFloat() * 0.1f)); // - (getOrigin().z - v_origin.z);
bool bIsGrenade = pWepInfo->isGrenade();

v_desired_offset->z *= 0.6f;
}
}
else if ((v_desired_offset->z < 64.0f) && !hasSomeConditions(CONDITION_SEE_ENEMY_GROUND))
{
if (rcbot_supermode.GetBool())
v_desired_offset->z += 15.0f;
else
v_desired_offset->z += randomFloat(0.0f, 16.0f);
}
}
else if (m_iClass == TF_CLASS_MEDIC)
{
if (pWp->getID() == TF2_WEAPON_SYRINGEGUN)
v_desired_offset->z += sqrt(fDist) * 2;
if (bIsGrenade)
fTime = fDist2D / (pWp->getProjectileSpeed() * 0.707);
else
fTime = fDist / (pWp->getProjectileSpeed());

// if (rcbot_supermode.GetBool())
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime));
/*else
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime) * m_pProfile->m_fAimSkill);*/

if ((sv_gravity.IsValid()) && bIsGrenade)
v_desired_offset->z +=
((pow(2, fTime) - 1.0f) * (sv_gravity.GetFloat() * 0.1f)); // - (getOrigin().z - v_origin.z);

/*if ((pWp->getID() == TF2_WEAPON_GRENADELAUNCHER) && hasSomeConditions(CONDITION_SEE_ENEMY_GROUND))
v_desired_offset->z -= randomFloat(8.0f, 32.0f); // aim for ground - with grenade launcher
else if ((pWp->getID() == TF2_WEAPON_ROCKETLAUNCHER) || (pWp->getID() == TF2_WEAPON_COWMANGLER)
|| (v_origin.z > (getOrigin().z + 16.0f)))*/
v_desired_offset->z += randomFloat(8.0f, 32.0f); // aim for body, not ground
/*}
break;
}*/
}
else if (m_iClass == TF_CLASS_HWGUY)

if (m_iClass == TF_CLASS_HWGUY)
{
if (pWp->getID() == TF2_WEAPON_MINIGUN)
{
Expand All @@ -7010,63 +7065,18 @@ void CBotTF2 ::modAim(edict_t *pEntity, Vector &v_origin, Vector *v_desired_offs
*v_desired_offset + (((vRight * 24) - Vector(0, 0, 24)) * bot_heavyaimoffset.GetFloat());
}
}
else if ((m_iClass == TF_CLASS_SOLDIER) || (m_iClass == TF_CLASS_DEMOMAN))
{
// int iSpeed = 0;

switch (pWp->getID())
{
case TF2_WEAPON_ROCKETLAUNCHER:
// fall through
case TF2_WEAPON_COWMANGLER:
case TF2_WEAPON_FLAREGUN:
case TF2_WEAPON_GRENADELAUNCHER:
{
CClient *pClient = CClients::get(pEntity);
Vector vVelocity;

// if ( iSpeed == 0 )
// iSpeed = TF2_GRENADESPEED;

// if ( pClient )
//{
if (CClassInterface ::getVelocity(pEntity, &vVelocity))
{
if (pClient && (vVelocity == Vector(0, 0, 0)))
vVelocity = pClient->getVelocity();
}
else if (pClient)
vVelocity = pClient->getVelocity();

// speed = distance/time
// .'.
// time = distance/speed

if (pWp->getProjectileSpeed() > 0)
{
if ((pWp->getID() == TF2_WEAPON_GRENADELAUNCHER))
fTime = fDist2D / (pWp->getProjectileSpeed() * 0.707);
else
fTime = fDist / (pWp->getProjectileSpeed());

if (rcbot_supermode.GetBool())
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime));
else
*v_desired_offset = *v_desired_offset + ((vVelocity * fTime) * m_pProfile->m_fAimSkill);

if ((sv_gravity.IsValid()) && (pWp->getID() == TF2_WEAPON_GRENADELAUNCHER))
v_desired_offset->z += ((pow(2, fTime) - 1.0f)
* (sv_gravity.GetFloat() * 0.1f)); // - (getOrigin().z - v_origin.z);
if (m_iClass == TF_CLASS_MEDIC)
{
if (pWp->getID() != TF2_WEAPON_CROSSBOW)
v_desired_offset->z += sqrt(fDist) * 2;
}

if ((pWp->getID() == TF2_WEAPON_GRENADELAUNCHER) && hasSomeConditions(CONDITION_SEE_ENEMY_GROUND))
v_desired_offset->z -= randomFloat(8.0f, 32.0f); // aim for ground - with grenade launcher
else if ((pWp->getID() == TF2_WEAPON_ROCKETLAUNCHER) || (pWp->getID() == TF2_WEAPON_COWMANGLER)
|| (v_origin.z > (getOrigin().z + 16.0f)))
v_desired_offset->z += randomFloat(8.0f, 32.0f); // aim for body, not ground
}
}
break;
}
if (m_iClass == TF_CLASS_SNIPER)
{
Vector eye;
gameclients->ClientEarPosition(pEntity, &eye);
v_desired_offset->z = (eye - v_origin).z;
}
}
}
Expand Down

0 comments on commit ae414d8

Please sign in to comment.