1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

CGHeroInstance::convertPosition is no longer static method

This commit is contained in:
Ivan Savenko 2022-12-07 22:34:08 +02:00
parent 908e6892f3
commit 49cbd5adc9
12 changed files with 34 additions and 50 deletions

View File

@ -92,8 +92,8 @@ void AIGateway::heroMoved(const TryMoveHero & details, bool verbose)
validateObject(details.id); //enemy hero may have left visible area
auto hero = cb->getHero(details.id);
const int3 from = CGHeroInstance::convertPosition(details.start, false);
const int3 to = CGHeroInstance::convertPosition(details.end, false);
const int3 from = hero->convertPosition(details.start, false);
const int3 to = hero->convertPosition(details.end, false);
const CGObjectInstance * o1 = vstd::frontOrNull(cb->getVisitableObjs(from, verbose));
const CGObjectInstance * o2 = vstd::frontOrNull(cb->getVisitableObjs(to, verbose));
@ -1178,7 +1178,7 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h)
{
//FIXME: this assertion fails also if AI moves onto defeated guarded object
assert(cb->getVisitableObjs(dst).size() > 1); //there's no point in revisiting tile where there is no visitable object
cb->moveHero(*h, CGHeroInstance::convertPosition(dst, true));
cb->moveHero(*h, h->convertPosition(dst, true));
afterMovementCheck(); // TODO: is it feasible to hero get killed there if game work properly?
// If revisiting, teleport probing is never done, and so the entries into the list would remain unused and uncleared
teleportChannelProbingList.clear();
@ -1232,14 +1232,14 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h)
auto doMovement = [&](int3 dst, bool transit)
{
cb->moveHero(*h, CGHeroInstance::convertPosition(dst, true), transit);
cb->moveHero(*h, h->convertPosition(dst, true), transit);
};
auto doTeleportMovement = [&](ObjectInstanceID exitId, int3 exitPos)
{
destinationTeleport = exitId;
if(exitPos.valid())
destinationTeleportPos = CGHeroInstance::convertPosition(exitPos, true);
destinationTeleportPos = h->convertPosition(exitPos, true);
cb->moveHero(*h, h->pos);
destinationTeleport = ObjectInstanceID();
destinationTeleportPos = int3(-1);
@ -1248,7 +1248,7 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h)
auto doChannelProbing = [&]() -> void
{
auto currentPos = CGHeroInstance::convertPosition(h->pos, false);
auto currentPos = h->convertPosition(h->pos, false);
auto currentExit = getObj(currentPos, true)->id;
status.setChannelProbing(true);
@ -1265,7 +1265,7 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h)
int3 currentCoord = path.nodes[i].coord;
int3 nextCoord = path.nodes[i - 1].coord;
auto currentObject = getObj(currentCoord, currentCoord == CGHeroInstance::convertPosition(h->pos, false));
auto currentObject = getObj(currentCoord, currentCoord == h->convertPosition(h->pos, false));
auto nextObjectTop = getObj(nextCoord, false);
auto nextObject = getObj(nextCoord, true);
auto destTeleportObj = getDestTeleportObj(currentObject, nextObjectTop, nextObject);

View File

@ -101,8 +101,8 @@ void VCAI::heroMoved(const TryMoveHero & details, bool verbose)
validateObject(details.id); //enemy hero may have left visible area
auto hero = cb->getHero(details.id);
const int3 from = CGHeroInstance::convertPosition(details.start, false);
const int3 to = CGHeroInstance::convertPosition(details.end, false);
const int3 from = hero->convertPosition(details.start, false);
const int3 to = hero->convertPosition(details.end, false);
const CGObjectInstance * o1 = vstd::frontOrNull(cb->getVisitableObjs(from, verbose));
const CGObjectInstance * o2 = vstd::frontOrNull(cb->getVisitableObjs(to, verbose));
@ -1813,7 +1813,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
{
//FIXME: this assertion fails also if AI moves onto defeated guarded object
assert(cb->getVisitableObjs(dst).size() > 1); //there's no point in revisiting tile where there is no visitable object
cb->moveHero(*h, CGHeroInstance::convertPosition(dst, true));
cb->moveHero(*h, h->convertPosition(dst, true));
afterMovementCheck(); // TODO: is it feasible to hero get killed there if game work properly?
// If revisiting, teleport probing is never done, and so the entries into the list would remain unused and uncleared
teleportChannelProbingList.clear();
@ -1867,14 +1867,14 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
auto doMovement = [&](int3 dst, bool transit)
{
cb->moveHero(*h, CGHeroInstance::convertPosition(dst, true), transit);
cb->moveHero(*h, h->convertPosition(dst, true), transit);
};
auto doTeleportMovement = [&](ObjectInstanceID exitId, int3 exitPos)
{
destinationTeleport = exitId;
if(exitPos.valid())
destinationTeleportPos = CGHeroInstance::convertPosition(exitPos, true);
destinationTeleportPos = h->convertPosition(exitPos, true);
cb->moveHero(*h, h->pos);
destinationTeleport = ObjectInstanceID();
destinationTeleportPos = int3(-1);
@ -1883,7 +1883,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
auto doChannelProbing = [&]() -> void
{
auto currentPos = CGHeroInstance::convertPosition(h->pos, false);
auto currentPos = h->convertPosition(h->pos, false);
auto currentExit = getObj(currentPos, true)->id;
status.setChannelProbing(true);
@ -1900,7 +1900,7 @@ bool VCAI::moveHeroToTile(int3 dst, HeroPtr h)
int3 currentCoord = path.nodes[i].coord;
int3 nextCoord = path.nodes[i - 1].coord;
auto currentObject = getObj(currentCoord, currentCoord == CGHeroInstance::convertPosition(h->pos, false));
auto currentObject = getObj(currentCoord, currentCoord == h->convertPosition(h->pos, false));
auto nextObjectTop = getObj(nextCoord, false);
auto nextObject = getObj(nextCoord, true);
auto destTeleportObj = getDestTeleportObj(currentObject, nextObjectTop, nextObject);

View File

@ -264,8 +264,8 @@ void CPlayerInterface::heroMoved(const TryMoveHero & details, bool verbose)
assert(adventureInt->terrain.currentPath->nodes.size() >= 2);
std::vector<CGPathNode>::const_iterator nodesIt = adventureInt->terrain.currentPath->nodes.end() - 1;
if((nodesIt)->coord == CGHeroInstance::convertPosition(details.start, false)
&& (nodesIt - 1)->coord == CGHeroInstance::convertPosition(details.end, false))
if((nodesIt)->coord == hero->convertPosition(details.start, false)
&& (nodesIt - 1)->coord == hero->convertPosition(details.end, false))
{
//path was between entrance and exit of teleport -> OK, erase node as usual
removeLastNodeFromPath(hero);
@ -2405,7 +2405,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
int i = 1;
auto getObj = [&](int3 coord, bool ignoreHero)
{
return cb->getTile(CGHeroInstance::convertPosition(coord,false))->topVisitableObj(ignoreHero);
return cb->getTile(h->convertPosition(coord,false))->topVisitableObj(ignoreHero);
};
auto isTeleportAction = [&](CGPathNode::ENodeAction action) -> bool
@ -2444,7 +2444,9 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
};
{
path.convert(0);
for (auto & elem : path.nodes)
elem.coord = h->convertPosition(elem.coord,true);
TerrainId currentTerrain = Terrain::BORDER; // not init yet
TerrainId newTerrain;
int sh = -1;
@ -2501,7 +2503,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
sh = CCS->soundh->playSound(soundBase::horseFlying, -1);
#endif
{
newTerrain = cb->getTile(CGHeroInstance::convertPosition(currentCoord, false))->terType->id;
newTerrain = cb->getTile(h->convertPosition(currentCoord, false))->terType->id;
if(newTerrain != currentTerrain)
{
CCS->soundh->stopSound(sh);

View File

@ -1282,17 +1282,6 @@ int3 CGPath::endPos() const
return nodes[0].coord;
}
void CGPath::convert(ui8 mode)
{
if(mode==0)
{
for(auto & elem : nodes)
{
elem.coord = CGHeroInstance::convertPosition(elem.coord,true);
}
}
}
CPathsInfo::CPathsInfo(const int3 & Sizes, const CGHeroInstance * hero_)
: sizes(Sizes), hero(hero_)
{

View File

@ -170,7 +170,6 @@ struct DLL_LINKAGE CGPath
int3 startPos() const; // start point
int3 endPos() const; //destination point
void convert(ui8 mode); //mode=0 -> from 'manifest' to 'object'
};
struct DLL_LINKAGE CPathsInfo

View File

@ -550,7 +550,7 @@ void TryMoveHero::applyGs(CGameState *gs)
if(result == EMBARK) //hero enters boat at destination tile
{
const TerrainTile &tt = gs->map->getTile(CGHeroInstance::convertPosition(end, false));
const TerrainTile &tt = gs->map->getTile(h->convertPosition(end, false));
assert(tt.visitableObjects.size() >= 1 && tt.visitableObjects.back()->ID == Obj::BOAT); //the only visitable object at destination is Boat
CGBoat *boat = static_cast<CGBoat*>(tt.visitableObjects.back());

View File

@ -122,18 +122,12 @@ TerrainId CGHeroInstance::getNativeTerrain() const
return nativeTerrain;
}
int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) const //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
{
if (toh3m)
{
src.x+=1;
return src;
}
return src + getVisitableOffset();
else
{
src.x-=1;
return src;
}
return src - getVisitableOffset();
}
BattleField CGHeroInstance::getBattlefield() const

View File

@ -198,7 +198,7 @@ public:
int movementPointsAfterEmbark(int MPsBefore, int basicCost, bool disembark = false, const TurnInfo * ti = nullptr) const;
static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
int3 convertPosition(int3 src, bool toh3m) const; //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
double getFightingStrength() const; // takes attack / defense skill into account
double getMagicStrength() const; // takes knowledge / spell power skill into account
double getHeroStrength() const; // includes fighting and magic strength

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, CGHeroInstance::convertPosition(cb->getObj(exit)->visitablePos(), true)));
td.exits.push_back(std::make_pair(exit, h->convertPosition(cb->getObj(exit)->visitablePos(), true)));
}
}
@ -1106,7 +1106,7 @@ void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer,
else if(vstd::isValidIndex(exits, answer))
dPos = exits[answer].second;
else
dPos = CGHeroInstance::convertPosition(cb->getObj(randomExit)->visitablePos(), true);
dPos = hero->convertPosition(cb->getObj(randomExit)->visitablePos(), true);
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, CGHeroInstance::convertPosition(cb->getObj(exit)->visitablePos(), true)));
td.exits.push_back(std::make_pair(exit, h->convertPosition(cb->getObj(exit)->visitablePos(), true)));
}
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, CGHeroInstance::convertPosition(bPos, true)));
td.exits.push_back(std::make_pair(exit, h->convertPosition(bPos, true)));
}
}
@ -1283,7 +1283,7 @@ void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer
auto obj = cb->getObj(exit);
std::set<int3> tiles = obj->getBlockedPos();
dPos = CGHeroInstance::convertPosition(*RandomGeneratorUtil::nextItem(tiles, CRandomGenerator::getDefault()), true);
dPos = hero->convertPosition(*RandomGeneratorUtil::nextItem(tiles, CRandomGenerator::getDefault()), true);
}
cb->moveHero(hero->id, dPos, true);

View File

@ -1664,7 +1664,7 @@ CGObjectInstance * CMapLoaderH3M::readHero(ObjectInstanceID idToBeGiven, const i
else
{
nhi->patrol.patrolling = true;
nhi->patrol.initialPos = CGHeroInstance::convertPosition(initialPos, false);
nhi->patrol.initialPos = nhi->convertPosition(initialPos, false);
}
if(map->version > EMapFormat::ROE)

View File

@ -2326,7 +2326,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, ui8 teleporting, boo
}
logGlobal->trace("Player %d (%s) wants to move hero %d from %s to %s", asker, asker.getStr(), hid.getNum(), h->pos.toString(), dst.toString());
const int3 hmpos = CGHeroInstance::convertPosition(dst, false);
const int3 hmpos = h->convertPosition(dst, false);
if (!gs->map->isInTheMap(hmpos))
{

View File

@ -489,7 +489,7 @@ void CHeroMovementQuery::onExposure(QueryPtr topQuery)
logGlobal->trace("Hero %s after victory over guard finishes visit to %s", hero->name, tmh.end.toString());
//finish movement
visitDestAfterVictory = false;
gh->visitObjectOnTile(*gh->getTile(CGHeroInstance::convertPosition(tmh.end, false)), hero);
gh->visitObjectOnTile(*gh->getTile(hero->convertPosition(tmh.end, false)), hero);
}
owner->popIfTop(*this);