2022-06-20 16:39:50 +02:00
|
|
|
/*
|
|
|
|
* Terrain.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-08-09 07:54:32 +02:00
|
|
|
#include "StdInc.h"
|
2022-06-20 16:39:50 +02:00
|
|
|
#include "Terrain.h"
|
|
|
|
#include "VCMI_Lib.h"
|
|
|
|
#include "CModHandler.h"
|
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2022-06-20 16:39:50 +02:00
|
|
|
//regular expression to change id for string at config
|
|
|
|
//("allowedTerrain"\s*:\s*\[.*)9(.*\],\n)
|
|
|
|
//\1"rock"\2
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
TerrainTypeHandler::TerrainTypeHandler()
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
auto allConfigs = VLC->modh->getActiveMods();
|
2022-12-07 15:18:19 +02:00
|
|
|
allConfigs.insert(allConfigs.begin(), CModHandler::scopeBuiltin());
|
2022-09-19 16:13:58 +02:00
|
|
|
|
2022-09-23 19:26:38 +02:00
|
|
|
initRivers(allConfigs);
|
|
|
|
recreateRiverMaps();
|
|
|
|
initRoads(allConfigs);
|
|
|
|
recreateRoadMaps();
|
|
|
|
initTerrains(allConfigs); //maps will be populated inside
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainTypeHandler::initTerrains(const std::vector<std::string> & allConfigs)
|
|
|
|
{
|
2022-09-19 16:13:58 +02:00
|
|
|
std::vector<std::function<void()>> resolveLater;
|
|
|
|
|
2022-09-26 09:17:55 +02:00
|
|
|
objects.resize(Terrain::ORIGINAL_TERRAIN_COUNT); //make space for original terrains
|
2022-09-19 16:13:58 +02:00
|
|
|
|
2022-06-20 16:39:50 +02:00
|
|
|
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())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
TerrainType info(terr.first); //set name
|
2022-09-19 16:13:58 +02:00
|
|
|
|
2022-09-26 09:17:55 +02:00
|
|
|
info.moveCost = static_cast<int>(terr.second["moveCost"].Integer());
|
2022-06-20 16:39:50 +02:00
|
|
|
const JsonVector &unblockedVec = terr.second["minimapUnblocked"].Vector();
|
2022-09-26 09:17:55 +02:00
|
|
|
info.minimapUnblocked =
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
ui8(unblockedVec[0].Float()),
|
|
|
|
ui8(unblockedVec[1].Float()),
|
|
|
|
ui8(unblockedVec[2].Float())
|
|
|
|
};
|
|
|
|
|
|
|
|
const JsonVector &blockedVec = terr.second["minimapBlocked"].Vector();
|
2022-09-26 09:17:55 +02:00
|
|
|
info.minimapBlocked =
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
ui8(blockedVec[0].Float()),
|
|
|
|
ui8(blockedVec[1].Float()),
|
|
|
|
ui8(blockedVec[2].Float())
|
|
|
|
};
|
2022-09-26 09:17:55 +02:00
|
|
|
info.musicFilename = terr.second["music"].String();
|
|
|
|
info.tilesFilename = terr.second["tiles"].String();
|
2022-06-20 16:39:50 +02:00
|
|
|
|
|
|
|
if(terr.second["type"].isNull())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.passabilityType = TerrainType::PassabilityType::LAND | TerrainType::PassabilityType::SURFACE;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
2022-09-22 18:23:31 +02:00
|
|
|
else if (terr.second["type"].getType() == JsonNode::JsonType::DATA_VECTOR)
|
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
for(const auto& node : terr.second["type"].Vector())
|
2022-09-22 18:23:31 +02:00
|
|
|
{
|
|
|
|
//Set bits
|
|
|
|
auto s = node.String();
|
2022-09-26 09:17:55 +02:00
|
|
|
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;
|
2022-09-22 18:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else //should be string - one option only
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
auto s = terr.second["type"].String();
|
2022-09-26 09:17:55 +02:00
|
|
|
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;
|
2022-08-09 07:54:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(terr.second["river"].isNull())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.river = River::NO_RIVER;
|
2022-08-09 07:54:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.river = getRiverByCode(terr.second["river"].String())->id;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(terr.second["horseSoundId"].isNull())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.horseSoundId = Terrain::ROCK; //rock sound as default
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.horseSoundId = static_cast<int>(terr.second["horseSoundId"].Float());
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!terr.second["text"].isNull())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.terrainText = terr.second["text"].String();
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(terr.second["code"].isNull())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.typeCode = terr.first.substr(0, 2);
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.typeCode = terr.second["code"].String();
|
|
|
|
assert(info.typeCode.length() == 2);
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-06-22 10:41:02 +02:00
|
|
|
if(!terr.second["battleFields"].isNull())
|
|
|
|
{
|
|
|
|
for(auto & t : terr.second["battleFields"].Vector())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.battleFields.emplace_back(t.String());
|
2022-06-22 10:41:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 09:17:55 +02:00
|
|
|
info.transitionRequired = false;
|
2022-06-22 10:41:02 +02:00
|
|
|
if(!terr.second["transitionRequired"].isNull())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.transitionRequired = terr.second["transitionRequired"].Bool();
|
2022-06-22 10:41:02 +02:00
|
|
|
}
|
|
|
|
|
2022-09-26 09:17:55 +02:00
|
|
|
info.terrainViewPatterns = "normal";
|
2022-06-22 10:41:02 +02:00
|
|
|
if(!terr.second["terrainViewPatterns"].isNull())
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
info.terrainViewPatterns = terr.second["terrainViewPatterns"].String();
|
2022-06-22 10:41:02 +02:00
|
|
|
}
|
2022-09-19 16:13:58 +02:00
|
|
|
|
|
|
|
if(!terr.second["originalTerrainId"].isNull())
|
2022-09-07 02:20:02 +02:00
|
|
|
{
|
2022-09-19 16:13:58 +02:00
|
|
|
//place in reserved slot
|
2022-09-29 11:44:46 +02:00
|
|
|
info.id = (TerrainId)(terr.second["originalTerrainId"].Float());
|
2022-09-26 09:17:55 +02:00
|
|
|
objects[info.id] = info;
|
2022-09-19 16:13:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//append at the end
|
2022-09-29 11:44:46 +02:00
|
|
|
info.id = static_cast<TerrainId>(objects.size());
|
2022-09-19 16:13:58 +02:00
|
|
|
objects.push_back(info);
|
2022-09-07 02:20:02 +02:00
|
|
|
}
|
2022-09-29 11:44:46 +02:00
|
|
|
TerrainId id = info.id;
|
2022-09-26 09:17:55 +02:00
|
|
|
|
|
|
|
//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;
|
|
|
|
});
|
|
|
|
}
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-19 16:13:58 +02:00
|
|
|
|
2022-09-26 10:20:39 +02:00
|
|
|
for(size_t i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ORIGINAL_TERRAIN_COUNT; i++)
|
2022-09-19 16:13:58 +02:00
|
|
|
{
|
|
|
|
//Make sure that original terrains are loaded
|
2022-09-29 21:10:44 +02:00
|
|
|
assert(objects[i].id != Terrain::WRONG);
|
2022-09-19 16:13:58 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 13:43:57 +02:00
|
|
|
recreateTerrainMaps();
|
|
|
|
|
2022-09-26 10:20:39 +02:00
|
|
|
for(auto& functor : resolveLater)
|
2022-09-19 16:13:58 +02:00
|
|
|
{
|
|
|
|
functor();
|
|
|
|
}
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 19:26:38 +02:00
|
|
|
void TerrainTypeHandler::initRivers(const std::vector<std::string> & allConfigs)
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
2022-09-26 09:51:36 +02:00
|
|
|
riverTypes.resize(River::ORIGINAL_RIVER_COUNT); //make space for original rivers
|
2022-09-26 10:20:39 +02:00
|
|
|
//First object will be default NO_RIVER
|
2022-09-23 16:24:01 +02:00
|
|
|
|
2022-09-26 10:20:39 +02:00
|
|
|
for(auto & mod : allConfigs)
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
2022-09-23 18:57:16 +02:00
|
|
|
if (!CResourceHandler::get(mod)->existsResource(ResourceID("config/rivers.json")))
|
|
|
|
continue;
|
2022-09-23 16:24:01 +02:00
|
|
|
|
2022-09-23 18:57:16 +02:00
|
|
|
JsonNode rivs(mod, ResourceID("config/rivers.json"));
|
2022-09-26 10:20:39 +02:00
|
|
|
for(auto & river : rivs.Struct())
|
2022-09-23 18:57:16 +02:00
|
|
|
{
|
2022-09-26 09:51:36 +02:00
|
|
|
RiverType info;
|
2022-09-23 18:57:16 +02:00
|
|
|
|
2022-12-17 02:54:01 +02:00
|
|
|
info.name = river.first;
|
2022-09-26 09:51:36 +02:00
|
|
|
info.fileName = river.second["animation"].String();
|
|
|
|
info.code = river.second["code"].String();
|
|
|
|
info.deltaName = river.second["delta"].String();
|
2022-09-23 18:57:16 +02:00
|
|
|
|
|
|
|
if (!river.second["originalRiverId"].isNull())
|
|
|
|
{
|
2022-09-29 11:44:46 +02:00
|
|
|
info.id = static_cast<RiverId>(river.second["originalRiverId"].Float());
|
2022-09-26 09:51:36 +02:00
|
|
|
riverTypes[info.id] = info;
|
2022-09-23 18:57:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-29 11:44:46 +02:00
|
|
|
info.id = static_cast<RiverId>(riverTypes.size());
|
2022-09-23 18:57:16 +02:00
|
|
|
riverTypes.push_back(info);
|
|
|
|
}
|
|
|
|
}
|
2022-09-23 16:24:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
recreateRiverMaps();
|
|
|
|
}
|
|
|
|
|
2022-09-23 19:26:38 +02:00
|
|
|
void TerrainTypeHandler::initRoads(const std::vector<std::string> & allConfigs)
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
roadTypes.resize(Road::ORIGINAL_ROAD_COUNT); //make space for original rivers
|
|
|
|
//first object will be default NO_ROAD
|
2022-09-23 16:24:01 +02:00
|
|
|
|
2022-09-26 10:20:39 +02:00
|
|
|
for(auto & mod : allConfigs)
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
2022-09-23 18:57:16 +02:00
|
|
|
if (!CResourceHandler::get(mod)->existsResource(ResourceID("config/roads.json")))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
JsonNode rds(mod, ResourceID("config/roads.json"));
|
2022-09-26 10:20:39 +02:00
|
|
|
for(auto & road : rds.Struct())
|
2022-09-23 18:57:16 +02:00
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
RoadType info;
|
2022-09-23 18:57:16 +02:00
|
|
|
|
2022-12-17 02:54:01 +02:00
|
|
|
info.name = road.first;
|
2022-09-26 10:20:39 +02:00
|
|
|
info.fileName = road.second["animation"].String();
|
|
|
|
info.code = road.second["code"].String();
|
|
|
|
info.movementCost = static_cast<ui8>(road.second["moveCost"].Float());
|
2022-09-23 18:57:16 +02:00
|
|
|
|
|
|
|
if (!road.second["originalRoadId"].isNull())
|
|
|
|
{
|
2022-09-29 11:44:46 +02:00
|
|
|
info.id = static_cast<RoadId>(road.second["originalRoadId"].Float());
|
2022-09-26 10:20:39 +02:00
|
|
|
roadTypes[info.id] = info;
|
2022-09-23 18:57:16 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-29 11:44:46 +02:00
|
|
|
info.id = static_cast<RoadId>(roadTypes.size());
|
2022-09-23 18:57:16 +02:00
|
|
|
roadTypes.push_back(info);
|
|
|
|
}
|
|
|
|
}
|
2022-09-23 16:24:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
recreateRoadMaps();
|
|
|
|
}
|
|
|
|
|
2022-09-21 11:34:23 +02:00
|
|
|
void TerrainTypeHandler::recreateTerrainMaps()
|
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
//This assumes the vector will never be updated or reallocated in the future
|
|
|
|
|
2022-09-26 10:20:39 +02:00
|
|
|
for(size_t i = 0; i < objects.size(); i++)
|
2022-09-21 11:34:23 +02:00
|
|
|
{
|
2022-09-26 09:17:55 +02:00
|
|
|
const auto * terrainInfo = &objects[i];
|
|
|
|
|
2022-09-21 11:34:23 +02:00
|
|
|
terrainInfoByName[terrainInfo->name] = terrainInfo;
|
|
|
|
terrainInfoByCode[terrainInfo->typeCode] = terrainInfo;
|
|
|
|
terrainInfoById[terrainInfo->id] = terrainInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:24:01 +02:00
|
|
|
void TerrainTypeHandler::recreateRiverMaps()
|
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
for(size_t i = River::FIRST_REGULAR_RIVER ; i < riverTypes.size(); i++)
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
const auto * riverInfo = &riverTypes[i];
|
2022-09-23 18:57:16 +02:00
|
|
|
|
2022-12-17 02:54:01 +02:00
|
|
|
riverInfoByName[riverInfo->name] = riverInfo;
|
2022-09-23 16:24:01 +02:00
|
|
|
riverInfoByCode[riverInfo->code] = riverInfo;
|
|
|
|
riverInfoById[riverInfo->id] = riverInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerrainTypeHandler::recreateRoadMaps()
|
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
for(size_t i = Road::FIRST_REGULAR_ROAD ; i < roadTypes.size(); i++)
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
const auto * roadInfo = &roadTypes[i];
|
2022-09-23 18:57:16 +02:00
|
|
|
|
2022-12-17 02:54:01 +02:00
|
|
|
roadInfoByName[roadInfo->name] = roadInfo;
|
2022-09-23 16:24:01 +02:00
|
|
|
roadInfoByCode[roadInfo->code] = roadInfo;
|
|
|
|
roadInfoById[roadInfo->id] = roadInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-26 09:17:55 +02:00
|
|
|
const std::vector<TerrainType> & TerrainTypeHandler::terrains() const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-26 09:51:36 +02:00
|
|
|
//FIXME: somehow make it non-copyable? Pointers must point to original data and not its copy
|
2022-09-19 16:13:58 +02:00
|
|
|
return objects;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-09-26 09:51:36 +02:00
|
|
|
const std::vector<RiverType>& TerrainTypeHandler::rivers() const
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
|
|
|
return riverTypes;
|
|
|
|
}
|
|
|
|
|
2022-09-26 10:20:39 +02:00
|
|
|
const std::vector<RoadType>& TerrainTypeHandler::roads() const
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
|
|
|
return roadTypes;
|
|
|
|
}
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
const TerrainType* TerrainTypeHandler::getInfoByName(const std::string& terrainName) const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-21 11:34:23 +02:00
|
|
|
return terrainInfoByName.at(terrainName);
|
2022-09-07 02:20:02 +02:00
|
|
|
}
|
|
|
|
|
2022-09-21 11:34:23 +02:00
|
|
|
const TerrainType* TerrainTypeHandler::getInfoByCode(const std::string& terrainCode) const
|
2022-09-07 02:20:02 +02:00
|
|
|
{
|
2022-09-21 11:34:23 +02:00
|
|
|
return terrainInfoByCode.at(terrainCode);
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
const TerrainType* TerrainTypeHandler::getInfoById(TerrainId id) const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-21 11:34:23 +02:00
|
|
|
return terrainInfoById.at(id);
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:24:01 +02:00
|
|
|
const RiverType* TerrainTypeHandler::getRiverByName(const std::string& riverName) const
|
|
|
|
{
|
|
|
|
return riverInfoByName.at(riverName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const RiverType* TerrainTypeHandler::getRiverByCode(const std::string& riverCode) const
|
|
|
|
{
|
|
|
|
return riverInfoByCode.at(riverCode);
|
|
|
|
}
|
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
const RiverType* TerrainTypeHandler::getRiverById(RiverId id) const
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
|
|
|
return riverInfoById.at(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
const RoadType* TerrainTypeHandler::getRoadByName(const std::string& roadName) const
|
|
|
|
{
|
|
|
|
return roadInfoByName.at(roadName);
|
|
|
|
}
|
|
|
|
|
|
|
|
const RoadType* TerrainTypeHandler::getRoadByCode(const std::string& roadCode) const
|
|
|
|
{
|
|
|
|
return roadInfoByCode.at(roadCode);
|
|
|
|
}
|
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
const RoadType* TerrainTypeHandler::getRoadById(RoadId id) const
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
|
|
|
return roadInfoById.at(id);
|
|
|
|
}
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
std::ostream & operator<<(std::ostream & os, const TerrainType & terrainType)
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
return os << static_cast<const std::string &>(terrainType);
|
|
|
|
}
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
TerrainType::operator std::string() const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2022-09-21 11:34:23 +02:00
|
|
|
TerrainType::TerrainType(const std::string& _name):
|
2022-09-26 09:17:55 +02:00
|
|
|
minimapBlocked({0,0,0}), //black
|
|
|
|
minimapUnblocked({ 128,128,128 }), //grey
|
2022-09-21 13:43:57 +02:00
|
|
|
name(_name),
|
2022-09-26 09:17:55 +02:00
|
|
|
river(River::NO_RIVER),
|
2022-09-21 11:34:23 +02:00
|
|
|
id(Terrain::WRONG),
|
|
|
|
rockTerrain(Terrain::ROCK),
|
2022-09-26 09:17:55 +02:00
|
|
|
moveCost(GameConstants::BASE_MOVEMENT_COST),
|
2022-09-21 11:34:23 +02:00
|
|
|
horseSoundId(0),
|
2022-09-22 18:23:31 +02:00
|
|
|
passabilityType(0),
|
2022-09-21 11:34:23 +02:00
|
|
|
transitionRequired(false)
|
|
|
|
{
|
|
|
|
}
|
2022-06-20 16:39:50 +02:00
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
bool TerrainType::operator==(const TerrainType& other)
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-19 16:13:58 +02:00
|
|
|
return id == other.id;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
bool TerrainType::operator!=(const TerrainType& other)
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-19 16:13:58 +02:00
|
|
|
return id != other.id;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
bool TerrainType::operator<(const TerrainType& other)
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-19 16:13:58 +02:00
|
|
|
return id < other.id;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
bool TerrainType::isLand() const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
return !isWater();
|
|
|
|
}
|
2022-09-19 16:13:58 +02:00
|
|
|
|
|
|
|
bool TerrainType::isWater() const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-22 18:23:31 +02:00
|
|
|
return passabilityType & PassabilityType::WATER;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
2022-09-19 16:13:58 +02:00
|
|
|
|
|
|
|
bool TerrainType::isPassable() const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-22 18:23:31 +02:00
|
|
|
return !(passabilityType & PassabilityType::ROCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TerrainType::isSurface() const
|
|
|
|
{
|
|
|
|
return passabilityType & PassabilityType::SURFACE;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
2022-09-19 16:13:58 +02:00
|
|
|
|
|
|
|
bool TerrainType::isUnderground() const
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-22 18:23:31 +02:00
|
|
|
return passabilityType & PassabilityType::SUBTERRANEAN;
|
2022-06-20 16:39:50 +02:00
|
|
|
}
|
2022-09-19 16:13:58 +02:00
|
|
|
|
2022-12-30 16:09:09 +02:00
|
|
|
bool TerrainType::isSurfaceCartographerCompatible() const
|
|
|
|
{
|
2022-12-30 17:04:19 +02:00
|
|
|
return isSurface();
|
2022-12-30 16:09:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TerrainType::isUndergroundCartographerCompatible() const
|
|
|
|
{
|
2022-12-30 17:04:19 +02:00
|
|
|
return isLand() && isPassable() && !isSurface();
|
2022-12-30 16:09:09 +02:00
|
|
|
}
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
bool TerrainType::isTransitionRequired() const
|
2022-06-22 10:41:02 +02:00
|
|
|
{
|
2022-09-19 16:13:58 +02:00
|
|
|
return transitionRequired;
|
2022-06-22 10:41:02 +02:00
|
|
|
}
|
2022-09-23 16:24:01 +02:00
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
RiverType::RiverType(const std::string & fileName, const std::string & code, RiverId id):
|
2022-09-23 16:24:01 +02:00
|
|
|
fileName(fileName),
|
|
|
|
code(code),
|
|
|
|
id(id)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-29 11:44:46 +02:00
|
|
|
RoadType::RoadType(const std::string& fileName, const std::string& code, RoadId id):
|
2022-09-23 16:24:01 +02:00
|
|
|
fileName(fileName),
|
|
|
|
code(code),
|
2022-09-26 09:17:55 +02:00
|
|
|
id(id),
|
|
|
|
movementCost(GameConstants::BASE_MOVEMENT_COST)
|
2022-09-23 16:24:01 +02:00
|
|
|
{
|
2022-09-26 10:20:39 +02:00
|
|
|
}
|
|
|
|
|
2022-09-30 10:26:36 +02:00
|
|
|
VCMI_LIB_NAMESPACE_END
|