1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-12-20 00:22:54 +02:00

Proof of concept with OH3 obstacles

This commit is contained in:
Tomasz Zieliński
2024-04-04 21:39:01 +02:00
parent c2f160326c
commit b1a5693612
10 changed files with 514 additions and 1 deletions

View File

@@ -34,6 +34,7 @@
#include "../mapObjects/MiscObjects.h"
#include "../mapObjects/CGHeroInstance.h"
#include "../mapObjects/CGTownInstance.h"
#include "../mapObjects/ObstacleSetHandler.h"
#include "../modding/IdentifierStorage.h"
#include "../modding/CModHandler.h"
#include "../modding/ModScope.h"
@@ -107,6 +108,8 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
auto totalNumber = static_cast<size_t>(parser.readNumber()); // first line contains number of objects to read and nothing else
parser.endLine();
std::map<TerrainId, std::map<MapObjectID, std::map<MapObjectSubID, ObstacleSet>>> obstacleSets;
for (size_t i = 0; i < totalNumber; i++)
{
auto tmpl = std::make_shared<ObjectTemplate>();
@@ -116,8 +119,45 @@ std::vector<JsonNode> CObjectClassesHandler::loadLegacyData()
std::pair key(tmpl->id, tmpl->subid);
legacyTemplates.insert(std::make_pair(key, tmpl));
// Populate ObstacleSetHandler on our way
if (!tmpl->isVisitable())
{
// Create obstacle sets. Group by terrain for now
for (auto terrain : tmpl->getAllowedTerrains())
{
auto &obstacleMap = obstacleSets[terrain][tmpl->id];
auto it = obstacleMap.find(tmpl->subid);
if (it == obstacleMap.end())
{
// FIXME: This means this set will be available only on one terrain
auto type = VLC->biomeHandler->convertObstacleClass(tmpl->id);
auto newIt = obstacleMap.insert(std::make_pair(tmpl->subid, ObstacleSet(type, terrain)));
newIt.first->second.addObstacle(tmpl);
}
else
{
it->second.addObstacle(tmpl);
}
}
}
}
size_t count = 0;
for (auto terrain : obstacleSets)
{
for (auto obstacleType : terrain.second)
{
for (auto obstacleSet : obstacleType.second)
{
VLC->biomeHandler->addObstacleSet(obstacleSet.second);
count++;
}
}
}
logGlobal->info("Obstacle sets loaded: %d", count);
objects.resize(256);
std::vector<JsonNode> ret(dataSize);// create storage for 256 objects