1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-03 13:01:33 +02:00

NullkillerAI: Added movement cost by hero role. New priority engine looks more or less stable.

This commit is contained in:
Andrii Danylchenko 2021-05-16 14:14:07 +03:00 committed by Andrii Danylchenko
parent eea5cb7f0b
commit af9261d428
6 changed files with 25 additions and 11 deletions

View File

@ -34,6 +34,13 @@ const int ALLOWED_ROAMING_HEROES = 8;
extern const float SAFE_ATTACK_CONSTANT;
extern const int GOLD_RESERVE;
enum HeroRole
{
MAIN,
SCOUT
};
//provisional class for AI to store a reference to an owned hero object
//checks if it's valid on access, should be used in place of const CGHeroInstance*

View File

@ -53,7 +53,8 @@ void PriorityEvaluator::initVisitTile()
armyLossPersentageVariable = engine->getInputVariable("armyLoss");
heroRoleVariable = engine->getInputVariable("heroRole");
dangerVariable = engine->getInputVariable("danger");
turnDistanceVariable = engine->getInputVariable("turnDistance");
mainTurnDistanceVariable = engine->getInputVariable("mainTurnDistance");
scoutTurnDistanceVariable = engine->getInputVariable("scoutTurnDistance");
goldRewardVariable = engine->getInputVariable("goldReward");
armyRewardVariable = engine->getInputVariable("armyReward");
skillRewardVariable = engine->getInputVariable("skillReward");
@ -380,7 +381,8 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task)
{
armyLossPersentageVariable->setValue(armyLossPersentage);
heroRoleVariable->setValue(heroRole);
turnDistanceVariable->setValue(task->evaluationContext.movementCost);
mainTurnDistanceVariable->setValue(task->evaluationContext.movementCostByRole[HeroRole::MAIN]);
scoutTurnDistanceVariable->setValue(task->evaluationContext.movementCostByRole[HeroRole::SCOUT]);
goldRewardVariable->setValue(goldReward);
armyRewardVariable->setValue(armyReward);
skillRewardVariable->setValue(skillReward);

View File

@ -30,7 +30,8 @@ private:
fl::Engine * engine;
fl::InputVariable * armyLossPersentageVariable;
fl::InputVariable * heroRoleVariable;
fl::InputVariable * turnDistanceVariable;
fl::InputVariable * mainTurnDistanceVariable;
fl::InputVariable * scoutTurnDistanceVariable;
fl::InputVariable * goldRewardVariable;
fl::InputVariable * armyRewardVariable;
fl::InputVariable * dangerVariable;

View File

@ -95,6 +95,8 @@ namespace Goals
struct DLL_EXPORT EvaluationContext
{
float movementCost;
std::map<HeroRole, float> movementCostByRole;
float scoutMovementCost;
int manaCost;
uint64_t danger;
float closestWayRatio;
@ -107,7 +109,8 @@ namespace Goals
danger(0),
closestWayRatio(1),
armyLoss(0),
heroStrength(0)
heroStrength(0),
movementCostByRole()
{
}
};

View File

@ -30,9 +30,17 @@ ExecuteHeroChain::ExecuteHeroChain(const AIPath & path, const CGObjectInstance *
evaluationContext.movementCost = path.movementCost();
evaluationContext.armyLoss = path.getTotalArmyLoss();
evaluationContext.heroStrength = path.getHeroStrength();
hero = path.targetHero;
tile = path.targetTile();
for(auto & node : path.nodes)
{
auto role = ai->ah->getHeroRole(node.targetHero);
evaluationContext.movementCostByRole[role] += node.cost;
}
if(obj)
{
objid = obj->id.getNum();

View File

@ -18,13 +18,6 @@
#include "../../lib/CBuildingHandler.h"
#include "VCAI.h"
enum HeroRole
{
MAIN,
SCOUT
};
class DLL_EXPORT IHeroManager //: public: IAbstractManager
{
public: