2021-05-15 18:22:44 +02:00
|
|
|
/*
|
|
|
|
* AIhelper.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
|
|
|
|
|
|
|
|
/*
|
|
|
|
!!! Note: Include THIS file at the end of include list to avoid "undefined base class" error
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ResourceManager.h"
|
|
|
|
#include "BuildingManager.h"
|
2021-05-15 20:36:50 +02:00
|
|
|
#include "ArmyManager.h"
|
2021-05-15 21:00:02 +02:00
|
|
|
#include "HeroManager.h"
|
2021-05-15 18:22:44 +02:00
|
|
|
#include "Pathfinding/PathfindingManager.h"
|
|
|
|
|
|
|
|
class ResourceManager;
|
|
|
|
class BuildingManager;
|
|
|
|
|
|
|
|
|
|
|
|
//indirection interface for various modules
|
2021-05-15 21:00:02 +02:00
|
|
|
class DLL_EXPORT AIhelper : public IResourceManager, public IBuildingManager, public IPathfindingManager, public IArmyManager, public IHeroManager
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
|
|
|
friend class VCAI;
|
|
|
|
friend struct SetGlobalState; //mess?
|
|
|
|
|
|
|
|
std::shared_ptr<ResourceManager> resourceManager;
|
|
|
|
std::shared_ptr<BuildingManager> buildingManager;
|
|
|
|
std::shared_ptr<PathfindingManager> pathfindingManager;
|
2021-05-15 20:36:50 +02:00
|
|
|
std::shared_ptr<ArmyManager> armyManager;
|
2021-05-15 21:00:02 +02:00
|
|
|
std::shared_ptr<HeroManager> heroManager;
|
2021-05-15 18:22:44 +02:00
|
|
|
//TODO: vector<IAbstractManager>
|
|
|
|
public:
|
|
|
|
AIhelper();
|
|
|
|
~AIhelper();
|
|
|
|
|
|
|
|
bool canAfford(const TResources & cost) const;
|
|
|
|
TResources reservedResources() const override;
|
|
|
|
TResources freeResources() const override;
|
|
|
|
TResource freeGold() const override;
|
|
|
|
TResources allResources() const override;
|
|
|
|
TResource allGold() const override;
|
|
|
|
|
|
|
|
Goals::TSubgoal whatToDo(TResources &res, Goals::TSubgoal goal) override;
|
|
|
|
Goals::TSubgoal whatToDo() const override;
|
|
|
|
bool containsObjective(Goals::TSubgoal goal) const override;
|
|
|
|
bool hasTasksLeft() const override;
|
|
|
|
bool removeOutdatedObjectives(std::function<bool(const Goals::TSubgoal &)> predicate) override;
|
|
|
|
|
|
|
|
bool getBuildingOptions(const CGTownInstance * t) override;
|
|
|
|
BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t);
|
|
|
|
boost::optional<PotentialBuilding> immediateBuilding() const override;
|
|
|
|
boost::optional<PotentialBuilding> expensiveBuilding() const override;
|
|
|
|
boost::optional<BuildingID> canBuildAnyStructure(const CGTownInstance * t, const std::vector<BuildingID> & buildList, unsigned int maxDays = 7) const override;
|
|
|
|
|
|
|
|
Goals::TGoalVec howToVisitTile(const HeroPtr & hero, const int3 & tile, bool allowGatherArmy = true) const override;
|
|
|
|
Goals::TGoalVec howToVisitObj(const HeroPtr & hero, ObjectIdRef obj, bool allowGatherArmy = true) const override;
|
2021-05-15 18:23:11 +02:00
|
|
|
Goals::TGoalVec howToVisitTile(const int3 & tile, bool allowGatherArmy = true) const override;
|
|
|
|
Goals::TGoalVec howToVisitObj(ObjectIdRef obj, bool allowGatherArmy = true) const override;
|
2021-05-15 18:22:44 +02:00
|
|
|
std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
|
2021-05-15 20:56:31 +02:00
|
|
|
std::vector<AIPath> getPathsToTile(const int3 & tile) const override;
|
2021-05-15 20:27:22 +02:00
|
|
|
void updatePaths(std::vector<HeroPtr> heroes, bool useHeroChain = false) override;
|
2021-05-15 18:22:44 +02:00
|
|
|
|
|
|
|
STRONG_INLINE
|
|
|
|
bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const
|
|
|
|
{
|
|
|
|
return pathfindingManager->isTileAccessible(hero, tile);
|
|
|
|
}
|
|
|
|
|
2021-05-15 20:36:50 +02:00
|
|
|
bool canGetArmy(const CArmedInstance * target, const CArmedInstance * source) const override;
|
|
|
|
ui64 howManyReinforcementsCanBuy(const CCreatureSet * target, const CGDwelling * source) const override;
|
|
|
|
ui64 howManyReinforcementsCanGet(const CCreatureSet * target, const CCreatureSet * source) const override;
|
|
|
|
std::vector<SlotInfo> getBestArmy(const CCreatureSet * target, const CCreatureSet * source) const override;
|
|
|
|
std::vector<SlotInfo>::iterator getWeakestCreature(std::vector<SlotInfo> & army) const override;
|
|
|
|
std::vector<SlotInfo> getSortedSlots(const CCreatureSet * target, const CCreatureSet * source) const override;
|
|
|
|
|
2021-05-15 21:02:27 +02:00
|
|
|
const std::map<HeroPtr, HeroRole> & getHeroRoles() const override;
|
|
|
|
HeroRole getHeroRole(const HeroPtr & hero) const override;
|
2021-05-15 21:00:02 +02:00
|
|
|
int selectBestSkill(const HeroPtr & hero, const std::vector<SecondarySkill> & skills) const override;
|
2021-05-15 21:02:27 +02:00
|
|
|
void updateHeroRoles() override;
|
|
|
|
float evaluateSecSkill(SecondarySkill skill, const CGHeroInstance * hero) const override;
|
2021-05-15 21:02:52 +02:00
|
|
|
float evaluateHero(const CGHeroInstance * hero) const override;
|
2021-05-15 21:00:02 +02:00
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
private:
|
|
|
|
bool notifyGoalCompleted(Goals::TSubgoal goal) override;
|
|
|
|
|
|
|
|
void init(CPlayerSpecificInfoCallback * CB) override;
|
|
|
|
void setAI(VCAI * AI) override;
|
|
|
|
};
|
|
|
|
|