1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/AI/Nullkiller/Analyzers/ObjectClusterizer.h

74 lines
1.6 KiB
C++
Raw Normal View History

2021-05-16 13:45:12 +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
*
*/
#pragma once
#include "../Pathfinding/AINodeStorage.h"
2022-09-26 20:01:07 +02:00
namespace NKAI
{
2021-05-16 13:55:57 +02:00
struct ClusterObjectInfo
2021-05-16 13:45:12 +02:00
{
float priority;
float movementCost;
uint64_t danger;
uint8_t turn;
};
2023-04-17 23:11:16 +02:00
using ClusterObjects = tbb::concurrent_hash_map<const CGObjectInstance *, ClusterObjectInfo>;
2021-05-16 13:45:12 +02:00
struct ObjectCluster
{
public:
ClusterObjects objects;
2021-05-16 13:45:12 +02:00
const CGObjectInstance * blocker;
void reset()
{
objects.clear();
}
void addObject(const CGObjectInstance * object, const AIPath & path, float priority);
2023-04-17 23:11:16 +02:00
ObjectCluster(const CGObjectInstance * blocker): blocker(blocker) {}
2021-05-16 13:45:12 +02:00
ObjectCluster() : ObjectCluster(nullptr)
{
}
std::vector<const CGObjectInstance *> getObjects() const;
const CGObjectInstance * calculateCenter() const;
};
2023-04-17 23:11:16 +02:00
using ClusterMap = tbb::concurrent_hash_map<const CGObjectInstance *, std::shared_ptr<ObjectCluster>>;
2021-05-16 13:45:12 +02:00
class ObjectClusterizer
{
private:
ObjectCluster nearObjects;
ObjectCluster farObjects;
ClusterMap blockedObjects;
const Nullkiller * ai;
2021-05-16 13:45:12 +02:00
public:
void clusterize();
std::vector<const CGObjectInstance *> getNearbyObjects() const;
2021-05-16 13:45:45 +02:00
std::vector<const CGObjectInstance *> getFarObjects() const;
2021-05-16 13:45:12 +02:00
std::vector<std::shared_ptr<ObjectCluster>> getLockedClusters() const;
const CGObjectInstance * getBlocker(const AIPath & path) const;
2023-04-17 23:11:16 +02:00
ObjectClusterizer(const Nullkiller * ai): ai(ai) {}
private:
bool shouldVisitObject(const CGObjectInstance * obj) const;
2021-05-16 13:45:12 +02:00
};
2022-09-26 20:01:07 +02:00
}