diff --git a/media/baseset/openttd.grf b/media/baseset/openttd.grf index 9e08fb17c3..dd8acf3e82 100644 Binary files a/media/baseset/openttd.grf and b/media/baseset/openttd.grf differ diff --git a/media/baseset/openttd/mono.nfo b/media/baseset/openttd/mono.nfo index f855e8f0ec..e17b6aae14 100644 --- a/media/baseset/openttd/mono.nfo +++ b/media/baseset/openttd/mono.nfo @@ -5,233 +5,233 @@ // -1 * 0 0C "Monospaced characters (Liberation Mono)" -1 * 0 12 01 03 60 20 00 - -1 sprites/mono.png 8bpp 10 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 25 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 40 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 55 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 70 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 85 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 100 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 115 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 130 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 145 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 160 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 175 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 190 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 205 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 220 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 235 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 250 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 265 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 280 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 295 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 310 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 325 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 340 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 355 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 370 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 385 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 400 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 415 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 430 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 445 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 460 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 475 30 7 13 0 0 normal - -1 sprites/mono.png 8bpp 10 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 25 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 40 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 55 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 70 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 85 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 100 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 115 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 130 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 145 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 160 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 175 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 190 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 205 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 220 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 235 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 250 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 265 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 280 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 295 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 310 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 325 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 340 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 355 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 370 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 385 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 400 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 415 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 430 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 445 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 460 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 475 50 7 13 0 0 normal - -1 sprites/mono.png 8bpp 10 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 25 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 40 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 55 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 70 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 85 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 100 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 115 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 130 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 145 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 160 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 175 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 190 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 205 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 220 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 235 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 250 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 265 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 280 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 295 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 310 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 325 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 340 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 355 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 370 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 385 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 400 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 415 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 430 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 445 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 460 70 7 13 0 0 normal - -1 sprites/mono.png 8bpp 475 70 7 13 0 0 normal + -1 sprites/mono.png 8bpp 10 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 25 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 40 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 55 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 70 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 85 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 100 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 115 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 130 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 145 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 160 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 175 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 190 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 205 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 220 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 235 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 250 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 265 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 280 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 295 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 310 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 325 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 340 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 355 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 370 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 385 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 400 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 415 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 430 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 445 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 460 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 475 30 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 10 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 25 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 40 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 55 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 70 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 85 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 100 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 115 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 130 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 145 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 160 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 175 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 190 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 205 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 220 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 235 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 250 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 265 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 280 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 295 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 310 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 325 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 340 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 355 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 370 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 385 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 400 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 415 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 430 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 445 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 460 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 475 50 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 10 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 25 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 40 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 55 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 70 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 85 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 100 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 115 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 130 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 145 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 160 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 175 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 190 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 205 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 220 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 235 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 250 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 265 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 280 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 295 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 310 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 325 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 340 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 355 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 370 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 385 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 400 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 415 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 430 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 445 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 460 70 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 475 70 7 13 0 -2 normal -1 * 0 12 01 03 80 80 00 - -1 sprites/mono.png 8bpp 10 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 25 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 40 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 55 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 70 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 85 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 100 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 115 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 130 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 145 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 160 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 175 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 190 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 205 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 220 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 235 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 250 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 265 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 280 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 295 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 310 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 325 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 340 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 355 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 370 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 385 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 400 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 415 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 430 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 445 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 460 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 475 90 7 13 0 0 normal - -1 sprites/mono.png 8bpp 10 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 25 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 40 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 55 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 70 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 85 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 100 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 115 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 130 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 145 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 160 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 175 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 190 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 205 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 220 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 235 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 250 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 265 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 280 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 295 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 310 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 325 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 340 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 355 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 370 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 385 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 400 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 415 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 430 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 445 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 460 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 475 110 7 13 0 0 normal - -1 sprites/mono.png 8bpp 10 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 25 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 40 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 55 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 70 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 85 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 100 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 115 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 130 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 145 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 160 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 175 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 190 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 205 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 220 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 235 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 250 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 265 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 280 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 295 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 310 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 325 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 340 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 355 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 370 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 385 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 400 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 415 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 430 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 445 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 460 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 475 130 7 13 0 0 normal - -1 sprites/mono.png 8bpp 10 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 25 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 40 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 55 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 70 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 85 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 100 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 115 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 130 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 145 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 160 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 175 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 190 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 205 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 220 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 235 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 250 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 265 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 280 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 295 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 310 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 325 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 340 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 355 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 370 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 385 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 400 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 415 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 430 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 445 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 460 150 7 13 0 0 normal - -1 sprites/mono.png 8bpp 475 150 7 13 0 0 normal + -1 sprites/mono.png 8bpp 10 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 25 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 40 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 55 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 70 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 85 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 100 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 115 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 130 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 145 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 160 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 175 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 190 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 205 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 220 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 235 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 250 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 265 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 280 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 295 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 310 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 325 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 340 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 355 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 370 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 385 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 400 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 415 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 430 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 445 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 460 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 475 90 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 10 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 25 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 40 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 55 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 70 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 85 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 100 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 115 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 130 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 145 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 160 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 175 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 190 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 205 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 220 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 235 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 250 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 265 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 280 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 295 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 310 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 325 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 340 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 355 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 370 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 385 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 400 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 415 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 430 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 445 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 460 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 475 110 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 10 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 25 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 40 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 55 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 70 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 85 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 100 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 115 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 130 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 145 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 160 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 175 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 190 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 205 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 220 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 235 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 250 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 265 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 280 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 295 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 310 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 325 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 340 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 355 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 370 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 385 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 400 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 415 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 430 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 445 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 460 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 475 130 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 10 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 25 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 40 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 55 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 70 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 85 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 100 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 115 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 130 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 145 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 160 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 175 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 190 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 205 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 220 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 235 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 250 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 265 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 280 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 295 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 310 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 325 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 340 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 355 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 370 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 385 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 400 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 415 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 430 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 445 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 460 150 7 13 0 -2 normal + -1 sprites/mono.png 8bpp 475 150 7 13 0 -2 normal //U+0178 Latin Capital Letter Y With Diaeresis (only needed for mono as it is in the base set, but relocated by some code) -1 * 0 12 01 03 01 78 01 - -1 sprites/mono.png 8bpp 370 230 7 13 0 0 normal + -1 sprites/mono.png 8bpp 370 230 7 13 0 -2 normal diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 48e26ddf08..f7feb9d0a8 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1702,7 +1702,7 @@ static void AircraftEventHandler_AtTerminal(Aircraft *v, const AirportFTAClass * return; default: // orders have been deleted (no orders), goto depot and don't bother us v->current_order.Free(); - go_to_hangar = Station::Get(v->targetairport)->airport.HasHangar(); + go_to_hangar = true; } if (go_to_hangar && Station::Get(v->targetairport)->airport.HasHangar()) { diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp index d3e3e8c282..52dccf1d0c 100644 --- a/src/autoreplace_gui.cpp +++ b/src/autoreplace_gui.cpp @@ -215,7 +215,7 @@ class ReplaceVehicleWindow : public Window { if (this->engines[0].NeedRebuild()) { /* We need to rebuild the left engines list */ this->GenerateReplaceVehList(true); - this->vscroll[0]->SetCount((uint)this->engines[0].size()); + this->vscroll[0]->SetCount(this->engines[0].size()); if (this->reset_sel_engine && this->sel_engine[0] == INVALID_ENGINE && this->engines[0].size() != 0) { this->sel_engine[0] = this->engines[0][0].engine_id; } @@ -235,7 +235,7 @@ class ReplaceVehicleWindow : public Window { } /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */ this->GenerateReplaceVehList(false); - this->vscroll[1]->SetCount((uint)this->engines[1].size()); + this->vscroll[1]->SetCount(this->engines[1].size()); if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) { int position = 0; for (const auto &item : this->engines[1]) { diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index ff17505226..3dc859aa09 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -180,7 +180,7 @@ public: this->bridges->NeedResort(); this->SortBridgeList(); - this->vscroll->SetCount((uint)bl->size()); + this->vscroll->SetCount(bl->size()); } ~BuildBridgeWindow() diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 6f94d85ef0..4d570cfbce 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -62,17 +62,17 @@ static const NWidgetPart _nested_build_vehicle_widgets[] = { NWidget(WWT_DEFSIZEBOX, COLOUR_GREY), NWidget(WWT_STICKYBOX, COLOUR_GREY), EndContainer(), - NWidget(WWT_PANEL, COLOUR_GREY), - NWidget(NWID_VERTICAL), - NWidget(NWID_HORIZONTAL), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), - NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), - EndContainer(), - NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_ENGINES), - NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA), - EndContainer(), - NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER), SetMinimalSize(128, 0), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), + NWidget(NWID_VERTICAL), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), + EndContainer(), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_ENGINES), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA), + EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY), + NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER), SetResize(1, 0), SetFill(1, 0), SetPadding(2), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), EndContainer(), EndContainer(), /* Vehicle list. */ @@ -111,17 +111,17 @@ static const NWidgetPart _nested_build_vehicle_widgets_train_advanced[] = { NWidget(WWT_LABEL, COLOUR_GREY, WID_BV_CAPTION_LOCO), SetDataTip(STR_JUST_STRING, STR_NULL), SetTextStyle(TC_WHITE), SetResize(1, 0), SetFill(1, 0), EndContainer(), EndContainer(), - NWidget(WWT_PANEL, COLOUR_GREY), - NWidget(NWID_VERTICAL), - NWidget(NWID_HORIZONTAL), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING_LOCO), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), - NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN_LOCO), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), - EndContainer(), - NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_LOCOS), - NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN_LOCO), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA), - EndContainer(), - NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER_LOCO), SetMinimalSize(128, 0), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), + NWidget(NWID_VERTICAL), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING_LOCO), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN_LOCO), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), + EndContainer(), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_LOCOS), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN_LOCO), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA), + EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY), + NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER_LOCO), SetResize(1, 0), SetFill(1, 0), SetPadding(2), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), EndContainer(), EndContainer(), /* Vehicle list for locomotives. */ @@ -150,17 +150,17 @@ static const NWidgetPart _nested_build_vehicle_widgets_train_advanced[] = { NWidget(WWT_LABEL, COLOUR_GREY, WID_BV_CAPTION_WAGON), SetDataTip(STR_JUST_STRING, STR_NULL), SetTextStyle(TC_WHITE), SetResize(1, 0), SetFill(1, 0), EndContainer(), EndContainer(), - NWidget(WWT_PANEL, COLOUR_GREY), - NWidget(NWID_VERTICAL), - NWidget(NWID_HORIZONTAL), - NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING_WAGON), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), - NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN_WAGON), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), - EndContainer(), - NWidget(NWID_HORIZONTAL), - NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_WAGONS), - NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN_WAGON), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA), - EndContainer(), - NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER_WAGON), SetMinimalSize(128, 0), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), + NWidget(NWID_VERTICAL), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_BV_SORT_ASCENDING_DESCENDING_WAGON), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_SORT_DROPDOWN_WAGON), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA), + EndContainer(), + NWidget(NWID_HORIZONTAL), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_BV_SHOW_HIDDEN_WAGONS), + NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_BV_CARGO_FILTER_DROPDOWN_WAGON), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_FILTER_CRITERIA), + EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY), + NWidget(WWT_EDITBOX, COLOUR_GREY, WID_BV_FILTER_WAGON), SetResize(1, 0), SetFill(1, 0), SetPadding(2), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), EndContainer(), EndContainer(), /* Vehicle list for wagons. */ @@ -322,7 +322,7 @@ static bool EngineCostSorter(const GUIEngineListItem &a, const GUIEngineListItem { Money va = Engine::Get(a.engine_id)->GetCost(); Money vb = Engine::Get(b.engine_id)->GetCost(); - int r = ClampToI32(va - vb); + int r = ClampTo(va - vb); /* Use EngineID to sort instead since we want consistent sorting */ if (r == 0) return EngineNumberSorter(a, b); @@ -390,7 +390,7 @@ static bool EngineRunningCostSorter(const GUIEngineListItem &a, const GUIEngineL { Money va = Engine::Get(a.engine_id)->GetRunningCost(); Money vb = Engine::Get(b.engine_id)->GetRunningCost(); - int r = ClampToI32(va - vb); + int r = ClampTo(va - vb); /* Use EngineID to sort instead since we want consistent sorting */ if (r == 0) return EngineNumberSorter(a, b); @@ -2066,7 +2066,7 @@ struct BuildVehicleWindow : BuildVehicleWindowBase { void OnPaint() override { this->GenerateBuildList(); - this->vscroll->SetCount((uint)this->eng_list.size()); + this->vscroll->SetCount(this->eng_list.size()); this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD, WIDGET_LIST_END); diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index a33cbdced4..d27a28a33f 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -289,15 +289,20 @@ void SubtractMoneyFromCompanyFract(CompanyID company, const CommandCost &cst) if (cost != 0) SubtractMoneyFromAnyCompany(c, CommandCost(cst.GetExpensesType(), cost)); } +static constexpr void UpdateLandscapingLimit(uint32_t &limit, uint64_t per_64k_frames, uint64_t burst) +{ + limit = static_cast(std::min(limit + per_64k_frames, burst << 16)); +} + /** Update the landscaping limits per company. */ void UpdateLandscapingLimits() { for (Company *c : Company::Iterate()) { - c->terraform_limit = std::min((uint64)c->terraform_limit + _settings_game.construction.terraform_per_64k_frames, (uint64)_settings_game.construction.terraform_frame_burst << 16); - c->clear_limit = std::min((uint64)c->clear_limit + _settings_game.construction.clear_per_64k_frames, (uint64)_settings_game.construction.clear_frame_burst << 16); - c->tree_limit = std::min((uint64)c->tree_limit + _settings_game.construction.tree_per_64k_frames, (uint64)_settings_game.construction.tree_frame_burst << 16); - c->purchase_land_limit = std::min((uint64)c->purchase_land_limit + _settings_game.construction.purchase_land_per_64k_frames, (uint64)_settings_game.construction.purchase_land_frame_burst << 16); - c->build_object_limit = std::min((uint64)c->build_object_limit + _settings_game.construction.build_object_per_64k_frames, (uint64)_settings_game.construction.build_object_frame_burst << 16); + UpdateLandscapingLimit(c->terraform_limit, _settings_game.construction.terraform_per_64k_frames, _settings_game.construction.terraform_frame_burst); + UpdateLandscapingLimit(c->clear_limit, _settings_game.construction.clear_per_64k_frames, _settings_game.construction.clear_frame_burst); + UpdateLandscapingLimit(c->tree_limit, _settings_game.construction.tree_per_64k_frames, _settings_game.construction.tree_frame_burst); + UpdateLandscapingLimit(c->purchase_land_limit, _settings_game.construction.purchase_land_per_64k_frames, _settings_game.construction.purchase_land_frame_burst); + UpdateLandscapingLimit(c->build_object_limit, _settings_game.construction.build_object_per_64k_frames, _settings_game.construction.build_object_frame_burst); } } diff --git a/src/console_gui.cpp b/src/console_gui.cpp index dd132d8f13..b3af793acc 100644 --- a/src/console_gui.cpp +++ b/src/console_gui.cpp @@ -326,11 +326,11 @@ struct IConsoleWindow : Window return r; } - const char *GetTextCharacterAtPosition(const Point &pt) const override + ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const override { int delta = std::min(this->width - this->line_offset - _iconsole_cmdline.pixels - ICON_RIGHT_BORDERWIDTH, 0); - if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return nullptr; + if (!IsInsideMM(pt.y, this->height - this->line_height, this->height)) return -1; return GetCharAtPosition(_iconsole_cmdline.buf, pt.x - delta); } diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index ea0345ce5c..701eaaafad 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -10,6 +10,9 @@ #ifndef MATH_FUNC_HPP #define MATH_FUNC_HPP +#include +#include + /** * Returns the absolute value of (scalar) variable. * @@ -148,38 +151,65 @@ static inline uint ClampU(const uint a, const uint min, const uint max) } /** - * Reduce a signed 64-bit int to a signed 32-bit one + * Clamp the given value down to lie within the requested type. * - * This function clamps a 64-bit integer to a 32-bit integer. - * If the 64-bit value is smaller than the smallest 32-bit integer - * value 0x80000000 this value is returned (the left one bit is the sign bit). - * If the 64-bit value is greater than the greatest 32-bit integer value 0x7FFFFFFF - * this value is returned. In all other cases the 64-bit value 'fits' in a - * 32-bits integer field and so the value is casted to int32 and returned. + * For example ClampTo will return a value clamped to the range of 0 + * to 255. Anything smaller will become 0, anything larger will become 255. * - * @param a The 64-bit value to clamps - * @return The 64-bit value reduced to a 32-bit value + * @param a The 64-bit value to clamp. + * @return The 64-bit value reduced to a value within the given allowed range + * for the return type. * @see Clamp(int, int, int) */ -static inline int32 ClampToI32(const int64 a) +template +constexpr To ClampTo(From value) { - return static_cast(Clamp(a, INT32_MIN, INT32_MAX)); -} + static_assert(std::numeric_limits::is_integer, "Do not clamp from non-integer values"); + static_assert(std::numeric_limits::is_integer, "Do not clamp to non-integer values"); -/** - * Reduce an unsigned 64-bit int to an unsigned 16-bit one - * - * @param a The 64-bit value to clamp - * @return The 64-bit value reduced to a 16-bit value - * @see ClampU(uint, uint, uint) - */ -static inline uint16 ClampToU16(const uint64 a) -{ - /* MSVC thinks, in its infinite wisdom, that int min(int, int) is a better - * match for min(uint64, uint) than uint64 min(uint64, uint64). As such we - * need to cast the UINT16_MAX to prevent MSVC from displaying its - * infinite loads of warnings. */ - return static_cast(std::min(a, static_cast(UINT16_MAX))); + if (sizeof(To) >= sizeof(From) && std::numeric_limits::is_signed == std::numeric_limits::is_signed) { + /* Same signedness and To type is larger or equal than From type, no clamping is required. */ + return static_cast(value); + } + + if (sizeof(To) > sizeof(From) && std::numeric_limits::is_signed) { + /* Signed destination and a larger To type, no clamping is required. */ + return static_cast(value); + } + + /* Get the bigger of the two types based on essentially the number of bits. */ + using BiggerType = typename std::conditional= sizeof(To), From, To>::type; + + if constexpr (std::numeric_limits::is_signed) { + /* The output is a signed number. */ + if constexpr (std::numeric_limits::is_signed) { + /* Both input and output are signed. */ + return static_cast(std::clamp(value, + std::numeric_limits::lowest(), std::numeric_limits::max())); + } + + /* The input is unsigned, so skip the minimum check and use unsigned variant of the biggest type as intermediate type. */ + using BiggerUnsignedType = typename std::make_unsigned::type; + return static_cast(std::min(std::numeric_limits::max(), value)); + } + + /* The output is unsigned. */ + + if constexpr (std::numeric_limits::is_signed) { + /* Input is signed; account for the negative numbers in the input. */ + if constexpr (sizeof(To) >= sizeof(From)) { + /* If the output type is larger or equal to the input type, then only clamp the negative numbers. */ + return static_cast(std::max(value, 0)); + } + + /* The output type is smaller than the input type. */ + using BiggerSignedType = typename std::make_signed::type; + return static_cast(std::clamp(value, + std::numeric_limits::lowest(), std::numeric_limits::max())); + } + + /* The input and output are unsigned, just clamp at the high side. */ + return static_cast(std::min(value, std::numeric_limits::max())); } /** diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index 066261a859..d446ec5485 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -212,4 +212,8 @@ static_assert(OverflowSafeInt32(INT32_MAX) + 1 == OverflowSafeInt32(INT32_MAX)); static_assert(OverflowSafeInt32(INT32_MAX) * 2 == OverflowSafeInt32(INT32_MAX)); static_assert(OverflowSafeInt32(INT32_MIN) * 2 == OverflowSafeInt32(INT32_MIN)); +/* Specialisation of the generic ClampTo function for overflow safe integers to normal integers. */ +template +constexpr To ClampTo(OverflowSafeInt value) { return ClampTo(From(value)); } + #endif /* OVERFLOWSAFE_TYPE_HPP */ diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 31d63f2dcc..96dd9d65a4 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -735,7 +735,7 @@ struct DepotWindow : Window { max_width = std::max(max_width, width); } /* Always have 1 empty row, so people can change the setting of the train */ - this->vscroll->SetCount((uint)this->vehicle_list.size() + (uint)this->wagon_list.size() + 1); + this->vscroll->SetCount(this->vehicle_list.size() + this->wagon_list.size() + 1); /* Always make it longer than the longest train, so you can attach vehicles at the end, and also see the next vertical tile separator line */ this->hscroll->SetCount(max_width + ScaleSpriteTrad(2 * VEHICLEINFO_FULL_VEHICLE_WIDTH + 1)); } else { diff --git a/src/economy.cpp b/src/economy.cpp index 5778752b29..ffb2331f89 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -1051,7 +1051,7 @@ Money GetTransportedGoodsIncome(uint num_pieces, uint dist, uint16 transit_days, /* Use callback to calculate cargo profit, if available */ if (HasBit(cs->callback_mask, CBM_CARGO_PROFIT_CALC)) { - uint32 var18 = std::min(dist, 0xFFFFu) | (std::min(num_pieces, 0xFFu) << 16) | (std::min(transit_days, 0xFFu) << 24); + uint32 var18 = ClampTo(dist) | (ClampTo(num_pieces) << 16) | (ClampTo(transit_days) << 24); uint16 callback = GetCargoCallback(CBID_CARGO_PROFIT_CALC, 0, var18, cs); if (callback != CALLBACK_FAILED) { int result = GB(callback, 0, 14); @@ -1355,7 +1355,7 @@ static void TriggerIndustryProduction(Industry *i) if (cargo_waiting == 0) continue; for (uint ci_out = 0; ci_out < lengthof(i->produced_cargo_waiting); ci_out++) { - i->produced_cargo_waiting[ci_out] = std::min(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256), 0xFFFFu); + i->produced_cargo_waiting[ci_out] = ClampTo(i->produced_cargo_waiting[ci_out] + (cargo_waiting * indspec->input_cargo_multiplier[ci_in][ci_out] / 256)); } i->incoming_cargo_waiting[ci_in] = 0; @@ -2132,8 +2132,8 @@ static void LoadUnloadVehicle(Vehicle *front) } /* if last speed is 0, we treat that as if no vehicle has ever visited the station. */ - ge->last_speed = std::min(t, 255); - ge->last_age = std::min(_cur_year - front->build_year, 255); + ge->last_speed = ClampTo(t); + ge->last_age = ClampTo(_cur_year - front->build_year); assert(v->cargo_cap >= v->cargo.StoredCount()); /* Capacity available for loading more cargo. */ diff --git a/src/engine.cpp b/src/engine.cpp index 13422368a3..1bf9b17ff2 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -673,8 +673,8 @@ void CalcEngineReliability(Engine *e, bool new_month) re = Engine::Get(re->info.variant_id); } - uint age = re->age; - if (new_month && re->index > e->index && age != MAX_DAY) age++; /* parent variant's age has not yet updated. */ + uint32 age = re->age; + if (new_month && re->index > e->index && age != INT32_MAX) age++; /* parent variant's age has not yet updated. */ /* Check for early retirement */ if (e->company_avail != 0 && !_settings_game.vehicle.never_expire_vehicles && e->info.base_life != 0xFF) { @@ -1187,7 +1187,7 @@ void EnginesMonthlyLoop() bool refresh = false; for (Engine *e : Engine::Iterate()) { /* Age the vehicle */ - if ((e->flags & ENGINE_AVAILABLE) && e->age != MAX_DAY) { + if ((e->flags & ENGINE_AVAILABLE) && e->age != INT32_MAX) { e->age++; CalcEngineReliability(e, true); refresh = true; diff --git a/src/engine_base.h b/src/engine_base.h index 75371edf7e..299fd58fbf 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -44,7 +44,7 @@ struct EngineRefitCapacityValue { struct Engine : EnginePool::PoolItem<&_engine_pool> { TinyString name; ///< Custom name of engine. Date intro_date; ///< Date of introduction of the engine. - Date age; + int32 age; ///< Age of the engine in months. uint16 reliability; ///< Current reliability of the engine. uint16 reliability_spd_dec; ///< Speed of reliability decay between services (per day). uint16 reliability_start; ///< Initial reliability of the engine. diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 4ad2d981d0..ec87faffe7 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -861,7 +861,7 @@ public: _fios_path_changed = true; this->fios_items.BuildFileList(this->abstract_filetype, this->fop); - this->vscroll->SetCount((uint)this->fios_items.size()); + this->vscroll->SetCount(this->fios_items.size()); this->selected = nullptr; _load_check_data.Clear(); diff --git a/src/game/game_gui.cpp b/src/game/game_gui.cpp index 59d721ff5b..77b11a13b0 100644 --- a/src/game/game_gui.cpp +++ b/src/game/game_gui.cpp @@ -133,7 +133,7 @@ struct GSConfigWindow : public Window { } } - this->vscroll->SetCount((int)this->visible_settings.size()); + this->vscroll->SetCount(this->visible_settings.size()); } void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override diff --git a/src/gfx.cpp b/src/gfx.cpp index 46d9b689be..e3e1624716 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -679,7 +679,7 @@ static int DrawLayoutLine(const ParagraphLayouter::Line &line, int y, int left, * @return In case of left or center alignment the right most pixel we have drawn to. * In case of right alignment the left most pixel we have drawn to. */ -int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) +int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) { /* The string may contain control chars to change the font, just use the biggest font for clipping. */ int max_height = std::max({FONT_HEIGHT_SMALL, FONT_HEIGHT_NORMAL, FONT_HEIGHT_LARGE, FONT_HEIGHT_MONO}); @@ -698,28 +698,6 @@ int DrawString(int left, int right, int top, const char *str, TextColour colour, return DrawLayoutLine(*layout.front(), top, left, right, align, underline, true); } -/** - * Draw string, possibly truncated to make it fit in its allocated space - * - * @param left The left most position to draw on. - * @param right The right most position to draw on. - * @param top The top most position to draw on. - * @param str String to draw. - * @param colour Colour used for drawing the string, for details see _string_colourmap in - * table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h - * @param align The alignment of the string when drawing left-to-right. In the - * case a right-to-left language is chosen this is inverted so it - * will be drawn in the right direction. - * @param underline Whether to underline what has been drawn or not. - * @param fontsize The size of the initial characters. - * @return In case of left or center alignment the right most pixel we have drawn to. - * In case of right alignment the left most pixel we have drawn to. - */ -int DrawString(int left, int right, int top, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) -{ - return DrawString(left, right, top, str.c_str(), colour, align, underline, fontsize); -} - /** * Draw string, possibly truncated to make it fit in its allocated space * @@ -750,7 +728,7 @@ int DrawString(int left, int right, int top, StringID str, TextColour colour, St * @param maxw maximum string width * @return height of pixels of string when it is drawn */ -int GetStringHeight(const char *str, int maxw, FontSize fontsize) +int GetStringHeight(std::string_view str, int maxw, FontSize fontsize) { Layouter layout(str, maxw, TC_FROMSTRING, fontsize); return layout.GetBounds().height; @@ -802,7 +780,7 @@ Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestio * @param suggestion Suggested bounding box. * @return Bounding box for the multi-line string, may be bigger than \a suggestion. */ -Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion) +Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion) { Dimension box = {suggestion.width, (uint)GetStringHeight(str, suggestion.width)}; return box; @@ -824,7 +802,7 @@ Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &sugges * * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written. */ -int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) +int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) { int maxw = right - left + 1; int maxh = bottom - top + 1; @@ -870,28 +848,6 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, const char *st return ((align & SA_VERT_MASK) == SA_BOTTOM) ? first_line : last_line; } - -/** - * Draw string, possibly over multiple lines. - * - * @param left The left most position to draw on. - * @param right The right most position to draw on. - * @param top The top most position to draw on. - * @param bottom The bottom most position to draw on. - * @param str String to draw. - * @param colour Colour used for drawing the string, for details see _string_colourmap in - * table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h - * @param align The horizontal and vertical alignment of the string. - * @param underline Whether to underline all strings - * @param fontsize The size of the initial characters. - * - * @return If \a align is #SA_BOTTOM, the top to where we have written, else the bottom to where we have written. - */ -int DrawStringMultiLine(int left, int right, int top, int bottom, const std::string &str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) -{ - return DrawStringMultiLine(left, right, top, bottom, str.c_str(), colour, align, underline, fontsize); -} - /** * Draw string, possibly over multiple lines. * @@ -925,30 +881,15 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, * @param start_fontsize Fontsize to start the text with * @return string width and height in pixels */ -Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize) +Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize) { Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize); return layout.GetBounds(); } -/** - * Return the string dimension in pixels. The height and width are returned - * in a single Dimension value. TINYFONT, BIGFONT modifiers are only - * supported as the first character of the string. The returned dimensions - * are therefore a rough estimation correct for all the current strings - * but not every possible combination - * @param str string to calculate pixel-width - * @param start_fontsize Fontsize to start the text with - * @return string width and height in pixels - */ -Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize) -{ - return GetStringBoundingBox(str.c_str(), start_fontsize); -} - /** * Get bounding box of a string. Uses parameters set by #SetDParam if needed. - * Has the same restrictions as #GetStringBoundingBox(const char *str, FontSize start_fontsize). + * Has the same restrictions as #GetStringBoundingBox(std::string_view str, FontSize start_fontsize). * @param strid String to examine. * @return Width and height of the bounding box for the string in pixels. */ @@ -983,10 +924,14 @@ uint GetStringListWidth(const StringID *list, FontSize fontsize) * @param start_fontsize Font size to start the text with. * @return Upper left corner of the glyph associated with the character. */ -Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize) +Point GetCharPosInString(std::string_view str, const char *ch, FontSize start_fontsize) { + /* Ensure "ch" is inside "str" or at the exact end. */ + assert(ch >= str.data() && (ch - str.data()) <= static_cast(str.size())); + auto it_ch = str.begin() + (ch - str.data()); + Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize); - return layout.GetCharPosition(ch); + return layout.GetCharPosition(it_ch); } /** @@ -994,11 +939,11 @@ Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsiz * @param str String to test. * @param x Position relative to the start of the string. * @param start_fontsize Font size to start the text with. - * @return Pointer to the character at the position or nullptr if there is no character at the position. + * @return Index of the character position or -1 if there is no character at the position. */ -const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize) +ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize) { - if (x < 0) return nullptr; + if (x < 0) return -1; Layouter layout(str, INT32_MAX, TC_FROMSTRING, start_fontsize); return layout.GetCharAtPosition(x); diff --git a/src/gfx_func.h b/src/gfx_func.h index eaea93504b..1a26712b20 100644 --- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -109,11 +109,9 @@ void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, bool clicked, StringAlignment align); /* widget.cpp */ std::unique_ptr DrawSpriteToRgbaBuffer(SpriteID spriteId, ZoomLevel zoom = ZOOM_LVL_GUI); -int DrawString(int left, int right, int top, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL); -int DrawString(int left, int right, int top, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL); +int DrawString(int left, int right, int top, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL); int DrawString(int left, int right, int top, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL); -int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL); -int DrawStringMultiLine(int left, int right, int top, int bottom, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL); +int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL); int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL); void DrawCharCentered(WChar c, const Rect &r, TextColour colour); @@ -126,12 +124,7 @@ inline void GfxDrawLine(int left, int top, int right, int bottom, int colour, in void DrawBox(const DrawPixelInfo *dpi, int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3); /* Versions of DrawString/DrawStringMultiLine that accept a Rect instead of separate left, right, top and bottom parameters. */ -static inline int DrawString(const Rect &r, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL) -{ - return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); -} - -static inline int DrawString(const Rect &r, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL) +static inline int DrawString(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = SA_LEFT, bool underline = false, FontSize fontsize = FS_NORMAL) { return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); } @@ -141,12 +134,7 @@ static inline int DrawString(const Rect &r, StringID str, TextColour colour = TC return DrawString(r.left, r.right, r.top, str, colour, align, underline, fontsize); } -static inline int DrawStringMultiLine(const Rect &r, const char *str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL) -{ - return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); -} - -static inline int DrawStringMultiLine(const Rect &r, const std::string &str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL) +static inline int DrawStringMultiLine(const Rect &r, std::string_view str, TextColour colour = TC_FROMSTRING, StringAlignment align = (SA_TOP | SA_LEFT), bool underline = false, FontSize fontsize = FS_NORMAL) { return DrawStringMultiLine(r.left, r.right, r.top, r.bottom, str, colour, align, underline, fontsize); } @@ -161,18 +149,17 @@ static inline void GfxFillRect(const Rect &r, int colour, FillRectMode mode = FI GfxFillRect(r.left, r.top, r.right, r.bottom, colour, mode); } -Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize = FS_NORMAL); -Dimension GetStringBoundingBox(const std::string &str, FontSize start_fontsize = FS_NORMAL); +Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize = FS_NORMAL); Dimension GetStringBoundingBox(StringID strid, FontSize start_fontsize = FS_NORMAL); uint GetStringListWidth(const StringID *list, FontSize fontsize = FS_NORMAL); -int GetStringHeight(const char *str, int maxw, FontSize fontsize = FS_NORMAL); +int GetStringHeight(std::string_view str, int maxw, FontSize fontsize = FS_NORMAL); int GetStringHeight(StringID str, int maxw); int GetStringLineCount(StringID str, int maxw); Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion); -Dimension GetStringMultiLineBoundingBox(const char *str, const Dimension &suggestion); +Dimension GetStringMultiLineBoundingBox(std::string_view str, const Dimension &suggestion); void LoadStringWidthTable(bool monospace = false); -Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize = FS_NORMAL); -const char *GetCharAtPosition(const char *str, int x, FontSize start_fontsize = FS_NORMAL); +Point GetCharPosInString(std::string_view str, const char *ch, FontSize start_fontsize = FS_NORMAL); +ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize = FS_NORMAL); void DrawDirtyBlocks(); void SetDirtyBlocks(int left, int top, int right, int bottom); diff --git a/src/gfx_layout.cpp b/src/gfx_layout.cpp index 6ddb0c4b85..2c4e0d3ed4 100644 --- a/src/gfx_layout.cpp +++ b/src/gfx_layout.cpp @@ -59,7 +59,7 @@ Font::Font(FontSize size, TextColour colour) : * @tparam T The type of layouter we want. */ template -static inline void GetLayouter(Layouter::LineCacheItem &line, const char *&str, FontState &state) +static inline void GetLayouter(Layouter::LineCacheItem &line, std::string_view str, FontState &state) { if (line.buffer != nullptr) free(line.buffer); @@ -72,15 +72,18 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, const char *&str, line.buffer = buff_begin; fontMapping.clear(); + auto cur = str.begin(); + /* * Go through the whole string while adding Font instances to the font map * whenever the font changes, and convert the wide characters into a format * usable by ParagraphLayout. */ - for (; buff < buffer_last;) { - WChar c = Utf8Consume(const_cast(&str)); + for (; buff < buffer_last && cur != str.end();) { + WChar c = Utf8Consume(cur); if (c == '\0' || c == '\n') { - break; + /* Caller should already have filtered out these characters. */ + NOT_REACHED(); } else if (c >= SCC_BLUE && c <= SCC_BLACK) { state.SetColour((TextColour)(c - SCC_BLUE)); } else if (c == SCC_PUSH_COLOUR) { @@ -123,65 +126,51 @@ static inline void GetLayouter(Layouter::LineCacheItem &line, const char *&str, * @param colour The colour of the font. * @param fontsize The size of font to use. */ -Layouter::Layouter(const char *str, int maxw, TextColour colour, FontSize fontsize) : string(str) +Layouter::Layouter(std::string_view str, int maxw, TextColour colour, FontSize fontsize) : string(str) { FontState state(colour, fontsize); - WChar c = 0; - do { - /* Scan string for end of line */ - const char *lineend = str; - for (;;) { - size_t len = Utf8Decode(&c, lineend); - if (c == '\0' || c == '\n') break; - lineend += len; - } + while (true) { + auto line_length = str.find_first_of('\n'); + auto str_line = str.substr(0, line_length); - LineCacheItem& line = GetCachedParagraphLayout(str, lineend - str, state); + LineCacheItem &line = GetCachedParagraphLayout(str_line, state); if (line.layout != nullptr) { - /* Line is in cache */ - str = lineend + 1; state = line.state_after; line.layout->Reflow(); } else { /* Line is new, layout it */ FontState old_state = state; -#if (defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ)) || defined(WITH_UNISCRIBE) || defined(WITH_COCOA) - const char *old_str = str; -#endif #if defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ) if (line.layout == nullptr) { - GetLayouter(line, str, state); + GetLayouter(line, str_line, state); if (line.layout == nullptr) { state = old_state; - str = old_str; } } #endif #ifdef WITH_UNISCRIBE if (line.layout == nullptr) { - GetLayouter(line, str, state); + GetLayouter(line, str_line, state); if (line.layout == nullptr) { state = old_state; - str = old_str; } } #endif #ifdef WITH_COCOA if (line.layout == nullptr) { - GetLayouter(line, str, state); + GetLayouter(line, str_line, state); if (line.layout == nullptr) { state = old_state; - str = old_str; } } #endif if (line.layout == nullptr) { - GetLayouter(line, str, state); + GetLayouter(line, str_line, state); } } @@ -191,7 +180,15 @@ Layouter::Layouter(const char *str, int maxw, TextColour colour, FontSize fontsi if (l == nullptr) break; this->push_back(std::move(l)); } - } while (c != '\0'); + + /* Break out if this was the last line. */ + if (line_length == std::string_view::npos) { + break; + } + + /* Go to the next line. */ + str.remove_prefix(line_length + 1); + } } /** @@ -210,58 +207,58 @@ Dimension Layouter::GetBounds() /** * Get the position of a character in the layout. - * @param ch Character to get the position of. + * @param ch Character to get the position of. Must be an iterator of the string passed to the constructor. * @return Upper left corner of the character relative to the start of the string. * @note Will only work right for single-line strings. */ -Point Layouter::GetCharPosition(const char *ch) const +Point Layouter::GetCharPosition(std::string_view::const_iterator ch) const { + const auto &line = this->front(); + + /* Pointer to the end-of-string marker? Return total line width. */ + if (ch == this->string.end()) { + Point p = { line->GetWidth(), 0 }; + return p; + } + /* Find the code point index which corresponds to the char * pointer into our UTF-8 source string. */ size_t index = 0; - const char *str = this->string; + auto str = this->string.begin(); while (str < ch) { - WChar c; - size_t len = Utf8Decode(&c, str); - if (c == '\0' || c == '\n') break; - str += len; - index += this->front()->GetInternalCharLength(c); + WChar c = Utf8Consume(str); + index += line->GetInternalCharLength(c); } - if (str == ch) { - /* Valid character. */ - const auto &line = this->front(); + /* We couldn't find the code point index. */ + if (str != ch) { + return { 0, 0 }; + } - /* Pointer to the end-of-string/line marker? Return total line width. */ - if (*ch == '\0' || *ch == '\n') { - Point p = { line->GetWidth(), 0 }; - return p; - } + /* Valid character. */ - /* Scan all runs until we've found our code point index. */ - for (int run_index = 0; run_index < line->CountRuns(); run_index++) { - const ParagraphLayouter::VisualRun &run = line->GetVisualRun(run_index); + /* Scan all runs until we've found our code point index. */ + for (int run_index = 0; run_index < line->CountRuns(); run_index++) { + const ParagraphLayouter::VisualRun &run = line->GetVisualRun(run_index); - for (int i = 0; i < run.GetGlyphCount(); i++) { - /* Matching glyph? Return position. */ - if ((size_t)run.GetGlyphToCharMap()[i] == index) { - Point p = { (int)run.GetPositions()[i * 2], (int)run.GetPositions()[i * 2 + 1] }; - return p; - } + for (int i = 0; i < run.GetGlyphCount(); i++) { + /* Matching glyph? Return position. */ + if ((size_t)run.GetGlyphToCharMap()[i] == index) { + Point p = { (int)run.GetPositions()[i * 2], (int)run.GetPositions()[i * 2 + 1] }; + return p; } } } - Point p = { 0, 0 }; - return p; + NOT_REACHED(); } /** * Get the character that is at a position. * @param x Position in the string. - * @return Pointer to the character at the position or nullptr if no character is at the position. + * @return Index of the position or -1 if no character is at the position. */ -const char *Layouter::GetCharAtPosition(int x) const +ptrdiff_t Layouter::GetCharAtPosition(int x) const { const auto &line = this->front(); @@ -280,17 +277,18 @@ const char *Layouter::GetCharAtPosition(int x) const size_t index = run.GetGlyphToCharMap()[i]; size_t cur_idx = 0; - for (const char *str = this->string; *str != '\0'; ) { - if (cur_idx == index) return str; + int char_index = 0; + for (auto str = this->string.begin(); str != this->string.end(); char_index++) { + if (cur_idx == index) return char_index; - WChar c = Utf8Consume(&str); + WChar c = Utf8Consume(str); cur_idx += line->GetInternalCharLength(c); } } } } - return nullptr; + return -1; } /** @@ -332,18 +330,17 @@ void Layouter::ResetFontCache(FontSize size) * Get reference to cache item. * If the item does not exist yet, it is default constructed. * @param str Source string of the line (including colour and font size codes). - * @param len Length of \a str in bytes (no termination). * @param state State of the font at the beginning of the line. * @return Reference to cache item. */ -Layouter::LineCacheItem &Layouter::GetCachedParagraphLayout(const char *str, size_t len, const FontState &state) +Layouter::LineCacheItem &Layouter::GetCachedParagraphLayout(std::string_view str, const FontState &state) { if (linecache == nullptr) { /* Create linecache on first access to avoid trouble with initialisation order of static variables. */ linecache = new LineCache(); } - if (auto match = linecache->find(LineCacheQuery{state, std::string_view{str, len}}); + if (auto match = linecache->find(LineCacheQuery{state, str}); match != linecache->end()) { return match->second; } @@ -351,7 +348,7 @@ Layouter::LineCacheItem &Layouter::GetCachedParagraphLayout(const char *str, siz /* Create missing entry */ LineCacheKey key; key.state_before = state; - key.str.assign(str, len); + key.str.assign(str); return (*linecache)[key]; } diff --git a/src/gfx_layout.h b/src/gfx_layout.h index 7fca7ca082..a227cd1db4 100644 --- a/src/gfx_layout.h +++ b/src/gfx_layout.h @@ -127,7 +127,7 @@ public: * It also accounts for the memory allocations and frees. */ class Layouter : public std::vector> { - const char *string; ///< Pointer to the original string. + std::string_view string; ///< Pointer to the original string. /** Key into the linecache */ struct LineCacheKey { @@ -171,17 +171,17 @@ private: typedef std::map LineCache; static LineCache *linecache; - static LineCacheItem &GetCachedParagraphLayout(const char *str, size_t len, const FontState &state); + static LineCacheItem &GetCachedParagraphLayout(std::string_view str, const FontState &state); typedef SmallMap FontColourMap; static FontColourMap fonts[FS_END]; public: static Font *GetFont(FontSize size, TextColour colour); - Layouter(const char *str, int maxw = INT32_MAX, TextColour colour = TC_FROMSTRING, FontSize fontsize = FS_NORMAL); + Layouter(std::string_view str, int maxw = INT32_MAX, TextColour colour = TC_FROMSTRING, FontSize fontsize = FS_NORMAL); Dimension GetBounds(); - Point GetCharPosition(const char *ch) const; - const char *GetCharAtPosition(int x) const; + Point GetCharPosition(std::string_view::const_iterator ch) const; + ptrdiff_t GetCharAtPosition(int x) const; static void ResetFontCache(FontSize size); static void ResetLineCache(); diff --git a/src/gfx_layout_icu.cpp b/src/gfx_layout_icu.cpp index d4160989a0..710dee19d0 100644 --- a/src/gfx_layout_icu.cpp +++ b/src/gfx_layout_icu.cpp @@ -208,7 +208,7 @@ void ICURun::Shape(UChar *buff, size_t buff_length) { x_advance = glyph_pos[i].x_advance / FONT_SCALE; } - this->glyph_to_char.push_back(glyph_info[i].cluster); + this->glyph_to_char.push_back(glyph_info[i].cluster - this->start); this->advance.push_back(x_advance); advance += x_advance; } diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index e4ba7095e2..5bf80d43d1 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -893,7 +893,7 @@ struct PaymentRatesGraphWindow : BaseGraphWindow { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_CPR_MATRIX_SCROLLBAR); - this->vscroll->SetCount(static_cast(_sorted_standard_cargo_specs.size())); + this->vscroll->SetCount(_sorted_standard_cargo_specs.size()); this->SetWidgetLoweredState(WID_CPR_DAYS, _cargo_payment_x_mode == 0); this->SetWidgetLoweredState(WID_CPR_SPEED, _cargo_payment_x_mode == 1); diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp index 3ab8722ceb..e5ee18f1b8 100644 --- a/src/ground_vehicle.cpp +++ b/src/ground_vehicle.cpp @@ -269,13 +269,13 @@ GroundVehicleAcceleration GroundVehicle::GetAcceleration() /* Assume that every part of a train is braked, not just the engine. * Exceptionally heavy freight trains should still have a sensible braking distance. * The total braking force is generally larger than the total tractive force. */ - braking_accel = ClampToI32((-braking_force - resistance - (Train::From(this)->tcache.cached_braking_length * (int64)RBC_BRAKE_FORCE_PER_LENGTH)) / (mass * 4)); + braking_accel = ClampTo((-braking_force - resistance - (Train::From(this)->tcache.cached_braking_length * (int64)RBC_BRAKE_FORCE_PER_LENGTH)) / (mass * 4)); /* Defensive driving: prevent ridiculously fast deceleration. * -130 corresponds to a braking distance of about 6.2 tiles from 160 km/h. */ braking_accel = std::max(braking_accel, -(GetTrainRealisticBrakingTargetDecelerationLimit(acceleration_type) + 10)); } else { - braking_accel = ClampToI32(std::min(-braking_force - resistance, -10000) / mass); + braking_accel = ClampTo(std::min(-braking_force - resistance, -10000) / mass); } if (mode == AS_ACCEL) { @@ -287,7 +287,7 @@ GroundVehicleAcceleration GroundVehicle::GetAcceleration() * down hill will never slow down enough, and a vehicle that came up * a hill will never speed up enough to (eventually) get back to the * same (maximum) speed. */ - int accel = ClampToI32((force - resistance) / (mass * 4)); + int accel = ClampTo((force - resistance) / (mass * 4)); accel = force < resistance ? std::min(-1, accel) : std::max(1, accel); if (this->type == VEH_TRAIN) { if(_settings_game.vehicle.train_acceleration_model == AM_ORIGINAL && diff --git a/src/group_gui.cpp b/src/group_gui.cpp index e651a9f38f..b3e2d34c32 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -438,7 +438,7 @@ public: this->groups.ForceRebuild(); this->groups.NeedResort(); this->BuildGroupList(vli.company); - this->group_sb->SetCount((uint)this->groups.size()); + this->group_sb->SetCount(this->groups.size()); this->RecalculateInfoTotals(); @@ -587,8 +587,8 @@ public: this->BuildGroupList(this->owner); - this->group_sb->SetCount(static_cast(this->groups.size())); - this->vscroll->SetCount(static_cast(this->vehgroups.size())); + this->group_sb->SetCount(this->groups.size()); + this->vscroll->SetCount(this->vehgroups.size()); /* The drop down menu is out, *but* it may not be used, retract it. */ if (!this->ShouldShowActionDropdownList() && this->IsWidgetLowered(WID_GL_MANAGE_VEHICLES_DROPDOWN)) { @@ -675,13 +675,13 @@ public: case WID_GL_LIST_GROUP: { int y1 = r.top + WidgetDimensions::scaled.framerect.top; - int max = std::min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.size()); - for (int i = this->group_sb->GetPosition(); i < max; ++i) { + size_t max = std::min(this->group_sb->GetPosition() + this->group_sb->GetCapacity(), this->groups.size()); + for (size_t i = this->group_sb->GetPosition(); i < max; ++i) { const Group *g = this->groups[i]; assert(g->owner == this->owner); - DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * WidgetDimensions::scaled.hsep_indent, HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION), g->folded || (i + 1 < (int)this->groups.size() && indents[i + 1] > this->indents[i])); + DrawGroupInfo(y1, r.left, r.right, g->index, this->indents[i] * WidgetDimensions::scaled.hsep_indent, HasBit(g->flags, GroupFlags::GF_REPLACE_PROTECTION), g->folded || (i + 1 < this->groups.size() && indents[i + 1] > this->indents[i])); y1 += this->tiny_step_height; } @@ -699,8 +699,8 @@ public: if (this->vli.index != ALL_GROUP && this->grouping == GB_NONE) { /* Mark vehicles which are in sub-groups (only if we are not using shared order coalescing) */ Rect mr = r.WithHeight(this->resize.step_height); - uint max = static_cast(std::min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size())); - for (uint i = this->vscroll->GetPosition(); i < max; ++i) { + size_t max = std::min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->vehgroups.size()); + for (size_t i = this->vscroll->GetPosition(); i < max; ++i) { const Vehicle *v = this->vehgroups[i].GetSingleVehicle(); if (v->group_id != this->vli.index) { GfxFillRect(mr.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[COLOUR_GREY][3], FILLRECT_CHECKER); @@ -1242,7 +1242,7 @@ public: } this->groups.ForceRebuild(); this->BuildGroupList(this->owner); - this->group_sb->SetCount((uint)this->groups.size()); + this->group_sb->SetCount(this->groups.size()); id_g = find_index(this->groups, g); } this->group_sb->ScrollTowards(id_g); diff --git a/src/highscore.cpp b/src/highscore.cpp index d40f2419de..69ca393a91 100644 --- a/src/highscore.cpp +++ b/src/highscore.cpp @@ -132,7 +132,7 @@ void SaveToHighScore() for (i = 0; i < SP_SAVED_HIGHSCORE_END; i++) { for (hs = _highscore_table[i]; hs != endof(_highscore_table[i]); hs++) { /* First character is a command character, so strlen will fail on that */ - byte length = std::min(sizeof(hs->company), StrEmpty(hs->company) ? 0 : strlen(&hs->company[1]) + 1); + byte length = ClampTo(std::min(sizeof(hs->company), StrEmpty(hs->company) ? 0 : strlen(&hs->company[1]) + 1)); if (fwrite(&length, sizeof(length), 1, fp) != 1 || // write away string length fwrite(hs->company, length, 1, fp) > 1 || // Yes... could be 0 bytes too diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 15fce1177f..ddf43ece47 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1182,7 +1182,7 @@ static void ChopLumberMillTrees(Industry *i) TileIndex tile = i->location.tile; if (CircularTileSearch(&tile, 40, SearchLumberMillTrees, nullptr)) { // 40x40 tiles to search. - i->produced_cargo_waiting[0] = std::min(0xffff, i->produced_cargo_waiting[0] + 45); // Found a tree, add according value to waiting cargo. + i->produced_cargo_waiting[0] = ClampTo(i->produced_cargo_waiting[0] + 45); // Found a tree, add according value to waiting cargo. } } @@ -1193,7 +1193,7 @@ static void ProduceIndustryGoodsFromRate(Industry *i, bool scale) if (amount != 0 && scale) { amount = ScaleQuantity(amount, _settings_game.economy.industry_cargo_scale_factor); } - i->produced_cargo_waiting[j] = std::min(0xffff, i->produced_cargo_waiting[j] + amount); + i->produced_cargo_waiting[j] = ClampTo(i->produced_cargo_waiting[j] + amount); } } @@ -1853,7 +1853,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, IndustryType type, /* Randomize inital production if non-original economy is used and there are no production related callbacks. */ if (!indspec->UsesOriginalEconomy()) { for (size_t ci = 0; ci < lengthof(i->production_rate); ci++) { - i->production_rate[ci] = std::min((RandomRange(256) + 128) * i->production_rate[ci] >> 8, 255u); + i->production_rate[ci] = ClampTo((RandomRange(256) + 128) * i->production_rate[ci] >> 8); } } @@ -2503,7 +2503,7 @@ static void UpdateIndustryStatistics(Industry *i) byte pct = 0; if (i->this_month_production[j] != 0) { i->last_prod_year = _cur_year; - pct = std::min(i->this_month_transported[j] * 256 / i->this_month_production[j], 255); + pct = ClampTo(i->this_month_transported[j] * 256 / i->this_month_production[j]); } i->last_month_pct_transported[j] = pct; @@ -2527,7 +2527,7 @@ void Industry::RecomputeProductionMultipliers() /* Rates are rounded up, so e.g. oilrig always produces some passengers */ for (size_t i = 0; i < lengthof(this->production_rate); i++) { - this->production_rate[i] = std::min(CeilDiv(indspec->production_rate[i] * this->prod_level, PRODLEVEL_DEFAULT), 0xFFu); + this->production_rate[i] = ClampTo(CeilDiv(indspec->production_rate[i] * this->prod_level, PRODLEVEL_DEFAULT)); } } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index abc721000d..13ee387bba 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -302,25 +302,23 @@ static WindowDesc _build_industry_desc( /** Build (fund or prospect) a new industry, */ class BuildIndustryWindow : public Window { - int selected_index; ///< index of the element in the matrix IndustryType selected_type; ///< industry corresponding to the above index - uint16 count; ///< How many industries are loaded - IndustryType index[NUM_INDUSTRYTYPES + 1]; ///< Type of industry, in the order it was loaded - bool enabled[NUM_INDUSTRYTYPES + 1]; ///< availability state, coming from CBID_INDUSTRY_PROBABILITY (if ever) + std::vector list; ///< List of industries. + bool enabled; ///< Availability state of the selected industry. Scrollbar *vscroll; Dimension legend; ///< Dimension of the legend 'blob'. /** The largest allowed minimum-width of the window, given in line heights */ static const int MAX_MINWIDTH_LINEHEIGHTS = 20; + void UpdateAvailability() + { + this->enabled = this->selected_type != INVALID_INDUSTRYTYPE && (_game_mode == GM_EDITOR || GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0); + } + void SetupArrays() { - this->count = 0; - - for (uint i = 0; i < lengthof(this->index); i++) { - this->index[i] = INVALID_INDUSTRYTYPE; - this->enabled[i] = false; - } + this->list.clear(); /* Fill the arrays with industries. * The tests performed after the enabled allow to load the industries @@ -334,32 +332,27 @@ class BuildIndustryWindow : public Window { * and raw ones are loaded only when setting allows it */ if (_game_mode != GM_EDITOR && indsp->IsRawIndustry() && _settings_game.construction.raw_industry_construction == 0) { /* Unselect if the industry is no longer in the list */ - if (this->selected_type == ind) this->selected_index = -1; + if (this->selected_type == ind) this->selected_type = INVALID_INDUSTRYTYPE; continue; } - this->index[this->count] = ind; - this->enabled[this->count] = (_game_mode == GM_EDITOR) || GetIndustryProbabilityCallback(ind, IACT_USERCREATION, 1) > 0; - /* Keep the selection to the correct line */ - if (this->selected_type == ind) this->selected_index = this->count; - this->count++; + + this->list.push_back(ind); } } - /* first industry type is selected if the current selection is invalid. - * I'll be damned if there are none available ;) */ - if (this->selected_index == -1) { - this->selected_index = 0; - this->selected_type = this->index[0]; - } + /* First industry type is selected if the current selection is invalid. */ + if (this->selected_type == INVALID_INDUSTRYTYPE && !this->list.empty()) this->selected_type = this->list[0]; - this->vscroll->SetCount(this->count); + this->UpdateAvailability(); + + this->vscroll->SetCount(this->list.size()); } /** Update status of the fund and display-chain widgets. */ void SetButtons() { - this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled[this->selected_index]); - this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled[this->selected_index]); + this->SetWidgetDisabledState(WID_DPI_FUND_WIDGET, this->selected_type != INVALID_INDUSTRYTYPE && !this->enabled); + this->SetWidgetDisabledState(WID_DPI_DISPLAY_WIDGET, this->selected_type == INVALID_INDUSTRYTYPE && this->enabled); } /** @@ -412,7 +405,6 @@ class BuildIndustryWindow : public Window { public: BuildIndustryWindow() : Window(&_build_industry_desc) { - this->selected_index = -1; this->selected_type = INVALID_INDUSTRYTYPE; this->CreateNestedTree(); @@ -443,9 +435,8 @@ public: switch (widget) { case WID_DPI_MATRIX_WIDGET: { Dimension d = GetStringBoundingBox(STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES); - for (uint16 i = 0; i < this->count; i++) { - if (this->index[i] == INVALID_INDUSTRYTYPE) continue; - d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(this->index[i])->name)); + for (const auto &indtype : this->list) { + d = maxdim(d, GetStringBoundingBox(GetIndustrySpec(indtype)->name)); } resize->height = std::max(this->legend.height, FONT_HEIGHT_NORMAL) + padding.height; d.width += this->legend.width + WidgetDimensions::scaled.hsep_wide + padding.width; @@ -462,14 +453,12 @@ public: uint extra_lines_newgrf = 0; uint max_minwidth = FONT_HEIGHT_NORMAL * MAX_MINWIDTH_LINEHEIGHTS; Dimension d = {0, 0}; - for (uint16 i = 0; i < this->count; i++) { - if (this->index[i] == INVALID_INDUSTRYTYPE) continue; - - const IndustrySpec *indsp = GetIndustrySpec(this->index[i]); + for (const auto &indtype : this->list) { + const IndustrySpec *indsp = GetIndustrySpec(indtype); CargoSuffix cargo_suffix[lengthof(indsp->accepts_cargo)]; /* Measure the accepted cargoes, if any. */ - GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, this->index[i], indsp, indsp->accepts_cargo, cargo_suffix); + GetAllCargoSuffixes(CARGOSUFFIX_IN, CST_FUND, nullptr, indtype, indsp, indsp->accepts_cargo, cargo_suffix); std::string cargostring = this->MakeCargoListString(indsp->accepts_cargo, cargo_suffix, lengthof(indsp->accepts_cargo), STR_INDUSTRY_VIEW_REQUIRES_N_CARGO); Dimension strdim = GetStringBoundingBox(cargostring.c_str()); if (strdim.width > max_minwidth) { @@ -479,7 +468,7 @@ public: d = maxdim(d, strdim); /* Measure the produced cargoes, if any. */ - GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, this->index[i], indsp, indsp->produced_cargo, cargo_suffix); + GetAllCargoSuffixes(CARGOSUFFIX_OUT, CST_FUND, nullptr, indtype, indsp, indsp->produced_cargo, cargo_suffix); cargostring = this->MakeCargoListString(indsp->produced_cargo, cargo_suffix, lengthof(indsp->produced_cargo), STR_INDUSTRY_VIEW_PRODUCES_N_CARGO); strdim = GetStringBoundingBox(cargostring.c_str()); if (strdim.width > max_minwidth) { @@ -523,8 +512,8 @@ public: /* We've chosen many random industries but no industries have been specified */ SetDParam(0, STR_FUND_INDUSTRY_BUILD_NEW_INDUSTRY); } else { - if (count > 0) { - const IndustrySpec *indsp = GetIndustrySpec(this->index[this->selected_index]); + if (this->selected_type != INVALID_INDUSTRYTYPE) { + const IndustrySpec *indsp = GetIndustrySpec(this->selected_type); SetDParam(0, (_settings_game.construction.raw_industry_construction == 2 && indsp->IsRawIndustry()) ? STR_FUND_INDUSTRY_PROSPECT_NEW_INDUSTRY : STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY); } else { SetDParam(0, STR_FUND_INDUSTRY_FUND_NEW_INDUSTRY); @@ -547,19 +536,15 @@ public: icon.top = r.top + (this->resize.step_height - this->legend.height + 1) / 2; icon.bottom = icon.top + this->legend.height - 1; - for (uint16 i = 0; i < this->vscroll->GetCapacity() && i + this->vscroll->GetPosition() < this->count; i++) { - bool selected = this->selected_index == i + this->vscroll->GetPosition(); + for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) { + bool selected = this->selected_type == this->list[i]; - if (this->index[i + this->vscroll->GetPosition()] == INVALID_INDUSTRYTYPE) { - DrawString(text, STR_FUND_INDUSTRY_MANY_RANDOM_INDUSTRIES, selected ? TC_WHITE : TC_ORANGE); - } else { - const IndustrySpec *indsp = GetIndustrySpec(this->index[i + this->vscroll->GetPosition()]); + const IndustrySpec *indsp = GetIndustrySpec(this->list[i]); - /* Draw the name of the industry in white is selected, otherwise, in orange */ - DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE); - GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK); - GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour); - } + /* Draw the name of the industry in white is selected, otherwise, in orange */ + DrawString(text, indsp->name, selected ? TC_WHITE : TC_ORANGE); + GfxFillRect(icon, selected ? PC_WHITE : PC_BLACK); + GfxFillRect(icon.Shrink(WidgetDimensions::scaled.bevel), indsp->map_colour); text = text.Translate(0, this->resize.step_height); icon = icon.Translate(0, this->resize.step_height); @@ -666,24 +651,23 @@ public: case WID_DPI_MATRIX_WIDGET: { int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_DPI_MATRIX_WIDGET); - if (y < this->count) { // Is it within the boundaries of available data? - this->selected_index = y; - this->selected_type = this->index[y]; - const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type); + if (y != INT_MAX) { // Is it within the boundaries of available data? + this->selected_type = this->list[y]; + this->UpdateAvailability(); + + const IndustrySpec *indsp = GetIndustrySpec(this->selected_type); this->SetDirty(); if (_thd.GetCallbackWnd() == this && - ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) || - this->selected_type == INVALID_INDUSTRYTYPE || - !this->enabled[this->selected_index])) { + ((_game_mode != GM_EDITOR && _settings_game.construction.raw_industry_construction == 2 && indsp != nullptr && indsp->IsRawIndustry()) || !this->enabled)) { /* Reset the button state if going to prospecting or "build many industries" */ this->RaiseButtons(); ResetObjectToPlace(); } this->SetButtons(); - if (this->enabled[this->selected_index] && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1); + if (this->enabled && click_count > 1) this->OnClick(pt, WID_DPI_FUND_WIDGET, 1); } break; } @@ -749,18 +733,13 @@ public: void OnHundredthTick() override { if (_game_mode == GM_EDITOR) return; - if (this->count == 0) return; - const IndustrySpec *indsp = GetIndustrySpec(this->selected_type); + if (this->selected_type == INVALID_INDUSTRYTYPE) return; - if (indsp->enabled) { - bool call_back_result = GetIndustryProbabilityCallback(this->selected_type, IACT_USERCREATION, 1) > 0; - - /* Only if result does match the previous state would it require a redraw. */ - if (call_back_result != this->enabled[this->selected_index]) { - this->enabled[this->selected_index] = call_back_result; - this->SetButtons(); - this->SetDirty(); - } + bool enabled = this->enabled; + this->UpdateAvailability(); + if (enabled != this->enabled) { + this->SetButtons(); + this->SetDirty(); } } @@ -783,9 +762,6 @@ public: { if (!gui_scope) return; this->SetupArrays(); - - const IndustrySpec *indsp = (this->selected_type == INVALID_INDUSTRYTYPE) ? nullptr : GetIndustrySpec(this->selected_type); - if (indsp == nullptr) this->enabled[this->selected_index] = _settings_game.difficulty.industry_density != ID_FUND_ONLY; this->SetButtons(); this->SetDirty(); } @@ -1059,10 +1035,10 @@ public: case EA_MULTIPLIER: if (decrease) { if (i->prod_level <= PRODLEVEL_MINIMUM) return; - i->prod_level = std::max(i->prod_level / 2, PRODLEVEL_MINIMUM); + i->prod_level = static_cast(std::max(i->prod_level / 2, PRODLEVEL_MINIMUM)); } else { if (i->prod_level >= PRODLEVEL_MAXIMUM) return; - i->prod_level = std::min(i->prod_level * 2, PRODLEVEL_MAXIMUM); + i->prod_level = static_cast(std::min(i->prod_level * 2, PRODLEVEL_MAXIMUM)); } break; @@ -1074,7 +1050,7 @@ public: if (i->production_rate[line - IL_RATE1] >= 255) return; /* a zero production industry is unlikely to give anything but zero, so push it a little bit */ int new_prod = i->production_rate[line - IL_RATE1] == 0 ? 1 : i->production_rate[line - IL_RATE1] * 2; - i->production_rate[line - IL_RATE1] = std::min(new_prod, 255); + i->production_rate[line - IL_RATE1] = ClampTo(new_prod); } break; @@ -1465,7 +1441,7 @@ protected: IndustryDirectoryWindow::produced_cargo_filter = this->cargo_filter[this->produced_cargo_filter_criteria]; this->industries.Sort(); - this->vscroll->SetCount((uint)this->industries.size()); // Update scrollbar as well. + this->vscroll->SetCount(this->industries.size()); // Update scrollbar as well. this->SetDirty(); } @@ -1920,7 +1896,7 @@ static const NWidgetPart _nested_industry_cargoes_widgets[] = { EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(NWID_VERTICAL), - NWidget(WWT_PANEL, COLOUR_BROWN, WID_IC_PANEL), SetResize(1, 10), SetMinimalSize(200, 90), SetScrollbar(WID_IC_SCROLLBAR), EndContainer(), + NWidget(WWT_PANEL, COLOUR_BROWN, WID_IC_PANEL), SetResize(1, 10), SetScrollbar(WID_IC_SCROLLBAR), EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(NWID_BUTTON_DROPDOWN, COLOUR_BROWN, WID_IC_NOTIFY), SetDataTip(STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP, STR_INDUSTRY_CARGOES_NOTIFY_SMALLMAP_TOOLTIP), @@ -2983,19 +2959,19 @@ struct IndustryCargoesWindow : public Window { { if (widget != WID_IC_PANEL) return; - Rect ir = r.Shrink(WidgetDimensions::scaled.framerect); + Rect ir = r.Shrink(WidgetDimensions::scaled.bevel); DrawPixelInfo tmp_dpi; if (!FillDrawPixelInfo(&tmp_dpi, ir.left, ir.top, ir.Width(), ir.Height())) return; AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); - int left_pos = ir.left; + int left_pos = WidgetDimensions::scaled.frametext.left - WidgetDimensions::scaled.bevel.left; if (this->ind_cargo >= NUM_INDUSTRYTYPES) left_pos += (CargoesField::industry_width + CargoesField::cargo_field_width) / 2; int last_column = (this->ind_cargo < NUM_INDUSTRYTYPES) ? 4 : 2; const NWidgetBase *nwp = this->GetWidget(WID_IC_PANEL); - int vpos = -this->vscroll->GetPosition() * nwp->resize_y; - for (uint i = 0; i < this->fields.size(); i++) { - int row_height = (i == 0) ? CargoesField::small_height : CargoesField::normal_height; + int vpos = WidgetDimensions::scaled.frametext.top - WidgetDimensions::scaled.bevel.top - this->vscroll->GetPosition() * nwp->resize_y; + int row_height = CargoesField::small_height; + for (const auto &field : this->fields) { if (vpos + row_height >= 0) { int xpos = left_pos; int col, dir; @@ -3007,13 +2983,14 @@ struct IndustryCargoesWindow : public Window { dir = 1; } while (col >= 0 && col <= last_column) { - this->fields[i].columns[col].Draw(xpos, vpos); + field.columns[col].Draw(xpos, vpos); xpos += (col & 1) ? CargoesField::cargo_field_width : CargoesField::industry_width; col += dir; } } vpos += row_height; if (vpos >= height) break; + row_height = CargoesField::normal_height; } } diff --git a/src/lang/catalan.txt b/src/lang/catalan.txt index 864f2a5951..8fb144e603 100644 --- a/src/lang/catalan.txt +++ b/src/lang/catalan.txt @@ -932,8 +932,22 @@ STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Copia el # Game options window STR_GAME_OPTIONS_CAPTION :{WHITE}Opcions de la partida +STR_GAME_OPTIONS_TAB_GENERAL :General +STR_GAME_OPTIONS_TAB_GENERAL_TT :{BLACK}Trieu la configuració general. +STR_GAME_OPTIONS_TAB_GRAPHICS :Gràfics +STR_GAME_OPTIONS_TAB_GRAPHICS_TT :{BLACK}Trieu la configuració dels gràfics. +STR_GAME_OPTIONS_TAB_SOUND :So +STR_GAME_OPTIONS_TAB_SOUND_TT :{BLACK}Escolliu la configuració de so i de música. +STR_GAME_OPTIONS_VOLUME :Volum +STR_GAME_OPTIONS_SFX_VOLUME :Efectes de so +STR_GAME_OPTIONS_MUSIC_VOLUME :Música +STR_GAME_OPTIONS_VOLUME_0 :0{NBSP}% +STR_GAME_OPTIONS_VOLUME_25 :25{NBSP}% +STR_GAME_OPTIONS_VOLUME_50 :50{NBSP}% +STR_GAME_OPTIONS_VOLUME_75 :75{NBSP}% +STR_GAME_OPTIONS_VOLUME_100 :100{NBSP}% STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME :{BLACK}Moneda STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP :{BLACK}Selecció de la unitat monetària @@ -988,6 +1002,10 @@ STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP :{BLACK}Seleccio # Autosave dropdown ###length 5 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF :Inactiu +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_10_MINUTES :Cada 10 minuts +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_30_MINUTES :Cada 30 minuts +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_60_MINUTES :Cada 60 minuts +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_120_MINUTES :Cada 120 minuts STR_GAME_OPTIONS_LANGUAGE :{BLACK}Idioma STR_GAME_OPTIONS_LANGUAGE_TOOLTIP :{BLACK}Selecciona l'idioma de la interfície @@ -1153,6 +1171,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Desplega STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Plega-ho tot STR_CONFIG_SETTING_RESET_ALL :{BLACK}Restableix tots els valors STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(cap explicació disponible) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Valor per defecte: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Tipus de paràmetre: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Paràmetre del client (no s'emmagatzema a les partides; afecta a totes les partides) @@ -1713,7 +1732,7 @@ STR_CONFIG_SETTING_SCRIPT_MAX_MEMORY_HELPTEXT :Quantitat de me STR_CONFIG_SETTING_SCRIPT_MAX_MEMORY_VALUE :{COMMA}{NBSP}MiB STR_CONFIG_SETTING_SERVINT_ISPERCENT :Els intervals de revisions es mostren en percentatges: {STRING} -STR_CONFIG_SETTING_SERVINT_ISPERCENT_HELPTEXT :Escull si les revisions dels vehicles depenen del temps passat des de la darrera revisió o de la caiguda d'un cert percentatge de la fiabilitat màxima +STR_CONFIG_SETTING_SERVINT_ISPERCENT_HELPTEXT :Quan l'opció està activada, els vehicles intenten fer les seves revisions quan la seva fiabilitat baixa d'un cert percentatge de la fiabilitat màxima.{}{}Per exemple, si la fiabilitat màxima d'un vehicle és del 90{NBSP}% i l'interval de revisions és del 20{NBSP}%, el vehicle mirarà de fer la revisió quan arribi a un 72{NBSP}% de fiabilitat. STR_CONFIG_SETTING_SERVINT_TRAINS :Interval per defecte de servei per als trens: {STRING} STR_CONFIG_SETTING_SERVINT_TRAINS_HELPTEXT :Estableix l'interval de revisió predeterminat pels nous ferrocarrils, si no hi ha un interval de revisió explícit pel vehicle @@ -1918,6 +1937,10 @@ STR_CONFIG_SETTING_LARGER_TOWNS_DISABLED :Cap STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER :Multiplicador de mida inicial de ciutats: {STRING} STR_CONFIG_SETTING_CITY_SIZE_MULTIPLIER_HELPTEXT :La grandària mitjana de les ciutats en relació als pobles a l'inici de la partida. +STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL :Actualitza el graf de distribució cada {STRING}{NBSP}segon{P 0:2 "" s} +STR_CONFIG_SETTING_LINKGRAPH_RECALC_INTERVAL_HELPTEXT :Temps entre actualitzacions de les arestes del graf de distribució. Cada vegada es calcularan els plans d'un dels components del graf. Això vol dir que un valor X d'aquesta opció no significa que es recalculi el graf sencer cada X segons. Només ho farà algun component. Com més curt sigui, farà falta més temps de CPU per a calcular-lo. Com més llarg sigui, més es trigarà a què la distribució de càrrega s'apliqui a les rutes noves. +STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME :Triga {STRING}{NBSP}segon{P 0:2 "" s} per a recalcular el graf de distribució +STR_CONFIG_SETTING_LINKGRAPH_RECALC_TIME_HELPTEXT :Temps emprat per a cada actualització del component d'una aresta del graf. Quan comença el recàlcul, s'inicia un fil que pot executar-se durant aquests segons. Com més curt sigui, més probable és que el fil no acabi a temps. Llavors, la partida para fins que finalitzi, provocant una interrupció del desenvolupament de la partida. Com més llarg sigui, més es trigarà a actualitzar el graf de distribució quan es facin canvis de rutes. STR_CONFIG_SETTING_DISTRIBUTION_PAX :Mode de distribució per passatgers: {STRING} STR_CONFIG_SETTING_DISTRIBUTION_PAX_HELPTEXT :"Simètric" vol dir que aproximadament el mateix nombre de passatgers aniran des de l'estació A a la B que de B a A. "Asimètric" significa que un nombre arbitrari de passatgers poden anar en qualsevol dels dos sentits. "Manual" vol dir que no s'aplicarà una distribució automàtica pels passatgers. @@ -3806,6 +3829,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Envia in STR_VEHICLE_LIST_REPLACE_VEHICLES :Substitueix vehicles STR_VEHICLE_LIST_SEND_FOR_SERVICING :Envia a fer revisió STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Benefici enguany: {CURRENCY_LONG} (darrer any: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Envia a la cotxera STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Envia a la cotxera @@ -4572,6 +4597,7 @@ STR_AI_CONFIG_RANDOM_AI :IA aleatòria STR_AI_CONFIG_NONE :(cap) STR_AI_CONFIG_NAME_VERSION :{STRING} {YELLOW}v{NUM} STR_AI_CONFIG_MAX_COMPETITORS :{LTBLUE}Nombre màxim de competidors: {ORANGE}{COMMA} +STR_AI_CONFIG_COMPETITORS_INTERVAL :{LTBLUE}Interval entre l'inici de competidors: {ORANGE}{COMMA} minut{P "" s} STR_AI_CONFIG_MOVE_UP :{BLACK}Mou amunt STR_AI_CONFIG_MOVE_UP_TOOLTIP :{BLACK}Desplaça la IA seleccionada una posició cap amunt @@ -5086,6 +5112,7 @@ STR_ERROR_NO_BUOY :{WHITE}No hi ha STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Impossible establir l'horari del vehicle... STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS :{WHITE}Els vehicles només poden esperar a les estacions STR_ERROR_TIMETABLE_NOT_STOPPING_HERE :{WHITE}Aquest vehicle no para en aquesta estació +STR_ERROR_TIMETABLE_INCOMPLETE :{WHITE}... l'horari està incomplet. # Sign related errors STR_ERROR_TOO_MANY_SIGNS :{WHITE}... massa senyals @@ -5565,11 +5592,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/english_AU.txt b/src/lang/english_AU.txt index f06d0c8020..8867f9a63f 100644 --- a/src/lang/english_AU.txt +++ b/src/lang/english_AU.txt @@ -1170,6 +1170,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Expand a STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Collapse all STR_CONFIG_SETTING_RESET_ALL :{BLACK}Reset all values STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(no explanation available) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Default value: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Setting type: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Client setting (not stored in saves; affects all games) @@ -3827,6 +3828,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Send ins STR_VEHICLE_LIST_REPLACE_VEHICLES :Replace vehicles STR_VEHICLE_LIST_SEND_FOR_SERVICING :Send for Servicing STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Profit this year: {CURRENCY_LONG} (last year: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Send to Depot STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Send to Depot @@ -5588,11 +5591,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/english_US.txt b/src/lang/english_US.txt index b738947df7..4a51f38edb 100644 --- a/src/lang/english_US.txt +++ b/src/lang/english_US.txt @@ -1170,6 +1170,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Expand a STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Collapse all STR_CONFIG_SETTING_RESET_ALL :{BLACK}Reset all values STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(no explanation available) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Default value: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Setting type: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Client setting (not stored in saves; affects all games) @@ -3827,6 +3828,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Send ins STR_VEHICLE_LIST_REPLACE_VEHICLES :Replace vehicles STR_VEHICLE_LIST_SEND_FOR_SERVICING :Send for Maintenance STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Profit this year: {CURRENCY_LONG} (last year: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Send to Depot STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Send to Depot @@ -5588,11 +5591,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/finnish.txt b/src/lang/finnish.txt index dbcc5429b4..22d0ed40b6 100644 --- a/src/lang/finnish.txt +++ b/src/lang/finnish.txt @@ -1170,6 +1170,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Avaa kai STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Sulje kaikki STR_CONFIG_SETTING_RESET_ALL :{BLACK}Palauta oletukset STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(selitystä ei saatavilla) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Oletusarvo: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Asetuksen tyyppi: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Yleinen asetus (ei tallenneta tallennuksiin; vaikuttaa kaikkiin peleihin) @@ -3827,6 +3828,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Ohjaa ka STR_VEHICLE_LIST_REPLACE_VEHICLES :Korvaa kulkuneuvoja STR_VEHICLE_LIST_SEND_FOR_SERVICING :Lähetä huoltoon STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Tuotto tänä vuonna: {CURRENCY_LONG} (viime vuonna: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Lähetä varikolle STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Lähetä varikolle @@ -5588,11 +5591,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/french.txt b/src/lang/french.txt index 06ff368962..60651b27ba 100644 --- a/src/lang/french.txt +++ b/src/lang/french.txt @@ -932,8 +932,22 @@ STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT :{BLACK}Copier l # Game options window STR_GAME_OPTIONS_CAPTION :{WHITE}Options du jeu +STR_GAME_OPTIONS_TAB_GENERAL :Général +STR_GAME_OPTIONS_TAB_GENERAL_TT :{BLACK}Régler les paramètres généraux +STR_GAME_OPTIONS_TAB_GRAPHICS :Graphiques +STR_GAME_OPTIONS_TAB_GRAPHICS_TT :{BLACK}Régler les paramètres graphiques +STR_GAME_OPTIONS_TAB_SOUND :Son +STR_GAME_OPTIONS_TAB_SOUND_TT :{BLACK}Régler les paramètres de son et de musique +STR_GAME_OPTIONS_VOLUME :Volume +STR_GAME_OPTIONS_SFX_VOLUME :Effets sonores +STR_GAME_OPTIONS_MUSIC_VOLUME :Musique +STR_GAME_OPTIONS_VOLUME_0 :0% +STR_GAME_OPTIONS_VOLUME_25 :25% +STR_GAME_OPTIONS_VOLUME_50 :50% +STR_GAME_OPTIONS_VOLUME_75 :75% +STR_GAME_OPTIONS_VOLUME_100 :100% STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME :{BLACK}Devise STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP :{BLACK}Sélectionner l'unité monétaire @@ -988,6 +1002,10 @@ STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP :{BLACK}Sélecti # Autosave dropdown ###length 5 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF :Désactivée +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_10_MINUTES :Toutes les 10 minutes +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_30_MINUTES :Toutes les 30 minutes +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_60_MINUTES :Toutes les 60 minutes +STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_120_MINUTES :Toutes les 120 minutes STR_GAME_OPTIONS_LANGUAGE :{BLACK}Langue STR_GAME_OPTIONS_LANGUAGE_TOOLTIP :{BLACK}Sélectionner la langue à utiliser pour l'interface @@ -1153,6 +1171,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Tout dé STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Tout réduire STR_CONFIG_SETTING_RESET_ALL :{BLACK}Réinitialiser tous les réglages STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(pas d'explication disponible) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Valeur par défaut{NBSP}: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Type de paramètre{NBSP}: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Paramètre du client (n'est pas enregistré dans les sauvegardes{NBSP}; affecte toutes les parties) @@ -1713,7 +1732,7 @@ STR_CONFIG_SETTING_SCRIPT_MAX_MEMORY_HELPTEXT :Quantité de m STR_CONFIG_SETTING_SCRIPT_MAX_MEMORY_VALUE :{COMMA} Mio STR_CONFIG_SETTING_SERVINT_ISPERCENT :Les intervalles de service sont en pourcentage{NBSP}: {STRING} -STR_CONFIG_SETTING_SERVINT_ISPERCENT_HELPTEXT :Choisir si l'entretien des véhicule est activé par le temps passé depuis le dernier entretien ou par la fiabilité passant sous un pourcentage de la fiabilité maximum +STR_CONFIG_SETTING_SERVINT_ISPERCENT_HELPTEXT :Lorsqu'il est activé, les véhicules essaient d'être entretenus quand leur fiabilité passe sous le pourcentage donné de la fiabilité maximum.{}{}Par exemple, si la fiabilité maximum d'un véhicule est 90% et l'intervalle d'entretien 20%, le véhicule essayera d'être entretenu quand sa fiabilité atteindra 72%. STR_CONFIG_SETTING_SERVINT_TRAINS :Intervalle d'entretien par défaut pour les trains{NBSP}: {STRING} STR_CONFIG_SETTING_SERVINT_TRAINS_HELPTEXT :Définit l'intervalle d'entretien par défaut des nouveaux véhicules ferroviaires, si aucun intervalle d'entretien n'est défini pour le véhicule @@ -3810,6 +3829,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Envoyer STR_VEHICLE_LIST_REPLACE_VEHICLES :Remplacer des véhicules STR_VEHICLE_LIST_SEND_FOR_SERVICING :Envoyer à l'entretien STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Profit cette année{NBSP}: {CURRENCY_LONG} (année précédente{NBSP}: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Envoyer au dépôt STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Envoyer au dépôt @@ -5091,6 +5112,7 @@ STR_ERROR_NO_BUOY :{WHITE}Il n'y a STR_ERROR_CAN_T_TIMETABLE_VEHICLE :{WHITE}Impossible d'affecter un horaire au véhicule... STR_ERROR_TIMETABLE_ONLY_WAIT_AT_STATIONS :{WHITE}Les véhicules ne peuvent attendre qu'aux stations STR_ERROR_TIMETABLE_NOT_STOPPING_HERE :{WHITE}Ce véhicule ne s'arrête pas à cette station +STR_ERROR_TIMETABLE_INCOMPLETE :{WHITE}... l'horaire est incomplet # Sign related errors STR_ERROR_TOO_MANY_SIGNS :{WHITE}... trop de panneaux @@ -5570,11 +5592,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/italian.txt b/src/lang/italian.txt index 7615cb3bfe..e740ac05fd 100644 --- a/src/lang/italian.txt +++ b/src/lang/italian.txt @@ -1184,6 +1184,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Espandi STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Comprimi tutti STR_CONFIG_SETTING_RESET_ALL :{BLACK}Resetta tutti i valori STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(descrizione non disponibile) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Valore predefinito: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Tipo impostazione: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Impostazione del client (non conservata nei salvataggi; influenza tutte le partite) @@ -3868,6 +3869,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Invia is STR_VEHICLE_LIST_REPLACE_VEHICLES :Rimpiazza veicoli STR_VEHICLE_LIST_SEND_FOR_SERVICING :Manutenzione STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Profitto quest'anno: {CURRENCY_LONG} (anno scorso: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Manda al deposito STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Manda al deposito @@ -5629,11 +5632,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/korean.txt b/src/lang/korean.txt index 5161e11f0f..362801a0a1 100644 --- a/src/lang/korean.txt +++ b/src/lang/korean.txt @@ -1171,6 +1171,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}모두 STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}모두 접기 STR_CONFIG_SETTING_RESET_ALL :{BLACK}모든 설정 초기화 STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(설명이 존재하지 않습니다) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}기본값: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}설정 종류: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :접속자 설정 (게임 저장 파일에 저장되지 않음; 모든 게임에 적용됨) @@ -3828,6 +3829,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}이 목 STR_VEHICLE_LIST_REPLACE_VEHICLES :차량 교체 STR_VEHICLE_LIST_SEND_FOR_SERVICING :점검하러 보내기 STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}올해 이익: {CURRENCY_LONG} (작년: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :차량기지로 보내기 STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :차고지로 보내기 @@ -5589,11 +5592,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/polish.txt b/src/lang/polish.txt index dc16057939..d6eb756bc0 100644 --- a/src/lang/polish.txt +++ b/src/lang/polish.txt @@ -1550,6 +1550,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Otwórz STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Zamknij wszystko STR_CONFIG_SETTING_RESET_ALL :{BLACK}Zresetuj wszystkie ustawienia STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(wyjaśnienie niedostępne) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Domyślna wartość: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Typ ustawienia: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Ustawienie klienta (nie przechowywane w plikach zapisu; ma wpływ na wszystkie gry) @@ -4207,6 +4208,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Wyślij STR_VEHICLE_LIST_REPLACE_VEHICLES :Zastąp pojazdy STR_VEHICLE_LIST_SEND_FOR_SERVICING :Wyślij do serwisu STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Zysk w tym roku: {CURRENCY_LONG} (ostatni rok: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Wyślij do warsztatów STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Wyślij do zajezdni @@ -6011,11 +6014,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/portuguese.txt b/src/lang/portuguese.txt index 279b46dae8..2de20e0dc4 100644 --- a/src/lang/portuguese.txt +++ b/src/lang/portuguese.txt @@ -1171,6 +1171,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Expandir STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Colapsar todas STR_CONFIG_SETTING_RESET_ALL :{BLACK}Repor todos os valores STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(sem explicação disponível) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Valor por omissão: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Tipo de configuração: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Configuração de cliente (não guardado; afeta todos os jogos) @@ -3828,6 +3829,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Enviar i STR_VEHICLE_LIST_REPLACE_VEHICLES :Substituir Veículos STR_VEHICLE_LIST_SEND_FOR_SERVICING :Enviar para Serviço STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Lucro deste ano: {CURRENCY_LONG} (último ano: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Enviar para Depósito STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Enviar para Depósito @@ -5589,11 +5592,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/russian.txt b/src/lang/russian.txt index 6ecd782ee4..caa171ae33 100644 --- a/src/lang/russian.txt +++ b/src/lang/russian.txt @@ -1319,6 +1319,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Разв STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Свернуть всё STR_CONFIG_SETTING_RESET_ALL :{BLACK}Сбросить все значения STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(нет описания) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Значение по умолчанию: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Тип настроек: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Настройки клиента (не содержатся в файлах сохранений; влияют на все игры) @@ -4002,6 +4003,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Упра STR_VEHICLE_LIST_REPLACE_VEHICLES :Замена транспорта STR_VEHICLE_LIST_SEND_FOR_SERVICING :Отправить на тех. обслуживание STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Прибыль в этом году: {CURRENCY_LONG} (в прошлом году: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Отправить в депо STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Отправить в гараж @@ -5812,11 +5815,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/turkish.txt b/src/lang/turkish.txt index 22cbcd71e6..87b78680d2 100644 --- a/src/lang/turkish.txt +++ b/src/lang/turkish.txt @@ -1171,6 +1171,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Tümün STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Tümünü kısalt STR_CONFIG_SETTING_RESET_ALL :{BLACK}Tüm değerleri sıfırla STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(açıklama bulunmamaktadır) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Varsayılan değer: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Ayar türü: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Kullanıcı ayarları (kayıtlı dosyada saklanmaz; tüm oyunları etkilemektedir) @@ -3828,6 +3829,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Listedek STR_VEHICLE_LIST_REPLACE_VEHICLES :Araçları Değiştir STR_VEHICLE_LIST_SEND_FOR_SERVICING :Bakıma Gönder STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Bu seneki kar: {CURRENCY_LONG} (geçen sene: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Garaja Gönder STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Garaja Gönder @@ -5599,11 +5602,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/lang/vietnamese.txt b/src/lang/vietnamese.txt index aba4254d97..13f3a7ef02 100644 --- a/src/lang/vietnamese.txt +++ b/src/lang/vietnamese.txt @@ -1170,6 +1170,7 @@ STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Mở xu STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Đóng lại tất cả STR_CONFIG_SETTING_RESET_ALL :{BLACK}Thiết lập lại tất cả STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(hiện không có giải thích nào) +STR_CONFIG_SETTING_VALUE :{PUSH_COLOUR}{ORANGE}{STRING}{POP_COLOUR} STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Giá trị mặc định: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE :{LTBLUE}Kiểu thiết lập: {ORANGE}{STRING} STR_CONFIG_SETTING_TYPE_CLIENT :Cấu hình máy khách (không được lưu trong save; tác động tới tất cả các ván chơi) @@ -3827,6 +3828,8 @@ STR_VEHICLE_LIST_MANAGE_LIST_TOOLTIP :{BLACK}Gửi ch STR_VEHICLE_LIST_REPLACE_VEHICLES :Thay phương tiện STR_VEHICLE_LIST_SEND_FOR_SERVICING :Gửi về bảo trì STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR :{TINY_FONT}{BLACK}Lợi nhuận năm nay: {CURRENCY_LONG} (năm ngoái: {CURRENCY_LONG}) +STR_VEHICLE_LIST_CARGO :[{CARGO_LIST}] +STR_VEHICLE_LIST_NAME_AND_CARGO :{STRING} {STRING} STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT :Gửi về xưởng STR_VEHICLE_LIST_SEND_ROAD_VEHICLE_TO_DEPOT :Gửi về xưởng @@ -5588,11 +5591,13 @@ STR_VEHICLE_NAME :{VEHICLE} STR_WAYPOINT_NAME :{WAYPOINT} STR_JUST_CARGO :{CARGO_LONG} +STR_JUST_RIGHT_ARROW :{RIGHT_ARROW} STR_JUST_CHECKMARK :{CHECKMARK} STR_JUST_COMMA :{COMMA} STR_JUST_CURRENCY_SHORT :{CURRENCY_SHORT} STR_JUST_CURRENCY_LONG :{CURRENCY_LONG} STR_JUST_CARGO_LIST :{CARGO_LIST} +STR_JUST_DECIMAL :{DECIMAL} STR_JUST_INT :{NUM} STR_JUST_DATE_TINY :{DATE_TINY} STR_JUST_DATE_SHORT :{DATE_SHORT} diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 09a833ee6f..0aed65a9c0 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -975,9 +975,9 @@ Rect QueryString::GetBoundingRect(const Window *w, int wid, const char *from, co * @param w Window the edit box is in. * @param wid Widget index. * @param pt Position to test. - * @return Pointer to the character at the position or nullptr if no character is at the position. + * @return Index of the character position or -1 if no character is at the position. */ -const char *QueryString::GetCharAtPosition(const Window *w, int wid, const Point &pt) const +ptrdiff_t QueryString::GetCharAtPosition(const Window *w, int wid, const Point &pt) const { const NWidgetLeaf *wi = w->GetWidget(wid); @@ -989,7 +989,7 @@ const char *QueryString::GetCharAtPosition(const Window *w, int wid, const Point Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect); - if (!IsInsideMM(pt.y, r.top, r.bottom)) return nullptr; + if (!IsInsideMM(pt.y, r.top, r.bottom)) return -1; /* Clamp caret position to be inside our current width. */ const Textbuf *tb = &this->text; diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index a715ef2382..18daeac210 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -424,7 +424,7 @@ class NetworkContentListWindow : public Window, ContentCallback { this->content.RebuildDone(); this->SortContentList(); - this->vscroll->SetCount((int)this->content.size()); // Update the scrollbar + this->vscroll->SetCount(this->content.size()); // Update the scrollbar this->ScrollToSelected(); } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 1abd023795..63f18e972f 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -295,7 +295,7 @@ protected: this->servers.shrink_to_fit(); this->servers.RebuildDone(); - this->vscroll->SetCount((int)this->servers.size()); + this->vscroll->SetCount(this->servers.size()); /* Sort the list of network games as requested. */ this->servers.Sort(); diff --git a/src/newgrf_airport.cpp b/src/newgrf_airport.cpp index fdc2561846..e1bdbc7335 100644 --- a/src/newgrf_airport.cpp +++ b/src/newgrf_airport.cpp @@ -212,7 +212,7 @@ void AirportOverrideManager::SetEntitySpec(AirportSpec *as) case 0x7C: return (this->st->airport.psa != nullptr) ? this->st->airport.psa->GetValue(parameter) : 0; case 0xF0: return this->st->facilities; - case 0xFA: return Clamp(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); + case 0xFA: return ClampTo(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR); } return this->st->GetNewGRFVariable(this->ro, variable, parameter, &(extra->available)); diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index 43b2a77d5a..ef816bddf3 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -450,7 +450,7 @@ uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8, uint32 mask) int z; Slope tileh = GetTilePixelSlope(tile, &z); if (grf_version8) z /= TILE_HEIGHT; - result |= Clamp(z, 0, 0xFF) << 16 | tileh; + result |= ClampTo(z) << 16 | tileh; } return result; } diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 187e16204a..76524558f2 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -1502,7 +1502,7 @@ struct SpriteAlignerWindow : Window { if (data == 1) { /* Sprite picker finished */ this->RaiseWidget(WID_SA_PICKER); - this->vscroll->SetCount((uint)_newgrf_debug_sprite_picker.sprites.size()); + this->vscroll->SetCount(_newgrf_debug_sprite_picker.sprites.size()); } } diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 3d290ba207..58b491f2f5 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -660,7 +660,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, { const Vehicle *w = v->Next(); assert(w != nullptr); - uint16 altitude = ClampToU16(v->z_pos - w->z_pos); // Aircraft height - shadow height + uint16 altitude = ClampTo(v->z_pos - w->z_pos); // Aircraft height - shadow height byte airporttype = ATP_TTDP_LARGE; const Station *st = GetTargetAirportIfValid(Aircraft::From(v)); @@ -669,7 +669,7 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, airporttype = st->airport.GetSpec()->ttd_airport_type; } - return (Clamp(altitude, 0, 0xFF) << 8) | airporttype; + return (ClampTo(altitude) << 8) | airporttype; } case 0x45: { // Curvature info @@ -925,8 +925,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, } return (variable - 0x80) == 0x10 ? ticks : GB(ticks, 8, 8); } - case 0x12: return Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); - case 0x13: return GB(Clamp(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8); + case 0x12: return ClampTo(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR); + case 0x13: return GB(ClampTo(v->date_of_last_service - DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8); case 0x14: return v->GetServiceInterval(); case 0x15: return GB(v->GetServiceInterval(), 8, 8); case 0x16: return v->last_station_visited; @@ -979,14 +979,14 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, case 0x39: return v->cargo_type; case 0x3A: return v->cargo_cap; case 0x3B: return GB(v->cargo_cap, 8, 8); - case 0x3C: return ClampToU16(v->cargo.StoredCount()); - case 0x3D: return GB(ClampToU16(v->cargo.StoredCount()), 8, 8); + case 0x3C: return ClampTo(v->cargo.StoredCount()); + case 0x3D: return GB(ClampTo(v->cargo.StoredCount()), 8, 8); case 0x3E: return v->cargo.Source(); - case 0x3F: return ClampU(v->cargo.DaysInTransit(), 0, 0xFF); - case 0x40: return ClampToU16(v->age); - case 0x41: return GB(ClampToU16(v->age), 8, 8); - case 0x42: return ClampToU16(v->max_age); - case 0x43: return GB(ClampToU16(v->max_age), 8, 8); + case 0x3F: return ClampTo(v->cargo.DaysInTransit()); + case 0x40: return ClampTo(v->age); + case 0x41: return GB(ClampTo(v->age), 8, 8); + case 0x42: return ClampTo(v->max_age); + case 0x43: return GB(ClampTo(v->max_age), 8, 8); case 0x44: return Clamp(v->build_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; case 0x45: return v->unitnumber; case 0x46: return v->GetEngine()->grf_prop.local_id; @@ -1004,20 +1004,20 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, case 0x4F: return GB(v->reliability, 8, 8); case 0x50: return v->reliability_spd_dec; case 0x51: return GB(v->reliability_spd_dec, 8, 8); - case 0x52: return ClampToI32(v->GetDisplayProfitThisYear()); - case 0x53: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 8, 24); - case 0x54: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 16, 16); - case 0x55: return GB(ClampToI32(v->GetDisplayProfitThisYear()), 24, 8); - case 0x56: return ClampToI32(v->GetDisplayProfitLastYear()); - case 0x57: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 8, 24); - case 0x58: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 16, 16); - case 0x59: return GB(ClampToI32(v->GetDisplayProfitLastYear()), 24, 8); + case 0x52: return ClampTo(v->GetDisplayProfitThisYear()); + case 0x53: return GB(ClampTo(v->GetDisplayProfitThisYear()), 8, 24); + case 0x54: return GB(ClampTo(v->GetDisplayProfitThisYear()), 16, 16); + case 0x55: return GB(ClampTo(v->GetDisplayProfitThisYear()), 24, 8); + case 0x56: return ClampTo(v->GetDisplayProfitLastYear()); + case 0x57: return GB(ClampTo(v->GetDisplayProfitLastYear()), 8, 24); + case 0x58: return GB(ClampTo(v->GetDisplayProfitLastYear()), 16, 16); + case 0x59: return GB(ClampTo(v->GetDisplayProfitLastYear()), 24, 8); case 0x5A: return v->Next() == nullptr ? INVALID_VEHICLE : v->Next()->index; case 0x5B: break; // not implemented - case 0x5C: return ClampToI32(v->value); - case 0x5D: return GB(ClampToI32(v->value), 8, 24); - case 0x5E: return GB(ClampToI32(v->value), 16, 16); - case 0x5F: return GB(ClampToI32(v->value), 24, 8); + case 0x5C: return ClampTo(v->value); + case 0x5D: return GB(ClampTo(v->value), 8, 24); + case 0x5E: return GB(ClampTo(v->value), 16, 16); + case 0x5F: return GB(ClampTo(v->value), 24, 8); case 0x60: break; // not implemented case 0x61: break; // not implemented case 0x62: break; // vehicle specific, see below @@ -1132,8 +1132,8 @@ static uint32 VehicleGetVariable(Vehicle *v, const VehicleScopeResolver *object, case 0x48: return Engine::Get(this->self_type)->flags; // Vehicle Type Info case 0x49: return _cur_year; // 'Long' format build year case 0x4B: return _date; // Long date of last service - case 0x92: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF); // Date of last service - case 0x93: return GB(Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 0xFFFF), 8, 8); + case 0x92: return ClampTo(_date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date of last service + case 0x93: return GB(ClampTo(_date - DAYS_TILL_ORIGINAL_BASE_YEAR), 8, 8); case 0xC4: return Clamp(_cur_year, ORIGINAL_BASE_YEAR, ORIGINAL_MAX_YEAR) - ORIGINAL_BASE_YEAR; // Build year case 0xC6: return Engine::Get(this->self_type)->grf_prop.local_id; case 0xC7: return GB(Engine::Get(this->self_type)->grf_prop.local_id, 8, 8); diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index b0953a0bd4..5665c46ace 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1501,7 +1501,7 @@ private: } } - this->vscroll2->SetCount((uint)this->avails.size()); // Update the scrollbar + this->vscroll2->SetCount(this->avails.size()); // Update the scrollbar } /** @@ -2097,7 +2097,7 @@ struct SavePresetWindow : public Window { this->vscroll = this->GetScrollbar(WID_SVP_SCROLLBAR); this->FinishInitNested(0); - this->vscroll->SetCount((uint)this->presets.size()); + this->vscroll->SetCount(this->presets.size()); this->SetFocusedWidget(WID_SVP_EDITBOX); if (initial_text != nullptr) this->presetname_editbox.text.Assign(initial_text); } diff --git a/src/newgrf_house.cpp b/src/newgrf_house.cpp index 4147099612..05a94d271e 100644 --- a/src/newgrf_house.cpp +++ b/src/newgrf_house.cpp @@ -185,13 +185,12 @@ void DecreaseBuildingCount(Town *t, HouseID house_id) static uint32 GetNumHouses(HouseID house_id, const Town *town) { - uint8 map_id_count, town_id_count, map_class_count, town_class_count; HouseClassID class_id = HouseSpec::Get(house_id)->class_id; - map_id_count = ClampU(_building_counts.id_count[house_id], 0, 255); - map_class_count = ClampU(_building_counts.class_count[class_id], 0, 255); - town_id_count = ClampU(town->cache.building_counts.id_count[house_id], 0, 255); - town_class_count = ClampU(town->cache.building_counts.class_count[class_id], 0, 255); + uint8_t map_id_count = ClampTo(_building_counts.id_count[house_id]); + uint8_t map_class_count = ClampTo(_building_counts.class_count[class_id]); + uint8_t town_id_count = ClampTo(town->cache.building_counts.id_count[house_id]); + uint8_t town_class_count = ClampTo(town->cache.building_counts.class_count[class_id]); return map_class_count << 24 | town_class_count << 16 | map_id_count << 8 | town_id_count; } diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index 35a7777691..c5ed507908 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -164,7 +164,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout /* If the filter is 0, it could be because none was specified as well as being really a 0. * In either case, just do the regular var67 */ if (mask & 0xFFFF) closest_dist = GetClosestIndustry(current->location.tile, ind_index, current); - if (mask & 0xFF0000) count = std::min(Industry::GetIndustryTypeCount(ind_index), UINT8_MAX); // clamp to 8 bit + if (mask & 0xFF0000) count = ClampTo(Industry::GetIndustryTypeCount(ind_index)); } else { /* Count only those who match the same industry type and layout filter * Unfortunately, we have to do it manually */ @@ -205,16 +205,16 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout case 0x88: return GetTownRadiusGroup(this->industry->town, this->tile); /* Manhattan distance of the closest town */ - case 0x89: return std::min(DistanceManhattan(this->industry->town->xy, this->tile), 255u); + case 0x89: return ClampTo(DistanceManhattan(this->industry->town->xy, this->tile)); /* Lowest height of the tile */ - case 0x8A: return Clamp(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT), 0, 0xFF); + case 0x8A: return ClampTo(GetTileZ(this->tile) * (this->ro.grffile->grf_version >= 8 ? 1 : TILE_HEIGHT)); /* Distance to the nearest water/land tile */ case 0x8B: return GetClosestWaterDistance(this->tile, (GetIndustrySpec(this->industry->type)->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0); /* Square of Euclidian distance from town */ - case 0x8D: return std::min(DistanceSquare(this->industry->town->xy, this->tile), 65535u); + case 0x8D: return ClampTo(DistanceSquare(this->industry->town->xy, this->tile)); /* 32 random bits */ case 0x8F: return this->random_bits; @@ -238,9 +238,9 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout if (HasBit(callback, CBM_IND_PRODUCTION_CARGO_ARRIVAL) || HasBit(callback, CBM_IND_PRODUCTION_256_TICKS)) { if ((indspec->behaviour & INDUSTRYBEH_PROD_MULTI_HNDLING) != 0) { if (this->industry->prod_level == 0) return 0; - return std::min(this->industry->incoming_cargo_waiting[variable - 0x40] / this->industry->prod_level, 0xFFFFu); + return ClampTo(this->industry->incoming_cargo_waiting[variable - 0x40] / this->industry->prod_level); } else { - return std::min(this->industry->incoming_cargo_waiting[variable - 0x40], 0xFFFFu); + return ClampTo(this->industry->incoming_cargo_waiting[variable - 0x40]); } } else { return 0; @@ -309,7 +309,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout case 0x65: { if (this->tile == INVALID_TILE) break; TileIndex tile = GetNearbyTile(parameter, this->tile, true); - return GetTownRadiusGroup(this->industry->town, tile) << 16 | std::min(DistanceManhattan(tile, this->industry->town->xy), 0xFFFFu); + return GetTownRadiusGroup(this->industry->town, tile) << 16 | ClampTo(DistanceManhattan(tile, this->industry->town->xy)); } /* Get square of Euclidian distance of closest town */ case 0x66: { @@ -420,16 +420,16 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout case 0xA6: return indspec->grf_prop.local_id; case 0xA7: return this->industry->founder; case 0xA8: return this->industry->random_colour; - case 0xA9: return Clamp(this->industry->last_prod_year - ORIGINAL_BASE_YEAR, 0, 255); + case 0xA9: return ClampTo(this->industry->last_prod_year - ORIGINAL_BASE_YEAR); case 0xAA: return this->industry->counter; case 0xAB: return GB(this->industry->counter, 8, 8); case 0xAC: return this->industry->was_cargo_delivered; - case 0xB0: return Clamp(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date when built since 1920 (in days) + case 0xB0: return ClampTo(this->industry->construction_date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date when built since 1920 (in days) case 0xB3: return this->industry->construction_type; // Construction type case 0xB4: { Date *latest = std::max_element(this->industry->last_cargo_accepted_at, endof(this->industry->last_cargo_accepted_at)); - return Clamp((*latest) - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Date last cargo accepted since 1920 (in days) + return ClampTo((*latest) - DAYS_TILL_ORIGINAL_BASE_YEAR); // Date last cargo accepted since 1920 (in days) } } @@ -672,22 +672,22 @@ void IndustryProductionCallback(Industry *ind, int reason) if (group->version < 2) { /* Callback parameters map directly to industry cargo slot indices */ for (uint i = 0; i < group->num_input; i++) { - ind->incoming_cargo_waiting[i] = Clamp(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF); + ind->incoming_cargo_waiting[i] = ClampTo(ind->incoming_cargo_waiting[i] - DerefIndProd(group->subtract_input[i], deref) * multiplier); } for (uint i = 0; i < group->num_output; i++) { - ind->produced_cargo_waiting[i] = Clamp(ind->produced_cargo_waiting[i] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF); + ind->produced_cargo_waiting[i] = ClampTo(ind->produced_cargo_waiting[i] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier); } } else { /* Callback receives list of cargos to apply for, which need to have their cargo slots in industry looked up */ for (uint i = 0; i < group->num_input; i++) { int cargo_index = ind->GetCargoAcceptedIndex(group->cargo_input[i]); if (cargo_index < 0) continue; - ind->incoming_cargo_waiting[cargo_index] = Clamp(ind->incoming_cargo_waiting[cargo_index] - DerefIndProd(group->subtract_input[i], deref) * multiplier, 0, 0xFFFF); + ind->incoming_cargo_waiting[cargo_index] = ClampTo(ind->incoming_cargo_waiting[cargo_index] - DerefIndProd(group->subtract_input[i], deref) * multiplier); } for (uint i = 0; i < group->num_output; i++) { int cargo_index = ind->GetCargoProducedIndex(group->cargo_output[i]); if (cargo_index < 0) continue; - ind->produced_cargo_waiting[cargo_index] = Clamp(ind->produced_cargo_waiting[cargo_index] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier, 0, 0xFFFF); + ind->produced_cargo_waiting[cargo_index] = ClampTo(ind->produced_cargo_waiting[cargo_index] + std::max(DerefIndProd(group->add_output[i], deref), 0) * multiplier); } } diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 7cef121d96..84133a7807 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -253,7 +253,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(uint32 local_id, uint32 grfid /* If the object type is invalid, there is none and the closest is far away. */ if (idx >= NUM_OBJECTS) return 0 | 0xFFFF; - return Object::GetTypeCount(idx) << 16 | std::min(GetClosestObject(tile, idx, current), 0xFFFFu); + return Object::GetTypeCount(idx) << 16 | ClampTo(GetClosestObject(tile, idx, current)); } /** Used by the resolver to get values for feature 0F deterministic spritegroups. */ @@ -334,7 +334,7 @@ static uint32 GetCountAndDistanceOfClosestInstance(uint32 local_id, uint32 grfid case 0x44: return GetTileOwner(this->tile); /* Get town zone and Manhattan distance of closest town */ - case 0x45: return (t == nullptr) ? 0 : (GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceManhattan(this->tile, t->xy), 0xFFFFu)); + case 0x45: return (t == nullptr) ? 0 : (GetTownRadiusGroup(t, this->tile) << 16 | ClampTo(DistanceManhattan(this->tile, t->xy))); /* Get square of Euclidian distance of closest town */ case 0x46: return (t == nullptr) ? 0 : DistanceSquare(this->tile, t->xy); diff --git a/src/newgrf_roadstop.cpp b/src/newgrf_roadstop.cpp index 22f499cfd7..00c93e0099 100644 --- a/src/newgrf_roadstop.cpp +++ b/src/newgrf_roadstop.cpp @@ -32,13 +32,10 @@ template void NewGRFClass::InsertDefaults() { /* Set up initial data */ - classes[0].global_id = 'DFLT'; - classes[0].name = STR_STATION_CLASS_DFLT; - classes[0].Insert(nullptr); - - classes[1].global_id = 'WAYP'; - classes[1].name = STR_STATION_CLASS_WAYP; - classes[1].Insert(nullptr); + RoadStopClass::Get(RoadStopClass::Allocate('DFLT'))->name = STR_STATION_CLASS_DFLT; + RoadStopClass::Get(RoadStopClass::Allocate('DFLT'))->Insert(nullptr); + RoadStopClass::Get(RoadStopClass::Allocate('WAYP'))->name = STR_STATION_CLASS_WAYP; + RoadStopClass::Get(RoadStopClass::Allocate('WAYP'))->Insert(nullptr); } template @@ -96,7 +93,7 @@ uint32 RoadStopScopeResolver::GetNearbyRoadStopsInfo(uint32 parameter, RoadStopS switch (mode) { case NearbyRoadStopInfoMode::Standard: default: - return res | std::min(localidx, 0xFF); + return res | ClampTo(localidx); case NearbyRoadStopInfoMode::Extended: return res | (localidx & 0xFF) | ((localidx & 0xFF00) << 16); @@ -145,7 +142,7 @@ uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, Get case 0x45: { if (this->tile == INVALID_TILE) return HZB_TOWN_EDGE << 16; const Town *t = (this->st == nullptr) ? ClosestTownFromTile(this->tile, UINT_MAX) : this->st->town; - return t != nullptr ? (GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceManhattan(this->tile, t->xy), 0xFFFFu)) : HZB_TOWN_EDGE << 16; + return t != nullptr ? (GetTownRadiusGroup(t, this->tile) << 16 | ClampTo(DistanceManhattan(this->tile, t->xy))) : HZB_TOWN_EDGE << 16; } /* Get square of Euclidian distance of closest town */ @@ -241,7 +238,7 @@ uint32 RoadStopScopeResolver::GetVariable(uint16 variable, uint32 parameter, Get case 0xF0: return this->st == nullptr ? 0 : this->st->facilities; // facilities - case 0xFA: return Clamp((this->st == nullptr ? _date : this->st->build_date) - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // build date + case 0xFA: return ClampTo((this->st == nullptr ? _date : this->st->build_date) - DAYS_TILL_ORIGINAL_BASE_YEAR); // build date } if (this->st != nullptr) return this->st->GetNewGRFVariable(this->ro, variable, parameter, &(extra->available)); diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index facc30cbdd..5ae62e23b1 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -32,13 +32,10 @@ template /* static */ void NewGRFClass::InsertDefaults() { /* Set up initial data */ - classes[0].global_id = 'DFLT'; - classes[0].name = STR_STATION_CLASS_DFLT; - classes[0].Insert(nullptr); - - classes[1].global_id = 'WAYP'; - classes[1].name = STR_STATION_CLASS_WAYP; - classes[1].Insert(nullptr); + StationClass::Get(StationClass::Allocate('DFLT'))->name = STR_STATION_CLASS_DFLT; + StationClass::Get(StationClass::Allocate('DFLT'))->Insert(nullptr); + StationClass::Get(StationClass::Allocate('WAYP'))->name = STR_STATION_CLASS_WAYP; + StationClass::Get(StationClass::Allocate('WAYP'))->Insert(nullptr); } template @@ -290,7 +287,7 @@ uint32 StationScopeResolver::GetNearbyStationInfo(uint32 parameter, StationScope switch (mode) { case NearbyStationInfoMode::Standard: default: - return res | std::min(localidx, 0xFF); + return res | ClampTo(localidx); case NearbyStationInfoMode::Extended: return res | (localidx & 0xFF) | ((localidx & 0xFF00) << 16); @@ -327,7 +324,7 @@ uint32 StationScopeResolver::GetNearbyStationInfo(uint32 parameter, StationScope } break; - case 0xFA: return Clamp(_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); // Build date, clamped to a 16 bit value + case 0xFA: return ClampTo(_date - DAYS_TILL_ORIGINAL_BASE_YEAR); // Build date, clamped to a 16 bit value } extra->available = false; @@ -417,7 +414,7 @@ uint32 StationScopeResolver::GetNearbyStationInfo(uint32 parameter, StationScope case 0x84: return this->st->string_id; case 0x86: return 0; case 0xF0: return this->st->facilities; - case 0xFA: return Clamp(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR, 0, 65535); + case 0xFA: return ClampTo(this->st->build_date - DAYS_TILL_ORIGINAL_BASE_YEAR); } return this->st->GetNewGRFVariable(this->ro, variable, parameter, &(extra->available)); diff --git a/src/newgrf_town.cpp b/src/newgrf_town.cpp index c5e69943cf..31c1857545 100644 --- a/src/newgrf_town.cpp +++ b/src/newgrf_town.cpp @@ -47,21 +47,21 @@ /* Town properties */ case 0x80: return this->t->xy; case 0x81: return GB(this->t->xy, 8, 8); - case 0x82: return ClampToU16(this->t->cache.population); - case 0x83: return GB(ClampToU16(this->t->cache.population), 8, 8); + case 0x82: return ClampTo(this->t->cache.population); + case 0x83: return GB(ClampTo(this->t->cache.population), 8, 8); case 0x8A: return this->t->grow_counter / TOWN_GROWTH_TICKS; case 0x92: return this->t->flags; // In original game, 0x92 and 0x93 are really one word. Since flags is a byte, this is to adjust case 0x93: return 0; - case 0x94: return ClampToU16(this->t->cache.squared_town_zone_radius[0]); - case 0x95: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[0]), 8, 8); - case 0x96: return ClampToU16(this->t->cache.squared_town_zone_radius[1]); - case 0x97: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[1]), 8, 8); - case 0x98: return ClampToU16(this->t->cache.squared_town_zone_radius[2]); - case 0x99: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[2]), 8, 8); - case 0x9A: return ClampToU16(this->t->cache.squared_town_zone_radius[3]); - case 0x9B: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[3]), 8, 8); - case 0x9C: return ClampToU16(this->t->cache.squared_town_zone_radius[4]); - case 0x9D: return GB(ClampToU16(this->t->cache.squared_town_zone_radius[4]), 8, 8); + case 0x94: return ClampTo(this->t->cache.squared_town_zone_radius[0]); + case 0x95: return GB(ClampTo(this->t->cache.squared_town_zone_radius[0]), 8, 8); + case 0x96: return ClampTo(this->t->cache.squared_town_zone_radius[1]); + case 0x97: return GB(ClampTo(this->t->cache.squared_town_zone_radius[1]), 8, 8); + case 0x98: return ClampTo(this->t->cache.squared_town_zone_radius[2]); + case 0x99: return GB(ClampTo(this->t->cache.squared_town_zone_radius[2]), 8, 8); + case 0x9A: return ClampTo(this->t->cache.squared_town_zone_radius[3]); + case 0x9B: return GB(ClampTo(this->t->cache.squared_town_zone_radius[3]), 8, 8); + case 0x9C: return ClampTo(this->t->cache.squared_town_zone_radius[4]); + case 0x9D: return GB(ClampTo(this->t->cache.squared_town_zone_radius[4]), 8, 8); case 0x9E: return this->t->ratings[0]; case 0x9F: return GB(this->t->ratings[0], 8, 8); case 0xA0: return this->t->ratings[1]; @@ -80,24 +80,24 @@ case 0xAD: return GB(this->t->ratings[7], 8, 8); case 0xAE: return this->t->have_ratings; case 0xB2: return this->t->statues; - case 0xB6: return ClampToU16(this->t->cache.num_houses); + case 0xB6: return ClampTo(this->t->cache.num_houses); case 0xB9: return this->t->growth_rate / TOWN_GROWTH_TICKS; - case 0xBA: return ClampToU16(this->t->supplied[CT_PASSENGERS].new_max); - case 0xBB: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].new_max), 8, 8); - case 0xBC: return ClampToU16(this->t->supplied[CT_MAIL].new_max); - case 0xBD: return GB(ClampToU16(this->t->supplied[CT_MAIL].new_max), 8, 8); - case 0xBE: return ClampToU16(this->t->supplied[CT_PASSENGERS].new_act); - case 0xBF: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].new_act), 8, 8); - case 0xC0: return ClampToU16(this->t->supplied[CT_MAIL].new_act); - case 0xC1: return GB(ClampToU16(this->t->supplied[CT_MAIL].new_act), 8, 8); - case 0xC2: return ClampToU16(this->t->supplied[CT_PASSENGERS].old_max); - case 0xC3: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].old_max), 8, 8); - case 0xC4: return ClampToU16(this->t->supplied[CT_MAIL].old_max); - case 0xC5: return GB(ClampToU16(this->t->supplied[CT_MAIL].old_max), 8, 8); - case 0xC6: return ClampToU16(this->t->supplied[CT_PASSENGERS].old_act); - case 0xC7: return GB(ClampToU16(this->t->supplied[CT_PASSENGERS].old_act), 8, 8); - case 0xC8: return ClampToU16(this->t->supplied[CT_MAIL].old_act); - case 0xC9: return GB(ClampToU16(this->t->supplied[CT_MAIL].old_act), 8, 8); + case 0xBA: return ClampTo(this->t->supplied[CT_PASSENGERS].new_max); + case 0xBB: return GB(ClampTo(this->t->supplied[CT_PASSENGERS].new_max), 8, 8); + case 0xBC: return ClampTo(this->t->supplied[CT_MAIL].new_max); + case 0xBD: return GB(ClampTo(this->t->supplied[CT_MAIL].new_max), 8, 8); + case 0xBE: return ClampTo(this->t->supplied[CT_PASSENGERS].new_act); + case 0xBF: return GB(ClampTo(this->t->supplied[CT_PASSENGERS].new_act), 8, 8); + case 0xC0: return ClampTo(this->t->supplied[CT_MAIL].new_act); + case 0xC1: return GB(ClampTo(this->t->supplied[CT_MAIL].new_act), 8, 8); + case 0xC2: return ClampTo(this->t->supplied[CT_PASSENGERS].old_max); + case 0xC3: return GB(ClampTo(this->t->supplied[CT_PASSENGERS].old_max), 8, 8); + case 0xC4: return ClampTo(this->t->supplied[CT_MAIL].old_max); + case 0xC5: return GB(ClampTo(this->t->supplied[CT_MAIL].old_max), 8, 8); + case 0xC6: return ClampTo(this->t->supplied[CT_PASSENGERS].old_act); + case 0xC7: return GB(ClampTo(this->t->supplied[CT_PASSENGERS].old_act), 8, 8); + case 0xC8: return ClampTo(this->t->supplied[CT_MAIL].old_act); + case 0xC9: return GB(ClampTo(this->t->supplied[CT_MAIL].old_act), 8, 8); case 0xCA: return this->t->GetPercentTransported(CT_PASSENGERS); case 0xCB: return this->t->GetPercentTransported(CT_MAIL); case 0xCC: return this->t->received[TE_FOOD].new_act; diff --git a/src/object_gui.cpp b/src/object_gui.cpp index 34ab1c2321..a65fd457fe 100644 --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -123,7 +123,7 @@ public: ResetObjectToPlace(); - this->vscroll->SetCount((int)this->object_classes.size()); + this->vscroll->SetCount(this->object_classes.size()); EnsureSelectedObjectClassIsVisible(); @@ -164,7 +164,7 @@ public: this->object_classes.RebuildDone(); this->object_classes.Sort(); - this->vscroll->SetCount((uint)this->object_classes.size()); + this->vscroll->SetCount(this->object_classes.size()); } /** diff --git a/src/os/windows/string_uniscribe.cpp b/src/os/windows/string_uniscribe.cpp index 2fe5168ea3..595358e915 100644 --- a/src/os/windows/string_uniscribe.cpp +++ b/src/os/windows/string_uniscribe.cpp @@ -341,13 +341,13 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF } /* Gather runs until the line is full. */ - while (last_run != this->ranges.end() && cur_width < max_width) { + while (last_run != this->ranges.end() && cur_width <= max_width) { cur_width += last_run->total_advance; ++last_run; } /* If the text does not fit into the available width, find a suitable breaking point. */ - int remaining_offset = (last_run - 1)->len; + int remaining_offset = (last_run - 1)->len + 1; int whitespace_count = 0; if (cur_width > max_width) { std::vector log_attribs; @@ -433,7 +433,7 @@ static std::vector UniscribeItemizeString(UniscribeParagraphLayoutF cur_pos += run.total_advance; } - if (remaining_offset + whitespace_count < (last_run - 1)->len) { + if (remaining_offset + whitespace_count - 1 < (last_run - 1)->len) { /* We didn't use up all of the last run, store remainder for the next line. */ this->cur_range_offset = remaining_offset + whitespace_count - 1; this->cur_range = last_run - 1; diff --git a/src/querystring_gui.h b/src/querystring_gui.h index 1556334c3d..79eadc7993 100644 --- a/src/querystring_gui.h +++ b/src/querystring_gui.h @@ -54,7 +54,7 @@ public: Point GetCaretPosition(const Window *w, int wid) const; Rect GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const; - const char *GetCharAtPosition(const Window *w, int wid, const Point &pt) const; + ptrdiff_t GetCharAtPosition(const Window *w, int wid, const Point &pt) const; /** * Get the current text. diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 4149c0f6f7..5051a10896 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -72,8 +72,8 @@ struct RailStationGUISettings { bool newstations; ///< Are custom station definitions available? StationClassID station_class; ///< Currently selected custom station class (if newstations is \c true ) - uint16 station_type; ///< %Station type within the currently selected custom station class (if newstations is \c true ) - uint16 station_count; ///< Number of custom stations (if newstations is \c true ) + uint16 station_type; ///< %Station type within the currently selected custom station class (if newstations is \c true ) + uint16 station_count; ///< Number of custom stations (if newstations is \c true ) }; static RailStationGUISettings _railstation; ///< Settings of the station builder GUI @@ -1108,7 +1108,7 @@ private: if (station_class == _railstation.station_class) break; pos++; } - this->vscroll->SetCount((int)this->station_classes.size()); + this->vscroll->SetCount(this->station_classes.size()); this->vscroll->ScrollTowards(pos); } @@ -1253,7 +1253,7 @@ public: this->station_classes.RebuildDone(); this->station_classes.Sort(); - this->vscroll->SetCount((uint)this->station_classes.size()); + this->vscroll->SetCount(this->station_classes.size()); } } @@ -1470,7 +1470,7 @@ public: } case WID_BRAS_IMAGE: { - byte type = GB(widget, 16, 16); + uint16_t type = GB(widget, 16, 16); assert(type < _railstation.station_count); /* Check station availability callback */ const StationSpec *statspec = StationClass::Get(_railstation.station_class)->GetSpec(type); @@ -1658,7 +1658,7 @@ public: } case WID_BRAS_IMAGE: { - int y = GB(widget, 16, 16); + uint16_t y = GB(widget, 16, 16); if (y >= _railstation.station_count) return; /* Check station availability callback */ diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 4fb738eb91..38af08f70a 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -201,8 +201,10 @@ void CcRoadDepot(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2 * bit 2: Allow stations directly adjacent to other stations. * bit 3..4: Entrance direction (#DiagDirection) for normal stops. * bit 3: #Axis of the road for drive-through stops. - * bit 5..9: The roadtype. + * bit 5..10: The roadtype. * bit 16..31: Station ID to join (NEW_STATION if build new one). + * @param p3 bit 0..7: Roadstop class. + * bit 16..31: Roadstopspec index. * @param cmd Unused. * @see CmdBuildRoadStop */ @@ -217,7 +219,7 @@ void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, bool connect_to_road = true; RoadStopClassID spec_class = Extract(p3); - uint16 spec_index = GB(p3, 16, 16); + uint16 spec_index = GB(p3, 16, 16); if ((uint)spec_class < RoadStopClass::GetClassCount() && spec_index < RoadStopClass::Get(spec_class)->GetSpecCount()) { const RoadStopSpec *roadstopspec = RoadStopClass::Get(spec_class)->GetSpec(spec_index); if (roadstopspec != nullptr && HasBit(roadstopspec->flags, RSF_NO_AUTO_ROAD_CONNECTION)) connect_to_road = false; @@ -1251,7 +1253,7 @@ private: if (rs_class == _roadstop_gui_settings.roadstop_class) break; pos++; } - this->vscrollList->SetCount((int)this->roadstop_classes.size()); + this->vscrollList->SetCount(this->roadstop_classes.size()); this->vscrollList->ScrollTowards(pos); } @@ -1397,7 +1399,7 @@ public: this->roadstop_classes.RebuildDone(); this->roadstop_classes.Sort(); - this->vscrollList->SetCount((uint)this->roadstop_classes.size()); + this->vscrollList->SetCount(this->roadstop_classes.size()); } } @@ -1601,7 +1603,7 @@ public: } case WID_BROS_IMAGE: { - byte type = GB(widget, 16, 16); + uint16_t type = GB(widget, 16, 16); assert(type < _roadstop_gui_settings.roadstop_count); const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(type); @@ -1698,7 +1700,7 @@ public: } case WID_BROS_IMAGE: { - int y = GB(widget, 16, 16); + uint16_t y = GB(widget, 16, 16); if (y >= _roadstop_gui_settings.roadstop_count) return; const RoadStopSpec *spec = RoadStopClass::Get(_roadstop_gui_settings.roadstop_class)->GetSpec(y); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 1d96994fd8..67caac878f 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2301,7 +2301,7 @@ bool AfterLoadGame() /* Replace "house construction year" with "house age" */ if (IsTileType(t, MP_HOUSE) && IsHouseCompleted(t)) { - _m[t].m5 = Clamp(_cur_year - (_m[t].m5 + ORIGINAL_BASE_YEAR), 0, 0xFF); + _m[t].m5 = ClampTo(_cur_year - (_m[t].m5 + ORIGINAL_BASE_YEAR)); } } } diff --git a/src/schdispatch_cmd.cpp b/src/schdispatch_cmd.cpp index f7fa7e575f..cda2241190 100644 --- a/src/schdispatch_cmd.cpp +++ b/src/schdispatch_cmd.cpp @@ -638,7 +638,7 @@ bool DispatchSchedule::UpdateScheduledDispatchToDate(DateTicksScaled now) const int64 day = 24 * 60 * _settings_game.game_time.ticks_per_minute; this->scheduled_dispatch_last_dispatch = last_dispatch + (CeilDivT(INT_MIN - last_dispatch, day) * day); } else { - this->scheduled_dispatch_last_dispatch = ClampToI32(last_dispatch); + this->scheduled_dispatch_last_dispatch = ClampTo(last_dispatch); } } /* Most of the time this loop does not runs. It makes sure start date in in past */ diff --git a/src/script/api/CMakeLists.txt b/src/script/api/CMakeLists.txt index 844db3a99f..585d2d43fd 100644 --- a/src/script/api/CMakeLists.txt +++ b/src/script/api/CMakeLists.txt @@ -182,6 +182,7 @@ add_files( script_league.hpp script_list.hpp script_log.hpp + script_log_types.hpp script_map.hpp script_marine.hpp script_newgrf.hpp diff --git a/src/script/api/script_controller.cpp b/src/script/api/script_controller.cpp index 0b5b4ed8cd..ac5bee7ef5 100644 --- a/src/script/api/script_controller.cpp +++ b/src/script/api/script_controller.cpp @@ -52,7 +52,7 @@ char log_message[1024]; seprintf(log_message, lastof(log_message), "Break: %s", message); - ScriptLog::Log(ScriptLog::LOG_SQ_ERROR, log_message); + ScriptLog::Log(ScriptLogTypes::LOG_SQ_ERROR, log_message); /* Inform script developer that their script has been paused and * needs manual action to continue. */ @@ -65,7 +65,7 @@ /* static */ void ScriptController::Print(bool error_msg, const char *message) { - ScriptLog::Log(error_msg ? ScriptLog::LOG_SQ_ERROR : ScriptLog::LOG_SQ_INFO, message); + ScriptLog::Log(error_msg ? ScriptLogTypes::LOG_SQ_ERROR : ScriptLogTypes::LOG_SQ_INFO, message); } ScriptController::ScriptController(CompanyID company) : diff --git a/src/script/api/script_log.cpp b/src/script/api/script_log.cpp index faaf03e6c2..2b601a014f 100644 --- a/src/script/api/script_log.cpp +++ b/src/script/api/script_log.cpp @@ -8,6 +8,7 @@ /** @file script_log.cpp Implementation of ScriptLog. */ #include "../../stdafx.h" +#include "script_log_types.hpp" #include "script_log.hpp" #include "../../core/alloc_func.hpp" #include "../../debug.h" @@ -18,80 +19,50 @@ /* static */ void ScriptLog::Info(const char *message) { - ScriptLog::Log(LOG_INFO, message); + ScriptLog::Log(ScriptLogTypes::LOG_INFO, message); } /* static */ void ScriptLog::Warning(const char *message) { - ScriptLog::Log(LOG_WARNING, message); + ScriptLog::Log(ScriptLogTypes::LOG_WARNING, message); } /* static */ void ScriptLog::Error(const char *message) { - ScriptLog::Log(LOG_ERROR, message); + ScriptLog::Log(ScriptLogTypes::LOG_ERROR, message); } -/* static */ void ScriptLog::Log(ScriptLog::ScriptLogType level, const char *message) +/* static */ void ScriptLog::Log(ScriptLogTypes::ScriptLogType level, const char *message) { - if (ScriptObject::GetLogPointer() == nullptr) { - ScriptObject::GetLogPointer() = new LogData(); - LogData *log = (LogData *)ScriptObject::GetLogPointer(); + ScriptLogTypes::LogData &logdata = ScriptObject::GetLogData(); - log->lines = CallocT(400); - log->type = CallocT(400); - log->count = 400; - log->pos = log->count - 1; - log->used = 0; - } - LogData *log = (LogData *)ScriptObject::GetLogPointer(); + /* Limit the log to 400 lines. */ + if (logdata.size() >= 400U) logdata.pop_front(); - /* Go to the next log-line */ - log->pos = (log->pos + 1) % log->count; - - if (log->used != log->count) log->used++; - - /* Free last message, and write new message */ - free(log->lines[log->pos]); - log->lines[log->pos] = stredup(message); - log->type[log->pos] = level; + auto &line = logdata.emplace_back(); + line.type = level; /* Cut string after first \n */ - char *p; - while ((p = strchr(log->lines[log->pos], '\n')) != nullptr) { - *p = '\0'; - break; - } + const char *newline = strchr(message, '\n'); + line.text = std::string(message, 0, newline == nullptr ? strlen(message) : newline - message); char logc; switch (level) { - case LOG_SQ_ERROR: logc = 'S'; break; - case LOG_ERROR: logc = 'E'; break; - case LOG_SQ_INFO: logc = 'P'; break; - case LOG_WARNING: logc = 'W'; break; - case LOG_INFO: logc = 'I'; break; - default: logc = '?'; break; + case ScriptLogTypes::LOG_SQ_ERROR: logc = 'S'; break; + case ScriptLogTypes::LOG_ERROR: logc = 'E'; break; + case ScriptLogTypes::LOG_SQ_INFO: logc = 'P'; break; + case ScriptLogTypes::LOG_WARNING: logc = 'W'; break; + case ScriptLogTypes::LOG_INFO: logc = 'I'; break; + default: logc = '?'; break; } /* Also still print to debug window */ - DEBUG(script, level, "[%d] [%c] %s", (uint)ScriptObject::GetRootCompany(), logc, log->lines[log->pos]); + DEBUG(script, level, "[%d] [%c] %s", (uint)ScriptObject::GetRootCompany(), logc, line.text.c_str()); InvalidateWindowData(WC_SCRIPT_DEBUG, 0, ScriptObject::GetRootCompany()); } -/* static */ void ScriptLog::FreeLogPointer() -{ - LogData *log = (LogData *)ScriptObject::GetLogPointer(); - - for (int i = 0; i < log->count; i++) { - free(log->lines[i]); - } - - free(log->lines); - free(log->type); - delete log; -} - -/* static */ void ScriptLog::LogOnce(ScriptLog::ScriptLogType level, std::string &&message) +/* static */ void ScriptLog::LogOnce(ScriptLogTypes::ScriptLogType level, std::string &&message) { if (ScriptObject::IsNewUniqueLogMessage(message)) { ScriptLog::Log(level, message.c_str()); diff --git a/src/script/api/script_log.hpp b/src/script/api/script_log.hpp index c9d4a4a7c9..c17ea6bf55 100644 --- a/src/script/api/script_log.hpp +++ b/src/script/api/script_log.hpp @@ -22,32 +22,6 @@ class ScriptLog : public ScriptObject { friend class ScriptController; public: - /** - * Log levels; The value is also feed to DEBUG() lvl. - * This has no use for you, as script writer. - * @api -all - */ - enum ScriptLogType { - LOG_SQ_ERROR = 0, ///< Squirrel printed an error. - LOG_ERROR = 1, ///< User printed an error. - LOG_SQ_INFO = 2, ///< Squirrel printed some info. - LOG_WARNING = 3, ///< User printed some warning. - LOG_INFO = 4, ///< User printed some info. - }; - - /** - * Internal representation of the log-data inside the script. - * This has no use for you, as script writer. - * @api -all - */ - struct LogData { - char **lines; ///< The log-lines. - ScriptLog::ScriptLogType *type; ///< Per line, which type of log it was. - int count; ///< Total amount of log-lines possible. - int pos; ///< Current position in lines. - int used; ///< Total amount of used log-lines. - }; - /** * Print an Info message to the logs. * @param message The message to log. @@ -69,23 +43,17 @@ public: */ static void Error(const char *message); - /** - * Free the log pointer. - * @api -all - */ - static void FreeLogPointer(); - /** * Log this message once. * @api -all */ - static void LogOnce(ScriptLog::ScriptLogType level, std::string &&message); + static void LogOnce(ScriptLogTypes::ScriptLogType level, std::string &&message); private: /** * Internal command to log the message in a common way. */ - static void Log(ScriptLog::ScriptLogType level, const char *message); + static void Log(ScriptLogTypes::ScriptLogType level, const char *message); }; #endif /* SCRIPT_LOG_HPP */ diff --git a/src/script/api/script_log_types.hpp b/src/script/api/script_log_types.hpp new file mode 100644 index 0000000000..b10ea0cea3 --- /dev/null +++ b/src/script/api/script_log_types.hpp @@ -0,0 +1,47 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file script_log_types.hpp Data types for script log messages. */ + +#ifndef SCRIPT_LOG_TYPES_HPP +#define SCRIPT_LOG_TYPES_HPP + +#include + +namespace ScriptLogTypes { + /** + * Log levels; The value is also feed to Debug() lvl. + * This has no use for you, as script writer. + * @api -all + */ + enum ScriptLogType { + LOG_SQ_ERROR = 0, ///< Squirrel printed an error. + LOG_ERROR = 1, ///< User printed an error. + LOG_SQ_INFO = 2, ///< Squirrel printed some info. + LOG_WARNING = 3, ///< User printed some warning. + LOG_INFO = 4, ///< User printed some info. + }; + + /** + * Internal representation of the log-data inside the script. + * This has no use for you, as script writer. + * @api -all + */ + struct LogLine { + std::string text; ///< The text + ScriptLogType type; ///< Text type + }; + + /** + * Internal representation of the log-data inside the script. + * This has no use for you, as script writer. + * @api -all + */ + using LogData = std::deque; ///< The log type +}; + +#endif /* SCRIPT_LOG_TYPES_HPP */ diff --git a/src/script/api/script_object.cpp b/src/script/api/script_object.cpp index dccf8ba5f5..86404d202d 100644 --- a/src/script/api/script_object.cpp +++ b/src/script/api/script_object.cpp @@ -306,7 +306,7 @@ ScriptObject::ActiveInstance::~ActiveInstance() return GetStorage()->event_data; } -/* static */ void *&ScriptObject::GetLogPointer() +/* static */ ScriptLogTypes::LogData &ScriptObject::GetLogData() { return GetStorage()->log_data; } diff --git a/src/script/api/script_object.hpp b/src/script/api/script_object.hpp index deea660518..333c9a2cd1 100644 --- a/src/script/api/script_object.hpp +++ b/src/script/api/script_object.hpp @@ -16,6 +16,7 @@ #include "../../core/random_func.hpp" #include "script_types.hpp" +#include "script_log_types.hpp" #include "../script_suspend.hpp" #include "../squirrel.hpp" @@ -317,7 +318,7 @@ protected: /** * Get the pointer to store log message in. */ - static void *&GetLogPointer(); + static ScriptLogTypes::LogData &GetLogData(); /** * Get an allocated string with all control codes stripped off. diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index 301d5925af..500453801e 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -185,7 +185,7 @@ 0, source_industry, goal_industry, - std::min(255, distance / 2), + ClampTo(distance / 2), AICE_STATION_GET_STATION_ID, source_station ? 0 : 1, std::min(15u, num_platforms) << 4 | std::min(15u, platform_length), diff --git a/src/script/api/script_text.cpp b/src/script/api/script_text.cpp index ec1266c187..1c9cb1e619 100644 --- a/src/script/api/script_text.cpp +++ b/src/script/api/script_text.cpp @@ -174,7 +174,7 @@ const std::string ScriptText::GetEncodedText() void ScriptText::_TextParamError(std::string msg) { if (this->GetActiveInstance()->IsTextParamMismatchAllowed()) { - ScriptLog::LogOnce(ScriptLog::LOG_ERROR, std::move(msg)); + ScriptLog::LogOnce(ScriptLogTypes::LOG_ERROR, std::move(msg)); } else { throw Script_FatalError(std::move(msg)); } diff --git a/src/script/script_gui.cpp b/src/script/script_gui.cpp index 3151385760..b49dcb0ef9 100644 --- a/src/script/script_gui.cpp +++ b/src/script/script_gui.cpp @@ -78,7 +78,7 @@ struct ScriptListWindow : public Window { this->vscroll = this->GetScrollbar(WID_SCRL_SCROLLBAR); this->FinishInitNested(); // Initializes 'this->line_height' as side effect. - this->vscroll->SetCount((int)this->info_list->size() + 1); + this->vscroll->SetCount(this->info_list->size() + 1); /* Try if we can find the currently selected AI */ this->selected = -1; @@ -238,7 +238,7 @@ struct ScriptListWindow : public Window { if (!gui_scope) return; - this->vscroll->SetCount((int)this->info_list->size() + 1); + this->vscroll->SetCount(this->info_list->size() + 1); /* selected goes from -1 .. length of ai list - 1. */ this->selected = std::min(this->selected, this->vscroll->GetCount() - 2); @@ -346,7 +346,7 @@ struct ScriptSettingsWindow : public Window { } } - this->vscroll->SetCount((int)this->visible_settings.size()); + this->vscroll->SetCount(this->visible_settings.size()); } void SetStringParameters(int widget) const override @@ -720,10 +720,10 @@ struct ScriptDebugWindow : public Window { int highlight_row; ///< The output row that matches the given string, or -1 Scrollbar *vscroll; ///< Cache of the vertical scrollbar. - ScriptLog::LogData *GetLogPointer() const + ScriptLogTypes::LogData &GetLogData() const { - if (script_debug_company == OWNER_DEITY) return (ScriptLog::LogData *)Game::GetInstance()->GetLogPointer(); - return (ScriptLog::LogData *)Company::Get(script_debug_company)->ai_instance->GetLogPointer(); + if (script_debug_company == OWNER_DEITY) return Game::GetInstance()->GetLogData(); + return Company::Get(script_debug_company)->ai_instance->GetLogData(); } /** @@ -861,9 +861,9 @@ struct ScriptDebugWindow : public Window { /* If there are no active companies, don't display anything else. */ if (script_debug_company == INVALID_COMPANY) return; - ScriptLog::LogData *log = this->GetLogPointer(); + ScriptLogTypes::LogData &log = this->GetLogData(); - int scroll_count = (log == nullptr) ? 0 : log->used; + int scroll_count = (int)log.size(); if (this->vscroll->GetCount() != scroll_count) { this->vscroll->SetCount(scroll_count); @@ -871,16 +871,15 @@ struct ScriptDebugWindow : public Window { this->SetWidgetDirty(WID_SCRD_SCROLLBAR); } - if (log == nullptr) return; + if (log.empty()) return; /* Detect when the user scrolls the window. Enable autoscroll when the * bottom-most line becomes visible. */ if (this->last_vscroll_pos != this->vscroll->GetPosition()) { - this->autoscroll = this->vscroll->GetPosition() >= log->used - this->vscroll->GetCapacity(); + this->autoscroll = this->vscroll->GetPosition() + this->vscroll->GetCapacity() >= (int)log.size(); } if (this->autoscroll) { - int scroll_pos = std::max(0, log->used - this->vscroll->GetCapacity()); - if (this->vscroll->SetPosition(scroll_pos)) { + if (this->vscroll->SetPosition((int)log.size())) { /* We need a repaint */ this->SetWidgetDirty(WID_SCRD_SCROLLBAR); this->SetWidgetDirty(WID_SCRD_LOG_PANEL); @@ -916,32 +915,31 @@ struct ScriptDebugWindow : public Window { if (widget != WID_SCRD_LOG_PANEL) return; - ScriptLog::LogData *log = this->GetLogPointer(); - if (log == nullptr) return; + ScriptLogTypes::LogData &log = this->GetLogData(); + if (log.empty()) return; Rect br = r.Shrink(WidgetDimensions::scaled.bevel); Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); - for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < log->used; i++) { - int pos = (i + log->pos + 1 - log->used + log->count) % log->count; - if (log->lines[pos] == nullptr) break; + for (int i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && (size_t)i < log.size(); i++) { + const ScriptLogTypes::LogLine &line = log[i]; TextColour colour; - switch (log->type[pos]) { - case ScriptLog::LOG_SQ_INFO: colour = TC_BLACK; break; - case ScriptLog::LOG_SQ_ERROR: colour = TC_WHITE; break; - case ScriptLog::LOG_INFO: colour = TC_BLACK; break; - case ScriptLog::LOG_WARNING: colour = TC_YELLOW; break; - case ScriptLog::LOG_ERROR: colour = TC_RED; break; - default: colour = TC_BLACK; break; + switch (line.type) { + case ScriptLogTypes::LOG_SQ_INFO: colour = TC_BLACK; break; + case ScriptLogTypes::LOG_SQ_ERROR: colour = TC_WHITE; break; + case ScriptLogTypes::LOG_INFO: colour = TC_BLACK; break; + case ScriptLogTypes::LOG_WARNING: colour = TC_YELLOW; break; + case ScriptLogTypes::LOG_ERROR: colour = TC_RED; break; + default: colour = TC_BLACK; break; } /* Check if the current line should be highlighted */ - if (pos == this->highlight_row) { + if (i == this->highlight_row) { GfxFillRect(br.left, tr.top, br.right, tr.top + this->resize.step_height - 1, PC_BLACK); if (colour == TC_BLACK) colour = TC_WHITE; // Make black text readable by inverting it to white. } - DrawString(tr, log->lines[pos], colour, SA_LEFT | SA_FORCE); + DrawString(tr, line.text, colour, SA_LEFT | SA_FORCE); tr.top += this->resize.step_height; } } @@ -1064,11 +1062,11 @@ struct ScriptDebugWindow : public Window { * This needs to be done in gameloop-scope, so the AI is suspended immediately. */ if (!gui_scope && data == script_debug_company && this->IsValidDebugCompany(script_debug_company) && this->break_check_enabled && !this->break_string_filter.IsEmpty()) { /* Get the log instance of the active company */ - ScriptLog::LogData *log = this->GetLogPointer(); + ScriptLogTypes::LogData &log = this->GetLogData(); - if (log != nullptr) { + if (!log.empty()) { this->break_string_filter.ResetState(); - this->break_string_filter.AddLine(log->lines[log->pos]); + this->break_string_filter.AddLine(log.back().text); if (this->break_string_filter.GetState()) { /* Pause execution of script. */ if (!this->IsDead()) { @@ -1085,7 +1083,7 @@ struct ScriptDebugWindow : public Window { } /* Highlight row that matched */ - this->highlight_row = log->pos; + this->highlight_row = (int)(log.size() - 1); } } } @@ -1094,8 +1092,7 @@ struct ScriptDebugWindow : public Window { this->SelectValidDebugCompany(); - ScriptLog::LogData *log = script_debug_company != INVALID_COMPANY ? this->GetLogPointer() : nullptr; - this->vscroll->SetCount((log == nullptr) ? 0 : log->used); + this->vscroll->SetCount(script_debug_company != INVALID_COMPANY ? this->GetLogData().size() : 0); /* Update company buttons */ for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) { diff --git a/src/script/script_info.cpp b/src/script/script_info.cpp index 79f4982fb6..59e49bc358 100644 --- a/src/script/script_info.cpp +++ b/src/script/script_info.cpp @@ -146,42 +146,42 @@ SQInteger ScriptInfo::AddSetting(HSQUIRRELVM vm) } else if (strcmp(key, "min_value") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.min_value = ClampToI32(res); + config.min_value = ClampTo(res); items |= 0x004; } else if (strcmp(key, "max_value") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.max_value = ClampToI32(res); + config.max_value = ClampTo(res); items |= 0x008; } else if (strcmp(key, "easy_value") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.easy_value = ClampToI32(res); + config.easy_value = ClampTo(res); items |= 0x010; } else if (strcmp(key, "medium_value") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.medium_value = ClampToI32(res); + config.medium_value = ClampTo(res); items |= 0x020; } else if (strcmp(key, "hard_value") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.hard_value = ClampToI32(res); + config.hard_value = ClampTo(res); items |= 0x040; } else if (strcmp(key, "random_deviation") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.random_deviation = ClampToI32(abs(res)); + config.random_deviation = ClampTo(abs(res)); items |= 0x200; } else if (strcmp(key, "custom_value") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.custom_value = ClampToI32(res); + config.custom_value = ClampTo(res); items |= 0x080; } else if (strcmp(key, "step_size") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; - config.step_size = ClampToI32(res); + config.step_size = ClampTo(res); } else if (strcmp(key, "flags") == 0) { SQInteger res; if (SQ_FAILED(sq_getinteger(vm, -1, &res))) return SQ_ERROR; diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 3371924b91..21aca7683d 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -35,7 +35,6 @@ ScriptStorage::~ScriptStorage() { /* Free our pointers */ if (event_data != nullptr) ScriptEventController::FreeEventPointer(); - if (log_data != nullptr) ScriptLog::FreeLogPointer(); } /** @@ -350,11 +349,11 @@ ScriptStorage *ScriptInstance::GetStorage() return this->storage; } -void *ScriptInstance::GetLogPointer() +ScriptLogTypes::LogData &ScriptInstance::GetLogData() { ScriptObject::ActiveInstance active(this); - return ScriptObject::GetLogPointer(); + return ScriptObject::GetLogData(); } /* diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index e66ff4a80a..f3fc4aedf2 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -15,6 +15,7 @@ #include #include "squirrel.hpp" #include "script_suspend.hpp" +#include "script_log_types.hpp" #include "../command_type.h" #include "../company_type.h" @@ -96,7 +97,7 @@ public: /** * Get the log pointer of this script. */ - void *GetLogPointer(); + ScriptLogTypes::LogData &GetLogData(); /** * Return a true/false reply for a DoCommand. diff --git a/src/script/script_storage.hpp b/src/script/script_storage.hpp index 79f4784d20..5cd14980ad 100644 --- a/src/script/script_storage.hpp +++ b/src/script/script_storage.hpp @@ -18,6 +18,8 @@ #include "../story_type.h" #include "../3rdparty/robin_hood/robin_hood.h" +#include "script_log_types.hpp" + #include "table/strings.h" #include @@ -72,7 +74,7 @@ private: RailType rail_type; ///< The current railtype we build. void *event_data; ///< Pointer to the event data storage. - void *log_data; ///< Pointer to the log data storage. + ScriptLogTypes::LogData log_data;///< Log data storage. robin_hood::unordered_node_set seen_unique_log_messages; ///< Messages which have already been logged once and don't need to be logged again @@ -105,8 +107,7 @@ public: /* calback_value (can't be set) */ road_type (INVALID_ROADTYPE), rail_type (INVALID_RAILTYPE), - event_data (nullptr), - log_data (nullptr) + event_data (nullptr) { } ~ScriptStorage(); diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 24d7e1480f..ef3e7d17a8 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -2947,7 +2947,7 @@ struct GameSettingsWindow : Window { /* Save the correct currency-translated value */ if (sd->flags & SF_GUI_CURRENCY) llvalue /= _currency->rate; - value = (int32)ClampToI32(llvalue); + value = ClampTo(llvalue); /* Save the correct velocity-translated value */ if (sd->flags & SF_GUI_VELOCITY) value = ConvertDisplaySpeedToKmhishSpeed(value, VEH_TRAIN); diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index 8dd9ff6f4a..4e17f996ee 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -35,7 +35,7 @@ void NORETURN CDECL error(const char *s, ...) va_start(va, s); vseprintf(buf, lastof(buf), s, va); va_end(va); - fprintf(stderr, "FATAL: %s\n", buf); + fprintf(stderr, "settingsgen: FATAL: %s\n", buf); exit(1); } @@ -72,7 +72,7 @@ public: void Write(FILE *out_fp) const { if (fwrite(this->data, 1, this->size, out_fp) != this->size) { - fprintf(stderr, "Error: Cannot write output\n"); + error("Cannot write output"); } } @@ -329,8 +329,7 @@ static void DumpSections(IniLoadFile *ifile) IniItem *template_item = templates_grp->GetItem(grp->name, false); // Find template value. if (template_item == nullptr || !template_item->value.has_value()) { - fprintf(stderr, "settingsgen: Warning: Cannot find template %s\n", grp->name.c_str()); - continue; + error("Cannot find template %s", grp->name.c_str()); } DumpLine(template_item, grp, default_grp, _stored_output); @@ -354,8 +353,7 @@ static void CopyFile(const char *fname, FILE *out_fp) FILE *in_fp = fopen(fname, "r"); if (in_fp == nullptr) { - fprintf(stderr, "settingsgen: Warning: Cannot open file %s for copying\n", fname); - return; + error("Cannot open file %s for copying", fname); } char buffer[4096]; @@ -363,8 +361,7 @@ static void CopyFile(const char *fname, FILE *out_fp) do { length = fread(buffer, 1, lengthof(buffer), in_fp); if (fwrite(buffer, 1, length, out_fp) != length) { - fprintf(stderr, "Error: Cannot copy file\n"); - break; + error("Cannot copy file"); } } while (length == lengthof(buffer)); @@ -513,8 +510,7 @@ int CDECL main(int argc, char *argv[]) FILE *fp = fopen(tmp_output, "w"); if (fp == nullptr) { - fprintf(stderr, "settingsgen: Warning: Cannot open file %s\n", tmp_output); - return 1; + error("Cannot open file %s", tmp_output); } CopyFile(before_file, fp); _stored_output.Write(fp); diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index efc46664e6..4407c751ae 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -305,7 +305,7 @@ struct SignListWindow : Window, SignList { { if (this->signs.NeedRebuild()) { this->BuildSignsList(); - this->vscroll->SetCount((uint)this->signs.size()); + this->vscroll->SetCount(this->signs.size()); this->SetWidgetDirty(WID_SIL_CAPTION); } this->SortSignsList(); diff --git a/src/spriteloader/grf.cpp b/src/spriteloader/grf.cpp index 75ed1f6e40..bae60eda22 100644 --- a/src/spriteloader/grf.cpp +++ b/src/spriteloader/grf.cpp @@ -165,7 +165,7 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t f if (colour_fmt & SCC_PAL) { switch (sprite_type) { case SpriteType::Normal: data->m = file.NeedsPaletteRemap() ? _palmap_w2d[*dest] : *dest; break; - case SpriteType::Font: data->m = std::min(*dest, 2u); break; + case SpriteType::Font: data->m = std::min(*dest, 2u); break; default: data->m = *dest; break; } /* Magic blue. */ @@ -202,7 +202,7 @@ bool DecodeSingleSprite(SpriteLoader::Sprite *sprite, SpriteFile &file, size_t f if (colour_fmt & SCC_PAL) { switch (sprite_type) { case SpriteType::Normal: sprite->data[i].m = file.NeedsPaletteRemap() ? _palmap_w2d[*pixel] : *pixel; break; - case SpriteType::Font: sprite->data[i].m = std::min(*pixel, 2u); break; + case SpriteType::Font: sprite->data[i].m = std::min(*pixel, 2u); break; default: sprite->data[i].m = *pixel; break; } /* Magic blue. */ diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index d618ecd8fc..73bf260b66 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1015,7 +1015,7 @@ CommandCost IsRoadStopBridgeAboveOK(TileIndex tile, const RoadStopSpec *spec, bo * @param numtracks Number of platforms. * @return The cost in case of success, or an error code if it failed. */ -static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, Axis axis, StationID *station, RailType rt, std::vector &affected_vehicles, StationClassID spec_class, byte spec_index, byte plat_len, byte numtracks) +static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag flags, Axis axis, StationID *station, RailType rt, std::vector &affected_vehicles, StationClassID spec_class, uint16_t spec_index, byte plat_len, byte numtracks) { CommandCost cost(EXPENSES_CONSTRUCTION); int allowed_z = -1; @@ -1484,7 +1484,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32 bool adjacent = HasBit(p1, 24); StationClassID spec_class = Extract(p2); - byte spec_index = GB(p3, 0, 16); + uint16 spec_index = GB(p3, 0, 16); StationID station_to_join = GB(p2, 16, 16); /* Does the authority allow this? */ @@ -4251,7 +4251,7 @@ int GetTargetRating(const Station *st, const CargoSpec *cs, const GoodsEntry *ge rating += GetStatueRating(st); rating += GetVehicleAgeRating(ge); - return Clamp(rating, 0, 255); + return ClampTo(rating); } static void UpdateStationRating(Station *st) @@ -4671,7 +4671,7 @@ void ModifyStationRatingAround(TileIndex tile, Owner owner, int amount, uint rad GoodsEntry *ge = &st->goods[i]; if (ge->status != 0) { - ge->rating = Clamp(ge->rating + amount, 0, 255); + ge->rating = ClampTo(ge->rating + amount); } } } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index ddcfee3173..0049e6d995 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -311,7 +311,7 @@ protected: this->stations.shrink_to_fit(); this->stations.RebuildDone(); - this->vscroll->SetCount((uint)this->stations.size()); // Update the scrollbar + this->vscroll->SetCount(this->stations.size()); // Update the scrollbar } /** Sort stations by their name */ @@ -549,7 +549,7 @@ public: case WID_STL_LIST: { bool rtl = _current_text_dir == TD_RTL; - int max = std::min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size()); + size_t max = std::min(this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->stations.size()); Rect tr = r.Shrink(WidgetDimensions::scaled.framerect); uint line_height = this->GetWidget(widget)->resize_y; /* Spacing between station name and first rating graph. */ @@ -557,7 +557,7 @@ public: /* Spacing between additional rating graphs. */ int rating_spacing = WidgetDimensions::scaled.hsep_normal; - for (int i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner + for (size_t i = this->vscroll->GetPosition(); i < max; ++i) { // do until max number of stations of owner const Station *st = this->stations[i]; assert(st->xy != INVALID_TILE); @@ -2616,7 +2616,7 @@ struct SelectStationWindow : Window { { if (!gui_scope) return; FindStationsNearby(this->area, true, IsSpecializedStationRightType(this->select_station_cmd)); - this->vscroll->SetCount((uint)_stations_nearby_list.size() + 1); + this->vscroll->SetCount(_stations_nearby_list.size() + 1); this->SetDirty(); } diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index 604956cac6..062126b9b9 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -131,7 +131,7 @@ struct FileStringReader : StringReader { char *ReadLine(char *buffer, const char *last) override { - char *result = fgets(buffer, ClampToU16(last - buffer + 1), this->fh); + char *result = fgets(buffer, ClampTo(last - buffer + 1), this->fh); if (result == nullptr && this->fh2 != nullptr) { fclose(this->fh); this->fh = this->fh2; diff --git a/src/string.cpp b/src/string.cpp index d5939ce885..29dc221211 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -233,16 +233,19 @@ static void StrMakeValidInPlace(T &dst, const char *str, const char *last, Strin } while (--len != 0); } else if ((settings & SVS_ALLOW_NEWLINE) != 0 && c == '\n') { *dst++ = *str++; - } else if ((settings & SVS_ALLOW_SEPARATOR_CODE) != 0 && c == 0x1F) { - *dst++ = *str++; } else { if ((settings & SVS_ALLOW_NEWLINE) != 0 && c == '\r' && str[1] == '\n') { str += len; continue; } - /* Replace the undesirable character with a question mark */ str += len; - if ((settings & SVS_REPLACE_WITH_QUESTION_MARK) != 0) *dst++ = '?'; + if ((settings & SVS_REPLACE_TAB_CR_NL_WITH_SPACE) != 0 && (c == '\r' || c == '\n' || c == '\t')) { + /* Replace the tab, carriage return or newline with a space. */ + *dst++ = ' '; + } else if ((settings & SVS_REPLACE_WITH_QUESTION_MARK) != 0) { + /* Replace the undesirable character with a question mark */ + *dst++ = '?'; + } } } @@ -284,7 +287,7 @@ void StrMakeValidInPlace(char *str, StringValidationSettings settings) * @param str The string to validate. * @param settings The settings for the string validation. */ -std::string StrMakeValid(const std::string &str, StringValidationSettings settings) +std::string StrMakeValid(std::string_view str, StringValidationSettings settings) { auto buf = str.data(); auto last = buf + str.size(); diff --git a/src/string_func.h b/src/string_func.h index 16c8c3c0a6..7c655809eb 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -41,7 +41,7 @@ std::string CDECL stdstr_fmt(const char *str, ...) WARN_FORMAT(1, 2); std::string stdstr_vfmt(const char *str, va_list va) WARN_FORMAT(1, 0); char *StrMakeValidInPlace(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK) NOACCESS(2); -[[nodiscard]] std::string StrMakeValid(const std::string &str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK); +[[nodiscard]] std::string StrMakeValid(std::string_view str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK); void StrMakeValidInPlace(char *str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK); const char *str_fix_scc_encoded(char *str, const char *last) NOACCESS(2); diff --git a/src/string_type.h b/src/string_type.h index 88660e14c9..b61e0028d5 100644 --- a/src/string_type.h +++ b/src/string_type.h @@ -51,9 +51,14 @@ static const WChar CHAR_TD_PDF = 0x202C; ///< Restore the text-direction state t enum StringValidationSettings { SVS_NONE = 0, ///< Allow nothing and replace nothing. SVS_REPLACE_WITH_QUESTION_MARK = 1 << 0, ///< Replace the unknown/bad bits with question marks. - SVS_ALLOW_NEWLINE = 1 << 1, ///< Allow newlines. + SVS_ALLOW_NEWLINE = 1 << 1, ///< Allow newlines; replaces '\r\n' with '\n' during processing. SVS_ALLOW_CONTROL_CODE = 1 << 2, ///< Allow the special control codes. - SVS_ALLOW_SEPARATOR_CODE = 1 << 3, ///< Allow separator control code (0x1F). + /** + * Replace tabs ('\t'), carriage returns ('\r') and newlines ('\n') with spaces. + * When #SVS_ALLOW_NEWLINE is set, a '\n' or '\r\n' combination are not replaced with a space. A lone '\r' is replaced with a space. + * When #SVS_REPLACE_WITH_QUESTION_MARK is set, this replacement runs first. + */ + SVS_REPLACE_TAB_CR_NL_WITH_SPACE = 1 << 3, }; DECLARE_ENUM_AS_BIT_SET(StringValidationSettings) diff --git a/src/strings.cpp b/src/strings.cpp index da0e4fccab..5e767c305e 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -2504,9 +2504,13 @@ bool MissingGlyphSearcher::FindMissingGlyphs() } this->Reset(); - for (const char *text = this->NextString(); text != nullptr; text = this->NextString()) { + for (auto text = this->NextString(); text.has_value(); text = this->NextString()) { + auto src = text->cbegin(); + FontSize size = this->DefaultSize(); - for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) { + while (src != text->cend()) { + WChar c = Utf8Consume(src); + if (c >= SCC_FIRST_FONT && c <= SCC_LAST_FONT) { size = (FontSize)(c - SCC_FIRST_FONT); } else if (!IsInsideMM(c, SCC_SPRITE_START, SCC_SPRITE_END) && IsPrintable(c) && !IsTextDirectionChar(c) && c != '?' && GetGlyph(size, c) == question_mark[size]) { @@ -2545,9 +2549,9 @@ class LanguagePackGlyphSearcher : public MissingGlyphSearcher { return FS_NORMAL; } - const char *NextString() override + std::optional NextString() override { - if (this->i >= TEXT_TAB_END) return nullptr; + if (this->i >= TEXT_TAB_END) return std::nullopt; const char *ret = _langpack.offsets[_langpack.langtab_start[this->i] + this->j]; diff --git a/src/strings_func.h b/src/strings_func.h index 213fc1f1d4..d090663eb3 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -264,9 +264,9 @@ public: /** * Get the next string to search through. - * @return The next string or nullptr if there is none. + * @return The next string or nullopt if there is none. */ - virtual const char *NextString() = 0; + virtual std::optional NextString() = 0; /** * Get the default (font) size of the string. diff --git a/src/table/settings/network_private_settings.ini b/src/table/settings/network_private_settings.ini index ceb2a6935f..dd7d39b85b 100644 --- a/src/table/settings/network_private_settings.ini +++ b/src/table/settings/network_private_settings.ini @@ -15,11 +15,10 @@ static const SettingTable _network_private_settings = { [templates] SDTC_BOOL = SDTC_BOOL( $var, $flags, $def, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), SDTC_OMANY = SDTC_OMANY( $var, $type, $flags, $def, $max, $full, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), -SDTC_VAR = SDTC_VAR( $var, $type, $flags, $def, $min, $max, $interval, $str, $strhelp, $strval, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), +SDTC_SSTR = SDTC_SSTR( $var, $type, $flags, $def, $length, $pre_cb, $post_cb, $from, $to, $extver, $cat, $guiproc, $startup, nullptr), [validation] SDTC_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size"); -SDTC_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size"); [defaults] flags = SF_NONE diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 021d7326d5..15adddae67 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -70,11 +70,6 @@ TextfileWindow::TextfileWindow(TextfileType file_type) : Window(&_textfile_desc) this->hscroll->SetStepSize(10); // Speed up horizontal scrollbar } -/* virtual */ TextfileWindow::~TextfileWindow() -{ - free(this->text); -} - /** * Get the total height of the content displayed in this window, if wrapping is disabled. * @return the height in pixels @@ -124,11 +119,11 @@ void TextfileWindow::SetupScrollbars(bool force_reflow) if (IsWidgetLowered(WID_TF_WRAPTEXT)) { /* Reflow is mandatory if text wrapping is on */ uint height = this->ReflowContent(); - this->vscroll->SetCount(std::min(UINT16_MAX, height)); + this->vscroll->SetCount(ClampTo(height)); this->hscroll->SetCount(0); } else { uint height = force_reflow ? this->ReflowContent() : this->GetContentHeight(); - this->vscroll->SetCount(std::min(UINT16_MAX, height)); + this->vscroll->SetCount(ClampTo(height)); this->hscroll->SetCount(this->max_length + WidgetDimensions::scaled.frametext.Horizontal()); } @@ -199,9 +194,9 @@ void TextfileWindow::SetupScrollbars(bool force_reflow) return FS_MONO; } -/* virtual */ const char *TextfileWindow::NextString() +/* virtual */ std::optional TextfileWindow::NextString() { - if (this->search_iterator >= this->lines.size()) return nullptr; + if (this->search_iterator >= this->lines.size()) return std::nullopt; return this->lines[this->search_iterator++].text; } @@ -344,11 +339,14 @@ static void Xunzip(byte **bufp, size_t *sizep) FILE *handle = FioFOpenFile(textfile, "rb", dir, &filesize); if (handle == nullptr) return; - this->text = ReallocT(this->text, filesize); - size_t read = fread(this->text, 1, filesize, handle); + char *buf = MallocT(filesize); + size_t read = fread(buf, 1, filesize, handle); fclose(handle); - if (read != filesize) return; + if (read != filesize) { + free(buf); + return; + } #if defined(WITH_ZLIB) || defined(WITH_LIBLZMA) const char *suffix = strrchr(textfile, '.'); @@ -357,40 +355,37 @@ static void Xunzip(byte **bufp, size_t *sizep) #if defined(WITH_ZLIB) /* In-place gunzip */ - if (strcmp(suffix, ".gz") == 0) Gunzip((byte**)&this->text, &filesize); + if (StrEndsWith(textfile, ".gz")) Gunzip((byte**)&buf, &filesize); #endif #if defined(WITH_LIBLZMA) /* In-place xunzip */ - if (strcmp(suffix, ".xz") == 0) Xunzip((byte**)&this->text, &filesize); + if (StrEndsWith(textfile, ".xz")) Xunzip((byte**)&buf, &filesize); #endif - if (!this->text) return; + if (buf == nullptr) return; - /* Add space for trailing \0 */ - this->text = ReallocT(this->text, filesize + 1); - this->text[filesize] = '\0'; - - /* Replace tabs and line feeds with a space since StrMakeValidInPlace removes those. */ - for (char *p = this->text; *p != '\0'; p++) { - if (*p == '\t' || *p == '\r') *p = ' '; - } + std::string_view sv_buf(buf, filesize); /* Check for the byte-order-mark, and skip it if needed. */ - char *p = this->text + (strncmp(u8"\ufeff", this->text, 3) == 0 ? 3 : 0); + if (StrStartsWith(sv_buf, u8"\ufeff")) sv_buf.remove_prefix(3); - /* Make sure the string is a valid UTF-8 sequence. */ - StrMakeValidInPlace(p, this->text + filesize, SVS_REPLACE_WITH_QUESTION_MARK | SVS_ALLOW_NEWLINE); + /* Replace any invalid characters with a question-mark. This copies the buf in the process. */ + this->text = StrMakeValid(sv_buf, SVS_REPLACE_WITH_QUESTION_MARK | SVS_ALLOW_NEWLINE | SVS_REPLACE_TAB_CR_NL_WITH_SPACE); + free(buf); /* Split the string on newlines. */ + std::string_view p(this->text); int row = 0; - this->lines.emplace_back(row, p); - for (; *p != '\0'; p++) { - if (*p == '\n') { - *p = '\0'; - this->lines.emplace_back(++row, p + 1); - } + auto next = p.find_first_of('\n'); + while (next != std::string_view::npos) { + this->lines.emplace_back(row, p.substr(0, next)); + p.remove_prefix(next + 1); + + row++; + next = p.find_first_of('\n'); } + this->lines.emplace_back(row, p); /* Calculate maximum text line length. */ uint max_length = 0; diff --git a/src/textfile_gui.h b/src/textfile_gui.h index cdcae73888..046837f4ee 100644 --- a/src/textfile_gui.h +++ b/src/textfile_gui.h @@ -19,25 +19,14 @@ const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filenam /** Window for displaying a textfile */ struct TextfileWindow : public Window, MissingGlyphSearcher { - struct Line { - int top; ///< Top scroll position. - int bottom; ///< Bottom scroll position. - const char *text; ///< Pointer to text buffer. - - Line(int top, const char *text) : top(top), bottom(top + 1), text(text) {} - }; - TextfileType file_type; ///< Type of textfile to view. Scrollbar *vscroll; ///< Vertical scrollbar. Scrollbar *hscroll; ///< Horizontal scrollbar. - char *text; ///< Lines of text from the NewGRF's textfile. - std::vector lines; ///< #text, split into lines in a table with lines. uint search_iterator; ///< Iterator for the font check search. uint max_length; ///< Maximum length of unwrapped text line. TextfileWindow(TextfileType file_type); - ~TextfileWindow(); void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override; void OnClick(Point pt, int widget, int click_count) override; @@ -47,13 +36,24 @@ struct TextfileWindow : public Window, MissingGlyphSearcher { void Reset() override; FontSize DefaultSize() override; - const char *NextString() override; + std::optional NextString() override; bool Monospace() override; void SetFontNames(FontCacheSettings *settings, const char *font_name, const void *os_data) override; virtual void LoadTextfile(const char *textfile, Subdirectory dir); private: + struct Line { + int top; ///< Top scroll position. + int bottom; ///< Bottom scroll position. + std::string_view text; ///< Pointer to text buffer. + + Line(int top, std::string_view text) : top(top), bottom(top + 1), text(text) {} + }; + + std::string text; ///< Lines of text from the NewGRF's textfile. + std::vector lines; ///< #text, split into lines in a table with lines. + uint ReflowContent(); uint GetContentHeight(); void SetupScrollbars(bool force_reflow); diff --git a/src/tgp.cpp b/src/tgp.cpp index e4bc850f57..707f161a95 100644 --- a/src/tgp.cpp +++ b/src/tgp.cpp @@ -821,7 +821,7 @@ static void HeightMapSmoothCoastInDirection(int org_x, int org_y, int dir_x, int * Soften the coast slope */ for (depth = 0; IsValidXY(x, y) && depth <= max_coast_Smooth_depth; depth++, x += dir_x, y += dir_y) { h = _height_map.height(x, y); - h = std::min(h, h_prev + (4 + depth)); // coast softening formula + h = static_cast(std::min(h, h_prev + (4 + depth))); // coast softening formula _height_map.height(x, y) = h; h_prev = h; } diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index f5bc9adc30..fb67e42d41 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -3384,7 +3384,7 @@ CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (flags & DC_EXEC) { /* The more houses, the faster we grow */ if (p2 == 0) { - uint amount = RandomRange(ClampToU16(t->cache.num_houses / 10)) + 3; + uint amount = RandomRange(ClampTo(t->cache.num_houses / 10)) + 3; t->cache.num_houses += amount; UpdateTownRadius(t); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index b4cada27b2..e4372501f4 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -916,7 +916,7 @@ private: this->towns.shrink_to_fit(); this->towns.RebuildDone(); - this->vscroll->SetCount((uint)this->towns.size()); // Update scrollbar as well. + this->vscroll->SetCount(this->towns.size()); // Update scrollbar as well. } /* Always sort the towns. */ this->towns.Sort(); diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index c5045697af..be09565e9e 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -7447,7 +7447,7 @@ int GetTrainRealisticAccelerationAtSpeed(const int speed, const int mass, const /* Easy way out when there is no acceleration. */ if (force == resistance) return 0; - int acceleration = ClampToI32((force - resistance) / (mass * 4)); + int acceleration = ClampTo((force - resistance) / (mass * 4)); acceleration = force < resistance ? std::min(-1, acceleration) : std::max(1, acceleration); return acceleration; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index f9d5d0be36..821101bb68 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -2134,7 +2134,7 @@ void CheckVehicleBreakdown(Vehicle *v) /* increase chance of failure */ int chance = v->breakdown_chance + 1; if (Chance16I(1, 25, r)) chance += 25; - chance = std::min(255, chance); + chance = ClampTo(chance); v->breakdown_chance = chance; if (_settings_game.vehicle.improved_breakdowns) { diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index e0588a2533..2088790906 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -272,7 +272,7 @@ void BaseVehicleListWindow::BuildVehicleList() this->CountOwnVehicles(); this->vehgroups.RebuildDone(); - this->vscroll->SetCount(static_cast(this->vehgroups.size())); + this->vscroll->SetCount(this->vehgroups.size()); } static bool GroupCargoFilter(const GUIVehicleGroup* group, const CargoID cid) @@ -1573,21 +1573,21 @@ static bool VehicleAgeSorter(const Vehicle * const &a, const Vehicle * const &b) /** Sort vehicles by this year profit */ static bool VehicleProfitThisYearSorter(const Vehicle * const &a, const Vehicle * const &b) { - int r = ClampToI32(a->GetDisplayProfitThisYear() - b->GetDisplayProfitThisYear()); + int r = ClampTo(a->GetDisplayProfitThisYear() - b->GetDisplayProfitThisYear()); return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); } /** Sort vehicles by last year profit */ static bool VehicleProfitLastYearSorter(const Vehicle * const &a, const Vehicle * const &b) { - int r = ClampToI32(a->GetDisplayProfitLastYear() - b->GetDisplayProfitLastYear()); + int r = ClampTo(a->GetDisplayProfitLastYear() - b->GetDisplayProfitLastYear()); return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); } /** Sort vehicles by lifetime profit */ static bool VehicleProfitLifetimeSorter(const Vehicle * const &a, const Vehicle * const &b) { - int r = ClampToI32(a->GetDisplayProfitLifetime() - b->GetDisplayProfitLifetime()); + int r = ClampTo(a->GetDisplayProfitLifetime() - b->GetDisplayProfitLifetime()); return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); } @@ -1640,7 +1640,7 @@ static bool VehicleValueSorter(const Vehicle * const &a, const Vehicle * const & for (u = a; u != nullptr; u = u->Next()) diff += u->value; for (u = b; u != nullptr; u = u->Next()) diff -= u->value; - int r = ClampToI32(diff); + int r = ClampTo(diff); return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); } @@ -1654,7 +1654,7 @@ static bool VehicleLengthSorter(const Vehicle * const &a, const Vehicle * const /** Sort vehicles by the time they can still live */ static bool VehicleTimeToLiveSorter(const Vehicle * const &a, const Vehicle * const &b) { - int r = ClampToI32((a->max_age - a->age) - (b->max_age - b->age)); + int r = ClampTo((a->max_age - a->age) - (b->max_age - b->age)); return (r != 0) ? r < 0 : VehicleNumberSorter(a, b); } diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm index ab3c01f55c..d2d00d2ce2 100644 --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -1059,10 +1059,11 @@ void CocoaDialog(const char *title, const char *message, const char *buttonLabel Point pt = { (int)view_pt.x, (int)[ self frame ].size.height - (int)view_pt.y }; - const char *ch = _focused_window->GetTextCharacterAtPosition(pt); - if (ch == nullptr) return NSNotFound; + auto index = _focused_window->GetTextCharacterAtPosition(pt); + if (index == -1) return NSNotFound; - return CountUtf16Units(_focused_window->GetFocusedText(), ch); + auto text = _focused_window->GetFocusedText(); + return CountUtf16Units(text, text + index); } /** Get the bounding rect for the given range. */ diff --git a/src/widget.cpp b/src/widget.cpp index 7538a3a187..70c6dfbe0d 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -510,7 +510,7 @@ static inline void DrawText(const Rect &r, TextColour colour, StringID str, Stri { Dimension d = GetStringBoundingBox(str, fs); Point p = GetAlignedPosition(r, d, align); - if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align, fs); + if (str != STR_NULL) DrawString(r.left, r.right, p.y, str, colour, align, false, fs); } /** diff --git a/src/widget_type.h b/src/widget_type.h index 97405277a6..f31820c370 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -730,10 +730,11 @@ public: * Set the distance to scroll when using the buttons or the wheel. * @param stepsize Scrolling speed. */ - void SetStepSize(uint16 stepsize) + void SetStepSize(size_t stepsize) { assert(stepsize > 0); - this->stepsize = stepsize; + + this->stepsize = ClampTo(stepsize); } /** @@ -741,15 +742,13 @@ public: * @param num the number of elements in the list * @note updates the position if needed */ - void SetCount(int num) + void SetCount(size_t num) { - assert(num >= 0); assert(num <= MAX_UVALUE(uint16)); - this->count = num; - num -= this->cap; - if (num < 0) num = 0; - if (num < this->pos) this->pos = num; + this->count = ClampTo(num); + /* Ensure position is within bounds */ + this->SetPosition(this->pos); } /** @@ -757,13 +756,13 @@ public: * @param capacity the new capacity * @note updates the position if needed */ - void SetCapacity(int capacity) + void SetCapacity(size_t capacity) { - assert(capacity > 0); assert(capacity <= MAX_UVALUE(uint16)); - this->cap = capacity; - if (this->cap + this->pos > this->count) this->pos = std::max(0, this->count - this->cap); + this->cap = ClampTo(capacity); + /* Ensure position is within bounds */ + this->SetPosition(this->pos); } void SetCapacityFromWidget(Window *w, int widget, int padding = 0); diff --git a/src/widgets/dropdown.cpp b/src/widgets/dropdown.cpp index 208d985cbd..f3209e7d2b 100644 --- a/src/widgets/dropdown.cpp +++ b/src/widgets/dropdown.cpp @@ -176,8 +176,8 @@ struct DropdownWindow : Window { } /* Capacity is the average number of items visible */ - this->vscroll->SetCapacity(size.height * (uint16)this->list.size() / list_height); - this->vscroll->SetCount((uint16)this->list.size()); + this->vscroll->SetCapacity(size.height * this->list.size() / list_height); + this->vscroll->SetCount(this->list.size()); this->parent_button = button; this->selected_index = selected; @@ -289,14 +289,9 @@ struct DropdownWindow : Window { this->scrolling_timer.SetInterval(MILLISECONDS_PER_TICK); if (this->scrolling != 0) { - int pos = this->vscroll->GetPosition(); + if (this->vscroll->UpdatePosition(this->scrolling)) this->SetDirty(); - this->vscroll->UpdatePosition(this->scrolling); this->scrolling = 0; - - if (pos != this->vscroll->GetPosition()) { - this->SetDirty(); - } } } diff --git a/src/window.cpp b/src/window.cpp index 5ee9b3d770..880fc5d7f8 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -438,15 +438,15 @@ void Window::UpdateQueryStringSize() /** * Get the character that is rendered at a position by the focused edit box. * @param pt The position to test. - * @return Pointer to the character at the position or nullptr if no character is at the position. + * @return Index of the character position or -1 if no character is at the position. */ -/* virtual */ const char *Window::GetTextCharacterAtPosition(const Point &pt) const +/* virtual */ ptrdiff_t Window::GetTextCharacterAtPosition(const Point &pt) const { if (this->nested_focus != nullptr && this->nested_focus->type == WWT_EDITBOX) { return this->GetQueryString(this->nested_focus->index)->GetCharAtPosition(this, this->nested_focus->index, pt); } - return nullptr; + return -1; } /** @@ -2504,13 +2504,10 @@ static void HandleScrollbarScrolling(Window *w) return; } - /* Find the item we want to move to and make sure it's inside bounds. */ - int pos = std::min(RoundDivSU(std::max(0, i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size), std::max(0, sb->GetCount() - sb->GetCapacity())); - if (rtl) pos = std::max(0, sb->GetCount() - sb->GetCapacity() - pos); - if (pos != sb->GetPosition()) { - sb->SetPosition(pos); - w->SetDirty(); - } + /* Find the item we want to move to. SetPosition will make sure it's inside bounds. */ + int pos = RoundDivSU((i + _scrollbar_start_pos) * sb->GetCount(), _scrollbar_size); + if (rtl) pos = sb->GetCount() - sb->GetCapacity() - pos; + if (sb->SetPosition(pos)) w->SetDirty(); } /** diff --git a/src/window_gui.h b/src/window_gui.h index 1df8c5b2dc..7631fe7529 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -356,7 +356,7 @@ public: virtual const char *GetMarkedText(size_t *length) const; virtual Point GetCaretPosition() const; virtual Rect GetTextBoundingRect(const char *from, const char *to) const; - virtual const char *GetTextCharacterAtPosition(const Point &pt) const; + virtual ptrdiff_t GetTextCharacterAtPosition(const Point &pt) const; void InitNested(WindowNumber number = 0); void CreateNestedTree(bool fill_nested = true);