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

Fill obstacles as one operation (for undo).

However, it works only for obstacles on one type of terrain.
This commit is contained in:
Tomasz Zieliński 2022-09-06 20:51:45 +02:00
parent d790978dbb
commit 97b0fa16ae
3 changed files with 20 additions and 1 deletions

View File

@ -149,6 +149,16 @@ void CMapEditManager::insertObject(CGObjectInstance * obj)
execute(make_unique<CInsertObjectOperation>(map, obj));
}
void CMapEditManager::insertObjects(std::set<CGObjectInstance*>& objects)
{
auto composedOperation = make_unique<CComposedOperation>(map);
for (auto obj : objects)
{
composedOperation->addOperation(make_unique<CInsertObjectOperation>(map, obj));
}
execute(std::move(composedOperation));
}
void CMapEditManager::moveObject(CGObjectInstance * obj, const int3 & pos)
{
execute(make_unique<CMoveObjectOperation>(map, obj, pos));

View File

@ -78,6 +78,7 @@ public:
void drawRiver(const std::string & riverType, CRandomGenerator * gen = nullptr);
void insertObject(CGObjectInstance * obj);
void insertObjects(std::set<CGObjectInstance*>& objects);
void moveObject(CGObjectInstance * obj, const int3 & pos);
void removeObject(CGObjectInstance * obj);
void removeObjects(std::set<CGObjectInstance*>& objects);

View File

@ -143,6 +143,8 @@ void ObstacleProxy::placeObstacles(CMap * map, CRandomGenerator & rand)
//reverse order, since obstacles begin in bottom-right corner, while the map coordinates begin in top-left
auto blockedTiles = blockedArea.getTilesVector();
int tilePos = 0;
std::set<CGObjectInstance*> objs;
while(!blockedArea.empty() && tilePos < blockedArea.getTilesVector().size())
{
auto tile = blockedArea.getTilesVector()[tilePos];
@ -159,7 +161,11 @@ void ObstacleProxy::placeObstacles(CMap * map, CRandomGenerator & rand)
auto objIter = RandomGeneratorUtil::nextItem(weightedObjects, rand);
objIter->first->setPosition(objIter->second);
placeObject(map->getEditManager(), *objIter->first);
for (auto* instance : objIter->first->instances())
{
objs.insert(&instance->object());
}
blockedArea.subtract(objIter->first->getArea());
tilePos = 0;
@ -174,6 +180,8 @@ void ObstacleProxy::placeObstacles(CMap * map, CRandomGenerator & rand)
o.clear();
}
}
map->getEditManager()->insertObjects(objs); //insert as one operation - for undo purposes
}
void ObstacleProxy::postProcess(const rmg::Object & object)