1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00

CPathfinder: store pathfinding options in set instead of variables

There is plenty of variables now and in future I'm going to add more more once pathfinder become usable for all kind of things.
This commit is contained in:
ArseniyShestakov
2015-10-12 10:29:39 +03:00
parent 886042dc11
commit 0faedde6b9
2 changed files with 19 additions and 16 deletions

View File

@ -3407,7 +3407,7 @@ bool CPathfinder::checkDestinationTile()
return true; // This one is tricky, we can ignore fact that tile is not ACCESSIBLE in case if it's our hero block it. Though this need investigation return true; // This one is tricky, we can ignore fact that tile is not ACCESSIBLE in case if it's our hero block it. Though this need investigation
if(dp->accessible == CGPathNode::VISITABLE && CGTeleport::isTeleport(dt->topVisitableObj())) if(dp->accessible == CGPathNode::VISITABLE && CGTeleport::isTeleport(dt->topVisitableObj()))
return true; // For now we'll walways allos transit for teleports return true; // For now we'll walways allos transit for teleports
if(useEmbarkCost && allowEmbarkAndDisembark) if(useEmbarkCost && vstd::contains(options, EOptions::EMBARK_AND_DISEMBARK))
return true; return true;
if(isDestinationGuarded() && !isSourceGuarded()) if(isDestinationGuarded() && !isSourceGuarded())
return true; // Can step into a hostile tile once return true; // Can step into a hostile tile once
@ -3612,13 +3612,11 @@ CPathfinder::CPathfinder(CPathsInfo &_out, CGameState *_gs, const CGHeroInstance
initializeGraph(); initializeGraph();
allowEmbarkAndDisembark = true; options.insert(EOptions::EMBARK_AND_DISEMBARK);
allowTeleportTwoWay = true; options.insert(EOptions::TELEPORT_TWO_WAY);
allowTeleportOneWay = true; options.insert(EOptions::TELEPORT_ONE_WAY);
allowTeleportOneWayRandom = false;
allowTeleportWhirlpool = false;
if (CGWhirlpool::isProtected(hero)) if (CGWhirlpool::isProtected(hero))
allowTeleportWhirlpool = true; options.insert(EOptions::TELEPORT_WHIRLPOOL);
neighbours.reserve(16); neighbours.reserve(16);
} }
@ -3631,12 +3629,12 @@ CRandomGenerator & CGameState::getRandomGenerator()
bool CPathfinder::addTeleportTwoWay(const CGTeleport * obj) const bool CPathfinder::addTeleportTwoWay(const CGTeleport * obj) const
{ {
return allowTeleportTwoWay && gs->isTeleportChannelBidirectional(obj->channel, hero->tempOwner); return vstd::contains(options,EOptions::TELEPORT_TWO_WAY) && gs->isTeleportChannelBidirectional(obj->channel, hero->tempOwner);
} }
bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const
{ {
if(allowTeleportOneWay && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner)) if(vstd::contains(options,EOptions::TELEPORT_ONE_WAY) && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
{ {
auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, hero->tempOwner)); auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, hero->tempOwner));
if(passableExits.size() == 1) if(passableExits.size() == 1)
@ -3647,7 +3645,7 @@ bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const
bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const
{ {
if(allowTeleportOneWayRandom && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner)) if(vstd::contains(options,EOptions::TELEPORT_ONE_WAY_RANDOM) && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
{ {
auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, hero->tempOwner)); auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, hero->tempOwner));
if(passableExits.size() > 1) if(passableExits.size() > 1)
@ -3658,5 +3656,5 @@ bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const
bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const
{ {
return allowTeleportWhirlpool && obj; return vstd::contains(options,EOptions::TELEPORT_WHIRLPOOL) && obj;
} }

View File

@ -279,11 +279,16 @@ struct DLL_EXPORT DuelParameters
class CPathfinder : private CGameInfoCallback class CPathfinder : private CGameInfoCallback
{ {
private: private:
bool allowEmbarkAndDisembark; enum class EOptions
bool allowTeleportTwoWay; // Two-way monoliths and Subterranean Gate {
bool allowTeleportOneWay; // One-way monoliths with one known exit only EMBARK_AND_DISEMBARK,
bool allowTeleportOneWayRandom; // One-way monoliths with more than one known exit TELEPORT_TWO_WAY, // Two-way monoliths and Subterranean Gate
bool allowTeleportWhirlpool; // Force enabled if hero protected or unaffected (have one stack of one creature) TELEPORT_ONE_WAY, // One-way monoliths with one known exit only
TELEPORT_ONE_WAY_RANDOM, // One-way monoliths with more than one known exit
TELEPORT_WHIRLPOOL // Force enabled if hero protected or unaffected (have one stack of one creature)
};
std::set<EOptions> options;
CPathsInfo &out; CPathsInfo &out;
const CGHeroInstance *hero; const CGHeroInstance *hero;
const std::vector<std::vector<std::vector<ui8> > > &FoW; const std::vector<std::vector<std::vector<ui8> > > &FoW;