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

Added basic interface for AI to evaluate objects

This commit is contained in:
Dydzio 2018-07-20 21:14:57 +02:00
parent cae8acc56a
commit 6a9e91b99b
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,40 @@
#include "StdInc.h"
#include "MapObjectsEvaluator.h"
#include "../../lib/GameConstants.h"
#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>>();
void MapObjectsEvaluator::init()
{
for(auto primaryID : VLC->objtypeh->knownObjects())
{
auto newObject = std::pair<int, std::map<int, int>>(primaryID, std::map<int, int>());
for(auto secondaryID : VLC->objtypeh->knownSubObjects(primaryID))
{
auto handler = VLC->objtypeh->getHandlerFor(primaryID, secondaryID);
if(!handler->isStaticObject() && handler->getRMGInfo().value)
{
newObject.second.insert(std::pair<int,int>(secondaryID, handler->getRMGInfo().value));
}
}
objectDatabase.insert(newObject);
}
}
boost::optional<int> MapObjectsEvaluator::getObjectValue(int primaryID, int secondaryID)
{
auto object = objectDatabase.find(primaryID);
if(object != objectDatabase.end())
{
auto subobjects = (*object).second;
auto desiredObject = subobjects.find(secondaryID);
if(desiredObject != subobjects.end())
{
return (*desiredObject).second;
}
}
logGlobal->trace("Unknown object for AI, ID: " + std::to_string(primaryID) + " SubID: " + std::to_string(secondaryID));
return boost::optional<int>();
}

View File

@ -0,0 +1,21 @@
/*
* MapObjectsEvaluator.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
class MapObjectsEvaluator
{
private:
static std::map<int, std::map<int, int>> objectDatabase; //each object contains map of subobjects with their values
public:
static void init();
static boost::optional<int> getObjectValue(int primaryID, int secondaryID);
};