strings.c
changeset 3489 497361c60b90
parent 3485 1c77f46830c9
child 3601 138bf309cf27
equal deleted inserted replaced
3488:7bf7e30fb865 3489:497361c60b90
   493 	StringID l_weight; ///< Long string for weight
   493 	StringID l_weight; ///< Long string for weight
   494 	int v_m;           ///< Multiplier for volume
   494 	int v_m;           ///< Multiplier for volume
   495 	int v_s;           ///< Shift for volume
   495 	int v_s;           ///< Shift for volume
   496 	StringID s_volume; ///< Short string for volume
   496 	StringID s_volume; ///< Short string for volume
   497 	StringID l_volume; ///< Long string for volume
   497 	StringID l_volume; ///< Long string for volume
       
   498 	int f_m;           ///< Multiplier for force
       
   499 	int f_s;           ///< Shift for force
       
   500 	StringID force;    ///< String for force
   498 } Units;
   501 } Units;
   499 
   502 
       
   503 /* Unit conversions */
   500 static const Units units[] = {
   504 static const Units units[] = {
   501 	{ // Imperial (Original)
   505 	{ // Imperial (Original, mph, hp, metric ton, litre, metric ton force)
   502 		  10,  4, STR_UNITS_VELOCITY_IMPERIAL,
   506 		  10,  4, STR_UNITS_VELOCITY_IMPERIAL,
   503 		   1,  0, STR_UNITS_POWER_IMPERIAL,
   507 		   1,  0, STR_UNITS_POWER_IMPERIAL,
   504 		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
   508 		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
   505 		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
   509 		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
       
   510 		 835, 13, STR_UNITS_FORCE_METRIC,
   506 	},
   511 	},
   507 	{ // Metric
   512 	{ // Metric (km/h, hp, metric ton, litre, metric ton force)
   508 		   1,  0, STR_UNITS_VELOCITY_METRIC,
   513 		   1,  0, STR_UNITS_VELOCITY_METRIC,
   509 		   1,  0, STR_UNITS_POWER_METRIC,
   514 		   1,  0, STR_UNITS_POWER_METRIC,
   510 		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
   515 		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
   511 		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
   516 		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
       
   517 		 835, 13, STR_UNITS_FORCE_METRIC,
   512 	},
   518 	},
   513 	{ // SI
   519 	{ // SI (m/s, kilowatt, kilogram, cubic metres, kilonewton)
   514 		 284, 10, STR_UNITS_VELOCITY_SI,
   520 		 284, 10, STR_UNITS_VELOCITY_SI,
   515 		 764, 10, STR_UNITS_POWER_SI,
   521 		 764, 10, STR_UNITS_POWER_SI,
   516 		1000,  0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI,
   522 		1000,  0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI,
   517 		   1,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
   523 		   1,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
       
   524 		   1,  0, STR_UNITS_FORCE_SI,
   518 	},
   525 	},
   519 };
   526 };
   520 
   527 
   521 static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei)
   528 static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei)
   522 {
   529 {
   719 			case 19: { // {WEIGHT_S}
   726 			case 19: { // {WEIGHT_S}
   720 				int32 args[1];
   727 				int32 args[1];
   721 				assert(_opt_ptr->units < lengthof(units));
   728 				assert(_opt_ptr->units < lengthof(units));
   722 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   729 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   723 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24);
   730 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24);
       
   731 				modifier = 0;
       
   732 				break;
       
   733 			}
       
   734 
       
   735 			case 20: { // {FORCE}
       
   736 				int32 args[1];
       
   737 				assert(_opt_ptr->units < lengthof(units));
       
   738 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s;
       
   739 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24);
   724 				modifier = 0;
   740 				modifier = 0;
   725 				break;
   741 				break;
   726 			}
   742 			}
   727 
   743 
   728 			default:
   744 			default: