2013-10-18 23:17:25 +03:00
|
|
|
/*
|
|
|
|
* Goals.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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../lib/VCMI_Lib.h"
|
|
|
|
#include "../../lib/CBuildingHandler.h"
|
|
|
|
#include "../../lib/CCreatureHandler.h"
|
|
|
|
#include "../../lib/CTownHandler.h"
|
|
|
|
#include "AIUtility.h"
|
|
|
|
|
2013-10-18 23:17:25 +03:00
|
|
|
struct HeroPtr;
|
2013-11-23 21:16:25 +03:00
|
|
|
class VCAI;
|
2013-12-19 23:21:21 +03:00
|
|
|
class FuzzyHelper;
|
2013-10-18 23:17:25 +03:00
|
|
|
|
2013-10-19 08:52:30 +03:00
|
|
|
namespace Goals
|
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
class AbstractGoal;
|
|
|
|
class VisitTile;
|
2018-07-26 12:06:55 +02:00
|
|
|
|
|
|
|
class DLL_EXPORT TSubgoal : public std::shared_ptr<Goals::AbstractGoal>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool operator==(const TSubgoal & rhs) const;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator<(const TSubgoal & rhs) const;
|
2018-07-26 12:06:55 +02:00
|
|
|
//TODO: serialize?
|
|
|
|
};
|
2018-08-05 09:21:41 +02:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
typedef std::vector<TSubgoal> TGoalVec;
|
2013-10-19 08:52:30 +03:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
enum EGoals
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
|
|
|
INVALID = -1,
|
|
|
|
WIN, DO_NOT_LOSE, CONQUER, BUILD, //build needs to get a real reasoning
|
2018-07-26 12:06:55 +02:00
|
|
|
EXPLORE, GATHER_ARMY,
|
|
|
|
BOOST_HERO,
|
2013-10-18 23:17:25 +03:00
|
|
|
RECRUIT_HERO,
|
|
|
|
BUILD_STRUCTURE, //if hero set, then in visited town
|
|
|
|
COLLECT_RES,
|
|
|
|
GATHER_TROOPS, // val of creatures with objid
|
|
|
|
|
|
|
|
OBJECT_GOALS_BEGIN,
|
2018-08-10 16:48:42 +02:00
|
|
|
VISIT_OBJ, //visit or defeat or collect the object
|
2013-10-18 23:17:25 +03:00
|
|
|
FIND_OBJ, //find and visit any obj with objid + resid //TODO: consider universal subid for various types (aid, bid)
|
|
|
|
VISIT_HERO, //heroes can move around - set goal abstract and track hero every turn
|
|
|
|
|
|
|
|
GET_ART_TYPE,
|
|
|
|
|
|
|
|
//BUILD_STRUCTURE,
|
|
|
|
ISSUE_COMMAND,
|
|
|
|
|
|
|
|
VISIT_TILE, //tile, in conjunction with hero elementar; assumes tile is reachable
|
|
|
|
CLEAR_WAY_TO,
|
2018-07-26 12:06:55 +02:00
|
|
|
DIG_AT_TILE,//elementar with hero on tile
|
2018-08-04 10:20:40 +02:00
|
|
|
BUY_ARMY, //at specific town
|
|
|
|
TRADE //val resID at object objid
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
|
|
|
|
2013-11-15 20:30:16 +03:00
|
|
|
//method chaining + clone pattern
|
2014-01-06 17:17:56 +03:00
|
|
|
#define VSETTER(type, field) virtual AbstractGoal & set ## field(const type &rhs) {field = rhs; return *this;};
|
2013-11-23 21:16:25 +03:00
|
|
|
#define OSETTER(type, field) CGoal<T> & set ## field(const type &rhs) override { field = rhs; return *this; };
|
2013-11-15 20:30:16 +03:00
|
|
|
|
2013-10-18 23:17:25 +03:00
|
|
|
#if 0
|
|
|
|
#define SETTER
|
|
|
|
#endif // _DEBUG
|
|
|
|
|
|
|
|
enum {LOW_PR = -1};
|
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
DLL_EXPORT TSubgoal sptr(const AbstractGoal & tmp);
|
2014-01-06 17:17:56 +03:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT AbstractGoal
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
|
|
|
bool isElementar; VSETTER(bool, isElementar)
|
|
|
|
bool isAbstract; VSETTER(bool, isAbstract)
|
2013-12-25 19:05:11 +03:00
|
|
|
float priority; VSETTER(float, priority)
|
2013-11-15 20:30:16 +03:00
|
|
|
int value; VSETTER(int, value)
|
|
|
|
int resID; VSETTER(int, resID)
|
|
|
|
int objid; VSETTER(int, objid)
|
|
|
|
int aid; VSETTER(int, aid)
|
|
|
|
int3 tile; VSETTER(int3, tile)
|
|
|
|
HeroPtr hero; VSETTER(HeroPtr, hero)
|
|
|
|
const CGTownInstance *town; VSETTER(CGTownInstance *, town)
|
|
|
|
int bid; VSETTER(int, bid)
|
2013-10-18 23:17:25 +03:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
AbstractGoal(EGoals goal = INVALID)
|
|
|
|
: goalType (goal)
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
|
|
|
priority = 0;
|
|
|
|
isElementar = false;
|
|
|
|
isAbstract = false;
|
|
|
|
value = 0;
|
|
|
|
aid = -1;
|
|
|
|
resID = -1;
|
2016-08-18 17:53:28 +02:00
|
|
|
objid = -1;
|
2013-10-18 23:17:25 +03:00
|
|
|
tile = int3(-1, -1, -1);
|
|
|
|
town = nullptr;
|
2016-08-18 17:53:28 +02:00
|
|
|
bid = -1;
|
2013-10-18 23:17:25 +03:00
|
|
|
}
|
2018-04-07 10:44:14 +02:00
|
|
|
virtual ~AbstractGoal(){}
|
2014-01-06 17:17:56 +03:00
|
|
|
//FIXME: abstract goal should be abstract, but serializer fails to instantiate subgoals in such case
|
2018-04-07 10:44:14 +02:00
|
|
|
virtual AbstractGoal * clone() const
|
|
|
|
{
|
|
|
|
return const_cast<AbstractGoal *>(this);
|
|
|
|
}
|
|
|
|
virtual TGoalVec getAllPossibleSubgoals()
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
|
|
|
virtual TSubgoal whatToDoToAchieve()
|
|
|
|
{
|
|
|
|
return sptr(AbstractGoal());
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
|
2013-11-15 20:30:16 +03:00
|
|
|
EGoals goalType;
|
2013-12-20 12:43:12 +03:00
|
|
|
|
2013-11-15 20:30:16 +03:00
|
|
|
std::string name() const;
|
2018-04-07 10:44:14 +02:00
|
|
|
virtual std::string completeMessage() const
|
|
|
|
{
|
|
|
|
return "This goal is unspecified!";
|
|
|
|
}
|
2013-11-15 20:30:16 +03:00
|
|
|
|
2013-10-18 23:17:25 +03:00
|
|
|
bool invalid() const;
|
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
static TSubgoal goVisitOrLookFor(const CGObjectInstance * obj); //if obj is nullptr, then we'll explore
|
2013-10-18 23:17:25 +03:00
|
|
|
static TSubgoal lookForArtSmart(int aid); //checks non-standard ways of obtaining art (merchants, quests, etc.)
|
|
|
|
static TSubgoal tryRecruitHero();
|
|
|
|
|
2013-11-24 18:30:17 +03:00
|
|
|
///Visitor pattern
|
2015-12-29 04:43:33 +02:00
|
|
|
//TODO: make accept work for std::shared_ptr... somehow
|
2018-04-07 10:44:14 +02:00
|
|
|
virtual void accept(VCAI * ai); //unhandled goal will report standard error
|
|
|
|
virtual float accept(FuzzyHelper * f);
|
2013-10-18 23:17:25 +03:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
virtual bool operator==(AbstractGoal & g);
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator<(AbstractGoal & g); //final
|
2018-04-07 10:44:14 +02:00
|
|
|
virtual bool fulfillsMe(Goals::TSubgoal goal) //TODO: multimethod instead of type check
|
2013-11-24 22:15:08 +03:00
|
|
|
{
|
2018-07-26 12:06:55 +02:00
|
|
|
return false; //use this method to check if goal is fulfilled by another (not equal) goal, operator == is handled spearately
|
2013-11-24 22:15:08 +03:00
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
template<typename Handler> void serialize(Handler & h, const int version)
|
2014-01-06 17:17:56 +03:00
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & goalType;
|
|
|
|
h & isElementar;
|
|
|
|
h & isAbstract;
|
|
|
|
h & priority;
|
|
|
|
h & value;
|
|
|
|
h & resID;
|
|
|
|
h & objid;
|
|
|
|
h & aid;
|
|
|
|
h & tile;
|
|
|
|
h & hero;
|
|
|
|
h & town;
|
|
|
|
h & bid;
|
2014-01-06 17:17:56 +03:00
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
template<typename T> class DLL_EXPORT CGoal : public AbstractGoal
|
2013-11-15 20:30:16 +03:00
|
|
|
{
|
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
CGoal<T>(EGoals goal = INVALID) : AbstractGoal(goal)
|
2013-11-15 20:30:16 +03:00
|
|
|
{
|
|
|
|
priority = 0;
|
|
|
|
isElementar = false;
|
|
|
|
isAbstract = false;
|
|
|
|
value = 0;
|
|
|
|
aid = -1;
|
2015-10-25 12:16:43 +02:00
|
|
|
objid = -1;
|
2013-11-15 20:30:16 +03:00
|
|
|
resID = -1;
|
|
|
|
tile = int3(-1, -1, -1);
|
|
|
|
town = nullptr;
|
|
|
|
}
|
2013-11-23 15:30:10 +03:00
|
|
|
|
2013-11-15 20:30:16 +03:00
|
|
|
OSETTER(bool, isElementar)
|
2013-11-23 15:30:10 +03:00
|
|
|
OSETTER(bool, isAbstract)
|
2013-12-25 19:05:11 +03:00
|
|
|
OSETTER(float, priority)
|
2013-11-15 20:30:16 +03:00
|
|
|
OSETTER(int, value)
|
|
|
|
OSETTER(int, resID)
|
|
|
|
OSETTER(int, objid)
|
|
|
|
OSETTER(int, aid)
|
|
|
|
OSETTER(int3, tile)
|
|
|
|
OSETTER(HeroPtr, hero)
|
|
|
|
OSETTER(CGTownInstance *, town)
|
|
|
|
OSETTER(int, bid)
|
2013-11-23 21:16:25 +03:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
void accept(VCAI * ai) override;
|
|
|
|
float accept(FuzzyHelper * f) override;
|
2013-11-23 21:16:25 +03:00
|
|
|
|
|
|
|
CGoal<T> * clone() const override
|
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
return new T(static_cast<T const &>(*this)); //casting enforces template instantiation
|
2013-11-23 21:16:25 +03:00
|
|
|
}
|
|
|
|
TSubgoal iAmElementar()
|
|
|
|
{
|
2018-07-26 12:06:55 +02:00
|
|
|
setisElementar(true); //FIXME: it's not const-correct, maybe we shoudl only set returned clone?
|
|
|
|
TSubgoal ptr;
|
2013-11-23 21:16:25 +03:00
|
|
|
ptr.reset(clone());
|
|
|
|
return ptr;
|
2013-11-15 20:30:16 +03:00
|
|
|
}
|
2018-04-07 10:44:14 +02:00
|
|
|
template<typename Handler> void serialize(Handler & h, const int version)
|
2013-11-23 15:30:10 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
h & static_cast<AbstractGoal &>(*this);
|
2014-01-06 17:17:56 +03:00
|
|
|
//h & goalType & isElementar & isAbstract & priority;
|
|
|
|
//h & value & resID & objid & aid & tile & hero & town & bid;
|
2013-11-23 15:30:10 +03:00
|
|
|
}
|
2013-11-15 20:30:16 +03:00
|
|
|
};
|
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT Invalid : public CGoal<Invalid>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
Invalid()
|
|
|
|
: CGoal(Goals::INVALID)
|
|
|
|
{
|
|
|
|
priority = -1e10;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT Win : public CGoal<Win>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
Win()
|
|
|
|
: CGoal(Goals::WIN)
|
|
|
|
{
|
|
|
|
priority = 100;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT NotLose : public CGoal<NotLose>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
NotLose()
|
|
|
|
: CGoal(Goals::DO_NOT_LOSE)
|
|
|
|
{
|
|
|
|
priority = 100;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2014-02-20 23:18:49 +03:00
|
|
|
//TSubgoal whatToDoToAchieve() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT Conquer : public CGoal<Conquer>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
Conquer()
|
|
|
|
: CGoal(Goals::CONQUER)
|
|
|
|
{
|
|
|
|
priority = 10;
|
|
|
|
}
|
2013-12-20 16:01:44 +03:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT Build : public CGoal<Build>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
Build()
|
|
|
|
: CGoal(Goals::BUILD)
|
|
|
|
{
|
|
|
|
priority = 1;
|
|
|
|
}
|
2018-08-05 09:21:41 +02:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-07-26 12:06:55 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT Explore : public CGoal<Explore>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
Explore()
|
|
|
|
: CGoal(Goals::EXPLORE)
|
|
|
|
{
|
|
|
|
priority = 1;
|
|
|
|
}
|
|
|
|
Explore(HeroPtr h)
|
|
|
|
: CGoal(Goals::EXPLORE)
|
|
|
|
{
|
|
|
|
hero = h;
|
|
|
|
priority = 1;
|
|
|
|
}
|
2013-12-20 19:49:51 +03:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2013-11-24 11:21:51 +03:00
|
|
|
std::string completeMessage() const override;
|
2018-04-07 10:44:14 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT GatherArmy : public CGoal<GatherArmy>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
GatherArmy()
|
|
|
|
: CGoal(Goals::GATHER_ARMY)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
GatherArmy(int val)
|
|
|
|
: CGoal(Goals::GATHER_ARMY)
|
|
|
|
{
|
|
|
|
value = val;
|
|
|
|
priority = 2.5;
|
|
|
|
}
|
2013-12-23 23:46:01 +03:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2013-11-24 11:21:51 +03:00
|
|
|
std::string completeMessage() const override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT BuyArmy : public CGoal<BuyArmy>
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
BuyArmy()
|
|
|
|
: CGoal(Goals::BUY_ARMY)
|
|
|
|
{}
|
|
|
|
public:
|
|
|
|
BuyArmy(const CGTownInstance * Town, int val)
|
|
|
|
: CGoal(Goals::BUY_ARMY)
|
|
|
|
{
|
|
|
|
town = Town; //where to buy this army
|
|
|
|
value = val; //expressed in AI unit strength
|
2018-08-08 12:38:32 +02:00
|
|
|
priority = 3;//TODO: evaluate?
|
2018-07-26 12:06:55 +02:00
|
|
|
}
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2018-07-26 12:06:55 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
|
|
|
|
|
|
|
TSubgoal whatToDoToAchieve() override;
|
|
|
|
std::string completeMessage() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_EXPORT BoostHero : public CGoal<BoostHero>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
BoostHero()
|
|
|
|
: CGoal(Goals::INVALID)
|
|
|
|
{
|
|
|
|
priority = -1e10; //TODO
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2014-02-20 23:18:49 +03:00
|
|
|
//TSubgoal whatToDoToAchieve() override {return sptr(Invalid());};
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT RecruitHero : public CGoal<RecruitHero>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
RecruitHero()
|
|
|
|
: CGoal(Goals::RECRUIT_HERO)
|
|
|
|
{
|
|
|
|
priority = 1;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT BuildThis : public CGoal<BuildThis>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-07-26 12:06:55 +02:00
|
|
|
BuildThis() //should be private, but unit test uses it
|
2018-04-07 10:44:14 +02:00
|
|
|
: CGoal(Goals::BUILD_STRUCTURE)
|
2018-07-26 12:06:55 +02:00
|
|
|
{}
|
2018-04-07 10:44:14 +02:00
|
|
|
BuildThis(BuildingID Bid, const CGTownInstance * tid)
|
|
|
|
: CGoal(Goals::BUILD_STRUCTURE)
|
|
|
|
{
|
|
|
|
bid = Bid;
|
|
|
|
town = tid;
|
2018-07-26 12:06:55 +02:00
|
|
|
priority = 1;
|
2018-04-07 10:44:14 +02:00
|
|
|
}
|
|
|
|
BuildThis(BuildingID Bid)
|
|
|
|
: CGoal(Goals::BUILD_STRUCTURE)
|
|
|
|
{
|
|
|
|
bid = Bid;
|
2018-07-26 12:06:55 +02:00
|
|
|
priority = 1;
|
2018-04-07 10:44:14 +02:00
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-07-26 12:06:55 +02:00
|
|
|
//bool fulfillsMe(TSubgoal goal) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT CollectRes : public CGoal<CollectRes>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
CollectRes()
|
|
|
|
: CGoal(Goals::COLLECT_RES)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CollectRes(int rid, int val)
|
|
|
|
: CGoal(Goals::COLLECT_RES)
|
|
|
|
{
|
|
|
|
resID = rid;
|
|
|
|
value = val;
|
|
|
|
priority = 2;
|
|
|
|
}
|
2018-07-26 12:06:55 +02:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-07-26 12:06:55 +02:00
|
|
|
TSubgoal whatToDoToTrade();
|
2018-08-04 10:20:40 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override; //TODO: Trade
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2018-08-04 10:20:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_EXPORT Trade : public CGoal<Trade>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Trade()
|
|
|
|
: CGoal(Goals::TRADE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
Trade(int rid, int val, int Objid)
|
|
|
|
: CGoal(Goals::TRADE)
|
|
|
|
{
|
|
|
|
resID = rid;
|
|
|
|
value = val;
|
|
|
|
objid = Objid;
|
|
|
|
priority = 10; //do it immediately
|
|
|
|
}
|
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT GatherTroops : public CGoal<GatherTroops>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
GatherTroops()
|
|
|
|
: CGoal(Goals::GATHER_TROOPS)
|
|
|
|
{
|
|
|
|
priority = 2;
|
|
|
|
}
|
|
|
|
GatherTroops(int type, int val)
|
|
|
|
: CGoal(Goals::GATHER_TROOPS)
|
|
|
|
{
|
|
|
|
objid = type;
|
|
|
|
value = val;
|
|
|
|
priority = 2;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-07-26 12:06:55 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-08-10 16:42:55 +02:00
|
|
|
class DLL_EXPORT VisitObj : public CGoal<VisitObj> //this goal was previously known as GetObj
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-24 11:21:51 +03:00
|
|
|
public:
|
2018-08-10 16:42:55 +02:00
|
|
|
VisitObj() = delete; // empty constructor not allowed
|
|
|
|
VisitObj(int Objid);
|
2014-02-20 23:18:49 +03:00
|
|
|
|
2018-08-07 14:33:45 +02:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2018-04-07 10:44:14 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
2013-11-24 11:21:51 +03:00
|
|
|
std::string completeMessage() const override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT FindObj : public CGoal<FindObj>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-24 11:21:51 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
FindObj() {} // empty constructor not allowed
|
2014-02-20 23:18:49 +03:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
FindObj(int ID)
|
|
|
|
: CGoal(Goals::FIND_OBJ)
|
|
|
|
{
|
|
|
|
objid = ID;
|
2018-07-26 12:06:55 +02:00
|
|
|
resID = -1; //subid unspecified
|
2018-04-07 10:44:14 +02:00
|
|
|
priority = 1;
|
|
|
|
}
|
|
|
|
FindObj(int ID, int subID)
|
|
|
|
: CGoal(Goals::FIND_OBJ)
|
|
|
|
{
|
|
|
|
objid = ID;
|
|
|
|
resID = subID;
|
|
|
|
priority = 1;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-07-26 12:06:55 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT VisitHero : public CGoal<VisitHero>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
VisitHero()
|
|
|
|
: CGoal(Goals::VISIT_HERO)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
VisitHero(int hid)
|
|
|
|
: CGoal(Goals::VISIT_HERO)
|
|
|
|
{
|
|
|
|
objid = hid;
|
|
|
|
priority = 4;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2018-04-07 10:44:14 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
2013-11-24 11:21:51 +03:00
|
|
|
std::string completeMessage() const override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT GetArtOfType : public CGoal<GetArtOfType>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
GetArtOfType()
|
|
|
|
: CGoal(Goals::GET_ART_TYPE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
GetArtOfType(int type)
|
|
|
|
: CGoal(Goals::GET_ART_TYPE)
|
|
|
|
{
|
|
|
|
aid = type;
|
|
|
|
priority = 2;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT VisitTile : public CGoal<VisitTile>
|
2013-10-19 14:37:22 +03:00
|
|
|
//tile, in conjunction with hero elementar; assumes tile is reachable
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
VisitTile() {} // empty constructor not allowed
|
2014-02-20 23:18:49 +03:00
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
VisitTile(int3 Tile)
|
|
|
|
: CGoal(Goals::VISIT_TILE)
|
|
|
|
{
|
|
|
|
tile = Tile;
|
|
|
|
priority = 5;
|
|
|
|
}
|
2013-12-19 23:21:21 +03:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2013-11-24 11:21:51 +03:00
|
|
|
std::string completeMessage() const override;
|
2018-04-07 10:44:14 +02:00
|
|
|
};
|
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT ClearWayTo : public CGoal<ClearWayTo>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
ClearWayTo()
|
|
|
|
: CGoal(Goals::CLEAR_WAY_TO)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
ClearWayTo(int3 Tile)
|
|
|
|
: CGoal(Goals::CLEAR_WAY_TO)
|
|
|
|
{
|
|
|
|
tile = Tile;
|
|
|
|
priority = 5;
|
|
|
|
}
|
|
|
|
ClearWayTo(int3 Tile, HeroPtr h)
|
|
|
|
: CGoal(Goals::CLEAR_WAY_TO)
|
|
|
|
{
|
|
|
|
tile = Tile;
|
|
|
|
hero = h;
|
|
|
|
priority = 5;
|
|
|
|
}
|
2013-12-23 23:46:01 +03:00
|
|
|
TGoalVec getAllPossibleSubgoals() override;
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2018-07-26 12:06:55 +02:00
|
|
|
bool fulfillsMe(TSubgoal goal) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
2018-04-07 10:44:14 +02:00
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT DigAtTile : public CGoal<DigAtTile>
|
2013-10-19 14:37:22 +03:00
|
|
|
//elementar with hero on tile
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
2013-11-15 20:30:16 +03:00
|
|
|
public:
|
2018-04-07 10:44:14 +02:00
|
|
|
DigAtTile()
|
|
|
|
: CGoal(Goals::DIG_AT_TILE)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
DigAtTile(int3 Tile)
|
|
|
|
: CGoal(Goals::DIG_AT_TILE)
|
|
|
|
{
|
|
|
|
tile = Tile;
|
|
|
|
priority = 20;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
2013-10-18 23:17:25 +03:00
|
|
|
TSubgoal whatToDoToAchieve() override;
|
2018-08-05 09:21:41 +02:00
|
|
|
bool operator==(AbstractGoal & g) override;
|
2013-10-18 23:17:25 +03:00
|
|
|
};
|
|
|
|
|
2018-07-26 12:06:55 +02:00
|
|
|
class DLL_EXPORT CIssueCommand : public CGoal<CIssueCommand>
|
2013-10-18 23:17:25 +03:00
|
|
|
{
|
|
|
|
std::function<bool()> command;
|
|
|
|
|
2018-04-07 10:44:14 +02:00
|
|
|
public:
|
|
|
|
CIssueCommand()
|
|
|
|
: CGoal(ISSUE_COMMAND)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CIssueCommand(std::function<bool()> _command)
|
|
|
|
: CGoal(ISSUE_COMMAND), command(_command)
|
|
|
|
{
|
|
|
|
priority = 1e10;
|
|
|
|
}
|
|
|
|
TGoalVec getAllPossibleSubgoals() override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
|
|
|
//TSubgoal whatToDoToAchieve() override {return sptr(Invalid());}
|
2013-10-19 08:52:30 +03:00
|
|
|
};
|
|
|
|
|
2013-11-16 12:17:19 +03:00
|
|
|
}
|