diff --git a/src/creature.cpp b/src/creature.cpp index 142a5d69..1bffd224 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -166,7 +166,7 @@ void Creature::forceUpdatePath() return; } - lastPathUpdate = OTSYS_TIME() + EVENT_CREATURE_PATH_DELAY; + lastPathUpdate = OTSYS_TIME() + g_config.getNumber(ConfigManager::PATHFINDING_DELAY); g_dispatcher.addTask(createTask([id = getID()]() { g_game.updateCreatureWalk(id); })); } diff --git a/src/creature.h b/src/creature.h index 6adfd428..d8485345 100644 --- a/src/creature.h +++ b/src/creature.h @@ -20,7 +20,6 @@ #ifndef FS_CREATURE_H_5363C04015254E298F84E6D59A139508 #define FS_CREATURE_H_5363C04015254E298F84E6D59A139508 -#include "configmanager.h" #include "map.h" #include "position.h" #include "condition.h" @@ -29,8 +28,6 @@ #include "enums.h" #include "creatureevent.h" -extern ConfigManager g_config; - using ConditionList = std::list; using CreatureEventList = std::list; @@ -75,9 +72,6 @@ static constexpr int32_t EVENT_CREATURE_THINK_INTERVAL = 1000; //static constexpr int32_t EVENT_CREATURE_PATH_INTERVAL = 100; static constexpr int32_t EVENT_CHECK_CREATURE_INTERVAL = (EVENT_CREATURE_THINK_INTERVAL / EVENT_CREATURECOUNT); -static int32_t EVENT_CREATURE_PATH_INTERVAL = g_config.getNumber(ConfigManager::PATHFINDING_INTERVAL); -static int32_t EVENT_CREATURE_PATH_DELAY = g_config.getNumber(ConfigManager::PATHFINDING_DELAY); - class FrozenPathingConditionCall { public: diff --git a/src/game.cpp b/src/game.cpp index 30b38316..9751845a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -73,7 +73,8 @@ void Game::start(ServiceManager* manager) g_scheduler.addEvent(createSchedulerTask(EVENT_LIGHTINTERVAL, std::bind(&Game::checkLight, this))); } g_scheduler.addEvent(createSchedulerTask(EVENT_CREATURE_THINK_INTERVAL, std::bind(&Game::checkCreatures, this, 0))); - g_scheduler.addEvent(createSchedulerTask(EVENT_CREATURE_PATH_INTERVAL, [this]() { updateCreaturesPath(0); })); + g_scheduler.addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::PATHFINDING_INTERVAL), + [this]() { updateCreaturesPath(0); })); g_scheduler.addEvent(createSchedulerTask(EVENT_DECAYINTERVAL, std::bind(&Game::checkDecay, this))); } @@ -3600,7 +3601,7 @@ void Game::checkCreatures(size_t index) void Game::updateCreaturesPath(size_t index) { - g_scheduler.addEvent(createSchedulerTask(EVENT_CREATURE_PATH_INTERVAL, [=]() { updateCreaturesPath((index + 1) % EVENT_CREATURECOUNT); })); + g_scheduler.addEvent(createSchedulerTask(g_config.getNumber(ConfigManager::PATHFINDING_INTERVAL), [=]() { updateCreaturesPath((index + 1) % EVENT_CREATURECOUNT); })); auto& checkCreatureList = checkCreatureLists[index]; auto it = checkCreatureList.begin(), end = checkCreatureList.end(); diff --git a/src/map.cpp b/src/map.cpp index 8e49807b..ee9d23fb 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -722,6 +722,7 @@ bool Map::getPathMatching(const Creature& creature, const Position& targetPos, s const int_fast32_t y = n->y; pos.x = x; pos.y = y; + // Will be removed on future if (pathCondition(startPos, pos, fpp, bestMatch)) { found = n; endPos = pos; @@ -735,8 +736,8 @@ bool Map::getPathMatching(const Creature& creature, const Position& targetPos, s pos.y = y + allNeighbors[i][1]; if (fpp.maxSearchDist != 0 && - (Position::getDistanceX(startPos, pos) > fpp.maxSearchDist || Position::getDistanceY(startPos, pos) > fpp.maxSearchDist)) { - continue; + (Position::getDistanceX(startPos, pos) > fpp.maxSearchDist + 1 || Position::getDistanceY(startPos, pos) > fpp.maxSearchDist + 1)) { + break; } if (fpp.keepDistance && !pathCondition.isInRange(startPos, pos, fpp)) { @@ -779,6 +780,8 @@ bool Map::getPathMatching(const Creature& creature, const Position& targetPos, s n = nodes.getBestNode(); } + nodes.clear(); + if (!found) { return false; } diff --git a/src/map.h b/src/map.h index ef10131d..1dff7b50 100644 --- a/src/map.h +++ b/src/map.h @@ -60,6 +60,7 @@ class AStarNodes AStarNode* getBestNode(); AStarNode* getNodeByPosition(uint16_t x, uint16_t y) { return nodeMap[x][y]; }; + void clear() { nodes.clear(); nodeMap.clear(); }; static double calculateHeuristic(const Position& p1, const Position& p2); static double getMapWalkCost(AStarNode* node, const Position& neighborPos);