From c0c336500955a23e344651e5412c9d9d441ef4ee Mon Sep 17 00:00:00 2001 From: Ash Wolf Date: Wed, 28 Jun 2023 22:22:32 +0100 Subject: first pass of T2DLL --- src/T2DLL/UT2Utils.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'src/T2DLL/UT2Utils.cpp') diff --git a/src/T2DLL/UT2Utils.cpp b/src/T2DLL/UT2Utils.cpp index 281ec30..3af844f 100644 --- a/src/T2DLL/UT2Utils.cpp +++ b/src/T2DLL/UT2Utils.cpp @@ -1,13 +1,53 @@ #include "UT2Utils.h" -/*static*/ unsigned int UT2Utils::Float2Int(float) { +/*static*/ unsigned int UT2Utils::Float2Int(float inValue) { + unsigned int result = 0; + + if (inValue > 0.0f) { + result = inValue; + unsigned int decimal = (inValue - result) * 10.0f; + if (decimal > 0 && Randomize(10) < decimal) + result++; + } + + return result; } -/*static*/ void UT2Utils::GetRoomNumberString(int, CString&) { +/*static*/ void UT2Utils::GetRoomNumberString(int inNumber, CString& outStr) { + outStr.Format("%d", inNumber); + if (outStr.GetAt(0) == '-') + outStr.SetAt(0, 'B'); } -/*static*/ void UT2Utils::GetHourMinute(int, int&, int&) { +/*static*/ void UT2Utils::GetHourMinute(int inValue, int& outHour, int& outMinute) { + outHour = inValue / 60; + outMinute = inValue % 60; } -/*static*/ void UT2Utils::GetMonetaryString(int, CString&) { +/*static*/ void UT2Utils::GetMonetaryString(int inValue, CString& outStr) { + BOOL isNegative = false; + if (inValue < 0) { + isNegative = true; + inValue = -inValue; + } + + outStr.Format("%d", inValue); + + int len = outStr.GetLength(); + if (len > 3) { + int numExtraDigits = len % 3; + int numGroups = len / 3; + if (numExtraDigits == 0) { + numExtraDigits = 3; + numGroups--; + } + + for (int i = 0; i < numGroups; i++) { + int offset = numExtraDigits + (i * 3) + i; + outStr = outStr.Left(offset) + "," + outStr.Mid(offset); + } + } + + if (isNegative) + outStr = "-" + outStr; } -- cgit v1.2.3