2021-05-15 18:22:44 +02:00
|
|
|
/*
|
|
|
|
* CGoal.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 "AbstractGoal.h"
|
|
|
|
|
|
|
|
struct HeroPtr;
|
2021-05-16 14:39:38 +02:00
|
|
|
class AIGateway;
|
2021-05-15 18:22:44 +02:00
|
|
|
|
|
|
|
namespace Goals
|
|
|
|
{
|
|
|
|
template<typename T> class DLL_EXPORT CGoal : public AbstractGoal
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGoal<T>(EGoals goal = INVALID) : AbstractGoal(goal)
|
|
|
|
{
|
2021-05-16 13:38:26 +02:00
|
|
|
isAbstract = true;
|
2021-05-15 18:22:44 +02:00
|
|
|
value = 0;
|
|
|
|
aid = -1;
|
|
|
|
objid = -1;
|
|
|
|
resID = -1;
|
|
|
|
tile = int3(-1, -1, -1);
|
|
|
|
town = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGoal<T> * clone() const override
|
|
|
|
{
|
|
|
|
return new T(static_cast<T const &>(*this)); //casting enforces template instantiation
|
|
|
|
}
|
|
|
|
template<typename Handler> void serialize(Handler & h, const int version)
|
|
|
|
{
|
|
|
|
h & static_cast<AbstractGoal &>(*this);
|
|
|
|
//h & goalType & isElementar & isAbstract & priority;
|
|
|
|
//h & value & resID & objid & aid & tile & hero & town & bid;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool operator==(const AbstractGoal & g) const override
|
|
|
|
{
|
|
|
|
if(goalType != g.goalType)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return (*this) == (static_cast<const T &>(g));
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool operator==(const T & other) const = 0;
|
2021-05-16 13:38:26 +02:00
|
|
|
|
|
|
|
virtual TGoalVec decompose() const override
|
|
|
|
{
|
2021-05-16 13:38:53 +02:00
|
|
|
TSubgoal single = decomposeSingle();
|
|
|
|
|
2021-05-16 13:44:55 +02:00
|
|
|
if(!single || single->invalid())
|
2021-05-16 13:38:53 +02:00
|
|
|
return {};
|
|
|
|
|
|
|
|
return {single};
|
2021-05-16 13:38:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual TSubgoal decomposeSingle() const
|
|
|
|
{
|
2021-05-16 13:44:55 +02:00
|
|
|
return TSubgoal();
|
2021-05-16 13:38:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> class DLL_EXPORT ElementarGoal : public CGoal<T>, public ITask
|
|
|
|
{
|
|
|
|
public:
|
2021-05-16 13:45:35 +02:00
|
|
|
ElementarGoal<T>(EGoals goal = INVALID) : CGoal<T>(goal), ITask()
|
2021-05-16 13:38:26 +02:00
|
|
|
{
|
2021-05-16 13:45:35 +02:00
|
|
|
AbstractGoal::isAbstract = false;
|
2021-05-16 13:38:26 +02:00
|
|
|
}
|
|
|
|
|
2021-05-16 13:45:35 +02:00
|
|
|
ElementarGoal<T>(const ElementarGoal<T> & other) : CGoal<T>(other), ITask(other)
|
2021-05-16 13:38:53 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-16 13:38:26 +02:00
|
|
|
T & setpriority(float p)
|
|
|
|
{
|
2021-05-16 13:45:35 +02:00
|
|
|
ITask::priority = p;
|
2021-05-16 13:38:26 +02:00
|
|
|
|
|
|
|
return *((T *)this);
|
|
|
|
}
|
2021-05-16 13:38:53 +02:00
|
|
|
|
2021-05-16 14:01:34 +02:00
|
|
|
virtual bool isElementar() const override { return true; }
|
|
|
|
|
2021-05-16 14:10:35 +02:00
|
|
|
virtual HeroPtr getHero() const override { return AbstractGoal::hero; }
|
2021-05-16 13:38:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_EXPORT Invalid : public ElementarGoal<Invalid>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Invalid()
|
|
|
|
: ElementarGoal(Goals::INVALID)
|
|
|
|
{
|
|
|
|
priority = -1;
|
|
|
|
}
|
|
|
|
TGoalVec decompose() const override
|
|
|
|
{
|
|
|
|
return TGoalVec();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool operator==(const Invalid & other) const override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual std::string toString() const override
|
|
|
|
{
|
|
|
|
return "Invalid";
|
|
|
|
}
|
2020-05-04 17:58:43 +02:00
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
virtual void accept(AIGateway * ai) override
|
2020-05-04 17:58:43 +02:00
|
|
|
{
|
|
|
|
throw cannotFulfillGoalException("Can not fulfill Invalid goal!");
|
|
|
|
}
|
2021-05-15 18:22:44 +02:00
|
|
|
};
|
|
|
|
}
|