src/strings.cpp
branchnoai
changeset 9826 9707ad4c9b60
parent 9724 b39bc69bb2f2
child 9837 c9ec4f82e0d0
equal deleted inserted replaced
9825:cc77111ebd85 9826:9707ad4c9b60
     3 /** @file strings.cpp */
     3 /** @file strings.cpp */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "currency.h"
     7 #include "currency.h"
     8 #include "namegen.h"
     8 #include "namegen_func.h"
     9 #include "station.h"
     9 #include "station.h"
    10 #include "town.h"
    10 #include "town.h"
    11 #include "news.h"
       
    12 #include "screenshot.h"
    11 #include "screenshot.h"
    13 #include "waypoint.h"
    12 #include "waypoint.h"
    14 #include "industry.h"
    13 #include "industry.h"
    15 #include "variables.h"
    14 #include "variables.h"
    16 #include "newgrf_text.h"
    15 #include "newgrf_text.h"
   398 	}
   397 	}
   399 
   398 
   400 	return buff;
   399 	return buff;
   401 }
   400 }
   402 
   401 
   403 static int DeterminePluralForm(int64 cnt)
   402 static int DeterminePluralForm(int64 count)
   404 {
   403 {
   405 	uint64 n = cnt;
       
   406 	/* The absolute value determines plurality */
   404 	/* The absolute value determines plurality */
   407 	if (cnt < 0) n = -cnt;
   405 	uint64 n = abs(count);
   408 
   406 
   409 	switch (_langpack->plural_form) {
   407 	switch (_langpack->plural_form) {
   410 	/* Two forms, singular used for one only
   408 		default:
   411 	 * Used in:
   409 			NOT_REACHED();
   412 	 *   Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish,
   410 
   413 	 *   Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto */
   411 		/* Two forms, singular used for one only
   414 	case 0:
   412 		 * Used in:
   415 	default:
   413 		 *   Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish,
   416 		return n != 1;
   414 		 *   Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto */
   417 
   415 		case 0:
   418 	/* Only one form
   416 			return n != 1;
   419 	 * Used in:
   417 
   420 	 *   Hungarian, Japanese, Korean, Turkish */
   418 		/* Only one form
   421 	case 1:
   419 		 * Used in:
   422 		return 0;
   420 		 *   Hungarian, Japanese, Korean, Turkish */
   423 
   421 		case 1:
   424 	/* Two forms, singular used for zero and one
   422 			return 0;
   425 	 * Used in:
   423 
   426 	 *   French, Brazilian Portuguese */
   424 		/* Two forms, singular used for zero and one
   427 	case 2:
   425 		 * Used in:
   428 		return n > 1;
   426 		 *   French, Brazilian Portuguese */
   429 
   427 		case 2:
   430 	/* Three forms, special case for zero
   428 			return n > 1;
   431 	 * Used in:
   429 
   432 	 *   Latvian */
   430 		/* Three forms, special case for zero
   433 	case 3:
   431 		 * Used in:
   434 		return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
   432 		 *   Latvian */
   435 
   433 		case 3:
   436 	/* Three forms, special case for one and two
   434 			return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
   437 	 * Used in:
   435 
   438 	 *   Gaelige (Irish) */
   436 		/* Three forms, special case for one and two
   439 	case 4:
   437 		 * Used in:
   440 		return n == 1 ? 0 : n == 2 ? 1 : 2;
   438 		 *   Gaelige (Irish) */
   441 
   439 		case 4:
   442 	/* Three forms, special case for numbers ending in 1[2-9]
   440 			return n == 1 ? 0 : n == 2 ? 1 : 2;
   443 	 * Used in:
   441 
   444 	 *   Lithuanian */
   442 		/* Three forms, special case for numbers ending in 1[2-9]
   445 	case 5:
   443 		 * Used in:
   446 		return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
   444 		 *   Lithuanian */
   447 
   445 		case 5:
   448 	/* Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
   446 			return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
   449 	 * Used in:
   447 
   450 	 *   Croatian, Czech, Russian, Slovak, Ukrainian */
   448 		/* Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
   451 	case 6:
   449 		 * Used in:
   452 		return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
   450 		 *   Croatian, Czech, Russian, Slovak, Ukrainian */
   453 
   451 		case 6:
   454 	/* Three forms, special case for one and some numbers ending in 2, 3, or 4
   452 			return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
   455 	 * Used in:
   453 
   456 	 *   Polish */
   454 		/* Three forms, special case for one and some numbers ending in 2, 3, or 4
   457 	case 7:
   455 		 * Used in:
   458 		return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
   456 		 *   Polish */
   459 
   457 		case 7:
   460 	/* Four forms, special case for one and all numbers ending in 02, 03, or 04
   458 			return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
   461 	 * Used in:
   459 
   462 	 *   Slovenian */
   460 		/* Four forms, special case for one and all numbers ending in 02, 03, or 04
   463 	case 8:
   461 		 * Used in:
   464 		return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
   462 		 *   Slovenian */
       
   463 		case 8:
       
   464 			return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
       
   465 
       
   466 		/* Two forms; singular used for everything ending in 1 but not in 11.
       
   467 		 * Used in:
       
   468 		 *   Icelandic */
       
   469 		case 9:
       
   470 			return n % 10 == 1 && n % 100 != 11 ? 0 : 1;
   465 	}
   471 	}
   466 }
   472 }
   467 
   473 
   468 static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen)
   474 static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen)
   469 {
   475 {