mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Implement MapObjectsEvaluator as singleton utility
This commit is contained in:
parent
6a9e91b99b
commit
36f501ebf3
@ -4,9 +4,15 @@
|
|||||||
#include "../../lib/VCMI_Lib.h"
|
#include "../../lib/VCMI_Lib.h"
|
||||||
#include "../../lib/mapObjects/CObjectClassesHandler.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())
|
for(auto primaryID : VLC->objtypeh->knownObjects())
|
||||||
{
|
{
|
||||||
@ -35,6 +41,6 @@ boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int seco
|
|||||||
return (*desiredObject).second;
|
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>();
|
return boost::optional<int>();
|
||||||
}
|
}
|
||||||
|
@ -12,10 +12,12 @@
|
|||||||
class MapObjectsEvaluator
|
class MapObjectsEvaluator
|
||||||
{
|
{
|
||||||
private:
|
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:
|
public:
|
||||||
static void init();
|
MapObjectsEvaluator();
|
||||||
static boost::optional<int> getObjectValue(int primaryID, int secondaryID);
|
static MapObjectsEvaluator & getInstance();
|
||||||
|
boost::optional<int> getObjectValue(int primaryID, int secondaryID);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user