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

Replaced most of accesses to CGObjectInstance::pos with anchorPoint()

This commit is contained in:
Ivan Savenko
2024-10-02 16:40:06 +00:00
parent 7694e2da4b
commit a8f8c3f4b1
40 changed files with 142 additions and 150 deletions

View File

@ -232,22 +232,22 @@ CMap::~CMap()
void CMap::removeBlockVisTiles(CGObjectInstance * obj, bool total)
{
const int zVal = obj->pos.z;
const int zVal = obj->anchorPos().z;
for(int fx = 0; fx < obj->getWidth(); ++fx)
{
int xVal = obj->pos.x - fx;
int xVal = obj->anchorPos().x - fx;
for(int fy = 0; fy < obj->getHeight(); ++fy)
{
int yVal = obj->pos.y - fy;
int yVal = obj->anchorPos().y - fy;
if(xVal>=0 && xVal < width && yVal>=0 && yVal < height)
{
TerrainTile & curt = terrain[zVal][xVal][yVal];
if(total || obj->visitableAt(xVal, yVal))
if(total || obj->visitableAt(int3(xVal, yVal, zVal)))
{
curt.visitableObjects -= obj;
curt.visitable = curt.visitableObjects.size();
}
if(total || obj->blockingAt(xVal, yVal))
if(total || obj->blockingAt(int3(xVal, yVal, zVal)))
{
curt.blockingObjects -= obj;
curt.blocked = curt.blockingObjects.size();
@ -259,22 +259,22 @@ void CMap::removeBlockVisTiles(CGObjectInstance * obj, bool total)
void CMap::addBlockVisTiles(CGObjectInstance * obj)
{
const int zVal = obj->pos.z;
const int zVal = obj->anchorPos().z;
for(int fx = 0; fx < obj->getWidth(); ++fx)
{
int xVal = obj->pos.x - fx;
int xVal = obj->anchorPos().x - fx;
for(int fy = 0; fy < obj->getHeight(); ++fy)
{
int yVal = obj->pos.y - fy;
int yVal = obj->anchorPos().y - fy;
if(xVal>=0 && xVal < width && yVal >= 0 && yVal < height)
{
TerrainTile & curt = terrain[zVal][xVal][yVal];
if(obj->visitableAt(xVal, yVal))
if(obj->visitableAt(int3(xVal, yVal, zVal)))
{
curt.visitableObjects.push_back(obj);
curt.visitable = true;
}
if(obj->blockingAt(xVal, yVal))
if(obj->blockingAt(int3(xVal, yVal, zVal)))
{
curt.blockingObjects.push_back(obj);
curt.blocked = true;
@ -444,14 +444,14 @@ const CGObjectInstance * CMap::getObjectiveObjectFrom(const int3 & pos, Obj type
bestMatch = object;
else
{
if (object->pos.dist2dSQ(pos) < bestMatch->pos.dist2dSQ(pos))
if (object->anchorPos().dist2dSQ(pos) < bestMatch->anchorPos().dist2dSQ(pos))
bestMatch = object;// closer than one we already found
}
}
}
assert(bestMatch != nullptr); // if this happens - victory conditions or map itself is very, very broken
logGlobal->error("Will use %s from %s", bestMatch->getObjectName(), bestMatch->pos.toString());
logGlobal->error("Will use %s from %s", bestMatch->getObjectName(), bestMatch->anchorPos().toString());
return bestMatch;
}
@ -635,7 +635,7 @@ void CMap::addNewObject(CGObjectInstance * obj)
void CMap::moveObject(CGObjectInstance * obj, const int3 & pos)
{
removeBlockVisTiles(obj);
obj->pos = pos;
obj->setAnchorPos(pos);
addBlockVisTiles(obj);
}
@ -803,7 +803,7 @@ void CMap::reindexObjects()
if (lhs->isRemovable() && !rhs->isRemovable())
return false;
return lhs->pos.y < rhs->pos.y;
return lhs->anchorPos().y < rhs->anchorPos().y;
});
// instanceNames don't change