mirror of
https://github.com/1dot13/source.git
synced 2026-09-02 14:36:06 +02:00
Adjust constructors
This commit is contained in:
@@ -387,13 +387,13 @@ typedef struct SoldierID
|
|||||||
// TODO: Remove once SoldierID is used everywhere and these are no longer needed
|
// TODO: Remove once SoldierID is used everywhere and these are no longer needed
|
||||||
inline operator UINT16() const { return i; }
|
inline operator UINT16() const { return i; }
|
||||||
|
|
||||||
SoldierID(const UINT16 val = TOTAL_SOLDIERS) : i(val)
|
constexpr SoldierID(const UINT16 val = TOTAL_SOLDIERS) : i(val)
|
||||||
{
|
{
|
||||||
// Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid
|
// Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid
|
||||||
if ( i > TOTAL_SOLDIERS )
|
if ( i > TOTAL_SOLDIERS )
|
||||||
i = TOTAL_SOLDIERS;
|
i = TOTAL_SOLDIERS;
|
||||||
}
|
}
|
||||||
SoldierID( const UINT32 val ) : i( val )
|
constexpr SoldierID( const UINT32 val ) : i( val )
|
||||||
{
|
{
|
||||||
// Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid
|
// Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid
|
||||||
if ( i > TOTAL_SOLDIERS )
|
if ( i > TOTAL_SOLDIERS )
|
||||||
@@ -402,7 +402,7 @@ typedef struct SoldierID
|
|||||||
constexpr SoldierID( const INT32 val ) : i( val )
|
constexpr SoldierID( const INT32 val ) : i( val )
|
||||||
{
|
{
|
||||||
// Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid
|
// Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid
|
||||||
if ( i > TOTAL_SOLDIERS )
|
if ( i > TOTAL_SOLDIERS || i < 0)
|
||||||
i = TOTAL_SOLDIERS;
|
i = TOTAL_SOLDIERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,6 +486,5 @@ inline SoldierID operator+(const unsigned int lhs, const SoldierID rhs) { return
|
|||||||
inline SoldierID operator+(const INT16 lhs, const SoldierID rhs) { return SoldierID{ static_cast<UINT16>(lhs + rhs.i) }; }
|
inline SoldierID operator+(const INT16 lhs, const SoldierID rhs) { return SoldierID{ static_cast<UINT16>(lhs + rhs.i) }; }
|
||||||
|
|
||||||
|
|
||||||
//TODO: Change this to constexpr after SoldierID is ready and the user defined constructor from uint16 is not needed anymore.
|
|
||||||
inline constexpr SoldierID NOBODY{ TOTAL_SOLDIERS };
|
inline constexpr SoldierID NOBODY{ TOTAL_SOLDIERS };
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user