1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00
vcmi/AI/Nullkiller/Goals/StayAtTown.cpp
Xilmi 0edc17b7d8 Going to town when nothing to do.
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.
2024-09-06 22:14:59 +02:00

48 lines
1.1 KiB
C++

/*
* ArmyUpgrade.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 "StayAtTown.h"
#include "../AIGateway.h"
#include "../Engine/Nullkiller.h"
#include "../AIUtility.h"
namespace NKAI
{
using namespace Goals;
StayAtTown::StayAtTown(const CGTownInstance * town, AIPath & path)
: ElementarGoal(Goals::STAY_AT_TOWN)
{
sethero(path.targetHero);
settown(town);
movementWasted = static_cast<float>(hero->movementPointsRemaining()) / hero->movementPointsLimit(!hero->boat) - path.movementCost();
vstd::amax(movementWasted, 0);
}
bool StayAtTown::operator==(const StayAtTown & other) const
{
return hero == other.hero && town == other.town;
}
std::string StayAtTown::toString() const
{
return "Stay at town " + town->getNameTranslated()
+ " hero " + hero->getNameTranslated()
+ ", mana: " + std::to_string(hero->mana);
}
void StayAtTown::accept(AIGateway * ai)
{
ai->nullkiller->lockHero(hero, HeroLockedReason::DEFENCE);
}
}