2023-09-24 12:07:42 +02:00
|
|
|
/*
|
|
|
|
* StartupBehavior.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 "StayAtTownBehavior.h"
|
|
|
|
#include "../AIGateway.h"
|
|
|
|
#include "../AIUtility.h"
|
|
|
|
#include "../Goals/StayAtTown.h"
|
|
|
|
#include "../Goals/Composition.h"
|
|
|
|
#include "../Goals/ExecuteHeroChain.h"
|
|
|
|
#include "lib/mapObjects/MapObjects.h" //for victory conditions
|
|
|
|
#include "../Engine/Nullkiller.h"
|
|
|
|
|
|
|
|
namespace NKAI
|
|
|
|
{
|
|
|
|
|
|
|
|
using namespace Goals;
|
|
|
|
|
|
|
|
std::string StayAtTownBehavior::toString() const
|
|
|
|
{
|
|
|
|
return "StayAtTownBehavior";
|
|
|
|
}
|
|
|
|
|
2024-03-31 17:39:00 +02:00
|
|
|
Goals::TGoalVec StayAtTownBehavior::decompose(const Nullkiller * ai) const
|
2023-09-24 12:07:42 +02:00
|
|
|
{
|
|
|
|
Goals::TGoalVec tasks;
|
2024-03-31 17:39:00 +02:00
|
|
|
auto towns = ai->cb->getTownsInfo();
|
2023-09-24 12:07:42 +02:00
|
|
|
|
|
|
|
if(!towns.size())
|
|
|
|
return tasks;
|
|
|
|
|
2024-03-24 09:32:29 +02:00
|
|
|
std::vector<AIPath> paths;
|
|
|
|
|
2023-09-24 12:07:42 +02:00
|
|
|
for(auto town : towns)
|
|
|
|
{
|
2024-03-31 17:39:00 +02:00
|
|
|
ai->pathfinder->calculatePathInfo(paths, town->visitablePos());
|
2023-09-24 12:07:42 +02:00
|
|
|
|
|
|
|
for(auto & path : paths)
|
|
|
|
{
|
|
|
|
if(town->visitingHero && town->visitingHero.get() != path.targetHero)
|
|
|
|
continue;
|
|
|
|
|
2024-09-06 22:14:59 +02:00
|
|
|
if(!path.getFirstBlockedAction() && path.exchangeCount <= 1)
|
2023-09-24 12:07:42 +02:00
|
|
|
{
|
|
|
|
Composition stayAtTown;
|
|
|
|
|
|
|
|
stayAtTown.addNextSequence({
|
|
|
|
sptr(ExecuteHeroChain(path)),
|
|
|
|
sptr(StayAtTown(town, path))
|
|
|
|
});
|
|
|
|
|
|
|
|
tasks.push_back(sptr(stayAtTown));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return tasks;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|