2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* StupidAI.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
|
|
|
|
*
|
|
|
|
*/
|
2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
|
|
|
#include "../../lib/AI_Base.h"
|
2010-12-22 22:14:40 +02:00
|
|
|
#include "StupidAI.h"
|
2017-03-17 17:48:44 +02:00
|
|
|
#include "../../lib/CStack.h"
|
2011-01-07 12:48:31 +02:00
|
|
|
#include "../../CCallback.h"
|
2011-01-08 20:33:40 +02:00
|
|
|
#include "../../lib/CCreatureHandler.h"
|
|
|
|
|
2015-12-29 04:43:33 +02:00
|
|
|
static std::shared_ptr<CBattleCallback> cbc;
|
2010-12-22 22:14:40 +02:00
|
|
|
|
2018-01-13 10:43:26 +02:00
|
|
|
CStupidAI::CStupidAI()
|
2013-06-23 22:35:54 +03:00
|
|
|
: side(-1)
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
2010-12-25 03:43:40 +02:00
|
|
|
print("created");
|
2010-12-22 22:14:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-01-13 10:43:26 +02:00
|
|
|
CStupidAI::~CStupidAI()
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
2010-12-25 03:43:40 +02:00
|
|
|
print("destroyed");
|
2010-12-22 22:14:40 +02:00
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
void CStupidAI::init(std::shared_ptr<Environment> ENV, std::shared_ptr<CBattleCallback> CB)
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
2010-12-25 03:43:40 +02:00
|
|
|
print("init called, saving ptr to IBattleCallback");
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
env = ENV;
|
2011-01-08 20:33:40 +02:00
|
|
|
cbc = cb = CB;
|
2010-12-22 22:14:40 +02:00
|
|
|
}
|
|
|
|
|
2013-05-09 14:09:23 +03:00
|
|
|
void CStupidAI::actionFinished(const BattleAction &action)
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
2010-12-25 03:43:40 +02:00
|
|
|
print("actionFinished called");
|
2010-12-22 22:14:40 +02:00
|
|
|
}
|
|
|
|
|
2013-05-09 14:09:23 +03:00
|
|
|
void CStupidAI::actionStarted(const BattleAction &action)
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
2010-12-25 03:43:40 +02:00
|
|
|
print("actionStarted called");
|
2010-12-22 22:14:40 +02:00
|
|
|
}
|
|
|
|
|
2022-06-11 17:45:34 +02:00
|
|
|
class EnemyInfo
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
2022-06-11 17:45:34 +02:00
|
|
|
public:
|
2011-01-08 20:33:40 +02:00
|
|
|
const CStack * s;
|
|
|
|
int adi, adr;
|
2011-12-22 16:05:19 +03:00
|
|
|
std::vector<BattleHex> attackFrom; //for melee fight
|
2016-12-12 20:13:43 +02:00
|
|
|
EnemyInfo(const CStack * _s) : s(_s), adi(0), adr(0)
|
2011-01-08 20:33:40 +02:00
|
|
|
{}
|
|
|
|
void calcDmg(const CStack * ourStack)
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
TDmgRange retal, dmg = cbc->battleEstimateDamage(ourStack, s, &retal);
|
2020-10-01 10:38:06 +02:00
|
|
|
adi = static_cast<int>((dmg.first + dmg.second) / 2);
|
|
|
|
adr = static_cast<int>((retal.first + retal.second) / 2);
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const EnemyInfo& ei) const
|
|
|
|
{
|
|
|
|
return s == ei.s;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
bool isMoreProfitable(const EnemyInfo &ei1, const EnemyInfo& ei2)
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
|
|
|
return (ei1.adi-ei1.adr) < (ei2.adi - ei2.adr);
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:05:19 +03:00
|
|
|
static bool willSecondHexBlockMoreEnemyShooters(const BattleHex &h1, const BattleHex &h2)
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
|
|
|
int shooters[2] = {0}; //count of shooters on hexes
|
|
|
|
|
|
|
|
for(int i = 0; i < 2; i++)
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & neighbour : (i ? h2 : h1).neighbouringTiles())
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
if(const CStack * s = cbc->battleGetStackByPos(neighbour))
|
|
|
|
if(s->isShooter())
|
|
|
|
shooters[i]++;
|
|
|
|
}
|
2011-01-08 20:33:40 +02:00
|
|
|
|
|
|
|
return shooters[0] < shooters[1];
|
|
|
|
}
|
|
|
|
|
2010-12-23 22:18:10 +02:00
|
|
|
BattleAction CStupidAI::activeStack( const CStack * stack )
|
2010-12-22 22:14:40 +02:00
|
|
|
{
|
2011-01-08 21:38:42 +02:00
|
|
|
//boost::this_thread::sleep(boost::posix_time::seconds(2));
|
2012-08-26 12:07:48 +03:00
|
|
|
print("activeStack called for " + stack->nodeName());
|
2020-11-23 08:40:36 +02:00
|
|
|
ReachabilityInfo dists = cb->getReachability(stack);
|
2011-01-08 20:33:40 +02:00
|
|
|
std::vector<EnemyInfo> enemiesShootable, enemiesReachable, enemiesUnreachable;
|
|
|
|
|
2013-02-07 20:34:50 +03:00
|
|
|
if(stack->type->idNumber == CreatureID::CATAPULT)
|
2012-01-03 04:55:26 +03:00
|
|
|
{
|
|
|
|
BattleAction attack;
|
2016-02-14 13:38:24 +02:00
|
|
|
static const std::vector<int> wallHexes = {50, 183, 182, 130, 78, 29, 12, 95};
|
2017-07-20 06:08:49 +02:00
|
|
|
auto seletectedHex = *RandomGeneratorUtil::nextItem(wallHexes, CRandomGenerator::getDefault());
|
|
|
|
attack.aimToHex(seletectedHex);
|
|
|
|
attack.actionType = EActionType::CATAPULT;
|
2012-01-03 04:55:26 +03:00
|
|
|
attack.side = side;
|
|
|
|
attack.stackNumber = stack->ID;
|
|
|
|
|
|
|
|
return attack;
|
|
|
|
}
|
2013-08-25 16:03:29 +03:00
|
|
|
else if(stack->hasBonusOfType(Bonus::SIEGE_WEAPON))
|
|
|
|
{
|
|
|
|
return BattleAction::makeDefend(stack);
|
|
|
|
}
|
2012-01-03 04:55:26 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for (const CStack *s : cb->battleGetStacks(CBattleCallback::ONLY_ENEMY))
|
2011-01-07 12:48:31 +02:00
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
if(cb->battleCanShoot(stack, s->getPosition()))
|
2011-01-07 12:48:31 +02:00
|
|
|
{
|
2011-02-14 22:31:53 +02:00
|
|
|
enemiesShootable.push_back(s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-20 06:08:49 +02:00
|
|
|
std::vector<BattleHex> avHexes = cb->battleGetAvailableHexes(stack);
|
2012-08-26 22:13:57 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for (BattleHex hex : avHexes)
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
2011-02-14 22:31:53 +02:00
|
|
|
if(CStack::isMeleeAttackPossible(stack, s, hex))
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
2011-02-14 22:31:53 +02:00
|
|
|
std::vector<EnemyInfo>::iterator i = std::find(enemiesReachable.begin(), enemiesReachable.end(), s);
|
|
|
|
if(i == enemiesReachable.end())
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
2011-02-14 22:31:53 +02:00
|
|
|
enemiesReachable.push_back(s);
|
|
|
|
i = enemiesReachable.begin() + (enemiesReachable.size() - 1);
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
|
|
|
|
2011-02-14 22:31:53 +02:00
|
|
|
i->attackFrom.push_back(hex);
|
|
|
|
}
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
2011-02-14 22:31:53 +02:00
|
|
|
|
2017-07-20 06:08:49 +02:00
|
|
|
if(!vstd::contains(enemiesReachable, s) && s->getPosition().isValid())
|
2011-02-14 22:31:53 +02:00
|
|
|
enemiesUnreachable.push_back(s);
|
2011-01-07 12:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 21:28:01 +02:00
|
|
|
for ( auto & enemy : enemiesReachable )
|
|
|
|
enemy.calcDmg( stack );
|
|
|
|
|
|
|
|
for ( auto & enemy : enemiesShootable )
|
|
|
|
enemy.calcDmg( stack );
|
|
|
|
|
2011-01-08 20:33:40 +02:00
|
|
|
if(enemiesShootable.size())
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
2011-01-08 20:33:40 +02:00
|
|
|
const EnemyInfo &ei= *std::max_element(enemiesShootable.begin(), enemiesShootable.end(), isMoreProfitable);
|
|
|
|
return BattleAction::makeShotAttack(stack, ei.s);
|
2010-12-25 03:43:40 +02:00
|
|
|
}
|
2011-01-08 20:33:40 +02:00
|
|
|
else if(enemiesReachable.size())
|
|
|
|
{
|
|
|
|
const EnemyInfo &ei= *std::max_element(enemiesReachable.begin(), enemiesReachable.end(), &isMoreProfitable);
|
2017-07-20 06:08:49 +02:00
|
|
|
return BattleAction::makeMeleeAttack(stack, ei.s->getPosition(), *std::max_element(ei.attackFrom.begin(), ei.attackFrom.end(), &willSecondHexBlockMoreEnemyShooters));
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
2012-09-28 19:48:29 +03:00
|
|
|
else if(enemiesUnreachable.size()) //due to #955 - a buggy battle may occur when there are no enemies
|
2011-01-07 12:48:31 +02:00
|
|
|
{
|
2020-11-23 08:40:36 +02:00
|
|
|
auto closestEnemy = vstd::minElementByFun(enemiesUnreachable, [&](const EnemyInfo & ei) -> int
|
2011-01-07 12:48:31 +02:00
|
|
|
{
|
2020-11-23 08:40:36 +02:00
|
|
|
return dists.distToNearestNeighbour(stack, ei.s);
|
|
|
|
});
|
|
|
|
|
|
|
|
if(dists.distToNearestNeighbour(stack, closestEnemy->s) < GameConstants::BFIELD_SIZE)
|
|
|
|
{
|
2020-12-15 20:38:01 +02:00
|
|
|
return goTowards(stack, closestEnemy->s->getAttackableHexes(stack));
|
2011-01-07 12:48:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-25 03:48:02 +02:00
|
|
|
return BattleAction::makeDefend(stack);
|
2010-12-25 03:43:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CStupidAI::battleAttack(const BattleAttack *ba)
|
|
|
|
{
|
|
|
|
print("battleAttack called");
|
|
|
|
}
|
|
|
|
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
void CStupidAI::battleStacksAttacked(const std::vector<BattleStackAttacked> & bsa)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleStacksAttacked called");
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleEnd(const BattleResult *br)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleEnd called");
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
// void CStupidAI::battleResultsApplied()
|
2011-05-10 01:20:47 +03:00
|
|
|
// {
|
|
|
|
// print("battleResultsApplied called");
|
|
|
|
// }
|
2010-12-25 03:43:40 +02:00
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleNewRoundFirst(int round)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleNewRoundFirst called");
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleNewRound(int round)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleNewRound called");
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleStackMoved(const CStack * stack, std::vector<BattleHex> dest, int distance)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
2017-07-12 21:01:10 +02:00
|
|
|
print("battleStackMoved called");
|
2010-12-25 03:43:40 +02:00
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleSpellCast(const BattleSpellCast *sc)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleSpellCast called");
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleStacksEffectsSet(const SetStackEffect & sse)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleStacksEffectsSet called");
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool Side)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleStart called");
|
|
|
|
side = Side;
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:59:07 +03:00
|
|
|
void CStupidAI::battleCatapultAttacked(const CatapultAttack & ca)
|
2010-12-25 03:43:40 +02:00
|
|
|
{
|
|
|
|
print("battleCatapultAttacked called");
|
|
|
|
}
|
|
|
|
|
|
|
|
void CStupidAI::print(const std::string &text) const
|
|
|
|
{
|
2016-08-13 16:44:37 +02:00
|
|
|
logAi->trace("CStupidAI [%p]: %s", this, text);
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
|
|
|
|
2020-12-15 20:38:01 +02:00
|
|
|
BattleAction CStupidAI::goTowards(const CStack * stack, std::vector<BattleHex> hexes) const
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
2012-08-26 12:07:48 +03:00
|
|
|
auto reachability = cb->getReachability(stack);
|
2017-07-20 06:08:49 +02:00
|
|
|
auto avHexes = cb->battleGetAvailableHexes(reachability, stack);
|
2012-08-26 12:07:48 +03:00
|
|
|
|
2020-12-15 20:38:01 +02:00
|
|
|
if(!avHexes.size() || !hexes.size()) //we are blocked or dest is blocked
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
|
|
|
return BattleAction::makeDefend(stack);
|
|
|
|
}
|
|
|
|
|
2020-12-15 20:38:01 +02:00
|
|
|
std::sort(hexes.begin(), hexes.end(), [&](BattleHex h1, BattleHex h2) -> bool
|
2020-11-23 08:40:36 +02:00
|
|
|
{
|
2020-12-15 20:38:01 +02:00
|
|
|
return reachability.distances[h1] < reachability.distances[h2];
|
|
|
|
});
|
|
|
|
|
|
|
|
for(auto hex : hexes)
|
|
|
|
{
|
|
|
|
if(vstd::contains(avHexes, hex))
|
|
|
|
return BattleAction::makeMove(stack, hex);
|
|
|
|
|
|
|
|
if(stack->coversPos(hex))
|
|
|
|
{
|
|
|
|
logAi->warn("Warning: already standing on neighbouring tile!");
|
|
|
|
//We shouldn't even be here...
|
|
|
|
return BattleAction::makeDefend(stack);
|
|
|
|
}
|
2020-11-23 08:40:36 +02:00
|
|
|
}
|
2011-01-08 20:33:40 +02:00
|
|
|
|
2020-12-15 20:38:01 +02:00
|
|
|
BattleHex bestNeighbor = hexes.front();
|
|
|
|
|
|
|
|
if(reachability.distances[bestNeighbor] > GameConstants::BFIELD_SIZE)
|
2011-09-06 16:59:26 +03:00
|
|
|
{
|
|
|
|
return BattleAction::makeDefend(stack);
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:07:48 +03:00
|
|
|
if(stack->hasBonusOfType(Bonus::FLYING))
|
|
|
|
{
|
|
|
|
// Flying stack doesn't go hex by hex, so we can't backtrack using predecessors.
|
|
|
|
// We just check all available hexes and pick the one closest to the target.
|
2020-11-23 08:40:36 +02:00
|
|
|
auto nearestAvailableHex = vstd::minElementByFun(avHexes, [&](BattleHex hex) -> int
|
2012-08-26 12:07:48 +03:00
|
|
|
{
|
2020-11-23 08:40:36 +02:00
|
|
|
return BattleHex::getDistance(bestNeighbor, hex);
|
|
|
|
});
|
2012-08-26 12:07:48 +03:00
|
|
|
|
|
|
|
return BattleAction::makeMove(stack, *nearestAvailableHex);
|
|
|
|
}
|
|
|
|
else
|
2011-01-08 20:33:40 +02:00
|
|
|
{
|
2012-08-26 12:07:48 +03:00
|
|
|
BattleHex currentDest = bestNeighbor;
|
|
|
|
while(1)
|
|
|
|
{
|
2020-11-23 08:40:36 +02:00
|
|
|
if(!currentDest.isValid())
|
|
|
|
{
|
|
|
|
logAi->error("CBattleAI::goTowards: internal error");
|
|
|
|
return BattleAction::makeDefend(stack);
|
|
|
|
}
|
|
|
|
|
2012-08-26 12:07:48 +03:00
|
|
|
if(vstd::contains(avHexes, currentDest))
|
|
|
|
return BattleAction::makeMove(stack, currentDest);
|
|
|
|
|
|
|
|
currentDest = reachability.predecessors[currentDest];
|
|
|
|
}
|
2011-01-08 20:33:40 +02:00
|
|
|
}
|
|
|
|
}
|