src/strings.cpp
changeset 10134 9a2cfea36caf
parent 9286 d446bf9f4a68
child 10229 fba3f9fa44d7
--- a/src/strings.cpp	Sat Apr 12 09:59:58 2008 +0000
+++ b/src/strings.cpp	Sat Apr 12 10:00:52 2008 +0000
@@ -536,6 +536,26 @@
 	},
 };
 
+/**
+ * Convert the given (internal) speed to the display speed.
+ * @param speed the speed to convert
+ * @return the converted speed.
+ */
+uint ConvertSpeedToDisplaySpeed(uint speed)
+{
+ return (speed * units[_opt_ptr->units].s_m) >> units[_opt_ptr->units].s_s;
+}
+
+/**
+ * Convert the given display speed to the (internal) speed.
+ * @param speed the speed to convert
+ * @return the converted speed.
+ */
+uint ConvertDisplaySpeedToSpeed(uint speed)
+{
+	return ((speed << units[_opt_ptr->units].s_s) + units[_opt_ptr->units].s_m / 2) / units[_opt_ptr->units].s_m;
+}
+
 static char* FormatString(char* buff, const char* str, const int64* argv, uint casei, const char* last)
 {
 	extern const char _openttd_revision[];
@@ -581,7 +601,7 @@
 			case SCC_VELOCITY: {// {VELOCITY}
 				int64 args[1];
 				assert(_opt_ptr->units < lengthof(units));
-				args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s;
+				args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv));
 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24, last);
 				modifier = 0;
 				break;