mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
0edc17b7d8
The StayAtTown-behavior now always creates tasks for all heroes to go and stay at a town. It will be treated differently than going to a town for mana in the sense that it is only considered at the lowest priority-tier. So it will only happen when the AI doesn't find anything else to do. It should resolve one of the two main-reasons for losing weak heros. The hunter-gather-priority-tier now goes strictly by distance for all taks that are considered above 0 in value.
67 lines
1.3 KiB
C++
67 lines
1.3 KiB
C++
/*
|
|
* 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";
|
|
}
|
|
|
|
Goals::TGoalVec StayAtTownBehavior::decompose(const Nullkiller * ai) const
|
|
{
|
|
Goals::TGoalVec tasks;
|
|
auto towns = ai->cb->getTownsInfo();
|
|
|
|
if(!towns.size())
|
|
return tasks;
|
|
|
|
std::vector<AIPath> paths;
|
|
|
|
for(auto town : towns)
|
|
{
|
|
ai->pathfinder->calculatePathInfo(paths, town->visitablePos());
|
|
|
|
for(auto & path : paths)
|
|
{
|
|
if(town->visitingHero && town->visitingHero.get() != path.targetHero)
|
|
continue;
|
|
|
|
if(!path.getFirstBlockedAction() && path.exchangeCount <= 1)
|
|
{
|
|
Composition stayAtTown;
|
|
|
|
stayAtTown.addNextSequence({
|
|
sptr(ExecuteHeroChain(path)),
|
|
sptr(StayAtTown(town, path))
|
|
});
|
|
|
|
tasks.push_back(sptr(stayAtTown));
|
|
}
|
|
}
|
|
}
|
|
|
|
return tasks;
|
|
}
|
|
|
|
}
|