Untested navbot changes + gui free mouse

This commit is contained in:
TotallyNotElite 2018-08-25 00:29:09 +02:00
parent ebd074235e
commit 618f6961a8
3 changed files with 44 additions and 18 deletions

View File

@ -46,7 +46,7 @@ class inactivityTracker
return result;
}
std::pair<int, int> VectorToId(std::pair<Vector, Vector> &connection)
std::pair<int, int> VectorsToId(std::pair<Vector, Vector> &connection)
{
CNavArea *currnode = nullptr;
for (size_t i = 0; i < areas.size(); i++)
@ -81,6 +81,22 @@ class inactivityTracker
}
}
int VectorToID(Vector vec)
{
CNavArea *currnode = nullptr;
for (size_t i = 0; i < areas.size(); i++)
{
if (areas.at(i).m_center == vec)
{
currnode = &areas.at(i);
break;
}
}
if (!currnode)
return -1;
return currnode->m_id;
}
public:
void reset()
{
@ -92,16 +108,15 @@ public:
}
bool ShouldCancelPath(std::vector<Vector> crumbs)
{
for (auto sentry : sentries)
for (auto crumb : crumbs)
{
if (crumb.DistTo(sentry) > 1100)
continue;
if (!IsVectorVisible(crumb, sentry, true))
continue;
for (auto crumb : crumbs)
{
int id = VectorToID(crumb);
if (id == -1)
continue;
if (sentryAreas[id])
return true;
}
return false;
}
return false;
}
void updateSentries()
{
@ -110,7 +125,9 @@ public:
for (int i = 0; i < HIGHEST_ENTITY; i++)
{
CachedEntity *ent = ENTITY(i);
if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun) || ent->m_iTeam() == LOCAL_E->m_iTeam())
if (CE_BAD(ent) ||
ent->m_iClassID() != CL_CLASS(CObjectSentrygun) /*||
ent->m_iTeam() == LOCAL_E->m_iTeam()*/)
continue;
Vector sentryloc = GetBuildingPosition(ent);
sentries.push_back(sentryloc);
@ -128,8 +145,7 @@ public:
}
bool IsIgnored(std::pair<int, int> connection)
{
if (sentryAreas[connection.first] ||
sentryAreas[connection.second])
if (sentryAreas[connection.first] || sentryAreas[connection.second])
{
logging::Info("Ignored a connection due to sentry gun coverage");
return true;
@ -173,7 +189,7 @@ public:
void AddTime(std::pair<Vector, Vector> connection, Timer &timer,
bool &resetPather)
{
auto pair = VectorToId(connection);
auto pair = VectorsToId(connection);
if (pair.first == -1 || pair.second == -1)
return;
AddTime(pair, timer, resetPather);
@ -201,7 +217,7 @@ public:
}
bool CheckType2(std::pair<Vector, Vector> connection)
{
auto pair = VectorToId(connection);
auto pair = VectorsToId(connection);
if (pair.first == -1 || pair.second == -1)
return false;
return CheckType2(pair);

View File

@ -211,7 +211,7 @@ bool NavTo(Vector dest, bool navToLocalCenter, bool persistent,
// Only allow instructions to overwrite others if their priority is higher
if (instructionPriority < priority)
return false;
int locNav, tarNav;
int locNav = 0, tarNav = 0;
auto path = findPath(g_pLocalPlayer->v_Origin, dest, locNav, tarNav);
if (path.empty())
return false;
@ -266,7 +266,7 @@ void Repath()
logging::Info("Pathing: NavBot inactive for too long. Ignoring "
"connection and finding another path...");
// Throwaway int
int i1, i2;
int i1 = 0, i2 = 0;
// Find a new path
TF2MAP->pather->Reset();
crumbs = findPath(g_pLocalPlayer->v_Origin, crumbs.back(), i1, i2);
@ -402,7 +402,7 @@ CatCommand navprint("nav_print", "Debug nav print", [](const CCommand &args) {
});
CatCommand navfind("nav_find", "Debug nav find", [](const CCommand &args) {
int i1, i2;
int i1 = 0, i2 = 0;
std::vector<Vector> path = findPath(g_pLocalPlayer->v_Origin, loc, i1, i2);
if (path.empty())
{

View File

@ -156,6 +156,16 @@ bool gui::handleSdlEvent(SDL_Event *event)
logging::Info("GUI open button pressed");
zerokernel::Menu::instance->setInGame(
!zerokernel::Menu::instance->isInGame());
if (!zerokernel::Menu::instance->isInGame())
{
g_ISurface->UnlockCursor();
g_ISurface->SetCursorAlwaysVisible(true);
}
else
{
g_ISurface->LockCursor();
g_ISurface->SetCursorAlwaysVisible(false);
}
return true;
}
}