1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00
vcmi/AI/Nullkiller/Goals/Composition.cpp

75 lines
1.4 KiB
C++
Raw Normal View History

2021-05-16 13:38:53 +02:00
/*
* BuildThis.cpp, 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
*
*/
#include "StdInc.h"
#include "Composition.h"
2021-05-16 14:39:38 +02:00
#include "../AIGateway.h"
2021-05-16 13:38:53 +02:00
#include "../AIUtility.h"
#include "../../../lib/mapping/CMap.h" //for victory conditions
#include "../../../lib/CPathfinder.h"
#include "../../../lib/StringConstants.h"
extern boost::thread_specific_ptr<CCallback> cb;
2021-05-16 14:39:38 +02:00
extern boost::thread_specific_ptr<AIGateway> ai;
2021-05-16 13:38:53 +02:00
using namespace Goals;
bool Composition::operator==(const Composition & other) const
{
return false;
}
std::string Composition::toString() const
{
std::string result = "Composition";
for(auto goal : subtasks)
{
result += " " + goal->toString();
}
return result;
}
2021-05-16 14:39:38 +02:00
void Composition::accept(AIGateway * ai)
2021-05-16 13:38:53 +02:00
{
taskptr(*subtasks.back())->accept(ai);
}
TGoalVec Composition::decompose() const
{
return subtasks;
2021-05-16 13:38:53 +02:00
}
2021-05-16 13:45:35 +02:00
Composition & Composition::addNext(const AbstractGoal & goal)
2021-05-16 13:38:53 +02:00
{
return addNext(sptr(goal));
}
Composition & Composition::addNext(TSubgoal goal)
{
if(goal->goalType == COMPOSITION)
{
Composition & other = dynamic_cast<Composition &>(*goal);
vstd::concatenate(subtasks, other.subtasks);
}
else
{
subtasks.push_back(goal);
}
2021-05-16 13:38:53 +02:00
return *this;
}
bool Composition::isElementar() const
{
return subtasks.back()->isElementar();
}