2018-07-26 12:06:55 +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"
|
2018-07-29 18:27:21 +02:00
|
|
|
#include "BuildingManager.h"
|
2019-03-13 15:21:24 +02:00
|
|
|
#include "ArmyManager.h"
|
2018-10-07 13:51:27 +02:00
|
|
|
#include "Pathfinding/PathfindingManager.h"
|
2018-07-26 12:06:55 +02:00
|
|
|
|
|
|
|
class ResourceManager;
|
2018-07-29 18:27:21 +02:00
|
|
|
class BuildingManager;
|
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
|
|
|
|
//indirection interface for various modules
|
2019-03-13 15:21:24 +02:00
|
|
|
class DLL_EXPORT AIhelper : public IResourceManager, public IBuildingManager, public IPathfindingManager, public IArmyManager
|
2018-07-26 12:06:55 +02:00
|
|
|
{
|
|
|
|
friend class VCAI;
|
|
|
|
friend struct SetGlobalState; //mess?
|
|
|
|
|
|
|
|
std::shared_ptr<ResourceManager> resourceManager;
|
2018-07-29 18:27:21 +02:00
|
|
|
std::shared_ptr<BuildingManager> buildingManager;
|
2018-10-07 13:51:27 +02:00
|
|
|
std::shared_ptr<PathfindingManager> pathfindingManager;
|
2019-03-13 15:21:24 +02:00
|
|
|
std::shared_ptr<ArmyManager> armyManager;
|
2018-07-29 18:27:21 +02:00
|
|
|
//TODO: vector<IAbstractManager>
|
2018-07-26 12:06:55 +02:00
|
|
|
public:
|
|
|
|
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;
|
2018-08-12 13:31:31 +02:00
|
|
|
Goals::TSubgoal whatToDo() const override;
|
2019-01-19 12:52:02 +02:00
|
|
|
bool containsObjective(Goals::TSubgoal goal) const override;
|
2018-07-26 12:06:55 +02:00
|
|
|
bool hasTasksLeft() const override;
|
2019-01-01 16:41:52 +02:00
|
|
|
bool removeOutdatedObjectives(std::function<bool(const Goals::TSubgoal &)> predicate) override;
|
2018-07-26 12:06:55 +02:00
|
|
|
|
2018-08-12 13:31:31 +02:00
|
|
|
bool getBuildingOptions(const CGTownInstance * t) override;
|
2018-10-13 18:52:44 +02:00
|
|
|
BuildingID getMaxPossibleGoldBuilding(const CGTownInstance * t);
|
2018-08-12 13:31:31 +02:00
|
|
|
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;
|
|
|
|
|
2019-02-06 23:11:51 +02:00
|
|
|
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;
|
|
|
|
Goals::TGoalVec howToVisitTile(const int3 & tile) const override;
|
|
|
|
Goals::TGoalVec howToVisitObj(ObjectIdRef obj) const override;
|
|
|
|
std::vector<AIPath> getPathsToTile(const HeroPtr & hero, const int3 & tile) const override;
|
|
|
|
void updatePaths(std::vector<HeroPtr> heroes) override;
|
2018-08-12 13:31:31 +02:00
|
|
|
|
2019-01-14 13:20:46 +02:00
|
|
|
STRONG_INLINE
|
2019-02-06 23:11:51 +02:00
|
|
|
bool isTileAccessible(const HeroPtr & hero, const int3 & tile) const
|
2019-01-14 13:20:46 +02:00
|
|
|
{
|
|
|
|
return pathfindingManager->isTileAccessible(hero, tile);
|
|
|
|
}
|
|
|
|
|
2019-03-13 15:21:24 +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;
|
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
private:
|
2019-01-19 12:52:02 +02:00
|
|
|
bool notifyGoalCompleted(Goals::TSubgoal goal) override;
|
2018-07-26 12:06:55 +02:00
|
|
|
|
2018-10-09 21:31:44 +02:00
|
|
|
void init(CPlayerSpecificInfoCallback * CB) override;
|
2018-07-26 12:06:55 +02:00
|
|
|
void setAI(VCAI * AI) override;
|
|
|
|
};
|
|
|
|
|