|
|
@@ -17,31 +17,15 @@
|
|
|
//("allowedTerrain"\s*:\s*\[.*)9(.*\],\n)
|
|
|
//\1"rock"\2
|
|
|
|
|
|
-const Terrain Terrain::ANY("ANY");
|
|
|
-
|
|
|
-Terrain Terrain::createTerrainTypeH3M(int tId)
|
|
|
-{
|
|
|
- static std::array<std::string, 10> terrainsH3M
|
|
|
- {
|
|
|
- "dirt", "sand", "grass", "snow", "swamp", "rough", "subterra", "lava", "water", "rock"
|
|
|
- };
|
|
|
- return Terrain(terrainsH3M.at(tId));
|
|
|
-}
|
|
|
-
|
|
|
-Terrain Terrain::createTerrainByCode(const std::string & typeCode)
|
|
|
-{
|
|
|
- for(const auto & terrain : Manager::terrains())
|
|
|
- {
|
|
|
- if(Manager::getInfo(terrain).typeCode == typeCode)
|
|
|
- return terrain;
|
|
|
- }
|
|
|
- return Terrain::ANY;
|
|
|
-}
|
|
|
-
|
|
|
-Terrain::Manager::Manager()
|
|
|
+TerrainTypeHandler::TerrainTypeHandler()
|
|
|
{
|
|
|
auto allConfigs = VLC->modh->getActiveMods();
|
|
|
allConfigs.insert(allConfigs.begin(), "core");
|
|
|
+
|
|
|
+ std::vector<std::function<void()>> resolveLater;
|
|
|
+
|
|
|
+ objects.resize(Terrain::ORIGINAL_TERRAIN_COUNT, nullptr); //make space for original terrains
|
|
|
+
|
|
|
for(auto & mod : allConfigs)
|
|
|
{
|
|
|
if(!CResourceHandler::get(mod)->existsResource(ResourceID("config/terrains.json")))
|
|
|
@@ -50,10 +34,11 @@ Terrain::Manager::Manager()
|
|
|
JsonNode terrs(mod, ResourceID("config/terrains.json"));
|
|
|
for(auto & terr : terrs.Struct())
|
|
|
{
|
|
|
- Terrain::Info info;
|
|
|
- info.moveCost = terr.second["moveCost"].Integer();
|
|
|
+ auto * info = new TerrainType(terr.first);
|
|
|
+
|
|
|
+ info->moveCost = terr.second["moveCost"].Integer();
|
|
|
const JsonVector &unblockedVec = terr.second["minimapUnblocked"].Vector();
|
|
|
- info.minimapUnblocked =
|
|
|
+ info->minimapUnblocked =
|
|
|
{
|
|
|
ui8(unblockedVec[0].Float()),
|
|
|
ui8(unblockedVec[1].Float()),
|
|
|
@@ -61,75 +46,75 @@ Terrain::Manager::Manager()
|
|
|
};
|
|
|
|
|
|
const JsonVector &blockedVec = terr.second["minimapBlocked"].Vector();
|
|
|
- info.minimapBlocked =
|
|
|
+ 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();
|
|
|
+ info->musicFilename = terr.second["music"].String();
|
|
|
+ info->tilesFilename = terr.second["tiles"].String();
|
|
|
|
|
|
if(terr.second["type"].isNull())
|
|
|
{
|
|
|
- info.type = Terrain::Info::Type::Land;
|
|
|
+ info->passabilityType = TerrainType::PassabilityType::LAND;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
auto s = terr.second["type"].String();
|
|
|
- if(s == "LAND") info.type = Terrain::Info::Type::Land;
|
|
|
- if(s == "WATER") info.type = Terrain::Info::Type::Water;
|
|
|
- if(s == "ROCK") info.type = Terrain::Info::Type::Rock;
|
|
|
- if(s == "SUB") info.type = Terrain::Info::Type::Subterranean;
|
|
|
+ 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 == "SUB") info->passabilityType = TerrainType::PassabilityType::SUBTERRANEAN;
|
|
|
}
|
|
|
|
|
|
if(terr.second["rockTerrain"].isNull())
|
|
|
{
|
|
|
- info.rockTerrain = "rock";
|
|
|
+ info->rockTerrain = "rock";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- info.rockTerrain = terr.second["rockTerrain"].String();
|
|
|
+ info->rockTerrain = terr.second["rockTerrain"].String();
|
|
|
}
|
|
|
|
|
|
if(terr.second["river"].isNull())
|
|
|
{
|
|
|
- info.river = RIVER_NAMES[0];
|
|
|
+ info->river = RIVER_NAMES[0];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- info.river = terr.second["river"].String();
|
|
|
+ info->river = terr.second["river"].String();
|
|
|
}
|
|
|
|
|
|
if(terr.second["horseSoundId"].isNull())
|
|
|
{
|
|
|
- info.horseSoundId = 9; //rock sound as default
|
|
|
+ info->horseSoundId = 9; //rock sound as default
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- info.horseSoundId = terr.second["horseSoundId"].Integer();
|
|
|
+ info->horseSoundId = terr.second["horseSoundId"].Integer();
|
|
|
}
|
|
|
|
|
|
if(!terr.second["text"].isNull())
|
|
|
{
|
|
|
- info.terrainText = terr.second["text"].String();
|
|
|
+ info->terrainText = terr.second["text"].String();
|
|
|
}
|
|
|
|
|
|
if(terr.second["code"].isNull())
|
|
|
{
|
|
|
- info.typeCode = terr.first.substr(0, 2);
|
|
|
+ info->typeCode = terr.first.substr(0, 2);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- info.typeCode = terr.second["code"].String();
|
|
|
- assert(info.typeCode.length() == 2);
|
|
|
+ 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->battleFields.emplace_back(t.String());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -137,123 +122,133 @@ Terrain::Manager::Manager()
|
|
|
{
|
|
|
for(auto & t : terr.second["prohibitTransitions"].Vector())
|
|
|
{
|
|
|
- info.prohibitTransitions.emplace_back(t.String());
|
|
|
+ info->prohibitTransitions.emplace_back(t.String());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- info.transitionRequired = false;
|
|
|
+ info->transitionRequired = false;
|
|
|
if(!terr.second["transitionRequired"].isNull())
|
|
|
{
|
|
|
- info.transitionRequired = terr.second["transitionRequired"].Bool();
|
|
|
+ info->transitionRequired = terr.second["transitionRequired"].Bool();
|
|
|
}
|
|
|
|
|
|
- info.terrainViewPatterns = "normal";
|
|
|
+ info->terrainViewPatterns = "normal";
|
|
|
if(!terr.second["terrainViewPatterns"].isNull())
|
|
|
{
|
|
|
- info.terrainViewPatterns = terr.second["terrainViewPatterns"].String();
|
|
|
+ info->terrainViewPatterns = terr.second["terrainViewPatterns"].String();
|
|
|
}
|
|
|
+
|
|
|
+ //TODO: handle 10 origina terrains
|
|
|
|
|
|
- terrainInfo[terr.first] = info;
|
|
|
- if(!terrainId.count(terr.first))
|
|
|
+ terrainInfoByName[terr.first] = info;
|
|
|
+ terrainInfoByCode[info->typeCode] = info;
|
|
|
+ terrainInfoById[info->id] = info;
|
|
|
+
|
|
|
+ TTerrain id;
|
|
|
+ if(!terr.second["originalTerrainId"].isNull())
|
|
|
{
|
|
|
- terrainId[terr.first] = terrainVault.size();
|
|
|
- terrainVault.push_back(terr.first);
|
|
|
+ //place in reserved slot
|
|
|
+ id = (TTerrain)(terr.second["originalTerrainId"].Float());
|
|
|
+ objects[id] = info;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //append at the end
|
|
|
+ id = objects.size();
|
|
|
+ objects.push_back(info);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ for (size_t i = Terrain::FIRST_REGULAR_TERRAIN; i < Terrain::ORIGINAL_TERRAIN_COUNT; i++)
|
|
|
+ {
|
|
|
+ //Make sure that original terrains are loaded
|
|
|
+ assert(objects(i));
|
|
|
+ }
|
|
|
+
|
|
|
+ //TODO: add ids to resolve
|
|
|
+ for (auto& functor : resolveLater)
|
|
|
+ {
|
|
|
+ functor();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-Terrain::Manager & Terrain::Manager::get()
|
|
|
+const std::vector<TerrainType *> & TerrainTypeHandler::terrains()
|
|
|
{
|
|
|
- static Terrain::Manager manager;
|
|
|
- return manager;
|
|
|
+ return objects;
|
|
|
}
|
|
|
|
|
|
-const std::vector<Terrain> & Terrain::Manager::terrains()
|
|
|
+const TerrainType* TerrainTypeHandler::getInfoByName(const std::string& terrainName) const
|
|
|
{
|
|
|
- return Terrain::Manager::get().terrainVault;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-int Terrain::Manager::id(const Terrain & terrain)
|
|
|
+const TerrainType* TerrainTypeHandler::getInfoByCode(const std::string& terrainName) const
|
|
|
{
|
|
|
- if(terrain.name == "ANY") return -3;
|
|
|
- if(terrain.name == "WRONG") return -2;
|
|
|
- if(terrain.name == "BORDER") return -1;
|
|
|
-
|
|
|
- return Terrain::Manager::get().terrainId.at(terrain);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-const Terrain::Info & Terrain::Manager::getInfo(const Terrain & terrain)
|
|
|
+const TerrainType* TerrainTypeHandler::getInfoById(TTerrain id) const
|
|
|
{
|
|
|
- return Terrain::Manager::get().terrainInfo.at(static_cast<std::string>(terrain));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-std::ostream & operator<<(std::ostream & os, const Terrain terrainType)
|
|
|
+std::ostream & operator<<(std::ostream & os, const TerrainType & terrainType)
|
|
|
{
|
|
|
return os << static_cast<const std::string &>(terrainType);
|
|
|
}
|
|
|
|
|
|
-Terrain::operator std::string() const
|
|
|
+TerrainType::operator std::string() const
|
|
|
{
|
|
|
return name;
|
|
|
}
|
|
|
|
|
|
-Terrain::Terrain(const std::string & _name) : name(_name)
|
|
|
+TerrainType::TerrainType(const std::string & _name) : name(_name)
|
|
|
{}
|
|
|
|
|
|
-Terrain& Terrain::operator=(const Terrain & _name)
|
|
|
+TerrainType& TerrainType::operator=(const TerrainType & other)
|
|
|
{
|
|
|
- name = _name.name;
|
|
|
+ //TODO
|
|
|
+ name = other.name;
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
-Terrain& Terrain::operator=(const std::string & _name)
|
|
|
+bool TerrainType::operator==(const TerrainType& other)
|
|
|
{
|
|
|
- name = _name;
|
|
|
- return *this;
|
|
|
+ return id == other.id;
|
|
|
}
|
|
|
|
|
|
-bool operator==(const Terrain & l, const Terrain & r)
|
|
|
+bool TerrainType::operator!=(const TerrainType& other)
|
|
|
{
|
|
|
- return l.name == r.name;
|
|
|
+ return id != other.id;
|
|
|
}
|
|
|
|
|
|
-bool operator!=(const Terrain & l, const Terrain & r)
|
|
|
+bool TerrainType::operator<(const TerrainType& other)
|
|
|
{
|
|
|
- return l.name != r.name;
|
|
|
+ return id < other.id;
|
|
|
}
|
|
|
|
|
|
-bool operator<(const Terrain & l, const Terrain & r)
|
|
|
-{
|
|
|
- return l.name < r.name;
|
|
|
-}
|
|
|
-
|
|
|
-int Terrain::id() const
|
|
|
-{
|
|
|
- return Terrain::Manager::id(*this);
|
|
|
-}
|
|
|
-
|
|
|
-bool Terrain::isLand() const
|
|
|
+bool TerrainType::isLand() const
|
|
|
{
|
|
|
return !isWater();
|
|
|
}
|
|
|
-bool Terrain::isWater() const
|
|
|
-{
|
|
|
- return Terrain::Manager::getInfo(*this).type == Terrain::Info::Type::Water;
|
|
|
-}
|
|
|
-bool Terrain::isPassable() const
|
|
|
+
|
|
|
+bool TerrainType::isWater() const
|
|
|
{
|
|
|
- return Terrain::Manager::getInfo(*this).type != Terrain::Info::Type::Rock;
|
|
|
+ return passabilityType == PassabilityType::WATER;
|
|
|
}
|
|
|
-bool Terrain::isUnderground() const
|
|
|
+
|
|
|
+bool TerrainType::isPassable() const
|
|
|
{
|
|
|
- return Terrain::Manager::getInfo(*this).type == Terrain::Info::Type::Subterranean;
|
|
|
+ return passabilityType != PassabilityType::ROCK;
|
|
|
}
|
|
|
-bool Terrain::isNative() const
|
|
|
+
|
|
|
+bool TerrainType::isUnderground() const
|
|
|
{
|
|
|
- return name.empty();
|
|
|
+ return passabilityType != PassabilityType::SUBTERRANEAN;
|
|
|
}
|
|
|
-bool Terrain::isTransitionRequired() const
|
|
|
+
|
|
|
+bool TerrainType::isTransitionRequired() const
|
|
|
{
|
|
|
- return Terrain::Manager::getInfo(*this).transitionRequired;
|
|
|
+ return transitionRequired;
|
|
|
}
|