| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- /*
- * 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
- {
- Goals::TGoalVec tasks;
- auto towns = cb->getTownsInfo();
- if(!towns.size())
- return tasks;
- for(auto town : towns)
- {
- if(!town->hasBuilt(BuildingID::MAGES_GUILD_1))
- continue;
- auto paths = ai->nullkiller->pathfinder->getPathInfo(town->visitablePos());
- for(auto & path : paths)
- {
- if(town->visitingHero && town->visitingHero.get() != path.targetHero)
- continue;
- if(path.turn() == 0 && !path.getFirstBlockedAction() && path.exchangeCount <= 1)
- {
- if(path.targetHero->mana == path.targetHero->manaLimit())
- continue;
- Composition stayAtTown;
- stayAtTown.addNextSequence({
- sptr(ExecuteHeroChain(path)),
- sptr(StayAtTown(town, path))
- });
- tasks.push_back(sptr(stayAtTown));
- }
- }
- }
- return tasks;
- }
- }
|