1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
vcmi/AI/VCAI/Goals/CGoal.h

85 lines
1.6 KiB
C++
Raw Normal View History

2018-12-01 10:30:37 +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"
#include "../FuzzyHelper.h"
#include "../VCAI.h"
struct HeroPtr;
class VCAI;
namespace Goals
{
2024-05-17 12:10:06 +02:00
template<typename T>
class DLL_EXPORT CGoal : public AbstractGoal
2018-12-01 10:30:37 +02:00
{
public:
2024-05-17 12:10:06 +02:00
CGoal(EGoals goal = INVALID) : AbstractGoal(goal)
2018-12-01 10:30:37 +02:00
{
priority = 0;
isElementar = false;
isAbstract = false;
value = 0;
aid = -1;
objid = -1;
resID = -1;
tile = int3(-1, -1, -1);
town = nullptr;
}
OSETTER(bool, isElementar)
OSETTER(bool, isAbstract)
OSETTER(float, priority)
OSETTER(int, value)
OSETTER(int, resID)
OSETTER(int, objid)
OSETTER(int, aid)
OSETTER(int3, tile)
OSETTER(HeroPtr, hero)
OSETTER(CGTownInstance *, town)
OSETTER(int, bid)
void accept(VCAI * ai) override
{
ai->tryRealize(static_cast<T &>(*this)); //casting enforces template instantiation
}
float accept(FuzzyHelper * f) override
{
return f->evaluate(static_cast<T &>(*this)); //casting enforces template instantiation
}
2024-05-17 12:10:06 +02:00
CGoal * clone() const override
2018-12-01 10:30:37 +02:00
{
return new T(static_cast<T const &>(*this)); //casting enforces template instantiation
}
TSubgoal iAmElementar() const
2018-12-01 10:30:37 +02:00
{
TSubgoal ptr;
2018-12-01 10:30:37 +02:00
ptr.reset(clone());
ptr->setisElementar(true);
2018-12-01 10:30:37 +02:00
return ptr;
}
bool operator==(const AbstractGoal & g) const override
2018-12-01 10:30:37 +02:00
{
if(goalType != g.goalType)
return false;
return (*this) == (static_cast<const T &>(g));
2018-12-01 10:30:37 +02:00
}
virtual bool operator==(const T & other) const = 0;
};
}