|
@@ -19,6 +19,7 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|
|
//("allowedTerrain"\s*:\s*\[.*)9(.*\],\n)
|
|
|
//\1"rock"\2
|
|
|
|
|
|
+/*
|
|
|
TerrainTypeHandler::TerrainTypeHandler()
|
|
|
{
|
|
|
auto allConfigs = VLC->modh->getActiveMods();
|
|
@@ -29,377 +30,168 @@ TerrainTypeHandler::TerrainTypeHandler()
|
|
|
initRoads(allConfigs);
|
|
|
recreateRoadMaps();
|
|
|
initTerrains(allConfigs); //maps will be populated inside
|
|
|
-}
|
|
|
+}*/
|
|
|
|
|
|
-void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfigs)
|
|
|
+TerrainType * TerrainTypeHandler::loadFromJson( const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
|
|
|
{
|
|
|
- std::vector<std::function<void()>> resolveLater;
|
|
|
+ TerrainType * info = new TerrainType;
|
|
|
|
|
|
- objects.resize(Terrain::ORIGINAL_TERRAIN_COUNT); //make space for original terrains
|
|
|
+ info->id = TerrainId(index);
|
|
|
|
|
|
- for(auto & mod : allConfigs)
|
|
|
- {
|
|
|
- if(!CResourceHandler::get(mod)->existsResource(ResourceID("config/terrains.json")))
|
|
|
- continue;
|
|
|
-
|
|
|
- JsonNode terrs(mod, ResourceID("config/terrains.json"));
|
|
|
- for(auto & terr : terrs.Struct())
|
|
|
- {
|
|
|
- TerrainType info(terr.first); //set name
|
|
|
-
|
|
|
- info.moveCost = static_cast<int>(terr.second["moveCost"].Integer());
|
|
|
- const JsonVector &unblockedVec = terr.second["minimapUnblocked"].Vector();
|
|
|
- info.minimapUnblocked =
|
|
|
- {
|
|
|
- ui8(unblockedVec[0].Float()),
|
|
|
- ui8(unblockedVec[1].Float()),
|
|
|
- ui8(unblockedVec[2].Float())
|
|
|
- };
|
|
|
-
|
|
|
- const JsonVector &blockedVec = terr.second["minimapBlocked"].Vector();
|
|
|
- info.minimapBlocked =
|
|
|
- {
|
|
|
- ui8(blockedVec[0].Float()),
|
|
|
- ui8(blockedVec[1].Float()),
|
|
|
- ui8(blockedVec[2].Float())
|
|
|
- };
|
|
|
- info.musicFilename = terr.second["music"].String();
|
|
|
- info.tilesFilename = terr.second["tiles"].String();
|
|
|
-
|
|
|
- if(terr.second["type"].isNull())
|
|
|
- {
|
|
|
- info.passabilityType = TerrainType::PassabilityType::LAND | TerrainType::PassabilityType::SURFACE;
|
|
|
- }
|
|
|
- else if (terr.second["type"].getType() == JsonNode::JsonType::DATA_VECTOR)
|
|
|
- {
|
|
|
- for(const auto& node : terr.second["type"].Vector())
|
|
|
- {
|
|
|
- //Set bits
|
|
|
- auto s = node.String();
|
|
|
- if (s == "LAND") info.passabilityType |= TerrainType::PassabilityType::LAND;
|
|
|
- if (s == "WATER") info.passabilityType |= TerrainType::PassabilityType::WATER;
|
|
|
- if (s == "ROCK") info.passabilityType |= TerrainType::PassabilityType::ROCK;
|
|
|
- if (s == "SURFACE") info.passabilityType |= TerrainType::PassabilityType::SURFACE;
|
|
|
- if (s == "SUB") info.passabilityType |= TerrainType::PassabilityType::SUBTERRANEAN;
|
|
|
- }
|
|
|
- }
|
|
|
- else //should be string - one option only
|
|
|
- {
|
|
|
- auto s = terr.second["type"].String();
|
|
|
- if (s == "LAND") info.passabilityType = TerrainType::PassabilityType::LAND;
|
|
|
- if (s == "WATER") info.passabilityType = TerrainType::PassabilityType::WATER;
|
|
|
- if (s == "ROCK") info.passabilityType = TerrainType::PassabilityType::ROCK;
|
|
|
- if (s == "SURFACE") info.passabilityType = TerrainType::PassabilityType::SURFACE;
|
|
|
- if (s == "SUB") info.passabilityType = TerrainType::PassabilityType::SUBTERRANEAN;
|
|
|
- }
|
|
|
-
|
|
|
- if(terr.second["river"].isNull())
|
|
|
- {
|
|
|
- info.river = River::NO_RIVER;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- info.river = getRiverByCode(terr.second["river"].String())->id;
|
|
|
- }
|
|
|
-
|
|
|
- if(terr.second["horseSoundId"].isNull())
|
|
|
- {
|
|
|
- info.horseSoundId = Terrain::ROCK; //rock sound as default
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- info.horseSoundId = static_cast<int>(terr.second["horseSoundId"].Float());
|
|
|
- }
|
|
|
-
|
|
|
- if(!terr.second["text"].isNull())
|
|
|
- {
|
|
|
- info.terrainText = terr.second["text"].String();
|
|
|
- }
|
|
|
-
|
|
|
- if(terr.second["code"].isNull())
|
|
|
- {
|
|
|
- info.typeCode = terr.first.substr(0, 2);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- info.typeCode = terr.second["code"].String();
|
|
|
- assert(info.typeCode.length() == 2);
|
|
|
- }
|
|
|
-
|
|
|
- if(!terr.second["battleFields"].isNull())
|
|
|
- {
|
|
|
- for(auto & t : terr.second["battleFields"].Vector())
|
|
|
- {
|
|
|
- info.battleFields.emplace_back(t.String());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- info.transitionRequired = false;
|
|
|
- if(!terr.second["transitionRequired"].isNull())
|
|
|
- {
|
|
|
- info.transitionRequired = terr.second["transitionRequired"].Bool();
|
|
|
- }
|
|
|
-
|
|
|
- info.terrainViewPatterns = "normal";
|
|
|
- if(!terr.second["terrainViewPatterns"].isNull())
|
|
|
- {
|
|
|
- info.terrainViewPatterns = terr.second["terrainViewPatterns"].String();
|
|
|
- }
|
|
|
-
|
|
|
- if(!terr.second["originalTerrainId"].isNull())
|
|
|
- {
|
|
|
- //place in reserved slot
|
|
|
- info.id = (TerrainId)(terr.second["originalTerrainId"].Float());
|
|
|
- objects[info.id] = info;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- //append at the end
|
|
|
- info.id = static_cast<TerrainId>(objects.size());
|
|
|
- objects.push_back(info);
|
|
|
- }
|
|
|
- TerrainId id = info.id;
|
|
|
-
|
|
|
- //Update terrain with this id in the future, after all terrain types are populated
|
|
|
-
|
|
|
- if(!terr.second["prohibitTransitions"].isNull())
|
|
|
- {
|
|
|
- for(auto & t : terr.second["prohibitTransitions"].Vector())
|
|
|
- {
|
|
|
- std::string prohibitedTerrainName = t.String();
|
|
|
- resolveLater.push_back([this, prohibitedTerrainName, id]()
|
|
|
- {
|
|
|
- //FIXME: is that reference to the element in vector?
|
|
|
- objects[id].prohibitTransitions.emplace_back(getInfoByName(prohibitedTerrainName)->id);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(terr.second["rockTerrain"].isNull())
|
|
|
- {
|
|
|
- objects[id].rockTerrain = Terrain::ROCK;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- auto rockTerrainName = terr.second["rockTerrain"].String();
|
|
|
- resolveLater.push_back([this, rockTerrainName, id]()
|
|
|
- {
|
|
|
- //FIXME: is that reference to the element in vector?
|
|
|
- objects[id].rockTerrain = getInfoByName(rockTerrainName)->id;
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ info->moveCost = static_cast<int>(json["moveCost"].Integer());
|
|
|
+ info->musicFilename = json["music"].String();
|
|
|
+ info->tilesFilename = json["tiles"].String();
|
|
|
+ info->horseSoundId = static_cast<int>(json["horseSoundId"].Float());
|
|
|
+ info->transitionRequired = json["transitionRequired"].Bool();
|
|
|
+ info->terrainViewPatterns = json["terrainViewPatterns"].String();
|
|
|
+ info->terrainText = json["text"].String();
|
|
|
|
|
|
- for(size_t i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ORIGINAL_TERRAIN_COUNT; i++)
|
|
|
+ const JsonVector & unblockedVec = json["minimapUnblocked"].Vector();
|
|
|
+ info->minimapUnblocked =
|
|
|
{
|
|
|
- //Make sure that original terrains are loaded
|
|
|
- assert(objects[i].id != Terrain::WRONG);
|
|
|
- }
|
|
|
+ ui8(unblockedVec[0].Float()),
|
|
|
+ ui8(unblockedVec[1].Float()),
|
|
|
+ ui8(unblockedVec[2].Float())
|
|
|
+ };
|
|
|
|
|
|
- recreateTerrainMaps();
|
|
|
+ const JsonVector &blockedVec = json["minimapBlocked"].Vector();
|
|
|
+ info->minimapBlocked =
|
|
|
+ {
|
|
|
+ ui8(blockedVec[0].Float()),
|
|
|
+ ui8(blockedVec[1].Float()),
|
|
|
+ ui8(blockedVec[2].Float())
|
|
|
+ };
|
|
|
|
|
|
- for(auto& functor : resolveLater)
|
|
|
+ for(const auto& node : json["type"].Vector())
|
|
|
{
|
|
|
- functor();
|
|
|
+ //Set bits
|
|
|
+ auto s = node.String();
|
|
|
+ if (s == "LAND") info->passabilityType |= TerrainType::PassabilityType::LAND;
|
|
|
+ if (s == "WATER") info->passabilityType |= TerrainType::PassabilityType::WATER;
|
|
|
+ if (s == "ROCK") info->passabilityType |= TerrainType::PassabilityType::ROCK;
|
|
|
+ if (s == "SURFACE") info->passabilityType |= TerrainType::PassabilityType::SURFACE;
|
|
|
+ if (s == "SUB") info->passabilityType |= TerrainType::PassabilityType::SUBTERRANEAN;
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
-void TerrainTypeHandler::initRivers(const std::vector<std::string> & allConfigs)
|
|
|
-{
|
|
|
- riverTypes.resize(River::ORIGINAL_RIVER_COUNT); //make space for original rivers
|
|
|
- //First object will be default NO_RIVER
|
|
|
+// if(json["river"].isNull())
|
|
|
+// info->river = River::NO_RIVER;
|
|
|
+// else
|
|
|
+// info->river = getRiverByCode(json["river"].String())->id;
|
|
|
|
|
|
- for(auto & mod : allConfigs)
|
|
|
- {
|
|
|
- if (!CResourceHandler::get(mod)->existsResource(ResourceID("config/rivers.json")))
|
|
|
- continue;
|
|
|
+ info->typeCode = json["code"].String();
|
|
|
+ assert(info->typeCode.length() == 2);
|
|
|
|
|
|
- JsonNode rivs(mod, ResourceID("config/rivers.json"));
|
|
|
- for(auto & river : rivs.Struct())
|
|
|
- {
|
|
|
- RiverType info;
|
|
|
-
|
|
|
- info.name = river.first;
|
|
|
- info.fileName = river.second["animation"].String();
|
|
|
- info.code = river.second["code"].String();
|
|
|
- info.deltaName = river.second["delta"].String();
|
|
|
-
|
|
|
- if (!river.second["originalRiverId"].isNull())
|
|
|
- {
|
|
|
- info.id = static_cast<RiverId>(river.second["originalRiverId"].Float());
|
|
|
- riverTypes[info.id] = info;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- info.id = static_cast<RiverId>(riverTypes.size());
|
|
|
- riverTypes.push_back(info);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ for(auto & t : json["battleFields"].Vector())
|
|
|
+ info->battleFields.emplace_back(t.String());
|
|
|
|
|
|
- recreateRiverMaps();
|
|
|
-}
|
|
|
|
|
|
-void TerrainTypeHandler::initRoads(const std::vector<std::string> & allConfigs)
|
|
|
-{
|
|
|
- roadTypes.resize(Road::ORIGINAL_ROAD_COUNT); //make space for original rivers
|
|
|
- //first object will be default NO_ROAD
|
|
|
+ //Update terrain with this id in the future, after all terrain types are populated
|
|
|
|
|
|
- for(auto & mod : allConfigs)
|
|
|
+ for(auto & t : json["prohibitTransitions"].Vector())
|
|
|
{
|
|
|
- if (!CResourceHandler::get(mod)->existsResource(ResourceID("config/roads.json")))
|
|
|
- continue;
|
|
|
-
|
|
|
- JsonNode rds(mod, ResourceID("config/roads.json"));
|
|
|
- for(auto & road : rds.Struct())
|
|
|
+ VLC->modh->identifiers.requestIdentifier("terrain", t, [info](int32_t identifier)
|
|
|
{
|
|
|
- RoadType info;
|
|
|
-
|
|
|
- info.name = road.first;
|
|
|
- info.fileName = road.second["animation"].String();
|
|
|
- info.code = road.second["code"].String();
|
|
|
- info.movementCost = static_cast<ui8>(road.second["moveCost"].Float());
|
|
|
-
|
|
|
- if (!road.second["originalRoadId"].isNull())
|
|
|
- {
|
|
|
- info.id = static_cast<RoadId>(road.second["originalRoadId"].Float());
|
|
|
- roadTypes[info.id] = info;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- info.id = static_cast<RoadId>(roadTypes.size());
|
|
|
- roadTypes.push_back(info);
|
|
|
- }
|
|
|
- }
|
|
|
+ info->prohibitTransitions.push_back(TerrainId(identifier));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- recreateRoadMaps();
|
|
|
-}
|
|
|
-
|
|
|
-void TerrainTypeHandler::recreateTerrainMaps()
|
|
|
-{
|
|
|
- //This assumes the vector will never be updated or reallocated in the future
|
|
|
+ info->rockTerrain = TerrainId::ROCK;
|
|
|
|
|
|
- for(size_t i = 0; i < objects.size(); i++)
|
|
|
+ if(!json["rockTerrain"].isNull())
|
|
|
{
|
|
|
- const auto * terrainInfo = &objects[i];
|
|
|
-
|
|
|
- terrainInfoByName[terrainInfo->name] = terrainInfo;
|
|
|
- terrainInfoByCode[terrainInfo->typeCode] = terrainInfo;
|
|
|
- terrainInfoById[terrainInfo->id] = terrainInfo;
|
|
|
+ auto rockTerrainName = json["rockTerrain"].String();
|
|
|
+ VLC->modh->identifiers.requestIdentifier("terrain", rockTerrainName, [info](int32_t identifier)
|
|
|
+ {
|
|
|
+ info->rockTerrain = TerrainId(identifier);
|
|
|
+ });
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-void TerrainTypeHandler::recreateRiverMaps()
|
|
|
-{
|
|
|
- for(size_t i = River::FIRST_REGULAR_RIVER ; i < riverTypes.size(); i++)
|
|
|
- {
|
|
|
- const auto * riverInfo = &riverTypes[i];
|
|
|
|
|
|
- riverInfoByName[riverInfo->name] = riverInfo;
|
|
|
- riverInfoByCode[riverInfo->code] = riverInfo;
|
|
|
- riverInfoById[riverInfo->id] = riverInfo;
|
|
|
- }
|
|
|
+ return info;
|
|
|
}
|
|
|
|
|
|
-void TerrainTypeHandler::recreateRoadMaps()
|
|
|
+const std::vector<std::string> & TerrainTypeHandler::getTypeNames() const
|
|
|
{
|
|
|
- for(size_t i = Road::FIRST_REGULAR_ROAD ; i < roadTypes.size(); i++)
|
|
|
- {
|
|
|
- const auto * roadInfo = &roadTypes[i];
|
|
|
-
|
|
|
- roadInfoByName[roadInfo->name] = roadInfo;
|
|
|
- roadInfoByCode[roadInfo->code] = roadInfo;
|
|
|
- roadInfoById[roadInfo->id] = roadInfo;
|
|
|
- }
|
|
|
+ static const std::vector<std::string> typeNames = { "terrain" };
|
|
|
+ return typeNames;
|
|
|
}
|
|
|
|
|
|
-const std::vector<TerrainType> & TerrainTypeHandler::terrains() const
|
|
|
+std::vector<JsonNode> TerrainTypeHandler::loadLegacyData(size_t dataSize)
|
|
|
{
|
|
|
- //FIXME: somehow make it non-copyable? Pointers must point to original data and not its copy
|
|
|
- return objects;
|
|
|
+ return {};
|
|
|
}
|
|
|
|
|
|
-const std::vector<RiverType>& TerrainTypeHandler::rivers() const
|
|
|
+std::vector<bool> TerrainTypeHandler::getDefaultAllowed() const
|
|
|
{
|
|
|
- return riverTypes;
|
|
|
+ return {};
|
|
|
}
|
|
|
|
|
|
-const std::vector<RoadType>& TerrainTypeHandler::roads() const
|
|
|
+RiverType * RiverTypeHandler::loadFromJson(
|
|
|
+ const std::string & scope,
|
|
|
+ const JsonNode & json,
|
|
|
+ const std::string & identifier,
|
|
|
+ size_t index)
|
|
|
{
|
|
|
- return roadTypes;
|
|
|
-}
|
|
|
+ RiverType * info = new RiverType;
|
|
|
|
|
|
-const TerrainType* TerrainTypeHandler::getInfoByName(const std::string& terrainName) const
|
|
|
-{
|
|
|
- return terrainInfoByName.at(terrainName);
|
|
|
-}
|
|
|
+ info->fileName = json["animation"].String();
|
|
|
+ info->code = json["code"].String();
|
|
|
+ info->deltaName = json["delta"].String();
|
|
|
|
|
|
-const TerrainType* TerrainTypeHandler::getInfoByCode(const std::string& terrainCode) const
|
|
|
-{
|
|
|
- return terrainInfoByCode.at(terrainCode);
|
|
|
+ return info;
|
|
|
}
|
|
|
|
|
|
-const TerrainType* TerrainTypeHandler::getInfoById(TerrainId id) const
|
|
|
+const std::vector<std::string> & RiverTypeHandler::getTypeNames() const
|
|
|
{
|
|
|
- return terrainInfoById.at(id);
|
|
|
+ static const std::vector<std::string> typeNames = { "river" };
|
|
|
+ return typeNames;
|
|
|
}
|
|
|
|
|
|
-const RiverType* TerrainTypeHandler::getRiverByName(const std::string& riverName) const
|
|
|
+std::vector<JsonNode> RiverTypeHandler::loadLegacyData(size_t dataSize)
|
|
|
{
|
|
|
- return riverInfoByName.at(riverName);
|
|
|
+ return {};
|
|
|
}
|
|
|
|
|
|
-const RiverType* TerrainTypeHandler::getRiverByCode(const std::string& riverCode) const
|
|
|
+std::vector<bool> RiverTypeHandler::getDefaultAllowed() const
|
|
|
{
|
|
|
- return riverInfoByCode.at(riverCode);
|
|
|
+ return {};
|
|
|
}
|
|
|
|
|
|
-const RiverType* TerrainTypeHandler::getRiverById(RiverId id) const
|
|
|
+RoadType * RoadTypeHandler::loadFromJson(
|
|
|
+ const std::string & scope,
|
|
|
+ const JsonNode & json,
|
|
|
+ const std::string & identifier,
|
|
|
+ size_t index)
|
|
|
{
|
|
|
- return riverInfoById.at(id);
|
|
|
-}
|
|
|
+ RoadType * info = new RoadType;
|
|
|
|
|
|
-const RoadType* TerrainTypeHandler::getRoadByName(const std::string& roadName) const
|
|
|
-{
|
|
|
- return roadInfoByName.at(roadName);
|
|
|
+ info->fileName = json["animation"].String();
|
|
|
+ info->code = json["code"].String();
|
|
|
+ info->movementCost = json["moveCost"].Integer();
|
|
|
+
|
|
|
+ return info;
|
|
|
}
|
|
|
|
|
|
-const RoadType* TerrainTypeHandler::getRoadByCode(const std::string& roadCode) const
|
|
|
+const std::vector<std::string> & RoadTypeHandler::getTypeNames() const
|
|
|
{
|
|
|
- return roadInfoByCode.at(roadCode);
|
|
|
+ static const std::vector<std::string> typeNames = { "river" };
|
|
|
+ return typeNames;
|
|
|
}
|
|
|
|
|
|
-const RoadType* TerrainTypeHandler::getRoadById(RoadId id) const
|
|
|
+std::vector<JsonNode> RoadTypeHandler::loadLegacyData(size_t dataSize)
|
|
|
{
|
|
|
- return roadInfoById.at(id);
|
|
|
+ return {};
|
|
|
}
|
|
|
|
|
|
-std::ostream & operator<<(std::ostream & os, const TerrainType & terrainType)
|
|
|
+std::vector<bool> RoadTypeHandler::getDefaultAllowed() const
|
|
|
{
|
|
|
- return os << static_cast<const std::string &>(terrainType);
|
|
|
+ return {};
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
TerrainType::operator std::string() const
|
|
|
{
|
|
|
return name;
|
|
|
}
|
|
|
-
|
|
|
-TerrainType::TerrainType(const std::string& _name):
|
|
|
- minimapBlocked({0,0,0}), //black
|
|
|
- minimapUnblocked({ 128,128,128 }), //grey
|
|
|
- name(_name),
|
|
|
- river(River::NO_RIVER),
|
|
|
- id(Terrain::WRONG),
|
|
|
- rockTerrain(Terrain::ROCK),
|
|
|
- moveCost(GameConstants::BASE_MOVEMENT_COST),
|
|
|
- horseSoundId(0),
|
|
|
- passabilityType(0),
|
|
|
- transitionRequired(false)
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
+
|
|
|
bool TerrainType::operator==(const TerrainType& other)
|
|
|
{
|
|
|
return id == other.id;
|
|
@@ -455,19 +247,4 @@ bool TerrainType::isTransitionRequired() const
|
|
|
return transitionRequired;
|
|
|
}
|
|
|
|
|
|
-RiverType::RiverType(const std::string & fileName, const std::string & code, RiverId id):
|
|
|
- fileName(fileName),
|
|
|
- code(code),
|
|
|
- id(id)
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
-RoadType::RoadType(const std::string& fileName, const std::string& code, RoadId id):
|
|
|
- fileName(fileName),
|
|
|
- code(code),
|
|
|
- id(id),
|
|
|
- movementCost(GameConstants::BASE_MOVEMENT_COST)
|
|
|
-{
|
|
|
-}
|
|
|
-
|
|
|
VCMI_LIB_NAMESPACE_END
|