MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / ConScrollToTile

Function ConScrollToTile

src/console_cmds.cpp:365–413  ·  view source on GitHub ↗

* Scroll to a tile on the map. * param x tile number or tile x coordinate. * param y optional y coordinate. * @note When only one argument is given it is interpreted as the tile number. * When two arguments are given, they are interpreted as the tile's x * and y coordinates. * @return True when either console help was shown or a proper amount of parameters given. */

Source from the content-addressed store, hash-verified

363 * @return True when either console help was shown or a proper amount of parameters given.
364 */
365static bool ConScrollToTile(std::span<std::string_view> argv)
366{
367 if (argv.empty()) {
368 IConsolePrint(CC_HELP, "Center the screen on a given tile.");
369 IConsolePrint(CC_HELP, "Usage: 'scrollto [instant] <tile>' or 'scrollto [instant] <x> <y>'.");
370 IConsolePrint(CC_HELP, "Numbers can be either decimal (34161) or hexadecimal (0x4a5B).");
371 IConsolePrint(CC_HELP, "'instant' will immediately move and redraw viewport without smooth scrolling.");
372 return true;
373 }
374 if (argv.size() < 2) return false;
375
376 uint32_t arg_index = 1;
377 bool instant = false;
378 if (argv[arg_index] == "instant") {
379 ++arg_index;
380 instant = true;
381 }
382
383 switch (argv.size() - arg_index) {
384 case 1: {
385 auto result = ParseInteger(argv[arg_index], 0);
386 if (result.has_value()) {
387 if (*result >= Map::Size()) {
388 IConsolePrint(CC_ERROR, "Tile does not exist.");
389 return true;
390 }
391 ScrollMainWindowToTile(TileIndex{*result}, instant);
392 return true;
393 }
394 break;
395 }
396
397 case 2: {
398 auto x = ParseInteger(argv[arg_index], 0);
399 auto y = ParseInteger(argv[arg_index + 1], 0);
400 if (x.has_value() && y.has_value()) {
401 if (*x >= Map::SizeX() || *y >= Map::SizeY()) {
402 IConsolePrint(CC_ERROR, "Tile does not exist.");
403 return true;
404 }
405 ScrollMainWindowToTile(TileXY(*x, *y), instant);
406 return true;
407 }
408 break;
409 }
410 }
411
412 return false;
413}
414
415/**
416 * Save the map to a file.

Callers

nothing calls this directly

Calls 6

ParseIntegerFunction · 0.85
ScrollMainWindowToTileFunction · 0.85
TileXYFunction · 0.85
IConsolePrintFunction · 0.70
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected