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

194 lines
4.6 KiB
C
Raw Normal View History

/*
* Terrain.h, 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
*
*/
#pragma once
#include "ConstTransitivePtr.h"
#include "GameConstants.h"
#include "JsonNode.h"
VCMI_LIB_NAMESPACE_BEGIN
2022-06-22 10:41:02 +02:00
2022-09-19 16:13:58 +02:00
class DLL_LINKAGE TerrainType
{
public:
enum PassabilityType : ui8
{
LAND = 1,
WATER = 2,
SURFACE = 4,
SUBTERRANEAN = 8,
ROCK = 16
};
2022-09-19 16:13:58 +02:00
std::vector<std::string> battleFields;
2022-09-29 11:44:46 +02:00
std::vector<TerrainId> prohibitTransitions;
2022-09-19 16:13:58 +02:00
std::array<int, 3> minimapBlocked;
std::array<int, 3> minimapUnblocked;
std::string name;
std::string musicFilename;
std::string tilesFilename;
std::string terrainText;
std::string typeCode;
std::string terrainViewPatterns;
2022-09-29 11:44:46 +02:00
RiverId river;
2022-09-19 16:13:58 +02:00
2022-09-29 11:44:46 +02:00
TerrainId id;
TerrainId rockTerrain;
2022-09-19 16:13:58 +02:00
int moveCost;
int horseSoundId;
ui8 passabilityType;
2022-09-19 16:13:58 +02:00
bool transitionRequired;
2022-09-21 11:34:23 +02:00
TerrainType(const std::string & name = "");
2022-09-19 16:13:58 +02:00
bool operator==(const TerrainType & other);
bool operator!=(const TerrainType & other);
bool operator<(const TerrainType & other);
bool isLand() const;
bool isWater() const;
bool isPassable() const;
bool isSurface() const;
bool isUnderground() const;
2022-06-22 10:41:02 +02:00
bool isTransitionRequired() const;
operator std::string() const;
template <typename Handler> void serialize(Handler &h, const int version)
{
2022-09-19 16:13:58 +02:00
h & battleFields;
h & prohibitTransitions;
h & minimapBlocked;
h & minimapUnblocked;
h & name;
2022-09-19 16:13:58 +02:00
h & musicFilename;
h & tilesFilename;
h & terrainText;
h & typeCode;
h & terrainViewPatterns;
h & rockTerrain;
h & river;
h & id;
h & moveCost;
h & horseSoundId;
h & passabilityType;
h & transitionRequired;
}
};
class DLL_LINKAGE RiverType
{
public:
std::string fileName;
std::string code;
std::string deltaName;
2022-09-29 11:44:46 +02:00
RiverId id;
2022-09-29 11:44:46 +02:00
RiverType(const std::string & fileName = "", const std::string & code = "", RiverId id = River::NO_RIVER);
template <typename Handler> void serialize(Handler& h, const int version)
{
h & fileName;
h & code;
h & deltaName;
h & id;
}
};
class DLL_LINKAGE RoadType
{
public:
std::string fileName;
std::string code;
2022-09-29 11:44:46 +02:00
RoadId id;
ui8 movementCost;
2022-09-29 11:44:46 +02:00
RoadType(const std::string & fileName = "", const std::string& code = "", RoadId id = Road::NO_ROAD);
template <typename Handler> void serialize(Handler& h, const int version)
{
h & fileName;
h & code;
h & id;
h & movementCost;
}
};
2022-09-19 16:13:58 +02:00
DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const TerrainType & terrainType);
2022-09-21 11:34:23 +02:00
class DLL_LINKAGE TerrainTypeHandler //TODO: public IHandlerBase ?
2022-09-19 16:13:58 +02:00
{
public:
TerrainTypeHandler();
2022-09-26 10:20:39 +02:00
~TerrainTypeHandler() {};
2022-09-19 16:13:58 +02:00
const std::vector<TerrainType> & terrains() const;
2022-09-19 16:13:58 +02:00
const TerrainType * getInfoByName(const std::string & terrainName) const;
2022-09-21 11:34:23 +02:00
const TerrainType * getInfoByCode(const std::string & terrainCode) const;
2022-09-29 11:44:46 +02:00
const TerrainType * getInfoById(TerrainId id) const;
2022-09-19 16:13:58 +02:00
const std::vector<RiverType> & rivers() const;
const RiverType * getRiverByName(const std::string & riverName) const;
const RiverType * getRiverByCode(const std::string & riverCode) const;
2022-09-29 11:44:46 +02:00
const RiverType * getRiverById(RiverId id) const;
2022-09-26 10:20:39 +02:00
const std::vector<RoadType> & roads() const;
const RoadType * getRoadByName(const std::string & roadName) const;
const RoadType * getRoadByCode(const std::string & roadCode) const;
2022-09-29 11:44:46 +02:00
const RoadType * getRoadById(RoadId id) const;
2022-09-19 16:13:58 +02:00
2022-09-21 11:34:23 +02:00
template <typename Handler> void serialize(Handler &h, const int version)
{
h & objects;
h & riverTypes;
h & roadTypes;
2022-09-21 11:34:23 +02:00
if (!h.saving)
{
recreateTerrainMaps();
recreateRiverMaps();
recreateRoadMaps();
2022-09-21 11:34:23 +02:00
}
}
2022-09-19 16:13:58 +02:00
private:
std::vector<TerrainType> objects;
std::vector<RiverType> riverTypes;
2022-09-26 10:20:39 +02:00
std::vector<RoadType> roadTypes;
2022-09-19 16:13:58 +02:00
std::unordered_map<std::string, const TerrainType*> terrainInfoByName;
std::unordered_map<std::string, const TerrainType*> terrainInfoByCode;
2022-09-29 11:44:46 +02:00
std::unordered_map<TerrainId, const TerrainType*> terrainInfoById;
2022-09-19 16:13:58 +02:00
std::unordered_map<std::string, const RiverType*> riverInfoByName;
std::unordered_map<std::string, const RiverType*> riverInfoByCode;
2022-09-29 11:44:46 +02:00
std::unordered_map<RiverId, const RiverType*> riverInfoById;
std::unordered_map<std::string, const RoadType*> roadInfoByName;
std::unordered_map<std::string, const RoadType*> roadInfoByCode;
2022-09-29 11:44:46 +02:00
std::unordered_map<RoadId, const RoadType*> roadInfoById;
2022-09-25 09:33:56 +02:00
void initTerrains(const std::vector<std::string> & allConfigs);
void initRivers(const std::vector<std::string> & allConfigs);
void initRoads(const std::vector<std::string> & allConfigs);
2022-09-21 11:34:23 +02:00
void recreateTerrainMaps();
void recreateRiverMaps();
void recreateRoadMaps();
2022-09-19 16:13:58 +02:00
};
VCMI_LIB_NAMESPACE_END