WIP
This commit is contained in:
parent
c35e31e152
commit
6c27273f98
@ -77,7 +77,9 @@ bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos);
|
||||
bool VisCheckEntFromEnt(CachedEntity *startEnt, CachedEntity *endEnt);
|
||||
bool VisCheckEntFromEntVector(Vector startVector, CachedEntity *startEnt,
|
||||
CachedEntity *endEnt);
|
||||
Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
Vector VischeckCorner(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
bool checkWalkable);
|
||||
std::pair<Vector,Vector> VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
bool checkWalkable);
|
||||
float vectorMax(Vector i);
|
||||
Vector vectorAbs(Vector i);
|
||||
|
@ -221,7 +221,7 @@ void smart_crouch()
|
||||
{
|
||||
bool foundtar = false;
|
||||
static bool crouch = false;
|
||||
if (crouchcdr.test_and_set(1000))
|
||||
if (crouchcdr.test_and_set(2000))
|
||||
{
|
||||
for (int i = 0; i < g_IEngine->GetMaxClients(); i++)
|
||||
{
|
||||
@ -246,13 +246,10 @@ void smart_crouch()
|
||||
continue;
|
||||
if (!IsVectorVisible(ent->hitboxes.GetHitbox(0)->center, LOCAL_E->hitboxes.GetHitbox(j)->center) && !IsVectorVisible(ent->hitboxes.GetHitbox(0)->center, LOCAL_E->hitboxes.GetHitbox(j)->min) && !IsVectorVisible(ent->hitboxes.GetHitbox(0)->center, LOCAL_E->hitboxes.GetHitbox(j)->max))
|
||||
continue;
|
||||
else
|
||||
{
|
||||
foundtar = true;
|
||||
crouch = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!foundtar && crouch)
|
||||
crouch = false;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ static CatVar afktime(
|
||||
CV_INT, "fb_afk_time", "15000", "Max AFK Time",
|
||||
"Max time in ms spent standing still before player gets declared afk");
|
||||
static CatVar corneractivate(
|
||||
CV_SWITCH, "fb_activation_corners", "1", "Activate arround corners",
|
||||
CV_SWITCH, "fb_activation_corners", "1", "Activate around corners",
|
||||
"Try to find an activation path to an entity behind a corner.");
|
||||
|
||||
// Something to store breadcrumbs created by followed players
|
||||
@ -143,6 +143,8 @@ int ClassPriority(CachedEntity *ent)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Timer waittime{};
|
||||
int lastent = 0;
|
||||
void WorldTick()
|
||||
{
|
||||
if (!followbot)
|
||||
@ -195,15 +197,28 @@ void WorldTick()
|
||||
|
||||
if (!entity->m_bAlivePlayer()) // Dont follow dead players
|
||||
continue;
|
||||
lastent++;
|
||||
if (lastent > g_IEngine->GetMaxClients())
|
||||
lastent = 0;
|
||||
if (corneractivate)
|
||||
{
|
||||
Vector indirectOrigin =
|
||||
VischeckWall(LOCAL_E, entity, 250,
|
||||
VischeckCorner(LOCAL_E, entity, 500,
|
||||
true); // get the corner location that the
|
||||
// future target is visible from
|
||||
if (!indirectOrigin.z) // if we couldn't find it, exit
|
||||
std::pair<Vector, Vector> corners;
|
||||
if (!indirectOrigin.z && entity->m_IDX == lastent) // if we couldn't find it, run wallcheck instead
|
||||
{
|
||||
corners = VischeckWall(LOCAL_E, entity, 500, true);
|
||||
if (!corners.first.z || !corners.second.z)
|
||||
continue;
|
||||
addCrumbs(LOCAL_E, corners.first);
|
||||
addCrumbs(entity, corners.second);
|
||||
}
|
||||
if (indirectOrigin.z)
|
||||
addCrumbs(entity, indirectOrigin);
|
||||
else if (!indirectOrigin.z && !corners.first.z)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -265,9 +280,7 @@ void WorldTick()
|
||||
if (follow_target &&
|
||||
ENTITY(follow_target)->m_flDistance() <
|
||||
entity->m_flDistance()) // favor closer entitys
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// check if new target has a higher priority than current target
|
||||
if (ClassPriority(ENTITY(follow_target)) >=
|
||||
ClassPriority(ENTITY(i)))
|
||||
@ -276,12 +289,22 @@ void WorldTick()
|
||||
if (corneractivate)
|
||||
{
|
||||
Vector indirectOrigin =
|
||||
VischeckWall(LOCAL_E, entity, 250,
|
||||
VischeckCorner(LOCAL_E, entity, 500,
|
||||
true); // get the corner location that the
|
||||
// future target is visible from
|
||||
if (!indirectOrigin.z) // if we couldn't find it, exit
|
||||
std::pair<Vector, Vector> corners;
|
||||
if (!indirectOrigin.z && entity->m_IDX == lastent) // if we couldn't find it, run wallcheck instead
|
||||
{
|
||||
corners = VischeckWall(LOCAL_E, entity, 500, true);
|
||||
if (!corners.first.z || !corners.second.z)
|
||||
continue;
|
||||
addCrumbs(LOCAL_E, corners.first);
|
||||
addCrumbs(entity, corners.second);
|
||||
}
|
||||
if (indirectOrigin.z)
|
||||
addCrumbs(entity, indirectOrigin);
|
||||
else if (!indirectOrigin.z && !corners.first.z)
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ void WalkTo(const Vector &vector)
|
||||
|
||||
// Function to get the corner location that a vischeck to an entity is possible
|
||||
// from
|
||||
Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
Vector VischeckCorner(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
bool checkWalkable)
|
||||
{
|
||||
int maxiterations = maxdist / 40;
|
||||
@ -165,6 +165,91 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
return { 0, 0, 0 };
|
||||
}
|
||||
|
||||
// return Two Corners that connect perfectly to ent and local player
|
||||
std::pair<Vector,Vector> VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
bool checkWalkable)
|
||||
{
|
||||
int maxiterations = maxdist / 40;
|
||||
Vector origin = player->m_vecOrigin();
|
||||
|
||||
// if we can see an entity, we don't need to run calculations
|
||||
if (VisCheckEntFromEnt(player, target))
|
||||
{
|
||||
std::pair<Vector, Vector> orig(origin, origin);
|
||||
if (!checkWalkable)
|
||||
return orig;
|
||||
else if (canReachVector(origin, target->m_vecOrigin()))
|
||||
return orig;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) // for loop for all 4 directions
|
||||
{
|
||||
// 40 * maxiterations = range in HU
|
||||
for (int j = 0; j < maxiterations; j++)
|
||||
{
|
||||
Vector virtualOrigin = origin;
|
||||
// what direction to go in
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
virtualOrigin.x = virtualOrigin.x + 40 * (j + 1);
|
||||
break;
|
||||
case 1:
|
||||
virtualOrigin.x = virtualOrigin.x - 40 * (j + 1);
|
||||
break;
|
||||
case 2:
|
||||
virtualOrigin.y = virtualOrigin.y + 40 * (j + 1);
|
||||
break;
|
||||
case 3:
|
||||
virtualOrigin.y = virtualOrigin.y - 40 * (j + 1);
|
||||
break;
|
||||
}
|
||||
// check if player can see the players virtualOrigin
|
||||
if (!IsVectorVisible(origin, virtualOrigin, true))
|
||||
continue;
|
||||
for (int i = 0; i < 4; i++) // for loop for all 4 directions
|
||||
{
|
||||
// 40 * maxiterations = range in HU
|
||||
for (int j = 0; j < maxiterations; j++)
|
||||
{
|
||||
Vector virtualOrigin2 = origin;
|
||||
// what direction to go in
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
virtualOrigin2.x = virtualOrigin2.x + 40 * (j + 1);
|
||||
break;
|
||||
case 1:
|
||||
virtualOrigin2.x = virtualOrigin2.x - 40 * (j + 1);
|
||||
break;
|
||||
case 2:
|
||||
virtualOrigin2.y = virtualOrigin2.y + 40 * (j + 1);
|
||||
break;
|
||||
case 3:
|
||||
virtualOrigin2.y = virtualOrigin2.y - 40 * (j + 1);
|
||||
break;
|
||||
}
|
||||
// check if the virtualOrigin2 can see the target
|
||||
if (!VisCheckEntFromEntVector(virtualOrigin2, player, target))
|
||||
continue;
|
||||
if (!IsVectorVisible(virtualOrigin, virtualOrigin2, true))
|
||||
continue;
|
||||
std::pair<Vector, Vector> toret(virtualOrigin, virtualOrigin2);
|
||||
if (!checkWalkable)
|
||||
return toret;
|
||||
// check if the location is accessible
|
||||
if (!canReachVector(origin, virtualOrigin) || !canReachVector(target->m_vecOrigin(), virtualOrigin2))
|
||||
continue;
|
||||
if (canReachVector(virtualOrigin, target->m_vecOrigin()))
|
||||
return toret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we didn't find anything, return an empty Vector
|
||||
return { {0, 0, 0}, {0, 0, 0} };
|
||||
}
|
||||
|
||||
// Returns a vectors max value. For example: {123,-150, 125} = 125
|
||||
float vectorMax(Vector i)
|
||||
{
|
||||
@ -649,8 +734,7 @@ bool IsEntityVectorVisible(CachedEntity *entity, Vector endpos)
|
||||
g_ITrace->TraceRay(ray, MASK_SHOT_HULL, &trace::filter_default,
|
||||
&trace_object);
|
||||
}
|
||||
return (trace_object.fraction >= 0.99f ||
|
||||
(((IClientEntity *) trace_object.m_pEnt)) == RAW_ENT(entity));
|
||||
return (((IClientEntity *) trace_object.m_pEnt) == RAW_ENT(entity) || trace_object.fraction >= 0.99f);
|
||||
}
|
||||
|
||||
// For when you need to vis check something that isnt the local player
|
||||
|
Reference in New Issue
Block a user