2021-05-15 18:22:44 +02:00
|
|
|
/*
|
|
|
|
* AIPathfinder.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AINodeStorage.h"
|
2024-01-20 22:54:30 +02:00
|
|
|
#include "ObjectGraph.h"
|
2021-05-15 18:22:44 +02:00
|
|
|
#include "../AIUtility.h"
|
2020-05-04 17:58:43 +02:00
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2020-05-04 17:58:43 +02:00
|
|
|
class Nullkiller;
|
2021-05-15 18:22:44 +02:00
|
|
|
|
2021-05-16 13:56:21 +02:00
|
|
|
struct PathfinderSettings
|
|
|
|
{
|
|
|
|
bool useHeroChain;
|
|
|
|
uint8_t scoutTurnDistanceLimit;
|
2021-05-16 14:01:34 +02:00
|
|
|
uint8_t mainTurnDistanceLimit;
|
2024-01-20 22:54:30 +02:00
|
|
|
bool allowBypassObjects;
|
2021-05-16 13:56:21 +02:00
|
|
|
|
|
|
|
PathfinderSettings()
|
|
|
|
:useHeroChain(false),
|
2021-05-16 14:01:34 +02:00
|
|
|
scoutTurnDistanceLimit(255),
|
2024-01-20 22:54:30 +02:00
|
|
|
mainTurnDistanceLimit(255),
|
|
|
|
allowBypassObjects(true)
|
2021-05-16 13:56:21 +02:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
class AIPathfinder
|
|
|
|
{
|
|
|
|
private:
|
2021-05-16 13:49:39 +02:00
|
|
|
std::shared_ptr<AINodeStorage> storage;
|
2021-05-15 18:22:44 +02:00
|
|
|
CPlayerSpecificInfoCallback * cb;
|
2020-05-04 17:58:43 +02:00
|
|
|
Nullkiller * ai;
|
2024-03-24 09:32:29 +02:00
|
|
|
std::map<ObjectInstanceID, std::unique_ptr<GraphPaths>> heroGraphs;
|
2021-05-15 18:22:44 +02:00
|
|
|
|
|
|
|
public:
|
2020-05-04 17:58:43 +02:00
|
|
|
AIPathfinder(CPlayerSpecificInfoCallback * cb, Nullkiller * ai);
|
2024-03-24 09:32:29 +02:00
|
|
|
void calculatePathInfo(std::vector<AIPath> & paths, const int3 & tile, bool includeGraph = false) const;
|
2021-05-15 18:22:44 +02:00
|
|
|
bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const;
|
2024-03-09 16:20:00 +02:00
|
|
|
void updatePaths(const std::map<const CGHeroInstance *, HeroRole> & heroes, PathfinderSettings pathfinderSettings);
|
|
|
|
void updateGraphs(const std::map<const CGHeroInstance *, HeroRole> & heroes);
|
2024-03-24 09:32:29 +02:00
|
|
|
void calculateQuickPathsWithBlocker(std::vector<AIPath> & result, const std::vector<const CGHeroInstance *> & heroes, const int3 & tile);
|
2021-05-15 18:22:44 +02:00
|
|
|
void init();
|
2024-01-27 22:19:27 +02:00
|
|
|
|
|
|
|
std::shared_ptr<AINodeStorage>getStorage()
|
|
|
|
{
|
|
|
|
return storage;
|
|
|
|
}
|
2024-03-24 09:32:29 +02:00
|
|
|
|
|
|
|
std::vector<AIPath> getPathInfo(const int3 & tile, bool includeGraph = false)
|
|
|
|
{
|
|
|
|
std::vector<AIPath> result;
|
|
|
|
|
|
|
|
calculatePathInfo(result, tile, includeGraph);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2021-05-15 18:22:44 +02:00
|
|
|
};
|
2022-09-26 20:01:07 +02:00
|
|
|
|
|
|
|
}
|