wip playerfit check

This commit is contained in:
TotallyNotElite 2018-07-01 12:25:17 +02:00
parent a10831ac99
commit aff77d2d2c
3 changed files with 87 additions and 33 deletions

View File

@ -77,7 +77,11 @@ 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 VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
bool checkWalkable = false);
float vectorMax(Vector i);
Vector vectorAbs(Vector i);
bool canReachVector(Vector loc);
bool LineIntersectsBox(Vector &bmin, Vector &bmax, Vector &lmin, Vector &lmax);

View File

@ -82,13 +82,6 @@ void checkAFK()
}
}
float vectormax(Vector i) // TODO: Move to helpers.cpp soon tm
{
float res = fmaxf(i.x, i.y);
return fmaxf(res, i.z);
}
void init()
{
for (int i = 0; i < afkTicks.size(); i++)
@ -100,19 +93,19 @@ void init()
}
bool canReachVector(Vector loc)
{
trace_t trace;
Ray_t ray;
Vector down = loc;
down.z = down.z - 5;
ray.Init(loc, down);
g_ITrace->TraceRay(ray, MASK_PLAYERSOLID, &trace::filter_no_player,
&trace);
if (trace.startpos.z - trace.endpos.z <= 75) // higher as to avoid small false positives, player can jump 72 hu
return true;
return false;
}
//bool canReachVector(Vector loc)
//{
// trace_t trace;
// Ray_t ray;
// Vector down = loc;
// down.z = down.z - 5;
// ray.Init(loc, down);
// g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player,
// &trace);
// if (trace.startpos.z - trace.endpos.z <= 75) // higher as to avoid small false positives, player can jump 72 hu
// return true;
// return false;
//}
// auto add checked crumbs for the walbot to follow
bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin)
@ -120,14 +113,10 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin)
if (g_pLocalPlayer->v_Origin != corner)
{
Vector dist = corner - g_pLocalPlayer->v_Origin;
Vector distabs = dist;
distabs.x = fabsf(distabs.x);
distabs.y = fabsf(distabs.y);
distabs.z = fabsf(distabs.z);
int maxiterations = floor(corner.DistTo(g_pLocalPlayer->v_Origin)) / 40;
for (int i = 0; i < maxiterations; i++)
{
Vector result = g_pLocalPlayer->v_Origin + dist / vectormax(distabs) * 40.0f * (i + 1);
Vector result = g_pLocalPlayer->v_Origin + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1);
if (!canReachVector(result))
return false;
breadcrumbs.push_back(result);
@ -135,14 +124,10 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin)
}
Vector dist = target->m_vecOrigin() - corner;
Vector distabs = dist;
distabs.x = fabsf(distabs.x);
distabs.y = fabsf(distabs.y);
distabs.z = fabsf(distabs.z);
int maxiterations = floor(corner.DistTo(target->m_vecOrigin())) / 40;
for (int i = 0; i < maxiterations; i++)
{
Vector result = corner + dist / vectormax(distabs) * 40.0f * (i + 1);
Vector result = corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1);
if (!canReachVector(result))
return false;
breadcrumbs.push_back(result);

View File

@ -108,7 +108,8 @@ 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 VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
bool checkWalkable)
{
int maxiterations = maxdist / 40;
Vector origin = player->m_vecOrigin();
@ -141,9 +142,13 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist)
virtualOrigin)) // check if player can see the
// players virtualOrigin
continue;
if (VisCheckEntFromEntVector(
if (!VisCheckEntFromEntVector(
virtualOrigin, player,
target)) // check if the virtualOrigin can see the target
continue;
if (!checkWalkable)
return virtualOrigin;
if (canReachVector(virtualOrigin))
return virtualOrigin; // return the corner position that we know
// can see the target
}
@ -151,6 +156,66 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist)
return { 0, 0, 0 };
}
float vectorMax(Vector i) // Returns a vectors max value. For example: {123,
// -150, 125} = 125
{
float res = fmaxf(i.x, i.y);
return fmaxf(res, i.z);
}
Vector vectorABS(Vector i)
{
Vector result = i;
result.x = fabsf(i.x);
result.y = fabsf(i.y);
result.z = fabsf(i.z);
return result;
}
// check to see if we can reach a vector or if it is too high / doesn't leave
// enough space for the player
bool canReachVector(Vector loc)
{
// check if the vector is too high above ground
{
trace_t trace;
Ray_t ray;
Vector down = loc;
down.z = down.z - 5;
ray.Init(loc, down);
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace);
if (!(trace.startpos.z - trace.endpos.z <=
75)) // higher as to avoid small false positives, player can jump
// 72 hu
return false;
}
for (int i = 0; i < 4; i++) // for loop for all 4 directions
{
Vector directionalLoc = loc;
switch (i) // what to check
{
case 0:
directionalLoc.x = directionalLoc.x + 40;
break;
case 1:
directionalLoc.x = directionalLoc.x - 40;
break;
case 2:
directionalLoc.y = directionalLoc.y + 40;
break;
case 3:
directionalLoc.y = directionalLoc.y - 40;
break;
}
trace_t trace;
Ray_t ray;
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace);
if (trace.startpos.DistTo(trace.endpos) < 26.0f)
return false;
}
return true;
}
std::string GetLevelName()
{