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

Function ConSave

src/console_cmds.cpp:420–440  ·  view source on GitHub ↗

* Save the map to a file. * param filename the filename to save the map to. * @return True when help was displayed or the file attempted to be saved. */

Source from the content-addressed store, hash-verified

418 * @return True when help was displayed or the file attempted to be saved.
419 */
420static bool ConSave(std::span<std::string_view> argv)
421{
422 if (argv.empty()) {
423 IConsolePrint(CC_HELP, "Save the current game. Usage: 'save <filename>'.");
424 return true;
425 }
426
427 if (argv.size() == 2) {
428 std::string filename = fmt::format("{}.sav", argv[1]);
429 IConsolePrint(CC_DEFAULT, "Saving map...");
430
431 if (SaveOrLoad(filename, SLO_SAVE, DFT_GAME_FILE, SAVE_DIR) != SL_OK) {
432 IConsolePrint(CC_ERROR, "Saving map failed.");
433 } else {
434 IConsolePrint(CC_INFO, "Map successfully saved to '{}'.", filename);
435 }
436 return true;
437 }
438
439 return false;
440}
441
442/**
443 * Explicitly save the configuration.

Callers

nothing calls this directly

Calls 5

SaveOrLoadFunction · 0.85
IConsolePrintFunction · 0.70
formatFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected