1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Working fir for Corpse issue:

- Do not place guard next to blockVis object, if possible
- Do not place two blockVis objects next to each other
This commit is contained in:
Tomasz Zieliński
2023-12-06 20:49:28 +01:00
parent 03fa75c51e
commit 6cd19b81dd
11 changed files with 149 additions and 28 deletions

View File

@@ -153,6 +153,11 @@ bool Object::Instance::isBlockedVisitable() const
return dObject.isBlockedVisitable();
}
bool Object::Instance::isRemovable() const
{
return dObject.isRemovable();
}
CGObjectInstance & Object::Instance::object()
{
return dObject;
@@ -269,21 +274,52 @@ const rmg::Area & Object::getBlockVisitableArea() const
{
if(dInstances.empty())
return dBlockVisitableCache;
for(auto i = dInstances.begin(); i != std::prev(dInstances.end()); ++i)
for(const auto i : dInstances)
{
// FIXME: Account for blockvis objects with multiple visitable tiles
if (i->isBlockedVisitable())
dAccessibleAreaCache.add(i->getVisitablePosition());
if (i.isBlockedVisitable())
dBlockVisitableCache.add(i.getVisitablePosition());
}
return dBlockVisitableCache;
}
const rmg::Area & Object::getRemovableArea() const
{
if(dInstances.empty())
return dRemovableAreaCache;
for(const auto i : dInstances)
{
if (i.isRemovable())
dRemovableAreaCache.unite(i.getBlockedArea());
}
return dRemovableAreaCache;
}
const rmg::Area Object::getEntrableArea() const
{
// Calculate Area that hero can freely pass
// Do not use blockVisitTiles, unless they belong to removable objects (resources etc.)
// area = accessibleArea - (blockVisitableArea - removableArea)
rmg::Area entrableArea = getAccessibleArea();
rmg::Area blockVisitableArea = getBlockVisitableArea();
blockVisitableArea.subtract(getRemovableArea());
entrableArea.subtract(blockVisitableArea);
return entrableArea;
}
void Object::setPosition(const int3 & position)
{
dAccessibleAreaCache.translate(position - dPosition);
dAccessibleAreaFullCache.translate(position - dPosition);
dBlockVisitableCache.translate(position - dPosition);
dRemovableAreaCache.translate(position - dPosition);
dFullAreaCache.translate(position - dPosition);
dPosition = position;
@@ -390,6 +426,7 @@ void Object::clearCachedArea() const
dAccessibleAreaCache.clear();
dAccessibleAreaFullCache.clear();
dBlockVisitableCache.clear();
dRemovableAreaCache.clear();
}
void Object::clear()