From b3b3270e1e5ae3e4cd425e9bb74cfd94ed7eb6f8 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Fri, 27 Jun 2025 19:59:01 +0300 Subject: [PATCH] Adjust constructors --- Tactical/Overhead Types.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Tactical/Overhead Types.h b/Tactical/Overhead Types.h index 65e6ec04..02845695 100644 --- a/Tactical/Overhead Types.h +++ b/Tactical/Overhead Types.h @@ -387,13 +387,13 @@ typedef struct SoldierID // TODO: Remove once SoldierID is used everywhere and these are no longer needed 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 if ( 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 if ( i > TOTAL_SOLDIERS ) @@ -402,7 +402,7 @@ typedef struct SoldierID constexpr SoldierID( const INT32 val ) : i( val ) { // 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; } @@ -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(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 }; #endif