1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

Use isTeleportChannel callback functions to check teleport channel type

This commit is contained in:
ArseniyShestakov
2015-03-09 02:13:40 +03:00
parent 0c1a37e5a7
commit 8f8d237d5d
3 changed files with 12 additions and 28 deletions

View File

@@ -127,7 +127,7 @@ void VCAI::heroMoved(const TryMoveHero & details)
auto t2 = dynamic_cast<const CGTeleport *>(o2); auto t2 = dynamic_cast<const CGTeleport *>(o2);
if(t1 && t2) if(t1 && t2)
{ {
if(ETeleportChannelType::BIDIRECTIONAL == cb->getTeleportChannelType(t1->channel)) if(cb->isTeleportChannelBidirectional(t1->channel))
{ {
if(o1->ID == Obj::SUBTERRANEAN_GATE) if(o1->ID == Obj::SUBTERRANEAN_GATE)
{ {

View File

@@ -3557,17 +3557,12 @@ CRandomGenerator & CGameState::getRandomGenerator()
bool CPathfinder::addTeleportTwoWay(const CGTeleport * obj) const bool CPathfinder::addTeleportTwoWay(const CGTeleport * obj) const
{ {
if(allowTeleportTwoWay) return allowTeleportTwoWay && gs->isTeleportChannelBidirectional(obj->channel, hero->tempOwner);
{
if(ETeleportChannelType::BIDIRECTIONAL == gs->getTeleportChannelType(obj->channel, hero->tempOwner))
return true;
}
return false;
} }
bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const
{ {
if(allowTeleportOneWay) if(allowTeleportOneWay && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
{ {
auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, ObjectInstanceID(), hero->tempOwner)); auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, ObjectInstanceID(), hero->tempOwner));
if(passableExits.size() == 1) if(passableExits.size() == 1)
@@ -3578,24 +3573,16 @@ bool CPathfinder::addTeleportOneWay(const CGTeleport * obj) const
bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const bool CPathfinder::addTeleportOneWayRandom(const CGTeleport * obj) const
{ {
if(allowTeleportOneWayRandom) if(allowTeleportOneWayRandom && isTeleportChannelUnidirectional(obj->channel, hero->tempOwner))
{ {
if(ETeleportChannelType::UNIDIRECTIONAL == gs->getTeleportChannelType(obj->channel, hero->tempOwner)) auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, ObjectInstanceID(), hero->tempOwner));
{ if(passableExits.size() > 1)
auto passableExits = CGTeleport::getPassableExits(gs, hero, gs->getTeleportChannelExits(obj->channel, ObjectInstanceID(), hero->tempOwner)); return true;
if(passableExits.size() > 1)
return true;
}
} }
return false; return false;
} }
bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const bool CPathfinder::addTeleportWhirlpool(const CGWhirlpool * obj) const
{ {
if(allowTeleportWhirlpool && obj) return allowTeleportWhirlpool && !gs->isTeleportChannelImpassable(obj->channel, hero->tempOwner);
{
if(ETeleportChannelType::IMPASSABLE != gs->getTeleportChannelType(obj->channel, hero->tempOwner))
return true;
}
return false;
} }

View File

@@ -878,13 +878,10 @@ void CGMonolith::onHeroVisit( const CGHeroInstance * h ) const
TeleportDialog td(h, channel); TeleportDialog td(h, channel);
if(isEntrance()) if(isEntrance())
{ {
if(ETeleportChannelType::BIDIRECTIONAL == cb->getTeleportChannelType(channel) if(cb->isTeleportChannelBidirectional(channel) && 1 < cb->getTeleportChannelExits(channel).size())
&& cb->getTeleportChannelExits(channel).size() > 1)
{
td.exits = cb->getTeleportChannelExits(channel); td.exits = cb->getTeleportChannelExits(channel);
}
if(ETeleportChannelType::IMPASSABLE == cb->getTeleportChannelType(channel)) if(cb->isTeleportChannelImpassable(channel))
{ {
logGlobal->debugStream() << "Cannot find corresponding exit monolith for "<< id << " (obj at " << pos << ") :("; logGlobal->debugStream() << "Cannot find corresponding exit monolith for "<< id << " (obj at " << pos << ") :(";
td.impassable = true; td.impassable = true;
@@ -948,7 +945,7 @@ void CGMonolith::initObj()
void CGSubterraneanGate::onHeroVisit( const CGHeroInstance * h ) const void CGSubterraneanGate::onHeroVisit( const CGHeroInstance * h ) const
{ {
TeleportDialog td(h, channel); TeleportDialog td(h, channel);
if(ETeleportChannelType::IMPASSABLE == cb->getTeleportChannelType(channel)) //no exit if(cb->isTeleportChannelImpassable(channel))
{ {
showInfoDialog(h,153,0);//Just inside the entrance you find a large pile of rubble blocking the tunnel. You leave discouraged. showInfoDialog(h,153,0);//Just inside the entrance you find a large pile of rubble blocking the tunnel. You leave discouraged.
logGlobal->debugStream() << "Cannot find exit subterranean gate for "<< id << " (obj at " << pos << ") :("; logGlobal->debugStream() << "Cannot find exit subterranean gate for "<< id << " (obj at " << pos << ") :(";
@@ -1018,7 +1015,7 @@ void CGSubterraneanGate::postInit( CGameState * gs ) //matches subterranean gate
void CGWhirlpool::onHeroVisit( const CGHeroInstance * h ) const void CGWhirlpool::onHeroVisit( const CGHeroInstance * h ) const
{ {
TeleportDialog td(h, channel); TeleportDialog td(h, channel);
if(ETeleportChannelType::IMPASSABLE == cb->getTeleportChannelType(channel)) if(cb->isTeleportChannelImpassable(channel))
{ {
logGlobal->debugStream() << "Cannot find exit whirlpool for "<< id << " (obj at " << pos << ") :("; logGlobal->debugStream() << "Cannot find exit whirlpool for "<< id << " (obj at " << pos << ") :(";
td.impassable = true; td.impassable = true;