2022-06-20 16:39:50 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
2022-06-28 10:05:30 +02:00
|
|
|
#include "GameConstants.h"
|
2022-06-20 16:39:50 +02:00
|
|
|
#include "JsonNode.h"
|
|
|
|
|
2022-06-22 10:41:02 +02:00
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
class DLL_LINKAGE TerrainType
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
enum class PassabilityType
|
2022-06-20 16:39:50 +02:00
|
|
|
{
|
2022-09-19 16:13:58 +02:00
|
|
|
LAND,
|
|
|
|
WATER,
|
|
|
|
SUBTERRANEAN,
|
|
|
|
ROCK
|
2022-06-20 16:39:50 +02:00
|
|
|
};
|
|
|
|
|
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-06-20 16:39:50 +02:00
|
|
|
|
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-06-20 16:39:50 +02:00
|
|
|
|
2022-09-19 16:13:58 +02:00
|
|
|
bool operator==(const TerrainType & other);
|
|
|
|
bool operator!=(const TerrainType & other);
|
|
|
|
bool operator<(const TerrainType & other);
|
2022-06-20 16:39:50 +02:00
|
|
|
|
|
|
|
bool isLand() const;
|
|
|
|
bool isWater() const;
|
|
|
|
bool isPassable() const; //ROCK
|
|
|
|
bool isUnderground() const;
|
2022-06-22 10:41:02 +02:00
|
|
|
bool isTransitionRequired() const;
|
2022-06-20 16:39:50 +02:00
|
|
|
|
|
|
|
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;
|
2022-06-20 16:39:50 +02:00
|
|
|
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-06-20 16:39:50 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
};
|