(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
authorpeter1138
Sun, 26 Mar 2006 21:50:57 +0000
changeset 3342 0de5e6997611
parent 3341 b8febc9509d7
child 3343 5a2e3526a5bd
(svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
- Replace miles/kilometres game option with a general measuring units option.
- Add {POWER}, {WEIGHT}, {WEIGHT_S} and {VOLUME_S} (_S for short) tags to the language/string system.
- Add SI as option for measuring units.
Language file updates to use the system will come soon.
lang/english.txt
oldloader.c
settings.c
settings_gui.c
strgen/strgen.c
strings.c
variables.h
--- a/lang/english.txt	Sun Mar 26 21:15:09 2006 +0000
+++ b/lang/english.txt	Sun Mar 26 21:50:57 2006 +0000
@@ -278,8 +278,6 @@
 STR_OSNAME_AMIGAOS                                              :AmigaOS
 STR_OSNAME_OS2                                                  :OS/2
 
-STR_0139_IMPERIAL_MILES                                         :Imperial (miles)
-STR_013A_METRIC_KILOMETERS                                      :Metric (kilometers)
 STR_013B_OWNED_BY                                               :{WHITE}...owned by {STRING2}
 STR_013C_CARGO                                                  :{BLACK}Cargo
 STR_013D_INFORMATION                                            :{BLACK}Information
@@ -308,6 +306,34 @@
 STR_0152_TOWN_DIRECTORY                                         :Town directory
 STR_0153_SUBSIDIES                                              :Subsidies
 
+STR_UNITS_IMPERIAL                                              :Imperial
+STR_UNITS_METRIC                                                :Metric
+STR_UNITS_SI                                                    :SI
+
+STR_UNITS_VELOCITY_IMPERIAL                                     :{COMMA} mph
+STR_UNITS_VELOCITY_METRIC                                       :{COMMA} km/h
+STR_UNITS_VELOCITY_SI                                           :{COMMA} m/s
+
+STR_UNITS_POWER_IMPERIAL                                        :{COMMA}hp
+STR_UNITS_POWER_METRIC                                          :{COMMA}hp
+STR_UNITS_POWER_SI                                              :{COMMA}kW
+
+STR_UNITS_WEIGHT_SHORT_IMPERIAL                                 :{COMMA}t
+STR_UNITS_WEIGHT_SHORT_METRIC                                   :{COMMA}t
+STR_UNITS_WEIGHT_SHORT_SI                                       :{COMMA}kg
+
+STR_UNITS_WEIGHT_LONG_IMPERIAL                                  :{COMMA} ton{P "" s}
+STR_UNITS_WEIGHT_LONG_METRIC                                    :{COMMA} tonne{P "" s}
+STR_UNITS_WEIGHT_LONG_SI                                        :{COMMA} kg
+
+STR_UNITS_VOLUME_SHORT_IMPERIAL                                 :{COMMA}gal
+STR_UNITS_VOLUME_SHORT_METRIC                                   :{COMMA}l
+STR_UNITS_VOLUME_SHORT_SI                                       :{COMMA}m³
+
+STR_UNITS_VOLUME_LONG_IMPERIAL                                  :{COMMA} gallon{P "" s}
+STR_UNITS_VOLUME_LONG_METRIC                                    :{COMMA} litre{P "" s}
+STR_UNITS_VOLUME_LONG_SI                                        :{COMMA} m³
+
 ############ range for menu	starts
 STR_0154_OPERATING_PROFIT_GRAPH                                 :Operating profit graph
 STR_0155_INCOME_GRAPH                                           :Income graph
@@ -760,9 +786,9 @@
 STR_02E0_CURRENCY_UNITS                                         :{BLACK}Currency units
 STR_02E1                                                        :{BLACK}{SKIP}{STRING}
 STR_02E2_CURRENCY_UNITS_SELECTION                               :{BLACK}Currency units selection
-STR_02E3_DISTANCE_UNITS                                         :{BLACK}Distance units
+STR_MEASURING_UNITS                                             :{BLACK}Measuring units
 STR_02E4                                                        :{BLACK}{SKIP}{SKIP}{STRING}
-STR_02E5_DISTANCE_UNITS_SELECTION                               :{BLACK}Distance units selection
+STR_MEASURING_UNITS_SELECTION                                   :{BLACK}Measuring units selection
 STR_02E6_ROAD_VEHICLES                                          :{BLACK}Road vehicles
 STR_02E7                                                        :{BLACK}{SKIP}{SKIP}{SKIP}{STRING}
 STR_02E8_SELECT_SIDE_OF_ROAD_FOR                                :{BLACK}Select side of road for vehicles to drive on
--- a/oldloader.c	Sun Mar 26 21:15:09 2006 +0000
+++ b/oldloader.c	Sun Mar 26 21:50:57 2006 +0000
@@ -1495,7 +1495,7 @@
 	OCL_VAR ( OC_FILE_U8 | OC_VAR_U16,    1, &_station_tick_ctr ),
 
 	OCL_VAR (  OC_UINT8,    1, &_opt.currency ),
-	OCL_VAR (  OC_UINT8,    1, &_opt.kilometers ),
+	OCL_VAR (  OC_UINT8,    1, &_opt.units ),
 	OCL_VAR ( OC_FILE_U8 | OC_VAR_U32,    1, &_cur_player_tick_index ),
 
 	OCL_NULL( 2 ),               // Date stuff, calculated automatically
--- a/settings.c	Sun Mar 26 21:15:09 2006 +0000
+++ b/settings.c	Sun Mar 26 21:50:57 2006 +0000
@@ -1127,7 +1127,7 @@
 	SDT_GENERAL("diff_custom", SDT_INTLIST, SL_ARR, (SLE_FILE_I16 | SLE_VAR_I32), 0, 0, GameOptions, diff, 18, 0, 0, 0, NULL, STR_NULL, NULL, 4, SL_MAX_VERSION),
 	    SDT_VAR(GameOptions, diff_level,SLE_UINT8, 0, 0, 9,0, 9, STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, currency,  SLE_UINT8, N, 0, 0,  23, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SEK|custom", STR_NULL, NULL),
-	  SDT_OMANY(GameOptions, kilometers,SLE_UINT8, N, 0, 1,   1, "imperial|metric", STR_NULL, NULL),
+	  SDT_OMANY(GameOptions, units,     SLE_UINT8, N, 0, 1,   2, "imperial|metric|si", STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, town_name, SLE_UINT8, 0, 0, 0,  16, "english|french|german|american|latin|silly|swedish|dutch|finnish|polish|slovakish|norwegian|hungarian|austrian|romanian|czech|swiss", STR_NULL, NULL),
 	  SDT_OMANY(GameOptions, landscape, SLE_UINT8, 0, 0, 0,   3, "normal|hilly|desert|candy", STR_NULL, NULL),
 	    SDT_VAR(GameOptions, snow_line, SLE_UINT8, 0, 0, 1,0,56, STR_NULL, NULL),
--- a/settings_gui.c	Sun Mar 26 21:15:09 2006 +0000
+++ b/settings_gui.c	Sun Mar 26 21:50:57 2006 +0000
@@ -24,9 +24,10 @@
 static uint32 _difficulty_click_b;
 static byte _difficulty_timeout;
 
-static const StringID _distances_dropdown[] = {
-	STR_0139_IMPERIAL_MILES,
-	STR_013A_METRIC_KILOMETERS,
+static const StringID _units_dropdown[] = {
+	STR_UNITS_IMPERIAL,
+	STR_UNITS_METRIC,
+	STR_UNITS_SI,
 	INVALID_STRING_ID
 };
 
@@ -95,7 +96,7 @@
 		w->disabled_state = (_vehicle_design_names & 1) ? (++str, 0) : (1 << 21);
 		SetDParam(0, str);
 		SetDParam(1, _currency_string_list[_opt_ptr->currency]);
-		SetDParam(2, _opt_ptr->kilometers + STR_0139_IMPERIAL_MILES);
+		SetDParam(2, STR_UNITS_IMPERIAL + _opt_ptr->units);
 		SetDParam(3, STR_02E9_DRIVE_ON_LEFT + _opt_ptr->road_side);
 		SetDParam(4, STR_TOWNNAME_ORIGINAL_ENGLISH + _opt_ptr->town_name);
 		SetDParam(5, _autosave_dropdown[_opt_ptr->autosave]);
@@ -115,7 +116,7 @@
 			ShowDropDownMenu(w, _currency_string_list, _opt_ptr->currency, 5, _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies(), 0);
 			return;
 		case 7: case 8: /* Setup distance unit dropdown */
-			ShowDropDownMenu(w, _distances_dropdown, _opt_ptr->kilometers, 8, 0, 0);
+			ShowDropDownMenu(w, _units_dropdown, _opt_ptr->units, 8, 0, 0);
 			return;
 		case 10: case 11: { /* Setup road-side dropdown */
 			int i = 0;
@@ -174,8 +175,8 @@
 			_opt_ptr->currency = e->dropdown.index;
 			MarkWholeScreenDirty();
 			break;
-		case 8: /* Distance units */
-			_opt_ptr->kilometers = e->dropdown.index;
+		case 8: /* Measuring units */
+			_opt_ptr->units = e->dropdown.index;
 			MarkWholeScreenDirty();
 			break;
 		case 11: /* Road side */
@@ -241,9 +242,9 @@
 {      WWT_FRAME,   RESIZE_NONE,    14,    10,   179,    20,    55, STR_02E0_CURRENCY_UNITS,	STR_NULL},
 {          WWT_6,   RESIZE_NONE,    14,    20,   169,    34,    45, STR_02E1,								STR_02E2_CURRENCY_UNITS_SELECTION},
 {    WWT_TEXTBTN,   RESIZE_NONE,    14,   158,   168,    35,    44, STR_0225,								STR_02E2_CURRENCY_UNITS_SELECTION},
-{      WWT_FRAME,   RESIZE_NONE,    14,   190,   359,    20,    55, STR_02E3_DISTANCE_UNITS,	STR_NULL},
-{          WWT_6,   RESIZE_NONE,    14,   200,   349,    34,    45, STR_02E4,								STR_02E5_DISTANCE_UNITS_SELECTION},
-{    WWT_TEXTBTN,   RESIZE_NONE,    14,   338,   348,    35,    44, STR_0225,								STR_02E5_DISTANCE_UNITS_SELECTION},
+{      WWT_FRAME,   RESIZE_NONE,    14,   190,   359,    20,    55, STR_MEASURING_UNITS,		STR_NULL},
+{          WWT_6,   RESIZE_NONE,    14,   200,   349,    34,    45, STR_02E4,								STR_MEASURING_UNITS_SELECTION},
+{    WWT_TEXTBTN,   RESIZE_NONE,    14,   338,   348,    35,    44, STR_0225,								STR_MEASURING_UNITS_SELECTION},
 {      WWT_FRAME,   RESIZE_NONE,    14,    10,   179,    62,    97, STR_02E6_ROAD_VEHICLES,	STR_NULL},
 {          WWT_6,   RESIZE_NONE,    14,    20,   169,    76,    87, STR_02E7,								STR_02E8_SELECT_SIDE_OF_ROAD_FOR},
 {    WWT_TEXTBTN,   RESIZE_NONE,    14,   158,   168,    77,    86, STR_0225,								STR_02E8_SELECT_SIDE_OF_ROAD_FOR},
--- a/strgen/strgen.c	Sun Mar 26 21:15:09 2006 +0000
+++ b/strgen/strgen.c	Sun Mar 26 21:50:57 2006 +0000
@@ -438,6 +438,10 @@
 	{"VOLUME",          EmitEscapedByte, 12, 1, 0},
 	{"DATE_TINY",       EmitEscapedByte, 14, 1, 0},
 	{"CARGO",           EmitEscapedByte, 15, 2, 0},
+	{"POWER",           EmitEscapedByte, 16, 1, 0},
+	{"VOLUME_S",        EmitEscapedByte, 17, 1, 0},
+	{"WEIGHT",          EmitEscapedByte, 18, 1, 0},
+	{"WEIGHT_S",        EmitEscapedByte, 19, 1, 0},
 
 	{"P", EmitPlural, 0, 0, C_DONTCOUNT},					// plural specifier
 	{"G", EmitGender, 0, 0, C_DONTCOUNT},					// gender specifier
--- a/strings.c	Sun Mar 26 21:15:09 2006 +0000
+++ b/strings.c	Sun Mar 26 21:50:57 2006 +0000
@@ -480,6 +480,43 @@
 	return b + pos;
 }
 
+typedef struct Units {
+	int s_m;           ///< Multiplier for velocity
+	int s_s;           ///< Shift for velocity
+	StringID velocity; ///< String for velocity
+	int p_m;           ///< Multiplier for power
+	int p_s;           ///< Shift for power
+	StringID power;    ///< String for velocity
+	int w_m;           ///< Multiplier for weight
+	int w_s;           ///< Shift for weight
+	StringID s_weight; ///< Short string for weight
+	StringID l_weight; ///< Long string for weight
+	int v_m;           ///< Multiplier for volume
+	int v_s;           ///< Shift for volume
+	StringID s_volume; ///< Short string for volume
+	StringID l_volume; ///< Long string for volume
+} Units;
+
+static const Units units[] = {
+	{ // Imperial (Original)
+		   1,  0, STR_UNITS_VELOCITY_IMPERIAL,
+		   1,  0, STR_UNITS_POWER_IMPERIAL,
+		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
+		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
+	},
+	{ // Metric
+		1648, 10, STR_UNITS_VELOCITY_METRIC,
+		   1,  0, STR_UNITS_POWER_METRIC,
+		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
+		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
+	},
+	{ // SI
+		 458, 10, STR_UNITS_VELOCITY_SI,
+		 764, 10, STR_UNITS_POWER_SI,
+		1000,  0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI,
+		1000,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
+	},
+};
 
 static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei)
 {
@@ -510,16 +547,11 @@
 			buff = FormatMonthAndYear(buff, GetInt32(&argv));
 			break;
 		case 0x84: {// {VELOCITY}
-			int value = GetInt32(&argv);
-			if (_opt_ptr->kilometers) value = value * 1648 >> 10;
-			buff = FormatCommaNumber(buff, value);
-			if (_opt_ptr->kilometers) {
-				memcpy(buff, " km/h", 5);
-				buff += 5;
-			} else {
-				memcpy(buff, " mph", 4);
-				buff += 4;
-			}
+			int32 args[1];
+			assert(_opt_ptr->units < lengthof(units));
+			args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s;
+			buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24);
+			modifier = 0;
 			break;
 		}
 		// 0x85 is used as escape character..
@@ -536,11 +568,31 @@
 				// 8-bit = cargo type
 				// 16-bit = cargo count
 				StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][GetInt32(&argv)];
-				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
-				// liquid type of cargo is multiplied by 100 to get correct amount
-				buff = FormatCommaNumber(buff, GetInt32(&argv) * multiplier);
-				buff = strecpy(buff, " ", NULL);
-				buff = strecpy(buff, GetStringPtr(cargo_str), NULL);
+				switch (cargo_str) {
+					case STR_TONS: {
+						int32 args[1];
+						assert(_opt_ptr->units < lengthof(units));
+						args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
+						buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24);
+						modifier = 0;
+						break;
+					}
+
+					case STR_LITERS: {
+						int32 args[1];
+						assert(_opt_ptr->units < lengthof(units));
+						args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
+						buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24);
+						modifier = 0;
+						break;
+					}
+
+					default:
+						buff = FormatCommaNumber(buff, GetInt32(&argv));
+						buff = strecpy(buff, " ", NULL);
+						buff = strecpy(buff, GetStringPtr(cargo_str), NULL);
+						break;
+				}
 			} break;
 			case 4: {/* {CURRCOMPACT64} */
 				// 64 bit compact currency-unit
@@ -605,9 +657,10 @@
 			}
 
 			case 12: { // {VOLUME}
-				buff = FormatCommaNumber(buff, GetInt32(&argv) * 1000);
-				buff = strecpy(buff, " ", NULL);
-				buff = FormatString(buff, GetStringPtr(STR_LITERS), NULL, modifier >> 24);
+				int32 args[1];
+				assert(_opt_ptr->units < lengthof(units));
+				args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
+				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24);
 				modifier = 0;
 				break;
 			}
@@ -636,6 +689,42 @@
 				break;
 			}
 
+			case 16: { // {POWER}
+				int32 args[1];
+				assert(_opt_ptr->units < lengthof(units));
+				args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s;
+				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24);
+				modifier = 0;
+				break;
+			}
+
+			case 17: { // {VOLUME_S}
+				int32 args[1];
+				assert(_opt_ptr->units < lengthof(units));
+				args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
+				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24);
+				modifier = 0;
+				break;
+			}
+
+			case 18: { // {WEIGHT}
+				int32 args[1];
+				assert(_opt_ptr->units < lengthof(units));
+				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
+				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24);
+				modifier = 0;
+				break;
+			}
+
+			case 19: { // {WEIGHT_S}
+				int32 args[1];
+				assert(_opt_ptr->units < lengthof(units));
+				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
+				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24);
+				modifier = 0;
+				break;
+			}
+
 			default:
 				error("!invalid escape sequence in string");
 			}
--- a/variables.h	Sun Mar 26 21:15:09 2006 +0000
+++ b/variables.h	Sun Mar 26 21:50:57 2006 +0000
@@ -19,7 +19,7 @@
 	GameDifficulty diff;
 	byte diff_level;
 	byte currency;
-	bool kilometers;
+	byte units;
 	byte town_name;
 	byte landscape;
 	byte snow_line;