diff options
author | rubidium <rubidium@openttd.org> | 2008-04-12 10:00:52 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2008-04-12 10:00:52 +0000 |
commit | e9014c99b3e2e1b632236ae6ef9edb3c75cc0f8e (patch) | |
tree | 448abd48d9f99d594097f8d74575889845b0eec9 /src | |
parent | 8226c92c8a6eb6034d0007ad77efbb52c22a4cd8 (diff) | |
download | openttd-e9014c99b3e2e1b632236ae6ef9edb3c75cc0f8e.tar.xz |
(svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
Diffstat (limited to 'src')
-rw-r--r-- | src/strings.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/strings.cpp b/src/strings.cpp index 2fcb7055c..bc6bfff44 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -536,6 +536,26 @@ static const Units units[] = { }, }; +/** + * 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 @@ static char* FormatString(char* buff, const char* str, const int64* argv, uint c 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; |