Browse Source

Converted several enumerations into constants

Ivan Savenko 2 years ago
parent
commit
e2718db791

+ 4 - 8
client/battle/BattleSiegeController.cpp

@@ -65,16 +65,12 @@ std::string BattleSiegeController::getWallPieceImageName(EWallVisual::EWallVisua
 	{
 	case EWallVisual::BACKGROUND_WALL:
 		{
-			switch(town->town->faction->getIndex())
-			{
-			case ETownType::RAMPART:
-			case ETownType::NECROPOLIS:
-			case ETownType::DUNGEON:
-			case ETownType::STRONGHOLD:
+			auto faction = town->town->faction->getIndex();
+
+			if (faction == ETownType::RAMPART || faction == ETownType::NECROPOLIS || faction == ETownType::DUNGEON || faction == ETownType::STRONGHOLD)
 				return prefix + "TPW1.BMP";
-			default:
+			else
 				return prefix + "TPWL.BMP";
-			}
 		}
 	case EWallVisual::KEEP:
 		return prefix + "MAN" + addit + ".BMP";

+ 2 - 1
cmake_modules/VCMI_lib.cmake

@@ -42,6 +42,8 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/campaign/CampaignHandler.cpp
 		${MAIN_LIB_DIR}/campaign/CampaignState.cpp
 
+		${MAIN_LIB_DIR}/constants/EntityIdentifiers.cpp
+
 		${MAIN_LIB_DIR}/events/ApplyDamage.cpp
 		${MAIN_LIB_DIR}/events/GameResumed.cpp
 		${MAIN_LIB_DIR}/events/ObjectVisitEnded.cpp
@@ -246,7 +248,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
 		${MAIN_LIB_DIR}/CStack.cpp
 		${MAIN_LIB_DIR}/CThreadHelper.cpp
 		${MAIN_LIB_DIR}/CTownHandler.cpp
-		${MAIN_LIB_DIR}/GameConstants.cpp
 		${MAIN_LIB_DIR}/GameSettings.cpp
 		${MAIN_LIB_DIR}/IGameCallback.cpp
 		${MAIN_LIB_DIR}/IHandlerBase.cpp

+ 1 - 1
lib/CCreatureSet.h

@@ -55,7 +55,7 @@ public:
 			CreatureID idNumber;
 			h & idNumber;
 			if(idNumber != CreatureID::NONE)
-				setType(dynamic_cast<const CCreature*>(VLC->creatures()->getByIndex(idNumber)));
+				setType(dynamic_cast<const CCreature*>(VLC->creatures()->getById(idNumber)));
 			else
 				type = nullptr;
 		}

+ 1 - 1
lib/CTownHandler.cpp

@@ -186,7 +186,7 @@ EAlignment CFaction::getAlignment() const
 
 BoatId CFaction::getBoatType() const
 {
-	return boatType.toEnum();
+	return boatType;
 }
 
 TerrainId CFaction::getNativeTerrain() const

+ 42 - 67
lib/GameConstants.cpp → lib/constants/EntityIdentifiers.cpp

@@ -1,5 +1,5 @@
 /*
- * GameConstants.cpp, part of VCMI engine
+ * EntityIdentifiers.cpp, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *
@@ -8,8 +8,6 @@
  *
  */
 
-#define INSTANTIATE_BASE_FOR_ID_HERE
-
 #include "StdInc.h"
 
 #ifndef VCMI_NO_EXTRA_VERSION
@@ -56,6 +54,44 @@ const PlayerColor PlayerColor::NEUTRAL = PlayerColor(255);
 const PlayerColor PlayerColor::PLAYER_LIMIT = PlayerColor(PLAYER_LIMIT_I);
 const TeamID TeamID::NO_TEAM = TeamID(255);
 
+const SpellSchool SpellSchool::ANY = -1;
+const SpellSchool SpellSchool::AIR = 0;
+const SpellSchool SpellSchool::FIRE = 1;
+const SpellSchool SpellSchool::WATER = 2;
+const SpellSchool SpellSchool::EARTH = 3;
+
+const FactionID FactionID::NONE = -2;
+const FactionID FactionID::DEFAULT = -1;
+const FactionID FactionID::RANDOM = -1;
+const FactionID FactionID::ANY = -1;
+const FactionID FactionID::CASTLE = 0;
+const FactionID FactionID::RAMPART = 1;
+const FactionID FactionID::TOWER = 2;
+const FactionID FactionID::INFERNO = 3;
+const FactionID FactionID::NECROPOLIS = 4;
+const FactionID FactionID::DUNGEON = 5;
+const FactionID FactionID::STRONGHOLD = 6;
+const FactionID FactionID::FORTRESS = 7;
+const FactionID FactionID::CONFLUX = 8;
+const FactionID FactionID::NEUTRAL = 9;
+
+const BoatId BoatId::NONE = -1;
+const BoatId BoatId::NECROPOLIS = 0;
+const BoatId BoatId::CASTLE = 1;
+const BoatId BoatId::FORTRESS = 2;
+
+const RiverId RiverId::NO_RIVER = 0;
+const RiverId RiverId::WATER_RIVER = 1;
+const RiverId RiverId::ICY_RIVER = 2;
+const RiverId RiverId::MUD_RIVER = 3;
+const RiverId RiverId::LAVA_RIVER = 4;
+
+const RoadId RoadId::NO_ROAD = 0;
+const RoadId RoadId::DIRT_ROAD = 1;
+const RoadId RoadId::GRAVEL_ROAD = 2;
+const RoadId RoadId::COBBLESTONE_ROAD = 3;
+
+
 namespace GameConstants
 {
 #ifdef VCMI_NO_EXTRA_VERSION
@@ -192,7 +228,7 @@ std::string PlayerColor::getStrCap(bool L10n) const
 	return ret;
 }
 
-si32 FactionIDBase::decode(const std::string & identifier)
+si32 FactionID::decode(const std::string & identifier)
 {
 	auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), entityType(), identifier);
 	if(rawId)
@@ -201,17 +237,16 @@ si32 FactionIDBase::decode(const std::string & identifier)
 		return FactionID::DEFAULT;
 }
 
-std::string FactionIDBase::encode(const si32 index)
+std::string FactionID::encode(const si32 index)
 {
 	return VLC->factions()->getByIndex(index)->getJsonKey();
 }
 
-std::string FactionIDBase::entityType()
+std::string FactionID::entityType()
 {
 	return "faction";
 }
 
-
 si32 TerrainIdBase::decode(const std::string & identifier)
 {
 	auto rawId = VLC->identifiers()->getIdentifier(ModScope::scopeGame(), entityType(), identifier);
@@ -231,68 +266,8 @@ std::string TerrainIdBase::entityType()
 	return "terrain";
 }
 
-std::ostream & operator<<(std::ostream & os, const EActionType actionType)
-{
-	static const std::map<EActionType, std::string> actionTypeToString =
-	{
-		{EActionType::END_TACTIC_PHASE, "End tactic phase"},
-		{EActionType::NO_ACTION, "No action"},
-		{EActionType::HERO_SPELL, "Hero spell"},
-		{EActionType::WALK, "Walk"},
-		{EActionType::DEFEND, "Defend"},
-		{EActionType::RETREAT, "Retreat"},
-		{EActionType::SURRENDER, "Surrender"},
-		{EActionType::WALK_AND_ATTACK, "Walk and attack"},
-		{EActionType::SHOOT, "Shoot"},
-		{EActionType::WAIT, "Wait"},
-		{EActionType::CATAPULT, "Catapult"},
-		{EActionType::MONSTER_SPELL, "Monster spell"},
-		{EActionType::BAD_MORALE, "Bad morale"},
-		{EActionType::STACK_HEAL, "Stack heal"},
-	};
-
-	auto it = actionTypeToString.find(actionType);
-	if (it == actionTypeToString.end()) return os << "<Unknown type>";
-	else return os << it->second;
-}
-
-std::ostream & operator<<(std::ostream & os, const EPathfindingLayer & pathfindingLayer)
-{
-	static const std::map<EPathfindingLayer, std::string> pathfinderLayerToString
-	{
-	#define DEFINE_ELEMENT(element) {EPathfindingLayer::element, #element}
-		DEFINE_ELEMENT(WRONG),
-		DEFINE_ELEMENT(AUTO),
-		DEFINE_ELEMENT(LAND),
-		DEFINE_ELEMENT(SAIL),
-		DEFINE_ELEMENT(WATER),
-		DEFINE_ELEMENT(AIR),
-		DEFINE_ELEMENT(NUM_LAYERS)
-	#undef DEFINE_ELEMENT
-	};
-
-	auto it = pathfinderLayerToString.find(pathfindingLayer.num);
-	if (it == pathfinderLayerToString.end()) return os << "<Unknown type>";
-	else return os << it->second;
-}
-
 const BattleField BattleField::NONE;
 
-bool operator==(const BattleField & l, const BattleField & r)
-{
-	return l.num == r.num;
-}
-
-bool operator!=(const BattleField & l, const BattleField & r)
-{
-	return l.num != r.num;
-}
-
-bool operator<(const BattleField & l, const BattleField & r)
-{
-	return l.num < r.num;
-}
-
 const BattleFieldInfo * BattleField::getInfo() const
 {
 	return VLC->battlefields()->getById(*this);

+ 151 - 173
lib/constants/EntityIdentifiers.h

@@ -1,5 +1,5 @@
 /*
- * GameConstants.h, part of VCMI engine
+ * EntityIdentifiers.h, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *
@@ -41,6 +41,8 @@ protected:
 	constexpr IdentifierBase(int32_t value = -1 ):
 		num(value)
 	{}
+
+	~IdentifierBase() = default;
 public:
 	int32_t num;
 
@@ -57,6 +59,16 @@ public:
 		}
 	};
 
+	constexpr void advance(int change)
+	{
+		num += change;
+	}
+
+	constexpr operator int32_t () const
+	{
+		return num;
+	}
+
 	friend std::ostream& operator<<(std::ostream& os, const IdentifierBase& dt)
 	{
 		return os << dt.num;
@@ -69,7 +81,7 @@ public:
 template<typename FinalClass>
 class Identifier : public IdentifierBase
 {
-	using T = IdentifierBase;
+	using BaseClass = IdentifierBase;
 public:
 	constexpr Identifier(int32_t _num = -1)
 		:IdentifierBase(_num)
@@ -77,109 +89,89 @@ public:
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & T::num;
+		h & BaseClass::num;
 	}
 
-	constexpr bool operator == (const Identifier & b) const { return T::num == b.num; }
-	constexpr bool operator <= (const Identifier & b) const { return T::num <= b.num; }
-	constexpr bool operator >= (const Identifier & b) const { return T::num >= b.num; }
-	constexpr bool operator != (const Identifier & b) const { return T::num != b.num; }
-	constexpr bool operator <  (const Identifier & b) const { return T::num <  b.num; }
-	constexpr bool operator >  (const Identifier & b) const { return T::num >  b.num; }
+	constexpr bool operator == (const Identifier & b) const { return BaseClass::num == b.num; }
+	constexpr bool operator <= (const Identifier & b) const { return BaseClass::num <= b.num; }
+	constexpr bool operator >= (const Identifier & b) const { return BaseClass::num >= b.num; }
+	constexpr bool operator != (const Identifier & b) const { return BaseClass::num != b.num; }
+	constexpr bool operator <  (const Identifier & b) const { return BaseClass::num <  b.num; }
+	constexpr bool operator >  (const Identifier & b) const { return BaseClass::num >  b.num; }
 
 	constexpr FinalClass & operator++()
 	{
-		++T::num;
+		++BaseClass::num;
 		return static_cast<FinalClass&>(*this);
 	}
 
 	constexpr FinalClass operator++(int)
 	{
 		FinalClass ret(num);
-		++T::num;
+		++BaseClass::num;
 		return ret;
 	}
-
-	constexpr operator int32_t () const
-	{
-		return T::num;
-	}
-
-	constexpr void advance(int change)
-	{
-		T::num += change;
-	}
 };
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-template<typename T>
-class IdentifierWithEnum : public T
+template<typename FinalClass, typename BaseClass>
+class IdentifierWithEnum : public BaseClass
 {
-	using EnumType = typename T::Type;
+	using EnumType = typename BaseClass::Type;
 
 	static_assert(std::is_same_v<std::underlying_type_t<EnumType>, int32_t>, "Entity Identifier must use int32_t");
 public:
 	constexpr int32_t getNum() const
 	{
-		return T::num;
+		return BaseClass::num;
 	}
 
 	constexpr EnumType toEnum() const
 	{
-		return static_cast<EnumType>(T::num);
+		return static_cast<EnumType>(BaseClass::num);
 	}
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & T::num;
+		h & BaseClass::num;
 	}
 
 	constexpr IdentifierWithEnum(const EnumType & enumValue)
 	{
-		T::num = static_cast<int32_t>(enumValue);
+		BaseClass::num = static_cast<int32_t>(enumValue);
 	}
 
 	constexpr IdentifierWithEnum(int32_t _num = -1)
 	{
-		T::num = _num;
+		BaseClass::num = _num;
 	}
 
-	constexpr void advance(int change)
-	{
-		T::num += change;
-	}
+	constexpr bool operator == (const EnumType & b) const { return BaseClass::num == static_cast<int32_t>(b); }
+	constexpr bool operator <= (const EnumType & b) const { return BaseClass::num <= static_cast<int32_t>(b); }
+	constexpr bool operator >= (const EnumType & b) const { return BaseClass::num >= static_cast<int32_t>(b); }
+	constexpr bool operator != (const EnumType & b) const { return BaseClass::num != static_cast<int32_t>(b); }
+	constexpr bool operator <  (const EnumType & b) const { return BaseClass::num <  static_cast<int32_t>(b); }
+	constexpr bool operator >  (const EnumType & b) const { return BaseClass::num >  static_cast<int32_t>(b); }
 
-	constexpr bool operator == (const EnumType & b) const { return T::num == static_cast<int32_t>(b); }
-	constexpr bool operator <= (const EnumType & b) const { return T::num <= static_cast<int32_t>(b); }
-	constexpr bool operator >= (const EnumType & b) const { return T::num >= static_cast<int32_t>(b); }
-	constexpr bool operator != (const EnumType & b) const { return T::num != static_cast<int32_t>(b); }
-	constexpr bool operator <  (const EnumType & b) const { return T::num <  static_cast<int32_t>(b); }
-	constexpr bool operator >  (const EnumType & b) const { return T::num >  static_cast<int32_t>(b); }
-
-	constexpr bool operator == (const IdentifierWithEnum & b) const { return T::num == b.num; }
-	constexpr bool operator <= (const IdentifierWithEnum & b) const { return T::num <= b.num; }
-	constexpr bool operator >= (const IdentifierWithEnum & b) const { return T::num >= b.num; }
-	constexpr bool operator != (const IdentifierWithEnum & b) const { return T::num != b.num; }
-	constexpr bool operator <  (const IdentifierWithEnum & b) const { return T::num <  b.num; }
-	constexpr bool operator >  (const IdentifierWithEnum & b) const { return T::num >  b.num; }
-
-	constexpr IdentifierWithEnum & operator++()
-	{
-		++T::num;
-		return *this;
-	}
+	constexpr bool operator == (const IdentifierWithEnum & b) const { return BaseClass::num == b.num; }
+	constexpr bool operator <= (const IdentifierWithEnum & b) const { return BaseClass::num <= b.num; }
+	constexpr bool operator >= (const IdentifierWithEnum & b) const { return BaseClass::num >= b.num; }
+	constexpr bool operator != (const IdentifierWithEnum & b) const { return BaseClass::num != b.num; }
+	constexpr bool operator <  (const IdentifierWithEnum & b) const { return BaseClass::num <  b.num; }
+	constexpr bool operator >  (const IdentifierWithEnum & b) const { return BaseClass::num >  b.num; }
 
-	constexpr IdentifierWithEnum operator++(int)
+	constexpr FinalClass & operator++()
 	{
-		IdentifierWithEnum ret(*this);
-		++T::num;
-		return ret;
+		++BaseClass::num;
+		return static_cast<FinalClass&>(*this);
 	}
 
-	constexpr operator int32_t () const
+	constexpr FinalClass operator++(int)
 	{
-		return T::num;
+		FinalClass ret(BaseClass::num);
+		++BaseClass::num;
+		return ret;
 	}
 };
 
@@ -284,54 +276,70 @@ public:
 	{
 		WRONG = -2,
 		DEFAULT = -1,
-		PATHFINDING = 0, ARCHERY, LOGISTICS, SCOUTING, DIPLOMACY, NAVIGATION, LEADERSHIP, WISDOM, MYSTICISM,
-		LUCK, BALLISTICS, EAGLE_EYE, NECROMANCY, ESTATES, FIRE_MAGIC, AIR_MAGIC, WATER_MAGIC, EARTH_MAGIC,
-		SCHOLAR, TACTICS, ARTILLERY, LEARNING, OFFENCE, ARMORER, INTELLIGENCE, SORCERY, RESISTANCE,
-		FIRST_AID, SKILL_SIZE
+		PATHFINDING = 0,
+		ARCHERY,
+		LOGISTICS,
+		SCOUTING,
+		DIPLOMACY,
+		NAVIGATION,
+		LEADERSHIP,
+		WISDOM,
+		MYSTICISM,
+		LUCK,
+		BALLISTICS,
+		EAGLE_EYE,
+		NECROMANCY,
+		ESTATES,
+		FIRE_MAGIC,
+		AIR_MAGIC,
+		WATER_MAGIC,
+		EARTH_MAGIC,
+		SCHOLAR,
+		TACTICS,
+		ARTILLERY,
+		LEARNING,
+		OFFENCE,
+		ARMORER,
+		INTELLIGENCE,
+		SORCERY,
+		RESISTANCE,
+		FIRST_AID,
+		SKILL_SIZE
 	};
 	static_assert(GameConstants::SKILL_QUANTITY == SKILL_SIZE, "Incorrect number of skills");
 };
 
-class SecondarySkill : public IdentifierWithEnum<SecondarySkillBase>
+class SecondarySkill : public IdentifierWithEnum<SecondarySkill, SecondarySkillBase>
 {
 public:
-	using IdentifierWithEnum<SecondarySkillBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<SecondarySkill, SecondarySkillBase>::IdentifierWithEnum;
 };
 
-class FactionIDBase : public IdentifierBase
+class DLL_LINKAGE FactionID : public Identifier<FactionID>
 {
 public:
-	enum Type : int32_t
-	{
-		NONE = -2,
-		DEFAULT = -1,
-		RANDOM = -1,
-		ANY = -1,
-		CASTLE,
-		RAMPART,
-		TOWER,
-		INFERNO,
-		NECROPOLIS,
-		DUNGEON,
-		STRONGHOLD,
-		FORTRESS,
-		CONFLUX,
-		NEUTRAL
-	};
+	using Identifier<FactionID>::Identifier;
+
+	static const FactionID NONE;
+	static const FactionID DEFAULT;
+	static const FactionID RANDOM;
+	static const FactionID ANY;
+	static const FactionID CASTLE;
+	static const FactionID RAMPART;
+	static const FactionID TOWER;
+	static const FactionID INFERNO;
+	static const FactionID NECROPOLIS;
+	static const FactionID DUNGEON;
+	static const FactionID STRONGHOLD;
+	static const FactionID FORTRESS;
+	static const FactionID CONFLUX;
+	static const FactionID NEUTRAL;
 
 	static si32 decode(const std::string& identifier);
 	static std::string encode(const si32 index);
 	static std::string entityType();
 };
 
-class FactionID : public IdentifierWithEnum<FactionIDBase>
-{
-public:
-	using IdentifierWithEnum<FactionIDBase>::IdentifierWithEnum;
-};
-
-using ETownType = FactionID;
-
 class BuildingIDBase : public IdentifierBase
 {
 public:
@@ -379,10 +387,10 @@ public:
 	}
 };
 
-class BuildingID : public IdentifierWithEnum<BuildingIDBase>
+class BuildingID : public IdentifierWithEnum<BuildingID, BuildingIDBase>
 {
 public:
-	using IdentifierWithEnum<BuildingIDBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<BuildingID, BuildingIDBase>::IdentifierWithEnum;
 };
 
 class ObjBase : public IdentifierBase
@@ -530,56 +538,35 @@ public:
 	};
 };
 
-class Obj : public IdentifierWithEnum<ObjBase>
+class Obj : public IdentifierWithEnum<Obj, ObjBase>
 {
 public:
-	using IdentifierWithEnum<ObjBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<Obj, ObjBase>::IdentifierWithEnum;
 };
 
-class RoadIdBase : public IdentifierBase
+class DLL_LINKAGE RoadId : public Identifier<RoadId>
 {
 public:
-	enum Type : int32_t
-	{
-		NO_ROAD = 0,
-		FIRST_REGULAR_ROAD = 1,
-		DIRT_ROAD = 1,
-		GRAVEL_ROAD = 2,
-		COBBLESTONE_ROAD = 3,
-		ORIGINAL_ROAD_COUNT //+1
-	};
-};
+	using Identifier<RoadId>::Identifier;
 
-class RoadId : public IdentifierWithEnum<RoadIdBase>
-{
-public:
-	using IdentifierWithEnum<RoadIdBase>::IdentifierWithEnum;
+	static const RoadId NO_ROAD;
+	static const RoadId DIRT_ROAD;
+	static const RoadId GRAVEL_ROAD;
+	static const RoadId COBBLESTONE_ROAD;
 };
 
-class RiverIdBase : public IdentifierBase
+class DLL_LINKAGE RiverId : public Identifier<RiverId>
 {
 public:
-	enum Type : int32_t
-	{
-		NO_RIVER = 0,
-		FIRST_REGULAR_RIVER = 1,
-		WATER_RIVER = 1,
-		ICY_RIVER = 2,
-		MUD_RIVER = 3,
-		LAVA_RIVER = 4,
-		ORIGINAL_RIVER_COUNT //+1
-	};
-};
+	using Identifier<RiverId>::Identifier;
 
-class RiverId : public IdentifierWithEnum<RiverIdBase>
-{
-public:
-	using IdentifierWithEnum<RiverIdBase>::IdentifierWithEnum;
+	static const RiverId NO_RIVER;
+	static const RiverId WATER_RIVER;
+	static const RiverId ICY_RIVER;
+	static const RiverId MUD_RIVER;
+	static const RiverId LAVA_RIVER;
 };
 
-using River = RiverId;
-using Road = RoadId;
-
 class DLL_LINKAGE EPathfindingLayerBase : public IdentifierBase
 {
 public:
@@ -589,10 +576,10 @@ public:
 	};
 };
 
-class EPathfindingLayer : public IdentifierWithEnum<EPathfindingLayerBase>
+class EPathfindingLayer : public IdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>
 {
 public:
-	using IdentifierWithEnum<EPathfindingLayerBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<EPathfindingLayer, EPathfindingLayerBase>::IdentifierWithEnum;
 };
 
 class ArtifactPositionBase : public IdentifierBase
@@ -622,10 +609,10 @@ public:
 	static std::string encode(const si32 index);
 };
 
-class ArtifactPosition : public IdentifierWithEnum<ArtifactPositionBase>
+class ArtifactPosition : public IdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>
 {
 public:
-	using IdentifierWithEnum<ArtifactPositionBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<ArtifactPosition, ArtifactPositionBase>::IdentifierWithEnum;
 };
 
 class ArtifactIDBase : public IdentifierBase
@@ -656,10 +643,10 @@ public:
 	static std::string encode(const si32 index);
 };
 
-class ArtifactID : public IdentifierWithEnum<ArtifactIDBase>
+class ArtifactID : public IdentifierWithEnum<ArtifactID, ArtifactIDBase>
 {
 public:
-	using IdentifierWithEnum<ArtifactIDBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<ArtifactID, ArtifactIDBase>::IdentifierWithEnum;
 };
 
 class CreatureIDBase : public IdentifierBase
@@ -695,10 +682,10 @@ public:
 	static std::string encode(const si32 index);
 };
 
-class CreatureID : public IdentifierWithEnum<CreatureIDBase>
+class CreatureID : public IdentifierWithEnum<CreatureID, CreatureIDBase>
 {
 public:
-	using IdentifierWithEnum<CreatureIDBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<CreatureID, CreatureIDBase>::IdentifierWithEnum;
 };
 
 class SpellIDBase : public IdentifierBase
@@ -812,10 +799,10 @@ public:
 	static std::string encode(const si32 index);
 };
 
-class SpellID : public IdentifierWithEnum<SpellIDBase>
+class SpellID : public IdentifierWithEnum<SpellID, SpellIDBase>
 {
 public:
-	using IdentifierWithEnum<SpellIDBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<SpellID, SpellIDBase>::IdentifierWithEnum;
 };
 
 class BattleFieldInfo;
@@ -828,22 +815,15 @@ public:
 	DLL_LINKAGE const BattleFieldInfo * getInfo() const;
 };
 
-class BoatIdBase : public IdentifierBase
+class DLL_LINKAGE BoatId : public Identifier<BoatId>
 {
 public:
-	enum Type : int32_t
-	{
-		NONE = -1,
-		NECROPOLIS = 0,
-		CASTLE,
-		FORTRESS
-	};
-};
+	using Identifier<BoatId>::Identifier;
 
-class BoatId : public IdentifierWithEnum<BoatIdBase>
-{
-public:
-	using IdentifierWithEnum<BoatIdBase>::IdentifierWithEnum;
+	static const BoatId NONE;
+	static const BoatId NECROPOLIS;
+	static const BoatId CASTLE;
+	static const BoatId FORTRESS;
 };
 
 class TerrainIdBase : public IdentifierBase
@@ -873,14 +853,12 @@ public:
 	static std::string entityType();
 };
 
-class TerrainId : public IdentifierWithEnum<TerrainIdBase>
+class TerrainId : public IdentifierWithEnum<TerrainId, TerrainIdBase>
 {
 public:
-	using IdentifierWithEnum<TerrainIdBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<TerrainId, TerrainIdBase>::IdentifierWithEnum;
 };
 
-using ETerrainId = TerrainId;
-
 class ObstacleInfo;
 class Obstacle : public Identifier<Obstacle>
 {
@@ -889,27 +867,18 @@ public:
 	DLL_LINKAGE const ObstacleInfo * getInfo() const;
 };
 
-class SpellSchoolBase : public IdentifierBase
+class DLL_LINKAGE SpellSchool : public Identifier<SpellSchool>
 {
 public:
-	enum Type : int32_t
-	{
-		ANY 	= -1,
-		AIR 	= 0,
-		FIRE 	= 1,
-		WATER 	= 2,
-		EARTH 	= 3,
-	};
-};
+	using Identifier<SpellSchool>::Identifier;
 
-class SpellSchool : public IdentifierWithEnum<SpellSchoolBase>
-{
-public:
-	using IdentifierWithEnum<SpellSchoolBase>::IdentifierWithEnum;
+	static const SpellSchool ANY;
+	static const SpellSchool AIR;
+	static const SpellSchool FIRE;
+	static const SpellSchool WATER;
+	static const SpellSchool EARTH;
 };
 
-using ESpellSchool = SpellSchool;
-
 class GameResIDBase : public IdentifierBase
 {
 public:
@@ -930,12 +899,21 @@ public:
 	};
 };
 
-class GameResID : public IdentifierWithEnum<GameResIDBase>
+class GameResID : public IdentifierWithEnum<GameResID, GameResIDBase>
 {
 public:
-	using IdentifierWithEnum<GameResIDBase>::IdentifierWithEnum;
+	using IdentifierWithEnum<GameResID, GameResIDBase>::IdentifierWithEnum;
 };
 
+// Deprecated
+// TODO: remove
+using ESpellSchool = SpellSchool;
+using ETownType = FactionID;
 using EGameResID = GameResID;
+using River = RiverId;
+using Road = RoadId;
+using ETerrainId = TerrainId;
+
+
 
 VCMI_LIB_NAMESPACE_END

+ 1 - 1
lib/constants/Enumerations.h

@@ -1,5 +1,5 @@
 /*
- * GameConstants.h, part of VCMI engine
+ * Enumerations.h, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *

+ 1 - 1
lib/constants/NumericConstants.h

@@ -1,5 +1,5 @@
 /*
- * GameConstants.h, part of VCMI engine
+ * NumericConstants.h, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *

+ 2 - 0
lib/mapping/MapFeaturesH3M.cpp

@@ -58,6 +58,8 @@ MapFormatFeaturesH3M MapFormatFeaturesH3M::getFeaturesROE()
 	result.terrainsCount = 10;
 	result.artifactSlotsCount = 18;
 	result.buildingsCount = 41;
+	result.roadsCount = 3;
+	result.riversCount = 4;
 
 	result.heroIdentifierInvalid = 0xff;
 	result.artifactIdentifierInvalid = 0xff;

+ 2 - 0
lib/mapping/MapFeaturesH3M.h

@@ -47,6 +47,8 @@ public:
 	int spellsCount;
 	int skillsCount;
 	int terrainsCount;
+	int roadsCount;
+	int riversCount;
 	int artifactSlotsCount;
 	int buildingsCount;
 

+ 2 - 2
lib/mapping/MapReaderH3M.cpp

@@ -147,14 +147,14 @@ TerrainId MapReaderH3M::readTerrain()
 RoadId MapReaderH3M::readRoad()
 {
 	RoadId result(readInt8());
-	assert(result < Road::ORIGINAL_ROAD_COUNT);
+	assert(result.getNum() < features.roadsCount);
 	return result;
 }
 
 RiverId MapReaderH3M::readRiver()
 {
 	RiverId result(readInt8());
-	assert(result < River::ORIGINAL_RIVER_COUNT);
+	assert(result.getNum() < features.riversCount);
 	return result;
 }