summaryrefslogtreecommitdiff
path: root/src/T2DLL/UT2Utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/UT2Utils.cpp')
-rw-r--r--src/T2DLL/UT2Utils.cpp48
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;
}