mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Terrain/Road/River handler are now in compileable state
This commit is contained in:
@@ -149,12 +149,6 @@ STRONG_INLINE bool operator>=(const A & a, const B & b) \
|
||||
ID_LIKE_OPERATORS_INTERNAL(ENUM_NAME, CLASS_NAME, a, b.num)
|
||||
|
||||
|
||||
#define OP_DECL_INT(CLASS_NAME, OP) \
|
||||
bool operator OP (const CLASS_NAME & b) const \
|
||||
{ \
|
||||
return num OP b.num; \
|
||||
}
|
||||
|
||||
#define INSTID_LIKE_CLASS_COMMON(CLASS_NAME, NUMERIC_NAME) \
|
||||
public: \
|
||||
CLASS_NAME() : BaseForID<CLASS_NAME, NUMERIC_NAME>(-1) {} \
|
||||
@@ -205,14 +199,79 @@ public:
|
||||
}
|
||||
|
||||
typedef BaseForID<Derived, NumericType> __SelfType;
|
||||
OP_DECL_INT(__SelfType, ==)
|
||||
OP_DECL_INT(__SelfType, !=)
|
||||
OP_DECL_INT(__SelfType, <)
|
||||
OP_DECL_INT(__SelfType, >)
|
||||
OP_DECL_INT(__SelfType, <=)
|
||||
OP_DECL_INT(__SelfType, >=)
|
||||
bool operator == (const BaseForID & b) const { return num == b.num; }
|
||||
bool operator <= (const BaseForID & b) const { return num >= b.num; }
|
||||
bool operator >= (const BaseForID & b) const { return num <= b.num; }
|
||||
bool operator != (const BaseForID & b) const { return num != b.num; }
|
||||
bool operator < (const BaseForID & b) const { return num < b.num; }
|
||||
bool operator > (const BaseForID & b) const { return num > b.num; }
|
||||
|
||||
BaseForID & operator++() { ++num; return *this; }
|
||||
};
|
||||
|
||||
template < typename T>
|
||||
class Identifier : public IdTag
|
||||
{
|
||||
public:
|
||||
using EnumType = T;
|
||||
using NumericType = typename std::underlying_type<EnumType>::type;
|
||||
|
||||
private:
|
||||
NumericType num;
|
||||
|
||||
public:
|
||||
NumericType getNum() const
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
EnumType toEnum() const
|
||||
{
|
||||
return static_cast<EnumType>(num);
|
||||
}
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & num;
|
||||
}
|
||||
|
||||
explicit Identifier(NumericType _num = -1)
|
||||
{
|
||||
num = _num;
|
||||
}
|
||||
|
||||
/* implicit */ Identifier(EnumType _num)
|
||||
{
|
||||
num = static_cast<NumericType>(_num);
|
||||
}
|
||||
|
||||
void advance(int change)
|
||||
{
|
||||
num += change;
|
||||
}
|
||||
|
||||
bool operator == (const Identifier & b) const { return num == b.num; }
|
||||
bool operator <= (const Identifier & b) const { return num >= b.num; }
|
||||
bool operator >= (const Identifier & b) const { return num <= b.num; }
|
||||
bool operator != (const Identifier & b) const { return num != b.num; }
|
||||
bool operator < (const Identifier & b) const { return num < b.num; }
|
||||
bool operator > (const Identifier & b) const { return num > b.num; }
|
||||
|
||||
Identifier & operator++()
|
||||
{
|
||||
++num;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Identifier operator++(int)
|
||||
{
|
||||
Identifier ret(*this);
|
||||
++num;
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename Der, typename Num>
|
||||
std::ostream & operator << (std::ostream & os, BaseForID<Der, Num> id);
|
||||
|
||||
@@ -224,6 +283,14 @@ std::ostream & operator << (std::ostream & os, BaseForID<Der, Num> id)
|
||||
return os << static_cast<Number>(id.getNum());
|
||||
}
|
||||
|
||||
template<typename EnumType>
|
||||
std::ostream & operator << (std::ostream & os, Identifier<EnumType> id)
|
||||
{
|
||||
//We use common type with short to force char and unsigned char to be promoted and formatted as numbers.
|
||||
typedef typename std::common_type<short, typename Identifier<EnumType>::NumericType>::type Number;
|
||||
return os << static_cast<Number>(id.getNum());
|
||||
}
|
||||
|
||||
class ArtifactInstanceID : public BaseForID<ArtifactInstanceID, si32>
|
||||
{
|
||||
INSTID_LIKE_CLASS_COMMON(ArtifactInstanceID, si32)
|
||||
@@ -830,32 +897,26 @@ public:
|
||||
|
||||
ID_LIKE_OPERATORS(Obj, Obj::EObj)
|
||||
|
||||
namespace Road
|
||||
enum class Road : int8_t
|
||||
{
|
||||
enum ERoad : ui8
|
||||
{
|
||||
NO_ROAD = 0,
|
||||
FIRST_REGULAR_ROAD = 1,
|
||||
DIRT_ROAD = 1,
|
||||
GRAVEL_ROAD = 2,
|
||||
COBBLESTONE_ROAD = 3,
|
||||
ORIGINAL_ROAD_COUNT //+1
|
||||
};
|
||||
}
|
||||
NO_ROAD = 0,
|
||||
FIRST_REGULAR_ROAD = 1,
|
||||
DIRT_ROAD = 1,
|
||||
GRAVEL_ROAD = 2,
|
||||
COBBLESTONE_ROAD = 3,
|
||||
ORIGINAL_ROAD_COUNT //+1
|
||||
};
|
||||
|
||||
namespace River
|
||||
enum class River : int8_t
|
||||
{
|
||||
enum ERiver : ui8
|
||||
{
|
||||
NO_RIVER = 0,
|
||||
FIRST_REGULAR_RIVER = 1,
|
||||
WATER_RIVER = 1,
|
||||
ICY_RIVER = 2,
|
||||
MUD_RIVER = 3,
|
||||
LAVA_RIVER = 4,
|
||||
ORIGINAL_RIVER_COUNT //+1
|
||||
};
|
||||
}
|
||||
NO_RIVER = 0,
|
||||
FIRST_REGULAR_RIVER = 1,
|
||||
WATER_RIVER = 1,
|
||||
ICY_RIVER = 2,
|
||||
MUD_RIVER = 3,
|
||||
LAVA_RIVER = 4,
|
||||
ORIGINAL_RIVER_COUNT //+1
|
||||
};
|
||||
|
||||
namespace SecSkillLevel
|
||||
{
|
||||
@@ -1159,48 +1220,28 @@ class BattleField : public BaseForID<BattleField, si32>
|
||||
DLL_LINKAGE static BattleField fromString(std::string identifier);
|
||||
};
|
||||
|
||||
class TerrainId
|
||||
{
|
||||
public:
|
||||
enum ETerrainID {
|
||||
NATIVE_TERRAIN = -4,
|
||||
ANY_TERRAIN = -3,
|
||||
WRONG = -2,
|
||||
BORDER = -1,
|
||||
FIRST_REGULAR_TERRAIN = 0,
|
||||
DIRT,
|
||||
SAND,
|
||||
GRASS,
|
||||
SNOW,
|
||||
SWAMP,
|
||||
ROUGH,
|
||||
SUBTERRANEAN,
|
||||
LAVA,
|
||||
WATER,
|
||||
ROCK,
|
||||
ORIGINAL_TERRAIN_COUNT
|
||||
};
|
||||
|
||||
TerrainId(ETerrainID _num = WRONG) : num(_num)
|
||||
{}
|
||||
|
||||
ETerrainID num;
|
||||
|
||||
ID_LIKE_CLASS_COMMON(TerrainId, ETerrainID)
|
||||
|
||||
DLL_LINKAGE operator std::string() const;
|
||||
DLL_LINKAGE const TerrainId * getInfo() const;
|
||||
|
||||
DLL_LINKAGE static ETerrainID fromString(std::string identifier);
|
||||
|
||||
TerrainId & operator++()
|
||||
{
|
||||
num = static_cast<ETerrainID>(static_cast<int>(num) + 1);
|
||||
return *this;
|
||||
}
|
||||
enum class ETerrainId {
|
||||
NATIVE_TERRAIN = -4,
|
||||
ANY_TERRAIN = -3,
|
||||
WRONG = -2,
|
||||
BORDER = -1,
|
||||
FIRST_REGULAR_TERRAIN = 0,
|
||||
DIRT,
|
||||
SAND,
|
||||
GRASS,
|
||||
SNOW,
|
||||
SWAMP,
|
||||
ROUGH,
|
||||
SUBTERRANEAN,
|
||||
LAVA,
|
||||
WATER,
|
||||
ROCK,
|
||||
ORIGINAL_TERRAIN_COUNT
|
||||
};
|
||||
|
||||
ID_LIKE_OPERATORS(TerrainId, TerrainId::ETerrainID)
|
||||
using TerrainId = Identifier<ETerrainId>;
|
||||
using RoadId = Identifier<Road>;
|
||||
using RiverId = Identifier<River>;
|
||||
|
||||
class ObstacleInfo;
|
||||
class Obstacle : public BaseForID<Obstacle, si32>
|
||||
@@ -1259,9 +1300,6 @@ typedef si64 TExpType;
|
||||
typedef std::pair<si64, si64> TDmgRange;
|
||||
typedef si32 TBonusSubtype;
|
||||
typedef si32 TQuantity;
|
||||
//typedef si8 TerrainId;
|
||||
typedef si8 RoadId;
|
||||
typedef si8 RiverId;
|
||||
|
||||
typedef int TRmgTemplateZoneId;
|
||||
|
||||
@@ -1269,6 +1307,5 @@ typedef int TRmgTemplateZoneId;
|
||||
#undef ID_LIKE_OPERATORS
|
||||
#undef ID_LIKE_OPERATORS_INTERNAL
|
||||
#undef INSTID_LIKE_CLASS_COMMON
|
||||
#undef OP_DECL_INT
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
||||
|
||||
Reference in New Issue
Block a user