mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Removed CGHeroInstance::convertPosition method
This commit is contained in:
parent
49cbd5adc9
commit
d85ee019ec
@ -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 = hero->convertPosition(details.start, false);
|
||||
const int3 to = hero->convertPosition(details.end, false);
|
||||
const int3 from = details.start - hero->getVisitableOffset();
|
||||
const int3 to = details.end - hero->getVisitableOffset();
|
||||
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, h->convertPosition(dst, true));
|
||||
cb->moveHero(*h, dst + h->getVisitableOffset());
|
||||
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, h->convertPosition(dst, true), transit);
|
||||
cb->moveHero(*h, dst + h->getVisitableOffset(), transit);
|
||||
};
|
||||
|
||||
auto doTeleportMovement = [&](ObjectInstanceID exitId, int3 exitPos)
|
||||
{
|
||||
destinationTeleport = exitId;
|
||||
if(exitPos.valid())
|
||||
destinationTeleportPos = h->convertPosition(exitPos, true);
|
||||
destinationTeleportPos = exitPos + h->getVisitableOffset();
|
||||
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 = h->convertPosition(h->pos, false);
|
||||
auto currentPos = h->visitablePos();
|
||||
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 == h->convertPosition(h->pos, false));
|
||||
auto currentObject = getObj(currentCoord, currentCoord == h->visitablePos());
|
||||
auto nextObjectTop = getObj(nextCoord, false);
|
||||
auto nextObject = getObj(nextCoord, true);
|
||||
auto destTeleportObj = getDestTeleportObj(currentObject, nextObjectTop, nextObject);
|
||||
|
@ -50,7 +50,7 @@ namespace Goals
|
||||
sightRadius = hero->getSightRadius();
|
||||
bestGoal = sptr(Goals::Invalid());
|
||||
bestValue = 0;
|
||||
ourPos = h->convertPosition(h->pos, false);
|
||||
ourPos = h->visitablePos();
|
||||
allowDeadEndCancellation = true;
|
||||
allowGatherArmy = gatherArmy;
|
||||
}
|
||||
|
@ -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 = hero->convertPosition(details.start, false);
|
||||
const int3 to = hero->convertPosition(details.end, false);
|
||||
const int3 from = details.start - hero->getVisitableOffset();
|
||||
const int3 to = details.end - hero->getVisitableOffset();
|
||||
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, h->convertPosition(dst, true));
|
||||
cb->moveHero(*h, dst + h->getVisitableOffset());
|
||||
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, h->convertPosition(dst, true), transit);
|
||||
cb->moveHero(*h, dst + h->getVisitableOffset(), transit);
|
||||
};
|
||||
|
||||
auto doTeleportMovement = [&](ObjectInstanceID exitId, int3 exitPos)
|
||||
{
|
||||
destinationTeleport = exitId;
|
||||
if(exitPos.valid())
|
||||
destinationTeleportPos = h->convertPosition(exitPos, true);
|
||||
destinationTeleportPos = exitPos + h->getVisitableOffset();
|
||||
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 = h->convertPosition(h->pos, false);
|
||||
auto currentPos = h->visitablePos();
|
||||
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 == h->convertPosition(h->pos, false));
|
||||
auto currentObject = getObj(currentCoord, currentCoord == h->visitablePos());
|
||||
auto nextObjectTop = getObj(nextCoord, false);
|
||||
auto nextObject = getObj(nextCoord, true);
|
||||
auto destTeleportObj = getDestTeleportObj(currentObject, nextObjectTop, nextObject);
|
||||
|
@ -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 == hero->convertPosition(details.start, false)
|
||||
&& (nodesIt - 1)->coord == hero->convertPosition(details.end, false))
|
||||
if((nodesIt)->coord == details.start - hero->getVisitableOffset()
|
||||
&& (nodesIt - 1)->coord == details.end - hero->getVisitableOffset())
|
||||
{
|
||||
//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(h->convertPosition(coord,false))->topVisitableObj(ignoreHero);
|
||||
return cb->getTile(coord - h->getVisitableOffset())->topVisitableObj(ignoreHero);
|
||||
};
|
||||
|
||||
auto isTeleportAction = [&](CGPathNode::ENodeAction action) -> bool
|
||||
@ -2445,7 +2445,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
|
||||
|
||||
{
|
||||
for (auto & elem : path.nodes)
|
||||
elem.coord = h->convertPosition(elem.coord,true);
|
||||
elem.coord = elem.coord + h->getVisitableOffset();
|
||||
|
||||
TerrainId currentTerrain = Terrain::BORDER; // not init yet
|
||||
TerrainId newTerrain;
|
||||
@ -2503,7 +2503,7 @@ void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path)
|
||||
sh = CCS->soundh->playSound(soundBase::horseFlying, -1);
|
||||
#endif
|
||||
{
|
||||
newTerrain = cb->getTile(h->convertPosition(currentCoord, false))->terType->id;
|
||||
newTerrain = cb->getTile(currentCoord - h->getVisitableOffset())->terType->id;
|
||||
if(newTerrain != currentTerrain)
|
||||
{
|
||||
CCS->soundh->stopSound(sh);
|
||||
|
@ -550,7 +550,7 @@ void TryMoveHero::applyGs(CGameState *gs)
|
||||
|
||||
if(result == EMBARK) //hero enters boat at destination tile
|
||||
{
|
||||
const TerrainTile &tt = gs->map->getTile(h->convertPosition(end, false));
|
||||
const TerrainTile &tt = gs->map->getTile(end - h->getVisitableOffset());
|
||||
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());
|
||||
|
||||
|
@ -122,14 +122,6 @@ TerrainId CGHeroInstance::getNativeTerrain() const
|
||||
return nativeTerrain;
|
||||
}
|
||||
|
||||
int3 CGHeroInstance::convertPosition(int3 src, bool toh3m) const //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
|
||||
{
|
||||
if (toh3m)
|
||||
return src + getVisitableOffset();
|
||||
else
|
||||
return src - getVisitableOffset();
|
||||
}
|
||||
|
||||
BattleField CGHeroInstance::getBattlefield() const
|
||||
{
|
||||
return BattleField::NONE;
|
||||
@ -1593,7 +1585,7 @@ void CGHeroInstance::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
if(!handler.saving)
|
||||
{
|
||||
patrol.patrolling = (rawPatrolRadius > NO_PATROLING);
|
||||
patrol.initialPos = convertPosition(pos, false);
|
||||
patrol.initialPos = pos - getVisitableOffset();
|
||||
patrol.patrolRadius = (rawPatrolRadius > NO_PATROLING) ? rawPatrolRadius : 0;
|
||||
}
|
||||
}
|
||||
|
@ -198,7 +198,6 @@ public:
|
||||
|
||||
int movementPointsAfterEmbark(int MPsBefore, int basicCost, bool disembark = false, const TurnInfo * ti = nullptr) const;
|
||||
|
||||
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
|
||||
|
@ -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, h->convertPosition(cb->getObj(exit)->visitablePos(), true)));
|
||||
td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos() + h->getVisitableOffset()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1106,7 +1106,7 @@ void CGMonolith::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer,
|
||||
else if(vstd::isValidIndex(exits, answer))
|
||||
dPos = exits[answer].second;
|
||||
else
|
||||
dPos = hero->convertPosition(cb->getObj(randomExit)->visitablePos(), true);
|
||||
dPos = cb->getObj(randomExit)->visitablePos() + hero->getVisitableOffset();
|
||||
|
||||
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, h->convertPosition(cb->getObj(exit)->visitablePos(), true)));
|
||||
td.exits.push_back(std::make_pair(exit, cb->getObj(exit)->visitablePos() + h->getVisitableOffset()));
|
||||
}
|
||||
|
||||
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, h->convertPosition(bPos, true)));
|
||||
td.exits.push_back(std::make_pair(exit, bPos + h->getVisitableOffset()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1283,7 +1283,7 @@ void CGWhirlpool::teleportDialogAnswered(const CGHeroInstance *hero, ui32 answer
|
||||
|
||||
auto obj = cb->getObj(exit);
|
||||
std::set<int3> tiles = obj->getBlockedPos();
|
||||
dPos = hero->convertPosition(*RandomGeneratorUtil::nextItem(tiles, CRandomGenerator::getDefault()), true);
|
||||
dPos = *RandomGeneratorUtil::nextItem(tiles, CRandomGenerator::getDefault()) + hero->getVisitableOffset();
|
||||
}
|
||||
|
||||
cb->moveHero(hero->id, dPos, true);
|
||||
|
@ -1664,7 +1664,7 @@ CGObjectInstance * CMapLoaderH3M::readHero(ObjectInstanceID idToBeGiven, const i
|
||||
else
|
||||
{
|
||||
nhi->patrol.patrolling = true;
|
||||
nhi->patrol.initialPos = nhi->convertPosition(initialPos, false);
|
||||
nhi->patrol.initialPos = initialPos - nhi->getVisitableOffset();
|
||||
}
|
||||
|
||||
if(map->version > EMapFormat::ROE)
|
||||
|
@ -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 = h->convertPosition(dst, false);
|
||||
const int3 hmpos = dst - h->getVisitableOffset();
|
||||
|
||||
if (!gs->map->isInTheMap(hmpos))
|
||||
{
|
||||
|
@ -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(hero->convertPosition(tmh.end, false)), hero);
|
||||
gh->visitObjectOnTile(*gh->getTile(tmh.end - hero->getVisitableOffset()), hero);
|
||||
}
|
||||
|
||||
owner->popIfTop(*this);
|
||||
|
Loading…
Reference in New Issue
Block a user