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"
|
|
|
|
|
2022-09-26 20:01:07 +02:00
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
2021-05-16 14:39:38 +02:00
|
|
|
class AIGateway;
|
2021-05-15 18:22:44 +02:00
|
|
|
|
|
|
|
namespace Goals
|
|
|
|
{
|
2024-05-17 12:10:06 +02:00
|
|
|
template<typename T>
|
|
|
|
class DLL_EXPORT CGoal : public AbstractGoal
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
|
|
|
public:
|
2024-05-17 12:10:06 +02:00
|
|
|
CGoal(EGoals goal = INVALID) : AbstractGoal(goal)
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2024-05-17 12:10:06 +02:00
|
|
|
CGoal * clone() const override
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
|
|
|
return new T(static_cast<T const &>(*this)); //casting enforces template instantiation
|
|
|
|
}
|
|
|
|
|
2024-02-10 21:22:08 +02:00
|
|
|
bool operator==(const AbstractGoal & g) const override
|
2021-05-15 18:22:44 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
TGoalVec decompose(const Nullkiller * ai) const override
|
2021-05-16 13:38:26 +02:00
|
|
|
{
|
2024-03-31 17:39:00 +02:00
|
|
|
TSubgoal single = decomposeSingle(ai);
|
2021-05-16 13:38:53 +02:00
|
|
|
|
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:
|
2024-03-31 17:39:00 +02:00
|
|
|
virtual TSubgoal decomposeSingle(const Nullkiller * ai) const
|
2021-05-16 13:38:26 +02:00
|
|
|
{
|
2021-05-16 13:44:55 +02:00
|
|
|
return TSubgoal();
|
2021-05-16 13:38:26 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-17 12:10:06 +02:00
|
|
|
template<typename T>
|
|
|
|
class DLL_EXPORT ElementarGoal : public CGoal<T>, public ITask
|
2021-05-16 13:38:26 +02:00
|
|
|
{
|
|
|
|
public:
|
2024-05-17 12:10:06 +02:00
|
|
|
ElementarGoal(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
|
|
|
}
|
|
|
|
|
2024-05-17 12:10:06 +02:00
|
|
|
ElementarGoal(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
|
|
|
|
2024-02-10 21:22:08 +02:00
|
|
|
bool isElementar() const override { return true; }
|
2021-05-16 14:01:34 +02:00
|
|
|
|
2024-04-14 14:23:44 +02:00
|
|
|
const CGHeroInstance * getHero() const override { return AbstractGoal::hero; }
|
2022-09-06 20:14:22 +02:00
|
|
|
|
2024-02-10 21:22:08 +02:00
|
|
|
int getHeroExchangeCount() const override { return 0; }
|
2024-04-14 14:23:44 +02:00
|
|
|
|
|
|
|
bool isObjectAffected(ObjectInstanceID id) const override
|
|
|
|
{
|
|
|
|
return (AbstractGoal::hero && AbstractGoal::hero->id == id)
|
|
|
|
|| AbstractGoal::objid == id
|
|
|
|
|| (AbstractGoal::town && AbstractGoal::town->id == id);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<ObjectInstanceID> getAffectedObjects() const override
|
|
|
|
{
|
|
|
|
auto result = std::vector<ObjectInstanceID>();
|
|
|
|
|
|
|
|
if(AbstractGoal::hero)
|
|
|
|
result.push_back(AbstractGoal::hero->id);
|
|
|
|
|
|
|
|
if(AbstractGoal::objid != -1)
|
|
|
|
result.push_back(ObjectInstanceID(AbstractGoal::objid));
|
|
|
|
|
|
|
|
if(AbstractGoal::town)
|
|
|
|
result.push_back(AbstractGoal::town->id);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ITask * asTask() override
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
2021-05-16 13:38:26 +02:00
|
|
|
};
|
2022-09-26 20:01:07 +02:00
|
|
|
}
|
2021-05-16 13:38:26 +02:00
|
|
|
|
2021-05-15 18:22:44 +02:00
|
|
|
}
|