From 22b4df1a99fa5e4761e02ae373402e01a54596ec Mon Sep 17 00:00:00 2001 From: IntelOrca Date: Fri, 18 Dec 2015 21:11:24 +0000 Subject: [PATCH] implement SI units for distance / speed measurement, closes #2496 --- data/language/english_uk.txt | 2 ++ distribution/changelog.txt | 1 + src/config.c | 1 + src/config.h | 3 ++- src/localisation/localisation.c | 15 ++++++++++++--- src/localisation/string_ids.h | 8 ++++++++ src/util/util.c | 8 +++++++- src/util/util.h | 1 + src/windows/options.c | 17 ++++++++++++++--- src/windows/park.c | 2 +- 10 files changed, 49 insertions(+), 9 deletions(-) diff --git a/data/language/english_uk.txt b/data/language/english_uk.txt index 449cf38521..8d6275d510 100644 --- a/data/language/english_uk.txt +++ b/data/language/english_uk.txt @@ -3921,6 +3921,8 @@ STR_5579 :Window scale factor: STR_5580 :Czech koruna (Kc) STR_5581 :Show FPS STR_5582 :Trap mouse cursor in window +STR_5583 :{COMMA16}ms{POWERNEGATIVEONE} +STR_5584 :SI ##################### # Rides/attractions # diff --git a/distribution/changelog.txt b/distribution/changelog.txt index fe4d44c188..9e01dd71f8 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -2,6 +2,7 @@ ------------------------------------------------------------------------ - Feature: Add displaying of frames per second (FPS). - Feature: Changing the number of trains no longer requires retesting. +- Feature: Add SI units as a new measurement system for distance / speed. - Fix: [#2126] Ferris Wheels set to "backward rotation" stop working (original bug) - Fix: [#2449] Turning off Day/Night Circle while it is night doesn't reset back to day diff --git a/src/config.c b/src/config.c index 77683b1d69..ee8a140678 100644 --- a/src/config.c +++ b/src/config.c @@ -104,6 +104,7 @@ config_enum_definition _screenShotFormatEnum[] = { config_enum_definition _measurementFormatEnum[] = { { "IMPERIAL", MEASUREMENT_FORMAT_IMPERIAL }, { "METRIC", MEASUREMENT_FORMAT_METRIC }, + { "SI", MEASUREMENT_FORMAT_SI }, END_OF_ENUM }; diff --git a/src/config.h b/src/config.h index dc6c5d1259..d0b9dfa72d 100644 --- a/src/config.h +++ b/src/config.h @@ -94,7 +94,8 @@ enum { enum { MEASUREMENT_FORMAT_IMPERIAL, - MEASUREMENT_FORMAT_METRIC + MEASUREMENT_FORMAT_METRIC, + MEASUREMENT_FORMAT_SI }; enum { diff --git a/src/localisation/localisation.c b/src/localisation/localisation.c index 0224efbb10..5e13882fc2 100644 --- a/src/localisation/localisation.c +++ b/src/localisation/localisation.c @@ -450,11 +450,20 @@ void format_length(char **dest, sint16 value) void format_velocity(char **dest, uint16 value) { - rct_string_id stringId = 2734; + rct_string_id stringId; - if (gConfigGeneral.measurement_format == MEASUREMENT_FORMAT_METRIC) { + switch (gConfigGeneral.measurement_format) { + default: + stringId = STR_UNIT_SUFFIX_MILES_PER_HOUR; + break; + case MEASUREMENT_FORMAT_METRIC: value = mph_to_kmph(value); - stringId++; + stringId = STR_UNIT_SUFFIX_KILOMETRES_PER_HOUR; + break; + case MEASUREMENT_FORMAT_SI: + value = mph_to_mps(value); + stringId = STR_UNIT_SUFFIX_METRES_PER_SECOND; + break; } uint16 *argRef = &value; diff --git a/src/localisation/string_ids.h b/src/localisation/string_ids.h index 027107c96b..a684ad72ea 100644 --- a/src/localisation/string_ids.h +++ b/src/localisation/string_ids.h @@ -1407,6 +1407,11 @@ enum { STR_SAVE_EVERY_HOUR = 2705, STR_SAVE_NEVER = 2706, + STR_UNIT_SUFFIX_FEET = 2732, + STR_UNIT_SUFFIX_METRES = 2733, + STR_UNIT_SUFFIX_MILES_PER_HOUR = 2734, + STR_UNIT_SUFFIX_KILOMETRES_PER_HOUR = 2735, + STR_DATE_FORMAT_DMY = 2737, STR_ROLLERCOASTER_TYCOON_1_DROPDOWN = 2740, @@ -2182,6 +2187,9 @@ enum { STR_TRAP_MOUSE = 5582, + STR_UNIT_SUFFIX_METRES_PER_SECOND = 5583, + STR_SI = 5584, + // Have to include resource strings (from scenarios and objects) for the time being now that language is partially working STR_COUNT = 32768 }; diff --git a/src/util/util.c b/src/util/util.c index 890423e0fd..635224fcf1 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -40,7 +40,13 @@ int mph_to_kmph(int mph) { // 1 mph = 1.60934 kmph // RCT2 approximates as 1.609375 - return (mph * 1648) / 1024; + return (mph * 1648) >> 10; +} + +int mph_to_mps(int mph) +{ + // 1 mph = 0.44704 m/s + return (mph * 58594) >> 17; } bool filename_valid_characters(const utf8 *filename) diff --git a/src/util/util.h b/src/util/util.h index 23ea66c2d2..af0be0595b 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -26,6 +26,7 @@ int squaredmetres_to_squaredfeet(int squaredMetres); int metres_to_feet(int metres); int mph_to_kmph(int mph); +int mph_to_mps(int mph); bool filename_valid_characters(const utf8 *filename); diff --git a/src/windows/options.c b/src/windows/options.c index 136cc017ac..692d581ddd 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -830,10 +830,12 @@ static void window_options_mousedown(int widgetIndex, rct_window*w, rct_widget* case WIDX_DISTANCE_DROPDOWN: gDropdownItemsFormat[0] = 1142; gDropdownItemsFormat[1] = 1142; + gDropdownItemsFormat[2] = 1142; gDropdownItemsArgs[0] = STR_IMPERIAL; gDropdownItemsArgs[1] = STR_METRIC; + gDropdownItemsArgs[2] = STR_SI; - window_options_show_dropdown(w, widget, 2); + window_options_show_dropdown(w, widget, 3); dropdown_set_checked(gConfigGeneral.measurement_format, true); break; @@ -1225,8 +1227,17 @@ static void window_options_invalidate(rct_window *w) // currency: pounds, dollars, etc. (10 total) RCT2_GLOBAL(0x013CE952 + 12, uint16) = CurrencyDescriptors[gConfigGeneral.currency_format].stringId; - // distance: metric/imperial - RCT2_GLOBAL(0x013CE952 + 14, uint16) = STR_IMPERIAL + gConfigGeneral.measurement_format; + // distance: metric / imperial / si + { + rct_string_id stringId; + switch (gConfigGeneral.measurement_format) { + default: + case MEASUREMENT_FORMAT_IMPERIAL: stringId = STR_IMPERIAL; break; + case MEASUREMENT_FORMAT_METRIC: stringId = STR_METRIC; break; + case MEASUREMENT_FORMAT_SI: stringId = STR_SI; break; + } + RCT2_GLOBAL(0x013CE952 + 14, uint16) = stringId; + } // temperature: celsius/fahrenheit RCT2_GLOBAL(0x013CE952 + 20, uint16) = STR_CELSIUS + gConfigGeneral.temperature_format; diff --git a/src/windows/park.c b/src/windows/park.c index 91be02ae90..a0db8314c2 100644 --- a/src/windows/park.c +++ b/src/windows/park.c @@ -1585,7 +1585,7 @@ static void window_park_stats_paint(rct_window *w, rct_drawpixelinfo *dpi) // Draw park size parkSize = RCT2_GLOBAL(RCT2_ADDRESS_PARK_SIZE, uint16) * 10; stringIndex = STR_PARK_SIZE_METRIC_LABEL; - if (!RCT2_GLOBAL(RCT2_ADDRESS_CONFIG_METRIC, uint8)) { + if (gConfigGeneral.measurement_format == MEASUREMENT_FORMAT_IMPERIAL) { stringIndex = STR_PARK_SIZE_IMPERIAL_LABEL; parkSize = squaredmetres_to_squaredfeet(parkSize); }