#include "Walkbot.h"
#include "Global.h"
#include "MiscClasses.h"
#include "MathFunctions.h"
#include "Entities.h"
WalkBot::WalkBot() {
}
const std::vector<Vector> tDust2Points = { Vector(-503.56f, -739.92f, 114.16f),
Vector(-1913.50f,-735.72f, 121.20f),Vector(-1676.94f, 726.70f, 31.00f),
Vector(-1655.66f,1053.87f,31.57f), Vector(-1989.64f,1330.22f,28.93f),Vector(-1926.35f,2197.58f,-3.22f), Vector(-1685.82,2231.82,-2.47),
Vector(-1331.98f,2231.99f,2.05f), Vector(-1286.65f,2164.06f,4.25f),Vector(-606.69f,2370.25f,-105.67f),
Vector(-429.61f, 2196.21f, -123.86),Vector(279.11f,2175.06f,-128.18f),Vector(1380.f, 2131.6f, -5.48f),
Vector(1398.04f, 928.93f, -8.78f), Vector(841.17f, 950.18f, 0.14f),Vector(581.58f, 674.48f, 1.50f) ,
Vector(690.59f, 345.20f, 1.54f), Vector(446.82f, 70.25f, -3.26f), Vector(-5.52f, -829.16f, -3.58f)
};
const std::vector<Vector> BPlantPoints = { Vector(-1366.03f,2565.97f,4.65f), Vector(-1734.52f,1951.20f,-3.66f),Vector(-1680.61f,1796.50f,2.22f), Vector(-1676.78f, 1620.03f, 2.55f)
};
const std::vector<Vector> ctDust2Points = { Vector(279.11f,2175.06f,-128.18f),
Vector(1380.f, 2131.6f, -5.48f), Vector(1398.04f, 928.93f, -8.78f), Vector(841.17f, 950.18f, 0.14f),
Vector(581.58f, 674.48f, 1.50f) , Vector(690.59f, 345.20f, 1.54f), Vector(446.82f, 70.25f, -3.26f),
Vector(-5.52f, -829.16f, -3.58f), Vector(-503.56f, -739.92f, 114.16f), Vector(-1913.50f,-735.72f, 121.20f),
Vector(-1676.94f, 726.70f, 31.00f), Vector(-1655.66f,1053.87f,31.57f), Vector(-1989.64f,1330.22f,28.93f),
Vector(-1926.35f,2197.58f,-3.22f), Vector(-1331.98f,2231.99f,2.05f), Vector(-1286.65f,2164.06f,4.25f),
Vector(-606.69f,2370.25f,-105.67f),Vector(-429.61f, 2196.21f, -123.86)};
static bool bought;
void WalkBot::OnCreateMove(CInput::CUserCmd *ppCmd, C_BaseEntity * pLocal)
{
int team = pLocal->GetTeamNum();
CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)g_EntityList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
if (!pWeapon) return;
C_BaseEntity* weaponEnt = (C_BaseEntity*)pWeapon;
ClientClass* pWeaponClass = weaponEnt->GetClientClass();
if (!pLocal || !g_Engine->IsInGame() || g_Options.Misc.WalkBotReset) {
Reset();
return;
}
if (!g_Options.Misc.WalkBotEnabled) {
G::WalkBotting = false;
return;
}
if (!pLocal->IsAlive())
{
Reset();
return;
}
if (G::RoundStart)
{
Reset();
if (g_Options.Misc.WalkBotAutoBuy && !bought && (pLocal->GetMoney() >= g_Options.Misc.WalkBotAutoBuy)) // Handling the autobuy.
{
g_Engine->ClientCmd("autobuy");
bought = true;
}
G::RoundStart = false;
}
if (!pLocal->IsAlive())
{
if (team == 0) // unassigned
{
g_Engine->ClientCmd("teammenu"); // Start the Auto-Select team menu.
return;
}
else
{
bought = false;
return;
}
}
if ((pWeaponClass->m_ClassID == 29) && g_Options.Misc.WalkBotHandleC4 == 0 && !dropped) // If we prefer to drop the bomb and not plant, lets drop.
{
// Small delay so we don't drop our slot1 too.
droptick++;
if (droptick > 64)
{
g_Engine->ClientCmd("drop");
dropped = true;
}
}
if (team == 2) // Terrorist
MoveToPoint(tDust2Points, ppCmd, pLocal, true);
else if (team == 3) // CT
MoveToPoint(ctDust2Points, ppCmd, pLocal, false);
}
void WalkBot::Reset()
{
curpoint = 0;
BBombPoint = 0;
onB = false;
planting = false;
droptick = 0;
dropped = false;
if (g_Options.Misc.WalkBotReset) {
g_CVar->ConsoleColorPrintf(Color(225, 225, 10), "Reset The Bot\n");
curpoint = 0;
BBombPoint = 0;
onB = false;
planting = false;
droptick = 0;
dropped = false;
g_Options.Misc.WalkBotReset = false;
}
}
bool WalkBot::WalkInDirection(C_BaseEntity* pLocal, Vector point, CInput::CUserCmd *ppCmd)
{
bool ReturnValue = false;
if (point.Length() == 0) return ReturnValue;
Vector angles;
Vector src = pLocal->GetOrigin() + pLocal->GetViewOffset();
VectorAngles(point - src, angles);
ReturnValue = true;
sanitize_angles(angles);
ppCmd->forwardmove = g_Options.Misc.WalkBotSpeed;
movementfix(ppCmd, angles);
G::WalkBotting = true;
return ReturnValue;
}
bool WalkBot::MoveToPoint(const std::vector<Vector> points, CInput::CUserCmd *pCmd, C_BaseEntity * pLocal, bool Terrorist)
{
for (int i = 1; i < g_EntityList->GetHighestEntityIndex(); i++)
{
C_BaseEntity *entity = g_EntityList->GetClientEntity(i);
if (!entity
|| entity == pLocal
|| entity->IsDormant()
|| entity->GetLifeState() != LIFE_ALIVE
|| entity->GetClientClass()->m_ClassID != (int)ClassID::CCSPlayer
|| entity->GetTeamNum() == pLocal->GetTeamNum())
continue;
if (MiscFunctions::IsVisible(pLocal, entity, 0))
{
pCmd->forwardmove = 0.f;
return false;
}
}
// reload when nobody is visible.
CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)g_EntityList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
if (!pWeapon) return false;
else if ((pWeapon->GetAmmoInClip() <= g_Options.Misc.WalkBotReloadAmmo) && g_Options.Misc.WalkBotReload) pCmd->buttons |= IN_RELOAD;
if (pCmd->buttons & IN_ATTACK) return false;
if (curpoint == 18 && !Terrorist)
{
curpoint = 0;
g_CVar->ConsoleColorPrintf(Color(225, 225, 10), "Reached Destination\n");
}
else if (curpoint == 19 && Terrorist)
{
curpoint = 0;
g_CVar->ConsoleColorPrintf(Color(225, 225, 10), "Reached Destination\n");
}
C_BaseEntity* weaponEnt = (C_BaseEntity*)pWeapon;
ClientClass* pWeaponClass = weaponEnt->GetClientClass();
if ((Terrorist && curpoint == 7) && ((pWeaponClass->m_ClassID == 29) || planting ))
{
if (g_Options.Misc.WalkBotHandleC4 == 1)
{
PlantAtB(BPlantPoints, pCmd, pLocal, true);
planting = true;
return false;
}
}
if ((get_distance(pLocal->GetOrigin(), points[curpoint]) < g_Options.Misc.WalkBotLeeway))
{
curpoint++;
pCmd->forwardmove = 0.f;
G::WalkBotting = false;
}
else WalkInDirection(pLocal, points[curpoint], pCmd);
return false;
}
bool WalkBot::PlantAtB(const std::vector<Vector> points, CInput::CUserCmd *pCmd, C_BaseEntity * pLocal, bool deffend)
{
if ((get_distance(pLocal->GetOrigin(), points[BBombPoint]) < 3.0f))
{
if (BBombPoint == 0)
{
pCmd->buttons |= IN_ATTACK;
CBaseCombatWeapon* pWeapon = (CBaseCombatWeapon*)g_EntityList->GetClientEntityFromHandle(pLocal->GetActiveWeaponHandle());
if (!pWeapon) return false;
C_BaseEntity* weaponEnt = (C_BaseEntity*)pWeapon;
ClientClass* pWeaponClass = weaponEnt->GetClientClass();
if (pWeaponClass->m_ClassID != 29) BBombPoint++;
}
else
{
g_Engine->ClientCmd_Unrestricted("slot1");
BBombPoint++;
}
pCmd->forwardmove = 0.f;
G::WalkBotting = false;
if (BBombPoint > 3) BBombPoint = 3;
}
else WalkInDirection(pLocal, points[BBombPoint], pCmd);
return false;
}