1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00
vcmi/lib/Terrain.h

126 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:
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;
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;
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
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;
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;
}
};
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
};