From 98246d30661237cc69338d3425bdc81641ed1157 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 11 Jun 2018 00:58:38 +0200 Subject: [PATCH] more cleanup in parameters, restartGame cleanup --- basegraph.cpp | 4 - commandline.cpp | 101 ++++++-------- config.cpp | 23 +-- control.cpp | 4 +- geom-exp.cpp | 38 ++--- goldberg.cpp | 13 +- hyper.h | 15 +- hyperweb.cpp | 12 +- init.cpp | 5 +- mapeditor.cpp | 7 +- menus.cpp | 18 +-- pattern2.cpp | 16 ++- quit.cpp | 6 +- rogueviz-kohonen.cpp | 6 - rogueviz.cpp | 9 +- shmup.cpp | 4 +- system.cpp | 323 ++++++++++++++++++++++++------------------- textures.cpp | 6 +- tour.cpp | 29 ++-- yendor.cpp | 12 +- 20 files changed, 344 insertions(+), 307 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index 6af4139f..4b252e21 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -1166,10 +1166,6 @@ void initgraph() { restartGraph(); - initgeo(); - - buildpolys(); - if(noGUI) { #if CAP_COMMANDLINE arg::read(2); diff --git a/commandline.cpp b/commandline.cpp index 4f18f278..3c1a3090 100644 --- a/commandline.cpp +++ b/commandline.cpp @@ -205,65 +205,58 @@ int arg::readCommon() { // mode changes: #define TOGGLE(x, param, act) \ -else if(args()[0] == '-' && args()[1] == x && !args()[2]) { showstartmenu = false; if(curphase == 3) {act;} else {PHASE(2); param = !param;} } \ -else if(args()[0] == '-' && args()[1] == x && args()[2] == '1') { showstartmenu = false; if(curphase == 3 && !param) {act;} else {PHASE(2); param = true;} } \ -else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu = false; if(curphase == 3 && param) {act;} else {PHASE(2); param = false;} } +else if(args()[0] == '-' && args()[1] == x && !args()[2]) { showstartmenu = false; act; } \ +else if(args()[0] == '-' && args()[1] == x && args()[2] == '1') { showstartmenu = false; if(!param) act; } \ +else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu = false; if(param) act; } TOGGLE('o', vid.usingGL, switchGL()) - TOGGLE('C', chaosmode, restartGame(rg::chaos)) - TOGGLE('7', nonbitrunc, restartGame(rg::bitrunc)) + TOGGLE('C', chaosmode, stop_game_and_switch_mode(rg::chaos)) + TOGGLE('7', nonbitrunc, stop_game_and_switch_mode(rg::bitrunc)) TOGGLE('f', vid.full, switchFullscreen()) - TOGGLE('T', tactic::on, restartGame(rg::tactic)) - TOGGLE('S', shmup::on, restartGame(rg::shmup)) + TOGGLE('T', tactic::on, stop_game_and_switch_mode(rg::tactic)) + TOGGLE('S', shmup::on, stop_game_and_switch_mode(rg::shmup)) TOGGLE('H', hardcore, switchHardcore()) - TOGGLE('R', randomPatternsMode, restartGame(rg::randpattern)) - TOGGLE('i', inv::on, restartGame(rg::inv)) + TOGGLE('R', randomPatternsMode, stop_game_and_switch_mode(rg::randpattern)) + TOGGLE('i', inv::on, stop_game_and_switch_mode(rg::inv)) else if(argis("-peace")) { peace::otherpuzzles = true; - if(curphase == 3) restartGame(rg::peace); - else peace::on = !peace::on; + stop_game_and_switch_mode(peace::on ? 0 : rg::peace); } else if(argis("-pmem")) { peace::otherpuzzles = false; - if(curphase == 3) restartGame(rg::peace); - else peace::on = !peace::on; + stop_game_and_switch_mode(peace::on ? 0 : rg::peace); } else if(argis("-geo")) { - if(curphase == 3) { - shift(); targetgeometry = (eGeometry) argi(); - restartGame(rg::geometry); - } - else { - PHASE(2); shift(); geometry = targetgeometry = (eGeometry) argi(); - } + shift(); targetgeometry = (eGeometry) argi(); + stop_game_and_switch_mode(rg::geometry); } else if(argis("-gp")) { PHASEFROM(2); - if(nonbitrunc && curphase == 3) restartGame(rg::bitrunc); + stop_game_and_switch_mode(rg::nothing); shift(); gp::param.first = argi(); shift(); gp::param.second = argi(); - if(curphase == 3) restartGame(rg::gp); + stop_game_and_switch_mode(rg::gp); } // 'do something' else if(argis("-W")) { PHASEFROM(2); shift(); firstland0 = firstland = specialland = readland(args()); - if(curphase == 3) restartGame(); + stop_game_and_switch_mode(rg::nothing); showstartmenu = false; } else if(argis("-canvas")) { - PHASEFROM(2); CHEAT + PHASEFROM(2); firstland = specialland = laCanvas; shift(); if(args() == "i") canvas_invisible = !canvas_invisible; else if(args().size() == 1) patterns::whichCanvas = args()[0]; else patterns::canvasback = arghex(); - if(curphase == 3) restartGame(); + stop_game_and_switch_mode(rg::nothing); } else if(argis("-pattern")) { - PHASEFROM(2); CHEAT + PHASEFROM(2); shift(); const char *c = argcs(); using namespace patterns; @@ -318,24 +311,16 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu else if(argis("-test")) callhooks(hooks_tests); else if(argis("-qpar2")) { - if(curphase == 3) { - restartGame(rg::geometry); - } - else { - PHASE(2); - } - if(geometry == gQuotient2) restartGame(rg::geometry); + stop_game_and_switch_mode(rg::nothing); int a, b; shift(); sscanf(argcs(), "%d,%d", &a, &b); using namespace fieldpattern; current_extra = a; fgeomextras[current_extra].current_prime_id = b; enableFieldChange(); - if(curphase == 3) { - targetgeometry = gQuotient2; restartGame(rg::geometry); + if(geometry != gQuotient2) { + targetgeometry = gQuotient2; stop_game_and_switch_mode(rg::geometry); } - else - geometry = gQuotient2; } else if(argis("-tpar")) { torusconfig::torus_mode = torusconfig::tmSingle; @@ -346,7 +331,8 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu ); } else if(argis("-tparx")) { - shift(); sscanf(argcs(), "%d,%d,%d", + shift(); + sscanf(argcs(), "%d,%d,%d", (int*) &torusconfig::torus_mode, &torusconfig::sdx, &torusconfig::sdy @@ -357,14 +343,13 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu torusconfig::activate(); } else if(argis("-cs")) { - shift(); + shift(); CHEAT fieldpattern::matrix M = currfp.strtomatrix(args()); fieldpattern::subpathid = currfp.matcode[M]; fieldpattern::subpathorder = currfp.order(M); - autocheat = true; } else if(argis("-csp")) { - autocheat = true; + CHEAT currfp.findsubpath(); } else if(argis("-quantum")) { @@ -373,13 +358,16 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu } else if(argis("-P")) { PHASE(2); shift(); - vid.scfg.players = argi(); - // todo phase3 restart + vid.scfg.players = argi(); + stop_game_and_switch_mode(rg::nothing); } else if(argis("-PM")) { PHASEFROM(2); shift(); pmodel = eModel(argi()); } - else if(argis("-offline")) offlineMode = true; + else if(argis("-offline")) { + PHASE(1); + offlineMode = true; + } else if(argis("-debugf")) { debugfile = fopen("hyperrogue-debug.txt", "w"); shift(); debugflags = argi(); @@ -389,6 +377,7 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu shift(); debugflags = argi(); } else if(argis("-each")) { + PHASEFROM(2); start_game(); shift(); int q = argi(); autocheat = true; for(int i=0; i= 3 && valid) { - targetgeometry = gNormal; restartGame(rg::geometry, false, true); + targetgeometry = gNormal; stop_game_and_switch_mode(rg::geometry); torusconfig::torus_mode = torusconfig::newmode; torusconfig::qty = torusconfig::newqty; torusconfig::dy = torusconfig::newdy; torusconfig::sdx = torusconfig::newsdx; torusconfig::sdy = torusconfig::newsdy; torusconfig::activate(); - if((square && torus_bitrunc) != nonbitrunc) restartGame(rg::bitrunc, false, true); - targetgeometry = gTorus; restartGame(rg::geometry, false, true); + if((square && torus_bitrunc) != nonbitrunc) stop_game_and_switch_mode(rg::bitrunc); + targetgeometry = gTorus; stop_game_and_switch_mode(rg::geometry); + start_game(); } else if(uni == 'c') { - targetgeometry = gEuclid; restartGame(rg::geometry, false, true); + targetgeometry = gEuclid; stop_game_and_switch_mode(rg::geometry); torusconfig::torus_mode = torusconfig::tmSingle; torusconfig::qty = torusconfig::def_qty; torusconfig::dy = torusconfig::def_dy; - targetgeometry = gTorus; restartGame(rg::geometry, false, true); + targetgeometry = gTorus; stop_game_and_switch_mode(rg::geometry); + start_game(); } else if(uni == 'z') editScale(); #if CAP_RUG @@ -329,16 +333,16 @@ void showEuclideanMenu() { dialog::handleNavigation(sym, uni); if(uni >= 'a' && uni < 'a'+gGUARD) { targetgeometry = eGeometry(uni - 'a'); - restartGame(geometry == targetgeometry ? rg::nothing : rg::geometry); - pushScreen(showEuclideanMenu); + stop_game_and_switch_mode(geometry == targetgeometry ? rg::nothing : rg::geometry); + start_game(); } else if(uni == 't') { if(euclid6) ; else if(S3 == 3) gp::configure(); else { - restartGame(rg::bitrunc); - pushScreen(showEuclideanMenu); + stop_game_and_switch_mode(rg::bitrunc); + start_game(); } } else if(uni == '2' || sym == SDLK_F1) gotoHelp(euchelp); @@ -424,16 +428,16 @@ void showEuclideanMenu() { } else if(uni == '1') { if(chaosUnlocked) { - restartGame(rg::chaos); - pushScreen(showEuclideanMenu); + stop_game_and_switch_mode(rg::chaos); + start_game(); } } else if(lid >= 0 && lid < size(landlist)) { eLand nland = landlist[lid]; if(landvisited[nland]) { firstland = specialland = nland; - restartGame(tactic::on ? rg::tactic : rg::nothing); - pushScreen(showEuclideanMenu); + stop_game_and_switch_mode(tactic::on ? rg::tactic : rg::nothing); + start_game(); } } else if(uni == '2' || sym == SDLK_F1) gotoHelp(euchelp); diff --git a/goldberg.cpp b/goldberg.cpp index 486c9afa..83543116 100644 --- a/goldberg.cpp +++ b/goldberg.cpp @@ -543,18 +543,19 @@ namespace gp { auto g = screens; if(xy.first == 0 && xy.second == 0) xy.first = 1; if(xy.first == 1 && xy.second == 0) { - if(gp::on) restartGame(rg::bitrunc); - if(!nonbitrunc) restartGame(rg::bitrunc); + if(gp::on) stop_game_and_switch_mode(rg::bitrunc); + if(!nonbitrunc) stop_game_and_switch_mode(rg::bitrunc); } else if(xy.first == 1 && xy.second == 1) { - if(gp::on) restartGame(rg::bitrunc); - if(nonbitrunc) restartGame(rg::bitrunc); + if(gp::on) stop_game_and_switch_mode(rg::bitrunc); + if(nonbitrunc) stop_game_and_switch_mode(rg::bitrunc); } else { - if(nonbitrunc) restartGame(rg::bitrunc); + if(nonbitrunc) stop_game_and_switch_mode(rg::bitrunc); param = xy; - restartGame(rg::gp); + stop_game_and_switch_mode(rg::gp); } + start_game(); #if CAP_TEXTURE if(texture_remap) texture::config.remap(old_tstate, old_tstate_max); diff --git a/hyper.h b/hyper.h index 14720e3e..430eb236 100644 --- a/hyper.h +++ b/hyper.h @@ -362,7 +362,7 @@ int towerval(cell *c, cellfunction* cf = &coastvalEdge); int hrandpos(); // 0 to HRANDMAX namespace rg { - // possible parameters e.g. for restartGame and wrongmode + // possible parameters e.g. for restart_game and wrongmode static const char nothing = 0; static const char peace = 'P'; static const char inv = 'i'; @@ -381,10 +381,9 @@ namespace rg { // wrongmode only -- marks 'global' achievements not related to the current mode static const char global = 'x'; - // wrongmode only -- change vid.scfg.players then restartGame(rg::nothing) instead + // wrongmode only -- change vid.scfg.players then restart_game(rg::nothing) instead static const char multi = 'm'; } -void restartGame(char switchWhat = 0, bool push = false, bool keep_screens = false); int landMultiplier(eLand l); eItem treasureType(eLand l); @@ -2954,7 +2953,6 @@ extern void initializeCLI(); static const int max_vec = (1<<14); -extern void popGame(); string helptitle(string s, int col); pair cell_to_pair(cell *c); extern bool nohud, nofps; @@ -3400,3 +3398,12 @@ void handle_event(SDL_Event& ev); #ifndef XPRINTF template void Xprintf(const char *fmt, T... t) { printf(fmt, t...); } #endif + +void pop_game(); +void push_game(); +void start_game(); +void stop_game(); +void switch_game_mode(char switchWhat); + +void stop_game_and_switch_mode(char switchWhat = rg::nothing); // stop_game + switch_game_mode +void restart_game(char switchWhat = rg::nothing); // popAllScreens + popAllGames + stop_game + switch_game_mode + start_game diff --git a/hyperweb.cpp b/hyperweb.cpp index 050ff6e9..bdeebf34 100644 --- a/hyperweb.cpp +++ b/hyperweb.cpp @@ -89,8 +89,7 @@ void showDemo() { } else if(sym == 'f') { firstland = laIce; - if(tactic::on) restartGame(rg::tactic); - else restartGame(); + restart_game(tactic::on ? rg::tactic : rg::nothing); } #if CAP_TOUR else if(sym == 'T') { @@ -100,18 +99,15 @@ void showDemo() { #endif else if(sym == 't') { firstland = laTemple; - if(!tactic::on) restartGame(rg::tactic); - else restartGame(); + restart_game(tactic::on ? rg::tactic : rg::nothing); } else if(sym == 'l') { firstland = laStorms; - if(!tactic::on) restartGame(rg::tactic); - else restartGame(); + restart_game(tactic::on ? rg::tactic : rg::nothing); } else if(sym == 'b') { firstland = laBurial; - if(!tactic::on) restartGame(rg::tactic); - else restartGame(); + restart_game(tactic::on ? rg::tactic : rg::nothing); items[itOrbSword] = 60; } }; diff --git a/init.cpp b/init.cpp index a8a386be..b61ebd3f 100644 --- a/init.cpp +++ b/init.cpp @@ -475,12 +475,9 @@ void initAll() { #if CAP_SAVE loadsave(); #endif - resetGeometry(); - initcells(); + start_game(); shmup::safety = safety; - initgame(); - restartGraph(); if(!shmup::on) { restoreGolems(items[itOrbLife], moGolem); items[itOrbLife] = 0; diff --git a/mapeditor.cpp b/mapeditor.cpp index ea74bf04..e81495bd 100644 --- a/mapeditor.cpp +++ b/mapeditor.cpp @@ -817,7 +817,7 @@ namespace mapeditor { dialog::openColorDialog((unsigned&)(paintwhat = (painttype ==6 ? paintwhat : 0x808080))); } else if(sym == SDLK_F5) { - restartGame(); + restart_game(); } else if(sym == SDLK_F2) { dialog::openFileDialog(levelfile, XLAT("level to save:"), ".lev", [] () { @@ -1323,8 +1323,9 @@ namespace mapeditor { int tg, nt, wp; fscanf(f, "%d%d%d%d\n", &tg, &nt, &wp, &patterns::subpattern_flags); patterns::whichPattern = wp; - if(tg != geometry) { targetgeometry = eGeometry(tg); restartGame(rg::geometry, 0, true); } - if(nt != nonbitrunc) { restartGame(rg::bitrunc, 0, true); } + if(tg != geometry) { targetgeometry = eGeometry(tg); stop_game_and_switch_mode(rg::geometry); } + if(nt != nonbitrunc) stop_game_and_switch_mode(rg::bitrunc); + start_game(); } while(true) { diff --git a/menus.cpp b/menus.cpp index b2c9765d..9a94c884 100644 --- a/menus.cpp +++ b/menus.cpp @@ -261,7 +261,7 @@ void showMainMenu() { else if(sym == 't') scores::load(); #endif else if(uni == 'r' || sym == SDLK_F5) { - restartGame(); + restart_game(); } else if(sym == 'q' || sym == SDLK_F10) { #if ISMOBILE @@ -414,7 +414,7 @@ void showDisplayMode() { void switchHardcore() { if(hardcore && !canmove) { - restartGame(); + restart_game(); hardcore = false; } else if(hardcore && canmove) { hardcore = false; } @@ -506,7 +506,7 @@ void showChangeMode() { else { popScreen(); firstland = princess::challenge ? laPalace : laIce; - restartGame(); + restart_game(); } } @@ -525,7 +525,7 @@ void showChangeMode() { else if(xuni == 'p') pushScreen(peace::showMenu); else if(xuni == 'i') { - restartGame(rg::inv); + restart_game(rg::inv); } #if CAP_TOUR else if(uni == 'T') { @@ -533,14 +533,14 @@ void showChangeMode() { } #endif else if(uni == 'C') { - if(chaosUnlocked) restartGame(rg::chaos); + if(chaosUnlocked) restart_game(rg::chaos); if(chaosmode) help_nochaos(); } else if(xuni == 'P') { if(!princess::everSaved) addMessage(XLAT("Save %the1 first to unlock this challenge!", moPrincess)); else - restartGame(rg::princess); + restart_game(rg::princess); } #if CAP_EDIT else if(xuni == 'm') { @@ -556,7 +556,7 @@ void showChangeMode() { #endif else if(xuni == 's') { #if ISMOBILE==1 - restartGame(rg::shmup); + restart_game(rg::shmup); #else multi::shmupcfg = shmup::on; pushScreen(shmup::showShmupConfig); @@ -566,7 +566,7 @@ void showChangeMode() { switchHardcore(); else if(xuni == 'r') { firstland = laIce; - restartGame(rg::randpattern); + restart_game(rg::randpattern); } else if(doexiton(sym, uni)) popScreen(); @@ -777,7 +777,7 @@ void showStartMenu() { if(!sphere) { specialland = laHalloween; targetgeometry = gSphere; - restartGame(rg::geometry); + restart_game(rg::geometry); vid.alpha = 999; vid.scale = 998; } diff --git a/pattern2.cpp b/pattern2.cpp index 42a29f22..4a72949a 100644 --- a/pattern2.cpp +++ b/pattern2.cpp @@ -1315,21 +1315,24 @@ namespace patterns { canvasback = c >> 8; firstland = specialland = laCanvas; randomPatternsMode = false; - restartGame(0, false, true); + stop_game(); + start_game(); }; } else if(uni == 'i') { canvas_invisible = !canvas_invisible; firstland = specialland = laCanvas; randomPatternsMode = false; - restartGame(0, false, true); + stop_game(); + start_game(); } else if((uni >= 'a' && uni <= 'z') || (uni >= 'A' && uni <= 'Z')) { whichCanvas = uni; subcanvas = rand(); firstland = specialland = laCanvas; randomPatternsMode = false; - restartGame(0, false, true); + stop_game(); + start_game(); if(uni == 'x' || uni == 'z' || uni == 't') whichPattern = PAT_ZEBRA, subpattern_flags = SPF_SYM0123 | SPF_ROT; if(uni == 'e') @@ -1640,9 +1643,10 @@ namespace patterns { auto old_tstate_max = texture::config.tstate_max; #endif auto &g = cpatterns[cgroup].geometries[uni - 'a']; - if(g.geo != geometry) { targetgeometry = g.geo; restartGame(rg::geometry, false, true); } - if(gp::on) restartGame(rg::gp, false, true); - if(g.nonbitru != nonbitrunc) restartGame(rg::bitrunc, false, true); + if(g.geo != geometry) { targetgeometry = g.geo; stop_game_and_switch_mode(rg::geometry); } + if(gp::on) stop_game_and_switch_mode(rg::gp); + if(g.nonbitru != nonbitrunc) stop_game_and_switch_mode(rg::bitrunc);; + start_game(); whichPattern = g.whichPattern; subpattern_flags = g.subpattern_flags; #if CAP_TEXTURE diff --git a/quit.cpp b/quit.cpp index 01ecdbf5..e4da558d 100644 --- a/quit.cpp +++ b/quit.cpp @@ -179,7 +179,7 @@ hint hints[] = { }, []() { #if CAP_INV - restartGame(rg::inv); + restart_game(rg::inv); #endif } }, @@ -273,7 +273,7 @@ hint hints[] = { resetModes(); specialland = laHalloween; targetgeometry = gSphere; - restartGame(rg::geometry); + restart_game(rg::geometry); vid.alpha = 999; vid.scale = 998; } @@ -476,7 +476,7 @@ void handleKeyQuit(int sym, int uni) { if(sym == SDLK_RETURN || sym == SDLK_KP_ENTER || sym == SDLK_F10) quitmainloop = true; else if(uni == 'r' || sym == SDLK_F5) { - restartGame(); + restart_game(rg::nothing); msgs.clear(); } else if(uni == 'v') popScreenAll(), pushScreen(showMainMenu); diff --git a/rogueviz-kohonen.cpp b/rogueviz-kohonen.cpp index 67ab9ee1..19dd1a3d 100644 --- a/rogueviz-kohonen.cpp +++ b/rogueviz-kohonen.cpp @@ -546,12 +546,6 @@ void sominit(int initto) { init(); kind = kKohonen; - /* if(geometry != gQuotient1) { - targetGeometry = gQuotient1; - restartGame(rg::geometry); - } - if(!nonbitrunc) restartGame(rg::bitrunc); */ - printf("Initializing SOM (1)\n"); vector allcells; diff --git a/rogueviz.cpp b/rogueviz.cpp index aa8baea7..4f0071e0 100644 --- a/rogueviz.cpp +++ b/rogueviz.cpp @@ -1342,11 +1342,10 @@ void init() { #if !ISWEB mapeditor::drawplayer = false; firstland = specialland = laCanvas; - if(!shmup::on) restartGame(rg::shmup); - else restartGame(); + restart_game(shmup::on ? rg::shmup : rg::nothing); #else firstland = specialland = laCanvas; - restartGame(); + restart_game(rg::nothing); #endif on = true; items[itOrbLife] = 0; @@ -1839,7 +1838,7 @@ slide rvslides[] = { if(mode == pmStartAll) firstland = specialland = laPalace; if(mode == 4) { tour::slides = default_slides; - while(tour::on) restartGame(rg::tour, false); + while(tour::on) restart_game(rg::tour); firstland = specialland = laIce; tour::start(); } @@ -1973,7 +1972,7 @@ slide rvslides[] = { "Press '5' to leave the presentation.", [] (presmode mode) { firstland = specialland = laIce; - if(mode == 4) restartGame(rg::tour); + if(mode == 4) restart_game(rg::tour); } } }; diff --git a/shmup.cpp b/shmup.cpp index 2a893fbc..ad5b9e11 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -407,8 +407,8 @@ help += XLAT("This menu can be also used to configure keys.\n\n"); } else if(doexiton(sym, uni)) { popScreen(); - if(shmup::on != shmupcfg) { restartGame(rg::shmup); resetScores(); } - else if(vid.scfg.players != players) { restartGame(); resetScores(); } + if(shmup::on != shmupcfg) { restart_game(rg::shmup); resetScores(); } + else if(vid.scfg.players != players) { restart_game(); resetScores(); } } } else if(sc == SCJOY) { diff --git a/system.cpp b/system.cpp index 9383aef6..3352588c 100644 --- a/system.cpp +++ b/system.cpp @@ -4,6 +4,10 @@ // routines for: initializing/closing, loading/saving, and cheating +bool need_reset_geometry = true; + +bool game_active; + bool cblind; bool autocheat; bool canvas_invisible; @@ -1059,9 +1063,10 @@ namespace gamestack { }; -void popGame() { +void pop_game() { if(gamestack::pushed()) { gamestack::pop(); + game_active = true; } } @@ -1071,152 +1076,175 @@ void popAllGames() { } } -void restartGame(char switchWhat, bool push, bool keep_screens) { - if(!keep_screens) popScreenAll(); - DEBB(DF_INIT, (debugfile,"restartGame\n")); - - - if(push) { - gamestack::push(); - pd_from = NULL; - centerover.c = NULL; - } - else { - popAllGames(); - achievement_final(true); - #if CAP_SAVE - saveStats(); - #endif - for(int i=0; i d2(patterns::subpattern_flags, patterns::subpattern_flags); if(targetgeometry != geometry) { - restartGame(rg::geometry); + stop_game_and_switch_mode(rg::geometry); return config.load(); } if(nonbitrunc != target_nonbitru) { - restartGame(rg::bitrunc); + stop_game_and_switch_mode(rg::bitrunc); } } + + start_game(); if(true) { celllister cl(currentmap->gamestart(), 20, 10000, NULL); diff --git a/tour.cpp b/tour.cpp index 203287d9..fc92aaf2 100644 --- a/tour.cpp +++ b/tour.cpp @@ -22,16 +22,17 @@ void setCanvas(presmode mode, char canv) { static char wc; static eLand ld; if(mode == pmStart) { + push_game(); wc = patterns::whichCanvas; patterns::whichCanvas = canv; ld = firstland; firstland = laCanvas; - restartGame(0, true); + start_game(); } if(mode == pmStop) { patterns::whichCanvas = wc; firstland = ld; - popGame(); + pop_game(); } } @@ -73,7 +74,7 @@ void slidehelp() { } void return_geometry() { - popGame(); + pop_game(); vid.scale = 1; vid.alpha = 1; presentation(pmGeometryReset); addMessage(XLAT("Returned to your game.")); @@ -99,7 +100,7 @@ bool handleKeyTour(int sym, int uni) { } if(sym == SDLK_BACKSPACE) { if(geometry || nonbitrunc) { - popGame(); + pop_game(); if(!(flags & QUICKGEO)) return true; } if(currentslide == 0) { slidehelp(); return true; } @@ -157,7 +158,9 @@ bool handleKeyTour(int sym, int uni) { if(sym == '2') targetgeometry = gEuclid, vid.alpha = 1, vid.scale = .5; firstland = specialland = cwt.c->land; - restartGame(sym == '3' ? rg::bitrunc : rg::geometry, true); + push_game(); + switch_game_mode(sym == '3' ? rg::bitrunc : rg::geometry); + start_game(); presentation(pmGeometryStart); string x; if(slides[currentslide].flags & USE_SLIDE_NAME) { @@ -279,11 +282,11 @@ namespace ss { keyhandler = [] (int sym, int uni) { if(uni >= 'a' && uni < 'a' + sssize) { if(geometry || nonbitrunc) { - popGame(); + pop_game(); presentation(pmGeometryReset); } if(slides != wts) { - while(tour::on) restartGame(rg::tour, false); + while(tour::on) restart_game(rg::tour); slides = wts; tour::start(); } @@ -317,7 +320,7 @@ void start() { presentation(pmStop); firstland = specialland = laIce; } - restartGame(rg::tour); + restart_game(rg::tour); if(tour::on) { slidehelp(); presentation(pmStart); @@ -370,7 +373,7 @@ slide default_slides[] = { "as an introduction to hyperbolic geometry."; if(mode == 4) { slides = rogueviz::rvtour::rvslides; - while(tour::on) restartGame(rg::tour, false); + while(tour::on) restart_game(rg::tour); tour::start(); } #endif @@ -770,11 +773,13 @@ slide default_slides[] = { [] (presmode mode) { if(mode == 1) { firstland = cwt.c->land; - restartGame(rg::shmup, true); + push_game(); + switch_game_mode(rg::shmup); + start_game(); } if(mode == 3) { shmup::clearMonsters(); - popGame(); + pop_game(); } } }, @@ -787,7 +792,7 @@ slide default_slides[] = { "Press '5' to leave the tutorial mode.", [] (presmode mode) { slidecommand = "leave the Tutorial"; - if(mode == 4) restartGame(rg::tour); + if(mode == 4) restart_game(rg::tour); } } }; diff --git a/yendor.cpp b/yendor.cpp index 2bae268d..19d665e4 100644 --- a/yendor.cpp +++ b/yendor.cpp @@ -505,13 +505,13 @@ namespace yendor { if(new_challenge && new_challenge < YENDORLEVELS) { if(levelUnlocked(new_challenge) || autocheat) { challenge = new_challenge; - restartGame(yendor::on ? 0 : rg::yendor); + restart_game(yendor::on ? rg::nothing : rg::yendor); } else addMessage("Collect 10 treasures in various lands to unlock the challenges there"); } else if(uni == '0') { - if(yendor::on) restartGame(rg::yendor); + if(yendor::on) restart_game(rg::yendor); } else if(uni == '1') easy = !easy; else if(uni == '2' || sym == SDLK_F1) gotoHelp(chelp); @@ -748,11 +748,11 @@ namespace tactic { keyhandler = [] (int sym, int uni) { if(uni >= 1000 && uni < 1000 + size(landlist)) { specialland = landlist[uni - 1000]; - restartGame(tactic::on ? 0 : rg::tactic); + restart_game(tactic::on ? rg::nothing : rg::tactic); } else if(uni == '0') { firstland = laIce; - if(tactic::on) restartGame(rg::tactic); + if(tactic::on) restart_game(rg::tactic); else popScreen(); } @@ -1086,12 +1086,12 @@ namespace peace { if(uni == '1') otherpuzzles = !otherpuzzles; else if(uni >= 'a' && uni < 'a' + qty) { specialland = levellist[uni - 'a']; - restartGame(peace::on ? 0 : rg::peace); + restart_game(peace::on ? 0 : rg::peace); } else if(uni == '2') { hint = !hint; popScreen(); } else if(uni == '0') { firstland = laIce; - if(peace::on) restartGame(rg::peace); + if(peace::on) restart_game(rg::peace); } else if(uni == 'h' || sym == SDLK_F1) gotoHelp(chelp); else if(doexiton(sym, uni)) popScreen();