本文整理汇总了C++中Heroes::GetSquarePatrol方法的典型用法代码示例。如果您正苦于以下问题:C++ Heroes::GetSquarePatrol方法的具体用法?C++ Heroes::GetSquarePatrol怎么用?C++ Heroes::GetSquarePatrol使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Heroes
的用法示例。
在下文中一共展示了Heroes::GetSquarePatrol方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HeroesGetTask
bool AI::HeroesGetTask(Heroes & hero)
{
std::vector<s32> results;
results.reserve(5);
const Settings & conf = Settings::Get();
AIHero & ai_hero = AIHeroes::Get(hero);
AIKingdom & ai_kingdom = AIKingdoms::Get(hero.GetColor());
Queue & task = ai_hero.sheduled_visit;
IndexObjectMap & ai_objects = ai_kingdom.scans;
const u8 objs1[] = { MP2::OBJ_ARTIFACT, MP2::OBJ_RESOURCE, MP2::OBJ_CAMPFIRE, MP2::OBJ_TREASURECHEST, 0 };
const u8 objs2[] = { MP2::OBJ_SAWMILL, MP2::OBJ_MINES, MP2::OBJ_ALCHEMYLAB, 0 };
const u8 objs3[] = { MP2::OBJ_CASTLE, MP2::OBJ_HEROES, MP2::OBJ_MONSTER, 0 };
// rescan path
hero.RescanPath();
Castle* castle = hero.inCastle();
// if hero in castle
if(castle)
{
DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", in castle");
castle->RecruitAllMonster();
hero.GetArmy().UpgradeTroops(*castle);
// recruit army
if(hero.Modes(AI::HEROES_HUNTER))
hero.GetArmy().JoinStrongestFromArmy(castle->GetArmy());
else
if(hero.Modes(AI::HEROES_SCOUTER))
hero.GetArmy().KeepOnlyWeakestTroops(castle->GetArmy());
DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", " << hero.GetArmy().String());
}
// patrol task
if(hero.Modes(Heroes::PATROL))
{
DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", is patrol mode");
// goto patrol center
if(hero.GetCenterPatrol() != hero.GetCenter() &&
hero.GetPath().Calculate(Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol())))
return true;
// scan enemy hero
if(hero.GetSquarePatrol())
{
const Maps::Indexes & results = Maps::ScanAroundObject(Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol()),
hero.GetSquarePatrol(), MP2::OBJ_HEROES);
for(MapsIndexes::const_iterator
it = results.begin(); it != results.end(); ++it)
{
const Heroes* enemy = world.GetTiles(*it).GetHeroes();
if(enemy && ! enemy->isFriends(hero.GetColor()))
{
if(hero.GetPath().Calculate(enemy->GetIndex()))
{
DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ", find enemy");
return true;
}
}
}
}
// can pickup objects
if(conf.ExtHeroPatrolAllowPickup())
{
const Maps::Indexes & results = Maps::ScanAroundObjects(hero.GetIndex(),
hero.GetSquarePatrol(), objs1);
for(MapsIndexes::const_iterator
it = results.begin(); it != results.end(); ++it)
if(AI::HeroesValidObject(hero, *it) &&
hero.GetPath().Calculate(*it))
{
ai_objects.erase(*it);
DEBUG(DBG_AI, DBG_TRACE, hero.GetName() << ": find object: " <<
MP2::StringObject(world.GetTiles(*it).GetObject()) << "(" << *it << ")");
return true;
}
}
// random move
/*
// disable move: https://sourceforge.net/tracker/?func=detail&aid=3157397&group_id=96859&atid=616180
{
Maps::ScanAroundObject(hero.GetIndex(), hero.GetSquarePatrol(), MP2::OBJ_ZERO);
if(results.size())
{
std::random_shuffle(results.begin(), results.end());
std::vector<s32>::const_iterator it = results.begin();
for(; it != results.end(); ++it)
if(world.GetTiles(*it).isPassable(&hero, Direction::CENTER, true) &&
hero.GetPath().Calculate(*it))
{
DEBUG(DBG_AI, Color::String(hero.GetColor()) <<
//.........这里部分代码省略.........