2021-05-15 18:23:38 +02:00
|
|
|
/*
|
2021-05-15 21:04:26 +02:00
|
|
|
* PriorityEvaluator.cpp, 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
|
|
|
|
*
|
2021-05-15 18:23:38 +02:00
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "PriorityEvaluator.h"
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include "../../../lib/mapObjects/MapObjects.h"
|
|
|
|
#include "../../../lib/mapObjects/CommonConstructors.h"
|
|
|
|
#include "../../../lib/CCreatureHandler.h"
|
|
|
|
#include "../../../lib/CPathfinder.h"
|
|
|
|
#include "../../../lib/CGameStateFwd.h"
|
|
|
|
#include "../../../lib/VCMI_Lib.h"
|
|
|
|
#include "../../../CCallback.h"
|
2021-05-15 21:02:27 +02:00
|
|
|
#include "../../../lib/filesystem/Filesystem.h"
|
2021-05-15 18:23:38 +02:00
|
|
|
#include "../VCAI.h"
|
2021-05-15 21:02:27 +02:00
|
|
|
#include "../AIhelper.h"
|
2021-05-16 13:13:35 +02:00
|
|
|
#include "../Engine/Nullkiller.h"
|
2021-05-15 18:23:38 +02:00
|
|
|
|
|
|
|
#define MIN_AI_STRENGHT (0.5f) //lower when combat AI gets smarter
|
|
|
|
#define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us
|
|
|
|
|
|
|
|
struct BankConfig;
|
|
|
|
class CBankInfo;
|
|
|
|
class Engine;
|
|
|
|
class InputVariable;
|
|
|
|
class CGTownInstance;
|
|
|
|
|
|
|
|
extern boost::thread_specific_ptr<CCallback> cb;
|
|
|
|
extern boost::thread_specific_ptr<VCAI> ai;
|
|
|
|
|
|
|
|
PriorityEvaluator::PriorityEvaluator()
|
|
|
|
{
|
|
|
|
initVisitTile();
|
|
|
|
}
|
|
|
|
|
|
|
|
PriorityEvaluator::~PriorityEvaluator()
|
|
|
|
{
|
2021-05-15 21:02:27 +02:00
|
|
|
delete engine;
|
2021-05-15 18:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PriorityEvaluator::initVisitTile()
|
|
|
|
{
|
2021-05-15 21:04:26 +02:00
|
|
|
auto file = CResourceHandler::get()->load(ResourceID("config/ai/object-priorities.txt"))->readAll();
|
2021-05-15 21:02:27 +02:00
|
|
|
std::string str = std::string((char *)file.first.get(), file.second);
|
|
|
|
engine = fl::FllImporter().fromString(str);
|
|
|
|
armyLossPersentageVariable = engine->getInputVariable("armyLoss");
|
|
|
|
heroRoleVariable = engine->getInputVariable("heroRole");
|
|
|
|
dangerVariable = engine->getInputVariable("danger");
|
2021-05-16 13:14:07 +02:00
|
|
|
mainTurnDistanceVariable = engine->getInputVariable("mainTurnDistance");
|
|
|
|
scoutTurnDistanceVariable = engine->getInputVariable("scoutTurnDistance");
|
2021-05-15 21:02:27 +02:00
|
|
|
goldRewardVariable = engine->getInputVariable("goldReward");
|
|
|
|
armyRewardVariable = engine->getInputVariable("armyReward");
|
|
|
|
skillRewardVariable = engine->getInputVariable("skillReward");
|
|
|
|
rewardTypeVariable = engine->getInputVariable("rewardType");
|
|
|
|
closestHeroRatioVariable = engine->getInputVariable("closestHeroRatio");
|
2021-05-16 13:13:35 +02:00
|
|
|
strategicalValueVariable = engine->getInputVariable("strategicalValue");
|
2021-05-15 21:02:27 +02:00
|
|
|
value = engine->getOutputVariable("Value");
|
2021-05-15 18:23:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t estimateTownIncome(const CGObjectInstance * target, const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
auto relations = cb->getPlayerRelations(hero->tempOwner, target->tempOwner);
|
|
|
|
|
|
|
|
if(relations != PlayerRelations::ENEMIES)
|
|
|
|
return 0; // if we already own it, no additional reward will be received by just visiting it
|
|
|
|
|
|
|
|
auto town = cb->getTown(target->id);
|
|
|
|
auto isNeutral = target->tempOwner == PlayerColor::NEUTRAL;
|
|
|
|
auto isProbablyDeveloped = !isNeutral && town->hasFort();
|
|
|
|
|
|
|
|
return isProbablyDeveloped ? 1500 : 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
TResources getCreatureBankResources(const CGObjectInstance * target, const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
auto objectInfo = VLC->objtypeh->getHandlerFor(target->ID, target->subID)->getObjectInfo(target->appearance);
|
|
|
|
CBankInfo * bankInfo = dynamic_cast<CBankInfo *>(objectInfo.get());
|
|
|
|
auto resources = bankInfo->getPossibleResourcesReward();
|
|
|
|
|
|
|
|
return resources;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t getCreatureBankArmyReward(const CGObjectInstance * target, const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
auto objectInfo = VLC->objtypeh->getHandlerFor(target->ID, target->subID)->getObjectInfo(target->appearance);
|
|
|
|
CBankInfo * bankInfo = dynamic_cast<CBankInfo *>(objectInfo.get());
|
|
|
|
auto creatures = bankInfo->getPossibleCreaturesReward();
|
|
|
|
uint64_t result = 0;
|
|
|
|
|
|
|
|
for(auto c : creatures)
|
|
|
|
{
|
|
|
|
result += c.type->AIValue * c.count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-05-15 21:02:57 +02:00
|
|
|
uint64_t getDwellingScore(const CGObjectInstance * target, bool checkGold)
|
2021-05-15 18:23:38 +02:00
|
|
|
{
|
|
|
|
auto dwelling = dynamic_cast<const CGDwelling *>(target);
|
|
|
|
uint64_t score = 0;
|
|
|
|
|
|
|
|
for(auto & creLevel : dwelling->creatures)
|
|
|
|
{
|
|
|
|
if(creLevel.first && creLevel.second.size())
|
|
|
|
{
|
|
|
|
auto creature = creLevel.second.back().toCreature();
|
2021-05-15 21:02:57 +02:00
|
|
|
if(checkGold && !cb->getResourceAmount().canAfford(creature->cost * creLevel.first))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
score += creature->AIValue * creLevel.first;
|
2021-05-15 18:23:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
2021-05-16 12:52:34 +02:00
|
|
|
uint64_t evaluateArtifactArmyValue(CArtifactInstance * art)
|
|
|
|
{
|
|
|
|
if(art->artType->id == ArtifactID::SPELL_SCROLL)
|
|
|
|
return 1500;
|
|
|
|
|
|
|
|
auto statsValue =
|
|
|
|
4 * art->valOfBonuses(Bonus::LAND_MOVEMENT)
|
|
|
|
+ 700 * art->valOfBonuses(Bonus::MORALE)
|
|
|
|
+ 700 * art->getAttack(false)
|
|
|
|
+ 700 * art->getDefence(false)
|
|
|
|
+ 700 * art->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::KNOWLEDGE)
|
|
|
|
+ 700 * art->valOfBonuses(Bonus::PRIMARY_SKILL, PrimarySkill::SPELL_POWER)
|
|
|
|
+ 700 * art->getDefence(false)
|
|
|
|
+ 500 * art->valOfBonuses(Bonus::LUCK);
|
|
|
|
|
|
|
|
auto classValue = 0;
|
|
|
|
|
|
|
|
switch(art->artType->aClass)
|
|
|
|
{
|
|
|
|
case CArtifact::EartClass::ART_MINOR:
|
|
|
|
classValue = 1000;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CArtifact::EartClass::ART_MAJOR:
|
|
|
|
classValue = 3000;
|
|
|
|
break;
|
|
|
|
case CArtifact::EartClass::ART_RELIC:
|
|
|
|
case CArtifact::EartClass::ART_SPECIAL:
|
|
|
|
classValue = 8000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return statsValue > classValue ? statsValue : classValue;
|
|
|
|
}
|
|
|
|
|
2021-05-15 21:02:57 +02:00
|
|
|
uint64_t getArmyReward(const CGObjectInstance * target, const CGHeroInstance * hero, bool checkGold)
|
2021-05-15 18:23:38 +02:00
|
|
|
{
|
2021-05-16 12:53:05 +02:00
|
|
|
const float enemyArmyEliminationRewardRatio = 0.5f;
|
|
|
|
|
2021-05-15 18:23:38 +02:00
|
|
|
if(!target)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch(target->ID)
|
|
|
|
{
|
|
|
|
case Obj::TOWN:
|
2021-05-15 21:02:57 +02:00
|
|
|
return target->tempOwner == PlayerColor::NEUTRAL ? 1000 : 10000;
|
2021-05-15 18:23:38 +02:00
|
|
|
case Obj::CREATURE_BANK:
|
|
|
|
return getCreatureBankArmyReward(target, hero);
|
|
|
|
case Obj::CREATURE_GENERATOR1:
|
2021-05-15 21:02:57 +02:00
|
|
|
case Obj::CREATURE_GENERATOR2:
|
|
|
|
case Obj::CREATURE_GENERATOR3:
|
|
|
|
case Obj::CREATURE_GENERATOR4:
|
|
|
|
return getDwellingScore(target, checkGold);
|
2021-05-15 18:23:38 +02:00
|
|
|
case Obj::CRYPT:
|
|
|
|
case Obj::SHIPWRECK:
|
|
|
|
case Obj::SHIPWRECK_SURVIVOR:
|
2021-05-16 12:52:34 +02:00
|
|
|
case Obj::WARRIORS_TOMB:
|
2021-05-15 18:23:38 +02:00
|
|
|
return 1500;
|
|
|
|
case Obj::ARTIFACT:
|
2021-05-16 12:52:34 +02:00
|
|
|
return evaluateArtifactArmyValue(dynamic_cast<const CGArtifact *>(target)->storedArtifact);
|
2021-05-15 18:23:38 +02:00
|
|
|
case Obj::DRAGON_UTOPIA:
|
|
|
|
return 10000;
|
2021-05-16 12:53:05 +02:00
|
|
|
case Obj::HERO:
|
|
|
|
return cb->getPlayerRelations(target->tempOwner, ai->playerID) == PlayerRelations::ENEMIES
|
|
|
|
? enemyArmyEliminationRewardRatio * dynamic_cast<const CGHeroInstance *>(target)->getArmyStrength()
|
|
|
|
: 0;
|
2021-05-15 18:23:38 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:13:35 +02:00
|
|
|
float getStrategicalValue(const CGObjectInstance * target);
|
|
|
|
|
|
|
|
float getEnemyHeroStrategicalValue(const CGHeroInstance * enemy)
|
|
|
|
{
|
|
|
|
auto objectsUnderTreat = ai->nullkiller->dangerHitMap->getOneTurnAccessibleObjects(enemy);
|
|
|
|
float objectValue = 0;
|
|
|
|
|
|
|
|
for(auto obj : objectsUnderTreat)
|
|
|
|
{
|
2021-05-16 13:13:56 +02:00
|
|
|
vstd::amax(objectValue, getStrategicalValue(obj));
|
2021-05-16 13:13:35 +02:00
|
|
|
}
|
|
|
|
|
2021-05-16 13:13:56 +02:00
|
|
|
return objectValue / 2.0f + enemy->level / 15.0f;
|
2021-05-16 13:13:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
float getStrategicalValue(const CGObjectInstance * target)
|
|
|
|
{
|
|
|
|
if(!target)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch(target->ID)
|
|
|
|
{
|
|
|
|
case Obj::TOWN:
|
|
|
|
return target->tempOwner == PlayerColor::NEUTRAL ? 0.5 : 1;
|
|
|
|
|
|
|
|
case Obj::HERO:
|
|
|
|
return cb->getPlayerRelations(target->tempOwner, ai->playerID) == PlayerRelations::ENEMIES
|
|
|
|
? getEnemyHeroStrategicalValue(dynamic_cast<const CGHeroInstance *>(target))
|
|
|
|
: 0;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-15 21:02:27 +02:00
|
|
|
float evaluateWitchHutSkillScore(const CGWitchHut * hut, const CGHeroInstance * hero, HeroRole role)
|
|
|
|
{
|
|
|
|
if(!hut->wasVisited(hero->tempOwner))
|
|
|
|
return role == HeroRole::SCOUT ? 2 : 0;
|
|
|
|
|
|
|
|
auto skill = SecondarySkill(hut->ability);
|
|
|
|
|
|
|
|
if(hero->getSecSkillLevel(skill) != SecSkillLevel::NONE
|
|
|
|
|| hero->secSkills.size() >= GameConstants::SKILL_PER_HERO)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
auto score = ai->ah->evaluateSecSkill(skill, hero);
|
|
|
|
|
|
|
|
return score >= 2 ? (role == HeroRole::MAIN ? 10 : 4) : score;
|
|
|
|
}
|
|
|
|
|
|
|
|
float getSkillReward(const CGObjectInstance * target, const CGHeroInstance * hero, HeroRole role)
|
|
|
|
{
|
2021-05-16 12:53:05 +02:00
|
|
|
const float enemyHeroEliminationSkillRewardRatio = 0.5f;
|
|
|
|
|
2021-05-15 21:02:27 +02:00
|
|
|
if(!target)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch(target->ID)
|
|
|
|
{
|
|
|
|
case Obj::STAR_AXIS:
|
|
|
|
case Obj::SCHOLAR:
|
|
|
|
case Obj::SCHOOL_OF_MAGIC:
|
|
|
|
case Obj::SCHOOL_OF_WAR:
|
|
|
|
case Obj::GARDEN_OF_REVELATION:
|
|
|
|
case Obj::MARLETTO_TOWER:
|
|
|
|
case Obj::MERCENARY_CAMP:
|
|
|
|
case Obj::SHRINE_OF_MAGIC_GESTURE:
|
2021-05-15 21:02:52 +02:00
|
|
|
case Obj::SHRINE_OF_MAGIC_INCANTATION:
|
2021-05-15 21:02:27 +02:00
|
|
|
return 1;
|
|
|
|
case Obj::ARENA:
|
|
|
|
case Obj::SHRINE_OF_MAGIC_THOUGHT:
|
|
|
|
return 2;
|
|
|
|
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
|
|
|
return 8;
|
|
|
|
case Obj::WITCH_HUT:
|
|
|
|
return evaluateWitchHutSkillScore(dynamic_cast<const CGWitchHut *>(target), hero, role);
|
2021-05-16 12:53:05 +02:00
|
|
|
case Obj::HERO:
|
|
|
|
return cb->getPlayerRelations(target->tempOwner, ai->playerID) == PlayerRelations::ENEMIES
|
|
|
|
? enemyHeroEliminationSkillRewardRatio * dynamic_cast<const CGHeroInstance *>(target)->level
|
|
|
|
: 0;
|
2021-05-15 21:02:27 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-16 12:53:05 +02:00
|
|
|
int32_t getArmyCost(const CArmedInstance * army)
|
|
|
|
{
|
|
|
|
int32_t value = 0;
|
|
|
|
|
|
|
|
for(auto stack : army->Slots())
|
|
|
|
{
|
|
|
|
value += stack.second->getCreatureID().toCreature()->cost[Res::GOLD] * stack.second->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-05-15 18:23:38 +02:00
|
|
|
/// Gets aproximated reward in gold. Daily income is multiplied by 5
|
|
|
|
int32_t getGoldReward(const CGObjectInstance * target, const CGHeroInstance * hero)
|
|
|
|
{
|
|
|
|
if(!target)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const int dailyIncomeMultiplier = 5;
|
2021-05-16 12:53:05 +02:00
|
|
|
const float enemyArmyEliminationGoldRewardRatio = 0.2f;
|
|
|
|
const int32_t heroEliminationBonus = GameConstants::HERO_GOLD_COST / 2;
|
2021-05-15 18:23:38 +02:00
|
|
|
auto isGold = target->subID == Res::GOLD; // TODO: other resorces could be sold but need to evaluate market power
|
|
|
|
|
|
|
|
switch(target->ID)
|
|
|
|
{
|
|
|
|
case Obj::RESOURCE:
|
2021-05-15 21:02:27 +02:00
|
|
|
return isGold ? 600 : 100;
|
2021-05-15 18:23:38 +02:00
|
|
|
case Obj::TREASURE_CHEST:
|
|
|
|
return 1500;
|
|
|
|
case Obj::WATER_WHEEL:
|
|
|
|
return 1000;
|
|
|
|
case Obj::TOWN:
|
|
|
|
return dailyIncomeMultiplier * estimateTownIncome(target, hero);
|
|
|
|
case Obj::MINE:
|
|
|
|
case Obj::ABANDONED_MINE:
|
|
|
|
return dailyIncomeMultiplier * (isGold ? 1000 : 75);
|
|
|
|
case Obj::MYSTICAL_GARDEN:
|
|
|
|
case Obj::WINDMILL:
|
|
|
|
return 100;
|
|
|
|
case Obj::CAMPFIRE:
|
2021-05-15 21:02:27 +02:00
|
|
|
return 800;
|
2021-05-16 12:52:34 +02:00
|
|
|
case Obj::WAGON:
|
|
|
|
return 100;
|
2021-05-15 18:23:38 +02:00
|
|
|
case Obj::CREATURE_BANK:
|
|
|
|
return getCreatureBankResources(target, hero)[Res::GOLD];
|
|
|
|
case Obj::CRYPT:
|
|
|
|
case Obj::DERELICT_SHIP:
|
|
|
|
return 3000;
|
|
|
|
case Obj::DRAGON_UTOPIA:
|
|
|
|
return 10000;
|
|
|
|
case Obj::SEA_CHEST:
|
|
|
|
return 1500;
|
2021-05-16 12:53:05 +02:00
|
|
|
case Obj::HERO:
|
|
|
|
return cb->getPlayerRelations(target->tempOwner, ai->playerID) == PlayerRelations::ENEMIES
|
|
|
|
? heroEliminationBonus + enemyArmyEliminationGoldRewardRatio * getArmyCost(dynamic_cast<const CGHeroInstance *>(target))
|
|
|
|
: 0;
|
2021-05-15 18:23:38 +02:00
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// distance
|
|
|
|
/// nearest hero?
|
|
|
|
/// gold income
|
|
|
|
/// army income
|
|
|
|
/// hero strength - hero skills
|
|
|
|
/// danger
|
|
|
|
/// importance
|
|
|
|
float PriorityEvaluator::evaluate(Goals::TSubgoal task)
|
|
|
|
{
|
2021-05-15 21:02:52 +02:00
|
|
|
if(task->priority > 0)
|
|
|
|
return task->priority;
|
|
|
|
|
2021-05-15 18:23:38 +02:00
|
|
|
auto heroPtr = task->hero;
|
|
|
|
|
|
|
|
if(!heroPtr.validAndSet())
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
int objId = task->objid;
|
|
|
|
|
|
|
|
if(task->parent)
|
|
|
|
objId = task->parent->objid;
|
|
|
|
|
|
|
|
const CGObjectInstance * target = cb->getObj((ObjectInstanceID)objId, false);
|
|
|
|
|
2021-05-15 21:02:27 +02:00
|
|
|
auto day = cb->getDate(Date::DAY);
|
2021-05-15 18:23:38 +02:00
|
|
|
auto hero = heroPtr.get();
|
2021-05-15 20:26:24 +02:00
|
|
|
auto armyTotal = task->evaluationContext.heroStrength;
|
|
|
|
double armyLossPersentage = task->evaluationContext.armyLoss / (double)armyTotal;
|
2021-05-15 21:02:57 +02:00
|
|
|
uint64_t danger = task->evaluationContext.danger;
|
2021-05-15 21:02:27 +02:00
|
|
|
HeroRole heroRole = ai->ah->getHeroRole(heroPtr);
|
2021-05-15 21:02:57 +02:00
|
|
|
int32_t goldReward = getGoldReward(target, hero);
|
|
|
|
bool checkGold = danger == 0;
|
|
|
|
uint64_t armyReward = getArmyReward(target, hero, checkGold);
|
2021-05-15 21:02:27 +02:00
|
|
|
float skillReward = getSkillReward(target, hero, heroRole);
|
2021-05-16 13:13:35 +02:00
|
|
|
float strategicalValue = getStrategicalValue(target);
|
2021-05-15 18:23:38 +02:00
|
|
|
double result = 0;
|
2021-05-16 13:13:35 +02:00
|
|
|
int rewardType = (goldReward > 0 ? 1 : 0) + (armyReward > 0 ? 1 : 0) + (skillReward > 0 ? 1 : 0) + (strategicalValue > 0 ? 1 : 0);
|
2021-05-15 21:02:52 +02:00
|
|
|
|
2021-05-15 18:23:38 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
armyLossPersentageVariable->setValue(armyLossPersentage);
|
2021-05-15 21:02:27 +02:00
|
|
|
heroRoleVariable->setValue(heroRole);
|
2021-05-16 13:14:07 +02:00
|
|
|
mainTurnDistanceVariable->setValue(task->evaluationContext.movementCostByRole[HeroRole::MAIN]);
|
|
|
|
scoutTurnDistanceVariable->setValue(task->evaluationContext.movementCostByRole[HeroRole::SCOUT]);
|
2021-05-15 18:23:38 +02:00
|
|
|
goldRewardVariable->setValue(goldReward);
|
2021-05-15 21:02:27 +02:00
|
|
|
armyRewardVariable->setValue(armyReward);
|
|
|
|
skillRewardVariable->setValue(skillReward);
|
2021-05-15 20:57:40 +02:00
|
|
|
dangerVariable->setValue(danger);
|
2021-05-15 21:02:27 +02:00
|
|
|
rewardTypeVariable->setValue(rewardType);
|
|
|
|
closestHeroRatioVariable->setValue(task->evaluationContext.closestWayRatio);
|
2021-05-16 13:13:35 +02:00
|
|
|
strategicalValueVariable->setValue(strategicalValue);
|
2021-05-15 18:23:38 +02:00
|
|
|
|
2021-05-15 21:02:27 +02:00
|
|
|
engine->process();
|
2021-05-15 18:23:38 +02:00
|
|
|
//engine.process(VISIT_TILE); //TODO: Process only Visit_Tile
|
2021-05-15 21:02:27 +02:00
|
|
|
result = value->getValue();
|
2021-05-15 18:23:38 +02:00
|
|
|
}
|
|
|
|
catch(fl::Exception & fe)
|
|
|
|
{
|
|
|
|
logAi->error("evaluate VisitTile: %s", fe.getWhat());
|
|
|
|
}
|
|
|
|
assert(result >= 0);
|
|
|
|
|
|
|
|
#ifdef VCMI_TRACE_PATHFINDER
|
2021-05-16 13:13:56 +02:00
|
|
|
logAi->trace("Evaluated %s, hero %s, loss: %f, turns: %f, gold: %d, army gain: %d, danger: %d, role: %s, strategical value: %f, result %f",
|
2021-05-15 18:23:38 +02:00
|
|
|
task->name(),
|
2021-05-15 21:02:27 +02:00
|
|
|
hero->name,
|
2021-05-15 18:23:38 +02:00
|
|
|
armyLossPersentage,
|
|
|
|
task->evaluationContext.movementCost,
|
|
|
|
goldReward,
|
|
|
|
armyReward,
|
2021-05-15 20:57:40 +02:00
|
|
|
danger,
|
2021-05-15 21:02:27 +02:00
|
|
|
heroRole ? "scout" : "main",
|
2021-05-16 13:13:56 +02:00
|
|
|
strategicalValue,
|
2021-05-15 18:23:38 +02:00
|
|
|
result);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|