MCPcopy Create free account
hub / github.com/SimHacker/micropolis / loadCity

Method loadCity

MicropolisCore/src/MicropolisEngine/src/fileio.cpp:513–540  ·  view source on GitHub ↗

* Try to load a new game from disk. * @param filename Name of the file to load. * @return Game was loaded successfully. * @todo In what state is the game left when loading fails? * @todo String normalization code is duplicated in Micropolis::saveCityAs(). * Extract to a sub-function. * @bug Function fails if \c lastDot<lastSlash (ie with \c "x.y/bla" ) */

Source from the content-addressed store, hash-verified

511 * @bug Function fails if \c lastDot<lastSlash (ie with \c "x.y/bla" )
512 */
513bool Micropolis::loadCity(const char *filename)
514{
515 if (loadFile(filename)) {
516
517 cityFileName = filename;
518
519 unsigned int lastSlash = cityFileName.find_last_of('/');
520 unsigned int pos = (lastSlash == std::string::npos) ? 0 : lastSlash + 1;
521
522 unsigned int lastDot = cityFileName.find_last_of('.');
523 unsigned int last =
524 (lastDot == std::string::npos) ? cityFileName.length() : lastDot;
525
526 std::string newCityName = cityFileName.substr(pos, last - pos);
527 setCityName(newCityName);
528
529 didLoadCity();
530
531 return true;
532
533 } else {
534
535 didntLoadCity((filename && *filename) ? filename : "(null)");
536
537 return false;
538
539 }
540}
541
542/** Report to the frontend that the game was successfully loaded. */
543void Micropolis::didLoadCity()

Callers 2

loadCityFromDatabaseMethod · 0.80
loadMetaCityMethod · 0.80

Calls 1

loadFileFunction · 0.85

Tested by

no test coverage detected