2021-05-15 21:04:26 +02:00
|
|
|
/*
|
|
|
|
* DangerHitMapAnalyzer.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
|
|
|
|
*
|
|
|
|
*/
|
2021-05-15 20:57:36 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-05-16 13:55:47 +02:00
|
|
|
#include "../AIUtility.h"
|
2021-05-15 20:57:36 +02:00
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2023-05-24 01:05:59 +02:00
|
|
|
struct AIPath;
|
|
|
|
|
2021-05-15 20:57:36 +02:00
|
|
|
struct HitMapInfo
|
|
|
|
{
|
2023-10-27 21:32:52 +02:00
|
|
|
static HitMapInfo NoThreat;
|
2023-02-28 09:07:59 +02:00
|
|
|
|
2021-05-15 20:57:36 +02:00
|
|
|
uint64_t danger;
|
|
|
|
uint8_t turn;
|
2021-05-16 13:56:21 +02:00
|
|
|
HeroPtr hero;
|
2021-05-15 20:57:36 +02:00
|
|
|
|
2023-02-28 09:07:59 +02:00
|
|
|
HitMapInfo()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
2021-05-15 20:57:36 +02:00
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
danger = 0;
|
|
|
|
turn = 255;
|
2021-05-16 13:56:21 +02:00
|
|
|
hero = HeroPtr();
|
2021-05-15 20:57:36 +02:00
|
|
|
}
|
2023-06-11 18:21:50 +02:00
|
|
|
|
|
|
|
double value() const;
|
2021-05-15 20:57:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct HitMapNode
|
|
|
|
{
|
|
|
|
HitMapInfo maximumDanger;
|
|
|
|
HitMapInfo fastestDanger;
|
|
|
|
|
2023-06-11 18:21:50 +02:00
|
|
|
const CGTownInstance * closestTown = nullptr;
|
|
|
|
|
2023-02-28 09:07:59 +02:00
|
|
|
HitMapNode() = default;
|
|
|
|
|
2021-05-15 20:57:36 +02:00
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
maximumDanger.reset();
|
|
|
|
fastestDanger.reset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-08-06 07:57:14 +02:00
|
|
|
struct EnemyHeroAccessibleObject
|
|
|
|
{
|
|
|
|
const CGHeroInstance * hero;
|
|
|
|
const CGObjectInstance * obj;
|
|
|
|
|
|
|
|
EnemyHeroAccessibleObject(const CGHeroInstance * hero, const CGObjectInstance * obj)
|
|
|
|
:hero(hero), obj(obj)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-05-15 20:57:36 +02:00
|
|
|
class DangerHitMapAnalyzer
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
boost::multi_array<HitMapNode, 3> hitMap;
|
2023-08-06 07:57:14 +02:00
|
|
|
tbb::concurrent_vector<EnemyHeroAccessibleObject> enemyHeroAccessibleObjects;
|
2023-06-04 15:02:02 +02:00
|
|
|
bool hitMapUpToDate = false;
|
|
|
|
bool tileOwnersUpToDate = false;
|
2020-05-04 17:58:43 +02:00
|
|
|
const Nullkiller * ai;
|
2023-10-27 21:32:52 +02:00
|
|
|
std::map<ObjectInstanceID, std::vector<HitMapInfo>> townThreats;
|
2021-05-15 20:57:36 +02:00
|
|
|
|
|
|
|
public:
|
2020-05-04 17:58:43 +02:00
|
|
|
DangerHitMapAnalyzer(const Nullkiller * ai) :ai(ai) {}
|
|
|
|
|
2021-05-15 20:57:36 +02:00
|
|
|
void updateHitMap();
|
2023-06-04 15:02:02 +02:00
|
|
|
void calculateTileOwners();
|
2021-05-15 20:57:36 +02:00
|
|
|
uint64_t enemyCanKillOurHeroesAlongThePath(const AIPath & path) const;
|
2023-10-27 21:32:52 +02:00
|
|
|
const HitMapNode & getObjectThreat(const CGObjectInstance * obj) const;
|
|
|
|
const HitMapNode & getTileThreat(const int3 & tile) const;
|
2023-08-06 07:57:14 +02:00
|
|
|
std::set<const CGObjectInstance *> getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const;
|
2021-05-16 13:13:35 +02:00
|
|
|
void reset();
|
2023-06-04 15:02:02 +02:00
|
|
|
void resetTileOwners() { tileOwnersUpToDate = false; }
|
2023-06-11 18:21:50 +02:00
|
|
|
PlayerColor getTileOwner(const int3 & tile) const;
|
|
|
|
const CGTownInstance * getClosestTown(const int3 & tile) const;
|
2023-10-27 21:32:52 +02:00
|
|
|
const std::vector<HitMapInfo> & getTownThreats(const CGTownInstance * town) const;
|
2021-05-15 21:04:26 +02:00
|
|
|
};
|
2022-09-26 20:01:07 +02:00
|
|
|
|
|
|
|
}
|