2018-07-26 12:06:55 +02:00
/*
* ResourceManager . 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 "AIUtility.h"
# include "../../lib/GameConstants.h"
# include "../../lib/VCMI_Lib.h"
# include "VCAI.h"
# include <boost/heap/binomial_heap.hpp>
class AIhelper ;
class IResourceManager ;
struct DLL_EXPORT ResourceObjective
{
ResourceObjective ( ) = default ;
2018-07-27 08:10:21 +02:00
ResourceObjective ( const TResources & res , Goals : : TSubgoal goal ) ;
2018-07-26 12:06:55 +02:00
bool operator < ( const ResourceObjective & ro ) const ;
2024-06-24 03:23:26 +02:00
TResources resources ; //how many resources do we need
2018-07-26 12:06:55 +02:00
Goals : : TSubgoal goal ; //what for (build, gather army etc...)
} ;
2019-01-19 12:52:02 +02:00
class DLL_EXPORT IResourceManager //: public: IAbstractManager
2018-07-26 12:06:55 +02:00
{
public :
virtual ~ IResourceManager ( ) = default ;
2018-10-09 21:31:44 +02:00
virtual void init ( CPlayerSpecificInfoCallback * CB ) = 0 ;
2018-07-26 12:06:55 +02:00
virtual void setAI ( VCAI * AI ) = 0 ;
virtual TResources reservedResources ( ) const = 0 ;
virtual TResources freeResources ( ) const = 0 ;
virtual TResource freeGold ( ) const = 0 ;
virtual TResources allResources ( ) const = 0 ;
virtual TResource allGold ( ) const = 0 ;
virtual Goals : : TSubgoal whatToDo ( ) const = 0 ; //get highest-priority goal
virtual Goals : : TSubgoal whatToDo ( TResources & res , Goals : : TSubgoal goal ) = 0 ;
2018-07-26 13:29:46 +02:00
virtual bool containsObjective ( Goals : : TSubgoal goal ) const = 0 ;
2018-07-26 12:06:55 +02:00
virtual bool hasTasksLeft ( ) const = 0 ;
2019-01-01 16:41:52 +02:00
virtual bool removeOutdatedObjectives ( std : : function < bool ( const Goals : : TSubgoal & ) > predicate ) = 0 ; //remove ResourceObjectives from queue if ResourceObjective->goal meets specific criteria
2018-07-26 12:06:55 +02:00
virtual bool notifyGoalCompleted ( Goals : : TSubgoal goal ) = 0 ;
} ;
class DLL_EXPORT ResourceManager : public IResourceManager
{
/*Resource Manager is a smart shopping list for AI to help
Uses priority queue based on CGoal . priority */
friend class VCAI ;
friend class AIhelper ;
friend struct SetGlobalState ;
CPlayerSpecificInfoCallback * cb ; //this is enough, but we downcast from CCallback
VCAI * ai ;
public :
ResourceManager ( ) = default ;
ResourceManager ( CPlayerSpecificInfoCallback * CB , VCAI * AI = nullptr ) ; //for tests only
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 ( ) const override ; //peek highest-priority goal
2019-01-19 12:52:02 +02:00
Goals : : TSubgoal whatToDo ( TResources & res , Goals : : TSubgoal goal ) override ; //can we afford this goal or need to CollectRes?
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 ;
2019-01-19 12:52:02 +02:00
bool notifyGoalCompleted ( Goals : : TSubgoal goal ) override ;
2018-07-26 12:06:55 +02:00
protected : //not-const actions only for AI
2024-06-24 03:23:26 +02:00
virtual void reserveResources ( const TResources & res , Goals : : TSubgoal goal = Goals : : TSubgoal ( ) ) ;
2018-07-26 12:06:55 +02:00
virtual bool updateGoal ( Goals : : TSubgoal goal ) ; //new goal must have same properties but different priority
2018-07-27 08:10:21 +02:00
virtual bool tryPush ( const ResourceObjective & o ) ;
2018-07-26 12:06:55 +02:00
//inner processing
virtual TResources estimateIncome ( ) const ;
virtual Goals : : TSubgoal collectResourcesForOurGoal ( ResourceObjective & o ) const ;
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 ;
private :
TResources saving ;
boost : : heap : : binomial_heap < ResourceObjective > queue ;
2018-09-11 12:09:14 +02:00
void dumpToLog ( ) const ;
2019-01-19 12:52:02 +02:00
} ;