Refactoring
This commit is contained in:
parent
0c0c40a454
commit
4a200e0c40
@ -81,7 +81,7 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
bool checkWalkable);
|
||||
float vectorMax(Vector i);
|
||||
Vector vectorAbs(Vector i);
|
||||
bool canReachVector(Vector loc);
|
||||
bool canReachVector(Vector loc, Vector dest = {0,0,0});
|
||||
bool isJumping(Vector vec);
|
||||
|
||||
bool LineIntersectsBox(Vector &bmin, Vector &bmax, Vector &lmin, Vector &lmax);
|
||||
|
@ -491,10 +491,6 @@ free(logname);*/
|
||||
#if ENABLE_VISUALS
|
||||
|
||||
InitStrings();
|
||||
#if ENABLE_GUI
|
||||
// cat_reloadscheme to load imgui
|
||||
hack::command_stack().push("cat_reloadscheme");
|
||||
#endif
|
||||
#ifndef FEATURE_EFFECTS_DISABLED
|
||||
if (g_ppScreenSpaceRegistrationHead && g_pScreenSpaceEffects)
|
||||
{
|
||||
|
@ -102,13 +102,7 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin)
|
||||
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(vectorAbs(dist)) * 40.0f * (i + 1);
|
||||
if (!canReachVector(result))
|
||||
{
|
||||
breadcrumbs.clear();
|
||||
return false;
|
||||
}
|
||||
breadcrumbs.push_back(result);
|
||||
breadcrumbs.push_back(g_pLocalPlayer->v_Origin + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,13 +110,7 @@ bool addCrumbs(CachedEntity *target, Vector corner = g_pLocalPlayer->v_Origin)
|
||||
int maxiterations = floor(corner.DistTo(target->m_vecOrigin())) / 40;
|
||||
for (int i = 0; i < maxiterations; i++)
|
||||
{
|
||||
Vector result = corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1);
|
||||
if (!canReachVector(result))
|
||||
{
|
||||
breadcrumbs.clear();
|
||||
return false;
|
||||
}
|
||||
breadcrumbs.push_back(result);
|
||||
breadcrumbs.push_back(corner + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -245,8 +233,6 @@ void WorldTick()
|
||||
Vector indirectOrigin = VischeckWall(LOCAL_E, entity, 250, true); //get the corner location that the future target is visible from
|
||||
if (!indirectOrigin.z) //if we couldn't find it, exit
|
||||
continue;
|
||||
//breadcrumbs.clear(); //we need to ensure that the breadcrumbs std::vector is empty
|
||||
//breadcrumbs.push_back(indirectOrigin); //add the corner location to the breadcrumb list
|
||||
if (!addCrumbs(entity, indirectOrigin))
|
||||
continue;
|
||||
}
|
||||
@ -255,9 +241,9 @@ void WorldTick()
|
||||
if (!VisCheckEntFromEnt(LOCAL_E, entity))
|
||||
continue;
|
||||
}
|
||||
// favor closer entitys
|
||||
if (follow_target &&
|
||||
ENTITY(follow_target)->m_flDistance() >
|
||||
entity->m_flDistance()) // favor closer entitys
|
||||
ENTITY(follow_target)->m_flDistance() > entity->m_flDistance())
|
||||
continue;
|
||||
// ooooo, a target
|
||||
follow_target = i;
|
||||
|
@ -116,8 +116,13 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
|
||||
// if we can see an entity, we don't need to run calculations
|
||||
if (VisCheckEntFromEnt(player, target))
|
||||
|
||||
{
|
||||
if (!checkWalkable)
|
||||
return origin;
|
||||
else if (canReachVector(origin, target->m_vecOrigin()))
|
||||
return origin;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) // for loop for all 4 directions
|
||||
{
|
||||
// 40 * maxiterations = range in HU
|
||||
@ -148,8 +153,11 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
continue;
|
||||
if (!checkWalkable)
|
||||
return virtualOrigin;
|
||||
|
||||
// check if the location is accessible
|
||||
if (canReachVector(virtualOrigin))
|
||||
if (!canReachVector(origin, virtualOrigin))
|
||||
continue;
|
||||
if (canReachVector(virtualOrigin, target->m_vecOrigin()))
|
||||
return virtualOrigin;
|
||||
}
|
||||
}
|
||||
@ -160,8 +168,7 @@ Vector VischeckWall(CachedEntity *player, CachedEntity *target, float maxdist,
|
||||
// Returns a vectors max value. For example: {123,-150, 125} = 125
|
||||
float vectorMax(Vector i)
|
||||
{
|
||||
float res = fmaxf(i.x, i.y);
|
||||
return fmaxf(res, i.z);
|
||||
return fmaxf(fmaxf(i.x, i.y), i.z);
|
||||
}
|
||||
|
||||
// Returns a vectors absolute value. For example {123,-150, 125} = {123,150,
|
||||
@ -176,8 +183,58 @@ Vector vectorAbs(Vector i)
|
||||
}
|
||||
|
||||
// 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)
|
||||
// enough space for the player, optional second vector
|
||||
bool canReachVector(Vector loc, Vector dest)
|
||||
{
|
||||
if (!dest.IsZero())
|
||||
{
|
||||
Vector dist = dest - loc;
|
||||
int maxiterations = floor(dest.DistTo(loc)) / 40;
|
||||
for (int i = 0; i < maxiterations; i++)
|
||||
{
|
||||
Vector vec = loc + dist / vectorMax(vectorAbs(dist)) * 40.0f * (i + 1);
|
||||
|
||||
trace_t trace;
|
||||
Ray_t ray;
|
||||
Vector down = vec;
|
||||
down.z = down.z - 50;
|
||||
ray.Init(vec, down);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player,
|
||||
&trace);
|
||||
if (!(trace.startpos.DistTo(trace.endpos) <= 45))
|
||||
return false;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
Vector directionalLoc = vec;
|
||||
// what direction to check
|
||||
switch (j)
|
||||
{
|
||||
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 trace2;
|
||||
Ray_t ray2;
|
||||
ray2.Init(vec, directionalLoc);
|
||||
g_ITrace->TraceRay(ray2, 0x4200400B, &trace::filter_no_player,
|
||||
&trace2);
|
||||
// distance of trace < than 26
|
||||
if (trace2.startpos.DistTo(trace2.endpos) < 26.0f)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// check if the vector is too high above ground
|
||||
trace_t trace;
|
||||
@ -190,7 +247,6 @@ bool canReachVector(Vector loc)
|
||||
// the tf2 wiki
|
||||
if (!(trace.startpos.DistTo(trace.endpos) <= 45))
|
||||
return false;
|
||||
|
||||
// check if there is enough space arround the vector for a player to fit
|
||||
// for loop for all 4 directions
|
||||
for (int i = 0; i < 4; i++)
|
||||
@ -215,11 +271,12 @@ bool canReachVector(Vector loc)
|
||||
trace_t trace2;
|
||||
Ray_t ray2;
|
||||
ray2.Init(loc, directionalLoc);
|
||||
g_ITrace->TraceRay(ray2, 0x4200400B, &trace::filter_no_player, &trace);
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace2);
|
||||
// distance of trace < than 26
|
||||
if (trace2.startpos.DistTo(trace2.endpos) < 26.0f)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -238,7 +295,7 @@ bool isJumping(Vector vec)
|
||||
g_ITrace->TraceRay(ray, 0x4200400B, &trace::filter_no_player, &trace);
|
||||
// lower to avoid small false negatives, player can jump 42 hu according to
|
||||
// the tf2 wiki, higher because loc.z = loc.z + 5;
|
||||
if (fabsf(trace.startpos.DistTo(trace.endpos)) > 45)
|
||||
if (trace.startpos.DistTo(trace.endpos) > 45)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@ -1173,7 +1230,7 @@ void PrintChat(const char *fmt, ...)
|
||||
CHudBaseChat *chat = (CHudBaseChat *) g_CHUD->FindElement("CHudChat");
|
||||
if (chat)
|
||||
{
|
||||
std::unique_ptr<char> buf(new char[1024]);
|
||||
std::unique_ptr<char[]> buf(new char[1024]);
|
||||
va_list list;
|
||||
va_start(list, fmt);
|
||||
vsprintf(buf.get(), fmt, list);
|
||||
|
Reference in New Issue
Block a user