1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-12 10:03:53 +02:00
vcmi/lib/Terrain.h

124 lines
2.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"
2022-06-22 10:41:02 +02:00
2022-09-19 16:13:58 +02:00
class DLL_LINKAGE TerrainType
{
public:
2022-09-19 16:13:58 +02:00
enum class PassabilityType
{
2022-09-19 16:13:58 +02:00
LAND,
WATER,
SUBTERRANEAN,
ROCK
};
2022-09-19 16:13:58 +02:00
std::vector<std::string> battleFields;
std::vector<TTerrain> prohibitTransitions;
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;
std::string river;
TTerrain id;
2022-09-21 11:34:23 +02:00
TTerrain rockTerrain;
2022-09-19 16:13:58 +02:00
int moveCost;
int horseSoundId;
PassabilityType passabilityType;
bool transitionRequired;
2022-09-21 11:34:23 +02:00
TerrainType(const std::string & name = "");
2022-09-19 16:13:58 +02:00
TerrainType& operator=(const TerrainType & _type);
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; //ROCK
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;
}
};
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-21 11:34:23 +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-19 16:13:58 +02:00
const TerrainType * getInfoById(TTerrain id) const;
//TODO: road, river types?
2022-09-21 11:34:23 +02:00
template <typename Handler> void serialize(Handler &h, const int version)
{
h & objects;
if (!h.saving)
{
recreateTerrainMaps();
}
}
2022-09-19 16:13:58 +02:00
private:
std::vector<TerrainType *> objects;
std::unordered_map<std::string, const TerrainType*> terrainInfoByName;
std::unordered_map<std::string, const TerrainType*> terrainInfoByCode;
std::unordered_map<TTerrain, const TerrainType*> terrainInfoById;
2022-09-21 11:34:23 +02:00
void recreateTerrainMaps();
2022-09-19 16:13:58 +02:00
};