diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/UT2Utils.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to 'src/T2DLL/UT2Utils.cpp')
-rw-r--r-- | src/T2DLL/UT2Utils.cpp | 48 |
1 files changed, 44 insertions, 4 deletions
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; } |