1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Added convertToVisitablePos/convertFromVisitablePos to CGHeroInstance

This method replaces old convertPosition, but with more clear names and
without hardcoded magic constants.
This commit is contained in:
Ivan Savenko
2022-12-09 14:42:47 +02:00
parent 3e691d9033
commit 25bceda4ea
12 changed files with 47 additions and 36 deletions

View File

@ -1074,7 +1074,7 @@ void CGMonolith::onHeroVisit( const CGHeroInstance * h ) const
auto exits = cb->getTeleportChannelExits(channel);
for(auto exit : exits)
{
td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos() + h->getVisitableOffset()));
td.exits.push_back(std::make_pair(exit, h->convertFromVisitablePos(cb->getObj(exit)->visitablePos())));
}
}
@ -1106,7 +1106,7 @@ void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer,
else if(vstd::isValidIndex(exits, answer))
dPos = exits[answer].second;
else
dPos = cb->getObj(randomExit)->visitablePos() + hero->getVisitableOffset();
dPos = hero->convertFromVisitablePos(cb->getObj(randomExit)->visitablePos());
cb->moveHero(hero->id, dPos, true);
}
@ -1150,7 +1150,7 @@ void CGSubterraneanGate::onHeroVisit( const CGHeroInstance * h ) const
else
{
auto exit = getRandomExit(h);
td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos() + h->getVisitableOffset()));
td.exits.push_back(std::make_pair(exit, h->convertFromVisitablePos(cb->getObj(exit)->visitablePos())));
}
cb->showTeleportDialog(&td);
@ -1259,7 +1259,7 @@ void CGWhirlpool::onHeroVisit( const CGHeroInstance * h ) const
{
auto blockedPosList = cb->getObj(exit)->getBlockedPos();
for(auto bPos : blockedPosList)
td.exits.push_back(std::make_pair(exit, bPos + h->getVisitableOffset()));
td.exits.push_back(std::make_pair(exit, h->convertFromVisitablePos(bPos)));
}
}
@ -1283,7 +1283,7 @@ void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer
auto obj = cb->getObj(exit);
std::set<int3> tiles = obj->getBlockedPos();
dPos = *RandomGeneratorUtil::nextItem(tiles, CRandomGenerator::getDefault()) + hero->getVisitableOffset();
dPos = hero->convertFromVisitablePos(*RandomGeneratorUtil::nextItem(tiles, CRandomGenerator::getDefault()));
}
cb->moveHero(hero->id, dPos, true);