1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Implement MapObjectsEvaluator as singleton utility

This commit is contained in:
Dydzio 2018-07-21 11:28:55 +02:00
parent 6a9e91b99b
commit 36f501ebf3
2 changed files with 14 additions and 6 deletions

View File

@ -4,9 +4,15 @@
#include "../../lib/VCMI_Lib.h"
#include "../../lib/mapObjects/CObjectClassesHandler.h"
std::map<int, std::map<int, int>> MapObjectsEvaluator::objectDatabase = std::map<int, std::map<int, int>>();
MapObjectsEvaluator & MapObjectsEvaluator::getInstance()
{
if(singletonInstance == nullptr)
singletonInstance.reset(new MapObjectsEvaluator());
void MapObjectsEvaluator::init()
return *(singletonInstance.get());
}
MapObjectsEvaluator::MapObjectsEvaluator() : objectDatabase(std::map<int, std::map<int, int>>())
{
for(auto primaryID : VLC->objtypeh->knownObjects())
{
@ -35,6 +41,6 @@ boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int seco
return (*desiredObject).second;
}
}
logGlobal->trace("Unknown object for AI, ID: " + std::to_string(primaryID) + " SubID: " + std::to_string(secondaryID));
logGlobal->trace("Unknown object for AI, ID: " + std::to_string(primaryID) + ", SubID: " + std::to_string(secondaryID));
return boost::optional<int>();
}

View File

@ -12,10 +12,12 @@
class MapObjectsEvaluator
{
private:
static std::map<int, std::map<int, int>> objectDatabase; //each object contains map of subobjects with their values
std::map<int, std::map<int, int>> objectDatabase; //each object contains map of subobjects with their values (std::map<ObjID, std::map<SubObjID, Value>>)
static std::unique_ptr<MapObjectsEvaluator> singletonInstance;
public:
static void init();
static boost::optional<int> getObjectValue(int primaryID, int secondaryID);
MapObjectsEvaluator();
static MapObjectsEvaluator & getInstance();
boost::optional<int> getObjectValue(int primaryID, int secondaryID);
};