1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Fix boat positioning

This commit is contained in:
Ivan Savenko 2023-06-20 23:09:11 +03:00
parent caccd58eb0
commit 44261ecc21
3 changed files with 7 additions and 4 deletions

View File

@ -384,7 +384,9 @@ struct DLL_LINKAGE ChangeObjPos : public CPackForClient
{
void applyGs(CGameState * gs);
/// Object to move
ObjectInstanceID objid;
/// New position of visitable tile of an object
int3 nPos;
virtual void visitTyped(ICPackVisitor & visitor) override;

View File

@ -1019,7 +1019,7 @@ void ChangeObjPos::applyGs(CGameState *gs)
return;
}
gs->map->removeBlockVisTiles(obj);
obj->pos = nPos;
obj->pos = nPos + obj->getVisitableOffset();
gs->map->addBlockVisTiles(obj);
}
@ -1528,7 +1528,7 @@ void NewObject::applyGs(CGameState *gs)
o->id = ObjectInstanceID(static_cast<si32>(gs->map->objects.size()));
o->ID = ID;
o->subID = subID;
o->pos = targetPos - o->getVisitableOffset();
o->pos = targetPos + o->getVisitableOffset();
gs->map->objects.emplace_back(o);
gs->map->addBlockVisTiles(o);

View File

@ -92,12 +92,13 @@ int3 IBoatGenerator::bestLocation() const
for (auto & offset : offsets)
{
const TerrainTile *tile = getObject()->cb->getTile(getObject()->visitablePos() + offset, false);
int3 targetTile = getObject()->visitablePos() + offset;
const TerrainTile *tile = getObject()->cb->getTile(targetTile, false);
if(tile) //tile is in the map
{
if(tile->terType->isWater() && (!tile->blocked || tile->blockingObjects.front()->ID == Obj::BOAT)) //and is water and is not blocked or is blocked by boat
return getObject()->getPosition() + offset;
return targetTile;
}
}
return int3 (-1,-1,-1);