From 191af4da49dff68cb3be738f1b66e5394986ce58 Mon Sep 17 00:00:00 2001 From: Asdow <20314541+Asdow@users.noreply.github.com> Date: Mon, 18 Nov 2024 23:38:43 +0200 Subject: [PATCH] Update SoldierID constructors --- Tactical/Overhead Types.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Tactical/Overhead Types.h b/Tactical/Overhead Types.h index eb1a8571..2f0f548c 100644 --- a/Tactical/Overhead Types.h +++ b/Tactical/Overhead Types.h @@ -386,14 +386,31 @@ typedef struct SoldierID // Implicit conversion and constructor to provide compatibility with unchanged code // TODO: Remove once SoldierID is used everywhere and these are no longer needed inline operator UINT16() const { return i; } - SoldierID(const UINT16 val = 0) - : i(val) + + 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 ) + { + // Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid + if ( i > TOTAL_SOLDIERS ) + i = TOTAL_SOLDIERS; + } + SoldierID ( const INT32 val ) : i ( val ) { // Limit the maximum value to TOTAL_SOLDIERS. Anything beyond that is invalid if ( i > TOTAL_SOLDIERS ) i = TOTAL_SOLDIERS; } + // No conversions from 8-bit integers! + SoldierID ( const UINT8 ) = delete; + SoldierID ( const INT8 ) = delete; + + SOLDIERTYPE* operator->() { return MercPtrs[i]; } const SOLDIERTYPE* operator->() const { return MercPtrs[i]; } inline operator SOLDIERTYPE* () { return MercPtrs[i]; }