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:
parent
6a9e91b99b
commit
36f501ebf3
@ -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>();
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user