/* * BattleEvaluator.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 #include "../../lib/AI_Base.h" #include "../../lib/battle/ReachabilityInfo.h" #include "PossibleSpellcast.h" #include "PotentialTargets.h" #include "BattleExchangeVariant.h" VCMI_LIB_NAMESPACE_BEGIN class CSpell; VCMI_LIB_NAMESPACE_END class EnemyInfo; class BattleEvaluator { std::unique_ptr targets; std::shared_ptr hb; BattleExchangeEvaluator scoreEvaluator; std::shared_ptr cb; std::shared_ptr env; bool activeActionMade = false; std::optional cachedAttack; PlayerColor playerID; BattleID battleID; BattleSide side; float cachedScore; DamageCache damageCache; float strengthRatio; public: BattleAction selectStackAction(const CStack * stack); bool attemptCastingSpell(const CStack * stack); bool canCastSpell(); std::optional findBestCreatureSpell(const CStack * stack); BattleAction goTowardsNearest(const CStack * stack, std::vector hexes, const PotentialTargets & targets); std::vector getBrokenWallMoatHexes() const; void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only void print(const std::string & text) const; BattleEvaluator( std::shared_ptr env, std::shared_ptr cb, const battle::Unit * activeStack, PlayerColor playerID, BattleID battleID, BattleSide side, float strengthRatio) :scoreEvaluator(cb->getBattle(battleID), env, strengthRatio), cachedAttack(), playerID(playerID), side(side), env(env), cb(cb), strengthRatio(strengthRatio), battleID(battleID) { hb = std::make_shared(env.get(), cb->getBattle(battleID)); damageCache.buildDamageCache(hb, side); targets = std::make_unique(activeStack, damageCache, hb); cachedScore = EvaluationResult::INEFFECTIVE_SCORE; } BattleEvaluator( std::shared_ptr env, std::shared_ptr cb, std::shared_ptr hb, DamageCache & damageCache, const battle::Unit * activeStack, PlayerColor playerID, BattleID battleID, BattleSide side, float strengthRatio) :scoreEvaluator(cb->getBattle(battleID), env, strengthRatio), cachedAttack(), playerID(playerID), side(side), env(env), cb(cb), hb(hb), damageCache(damageCache), strengthRatio(strengthRatio), battleID(battleID) { targets = std::make_unique(activeStack, damageCache, hb); cachedScore = EvaluationResult::INEFFECTIVE_SCORE; } };