Wot why does this not work

This commit is contained in:
TotallyNotElite 2018-08-23 17:14:29 +02:00
parent 79fc4a44ef
commit 5177709fe8
2 changed files with 48 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include "micropather.h" #include "micropather.h"
#include "pwd.h" #include "pwd.h"
#include <thread> #include <thread>
#include <boost/functional/hash.hpp>
#if ENABLE_VISUALS #if ENABLE_VISUALS
#include <glez/draw.hpp> #include <glez/draw.hpp>
#endif #endif
@ -29,7 +30,11 @@ size_t FindInVector(size_t id);
class inactivityTracker class inactivityTracker
{ {
// Map for storing inactivity per connection // Map for storing inactivity per connection
std::map<std::pair<int, int>, std::pair<int, unsigned int>> inactives; std::unordered_map<std::pair<int, int>, std::pair<int, unsigned int>,
boost::hash<std::pair<int, int>>>
inactives;
std::vector<int> sentryAreas;
bool vischeckConnection(std::pair<int, int> &connection) bool vischeckConnection(std::pair<int, int> &connection)
{ {
Vector begin = areas.at(FindInVector(connection.first)).m_center; Vector begin = areas.at(FindInVector(connection.first)).m_center;
@ -39,6 +44,7 @@ class inactivityTracker
bool result = IsVectorVisible(begin, end, false); bool result = IsVectorVisible(begin, end, false);
return result; return result;
} }
std::pair<int, int> VectorToId(std::pair<Vector, Vector> &connection) std::pair<int, int> VectorToId(std::pair<Vector, Vector> &connection)
{ {
CNavArea *currnode = nullptr; CNavArea *currnode = nullptr;
@ -83,6 +89,30 @@ public:
i.second.second = 0; i.second.second = 0;
} }
} }
void updateSentries()
{
logging::Info("1");
sentryAreas.clear();
for (int i = 0; i < HIGHEST_ENTITY; i++)
{
CachedEntity *ent = ENTITY(i);
if (CE_BAD(ent) || ent->m_iClassID() != CL_CLASS(CObjectSentrygun))
continue;
Vector sentryloc = GetBuildingPosition(ent);
for (auto i : areas)
{
Vector area = i.m_center;
area.z += 30.0f;
if (area.DistTo(sentryloc) > 1100.0f)
continue;
if (!IsVectorVisible(area, sentryloc, true))
continue;
logging::Info("5");
sentryAreas.push_back(i.m_id);
}
}
}
bool IsIgnored(std::pair<int, int> connection) bool IsIgnored(std::pair<int, int> connection)
{ {
if (inactives.find(connection) == inactives.end()) if (inactives.find(connection) == inactives.end())
@ -101,6 +131,14 @@ public:
"Ignored a connection due to type 2 connection type."); "Ignored a connection due to type 2 connection type.");
return true; return true;
} }
if (std::find(sentryAreas.begin(), sentryAreas.end(),
connection.first) != sentryAreas.end() ||
std::find(sentryAreas.begin(), sentryAreas.end(),
connection.second) != sentryAreas.end())
{
logging::Info("Ignored a connection due to sentry gun coverage");
return true;
}
return false; return false;
} }
@ -113,9 +151,10 @@ public:
} }
auto &pair = inactives.at(connection); auto &pair = inactives.at(connection);
unsigned int newTime = std::chrono::duration_cast<std::chrono::milliseconds>( unsigned int newTime =
std::chrono::system_clock::now() - timer.last) std::chrono::duration_cast<std::chrono::milliseconds>(
.count(); std::chrono::system_clock::now() - timer.last)
.count();
if (pair.first == 2 && !vischeckConnection(connection)) if (pair.first == 2 && !vischeckConnection(connection))
newTime = (newTime > 2500 ? 2500 : newTime); newTime = (newTime > 2500 ? 2500 : newTime);
pair.second = pair.second + newTime; pair.second = pair.second + newTime;

View File

@ -242,8 +242,9 @@ void clearInstructions()
static Timer ignoreReset{}; static Timer ignoreReset{};
static Timer patherReset{}; static Timer patherReset{};
static Timer sentryUpdate{};
// Function for removing ignores // Function for removing ignores
void clearIgnores() void ignoreManagerCM()
{ {
if (!TF2MAP || !TF2MAP->pather) if (!TF2MAP || !TF2MAP->pather)
return; return;
@ -251,6 +252,8 @@ void clearIgnores()
TF2MAP->inactiveTracker.reset(); TF2MAP->inactiveTracker.reset();
if (patherReset.test_and_set(30000)) if (patherReset.test_and_set(30000))
TF2MAP->pather->Reset(); TF2MAP->pather->Reset();
if(sentryUpdate.test_and_set(2000))
TF2MAP->inactiveTracker.updateSentries();
} }
void Repath() void Repath()
@ -287,7 +290,7 @@ void CreateMove()
crumbs.clear(); crumbs.clear();
return; return;
} }
clearIgnores(); ignoreManagerCM();
// Crumbs empty, prepare for next instruction // Crumbs empty, prepare for next instruction
if (crumbs.empty()) if (crumbs.empty())
{ {