mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-01 00:45:26 +02:00
CPathfinder: use struct instead of enum for options
Suggested by @DjWarmonger as better alternative from performance standpoint while struct still more organized than bunch of variables. Other reason of change it's that in future we may need non-boolean options, e.g for patrol movement and some new pathfinder usages.
This commit is contained in:
@ -3410,7 +3410,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 always allow transit for teleporters
|
return true; // For now we'll always allow transit for teleporters
|
||||||
if(useEmbarkCost && vstd::contains(options, EOptions::EMBARK_AND_DISEMBARK))
|
if(useEmbarkCost && options.useEmbarkAndDisembark)
|
||||||
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
|
||||||
@ -3611,6 +3611,17 @@ bool CPathfinder::isMovementPossible()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPathfinder::PathfinderOptions::PathfinderOptions()
|
||||||
|
{
|
||||||
|
useFlying = false;
|
||||||
|
useWaterWalking = false;
|
||||||
|
useEmbarkAndDisembark = true;
|
||||||
|
useTeleportTWoWay = true;
|
||||||
|
useTeleportOneWay = true;
|
||||||
|
useTeleportOneWayRandom = false;
|
||||||
|
useTeleportWhirlpool = false;
|
||||||
|
}
|
||||||
|
|
||||||
CPathfinder::CPathfinder(CPathsInfo &_out, CGameState *_gs, const CGHeroInstance *_hero) : CGameInfoCallback(_gs, boost::optional<PlayerColor>()), out(_out), hero(_hero), FoW(getPlayerTeam(hero->tempOwner)->fogOfWarMap)
|
CPathfinder::CPathfinder(CPathsInfo &_out, CGameState *_gs, const CGHeroInstance *_hero) : CGameInfoCallback(_gs, boost::optional<PlayerColor>()), out(_out), hero(_hero), FoW(getPlayerTeam(hero->tempOwner)->fogOfWarMap)
|
||||||
{
|
{
|
||||||
assert(hero);
|
assert(hero);
|
||||||
@ -3627,14 +3638,11 @@ CPathfinder::CPathfinder(CPathsInfo &_out, CGameState *_gs, const CGHeroInstance
|
|||||||
initializeGraph();
|
initializeGraph();
|
||||||
|
|
||||||
if(hero->canFly())
|
if(hero->canFly())
|
||||||
options.insert(EOptions::FLYING);
|
options.useFlying = true;
|
||||||
else if(hero->canWalkOnSea())
|
if(hero->canWalkOnSea())
|
||||||
options.insert(EOptions::WALKING_ON_SEA);
|
options.useWaterWalking = true;
|
||||||
options.insert(EOptions::EMBARK_AND_DISEMBARK);
|
|
||||||
options.insert(EOptions::TELEPORT_TWO_WAY);
|
|
||||||
options.insert(EOptions::TELEPORT_ONE_WAY);
|
|
||||||
if (CGWhirlpool::isProtected(hero))
|
if (CGWhirlpool::isProtected(hero))
|
||||||
options.insert(EOptions::TELEPORT_WHIRLPOOL);
|
options.useTeleportWhirlpool = true;
|
||||||
|
|
||||||
neighbours.reserve(16);
|
neighbours.reserve(16);
|
||||||
}
|
}
|
||||||
@ -3647,12 +3655,12 @@ CRandomGenerator & CGameState::getRandomGenerator()
|
|||||||
|
|
||||||
bool CPathfinder::addTeleportTwoWay(const CGTeleport * obj) const
|
bool CPathfinder::addTeleportTwoWay(const CGTeleport * obj) const
|
||||||
{
|
{
|
||||||
return vstd::contains(options,EOptions::TELEPORT_TWO_WAY) && gs->isTeleportChannelBidirectional(obj->channel, hero->tempOwner);
|
return options.useTeleportTWoWay && gs->isTeleportChannelBidirectional(obj->channel, hero->tempOwner);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const
|
bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const
|
||||||
{
|
{
|
||||||
if(vstd::contains(options,EOptions::TELEPORT_ONE_WAY) && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
|
if(options.useTeleportOneWay && 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)
|
||||||
@ -3663,7 +3671,7 @@ bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const
|
|||||||
|
|
||||||
bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const
|
bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const
|
||||||
{
|
{
|
||||||
if(vstd::contains(options,EOptions::TELEPORT_ONE_WAY_RANDOM) && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
|
if(options.useTeleportOneWayRandom && 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)
|
||||||
@ -3674,5 +3682,5 @@ bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const
|
|||||||
|
|
||||||
bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const
|
bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const
|
||||||
{
|
{
|
||||||
return vstd::contains(options,EOptions::TELEPORT_WHIRLPOOL) && obj;
|
return options.useTeleportWhirlpool && obj;
|
||||||
}
|
}
|
||||||
|
@ -279,17 +279,19 @@ struct DLL_EXPORT DuelParameters
|
|||||||
class CPathfinder : private CGameInfoCallback
|
class CPathfinder : private CGameInfoCallback
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
enum class EOptions
|
struct PathfinderOptions
|
||||||
{
|
{
|
||||||
FLYING,
|
bool useFlying;
|
||||||
WALKING_ON_SEA,
|
bool useWaterWalking;
|
||||||
EMBARK_AND_DISEMBARK,
|
bool useEmbarkAndDisembark;
|
||||||
TELEPORT_TWO_WAY, // Two-way monoliths and Subterranean Gate
|
bool useTeleportTWoWay; // Two-way monoliths and Subterranean Gate
|
||||||
TELEPORT_ONE_WAY, // One-way monoliths with one known exit only
|
bool useTeleportOneWay; // One-way monoliths with one known exit only
|
||||||
TELEPORT_ONE_WAY_RANDOM, // One-way monoliths with more than one known exit
|
bool useTeleportOneWayRandom; // One-way monoliths with more than one known exit
|
||||||
TELEPORT_WHIRLPOOL // Force enabled if hero protected or unaffected (have one stack of one creature)
|
bool useTeleportWhirlpool; // Force enabled if hero protected or unaffected (have one stack of one creature)
|
||||||
|
|
||||||
|
PathfinderOptions();
|
||||||
};
|
};
|
||||||
std::set<EOptions> options;
|
PathfinderOptions options;
|
||||||
|
|
||||||
CPathsInfo &out;
|
CPathsInfo &out;
|
||||||
const CGHeroInstance *hero;
|
const CGHeroInstance *hero;
|
||||||
|
Reference in New Issue
Block a user