more cleanup in parameters, restartGame cleanup

This commit is contained in:
Zeno Rogue 2018-06-11 00:58:38 +02:00
parent 90573cf456
commit 98246d3066
20 changed files with 344 additions and 307 deletions

View File

@ -1166,10 +1166,6 @@ void initgraph() {
restartGraph();
initgeo();
buildpolys();
if(noGUI) {
#if CAP_COMMANDLINE
arg::read(2);

View File

@ -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<ittypes; i++)
if(itemclass(eItem(i)) == IC_TREASURE)
@ -414,12 +403,10 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu
if(clHeight) vid.yres = clHeight;
if(clFont) vid.fsize = clFont;
}
else if(argis("--version") || argis("-v")) {
printf("HyperRogue version " VER "\n");
exit(0);
}
else if(argis("--run")) {
PHASE(3); mainloop(); quitmainloop = false;
PHASE(3);
start_game();
mainloop(); quitmainloop = false;
}
else if(argis("--msg")) {
shift(); addMessage(args());
@ -430,11 +417,11 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu
}
#if CAP_TOUR
else if(argis("--tour")) {
PHASE(3); tour::start();
PHASEFROM(2); start_game(); tour::start();
}
else if(argis("--presentation")) {
PHASE(3); tour::texts = false;
tour::start();
PHASEFROM(2); tour::texts = false;
start_game(); tour::start();
}
#endif
else if(argis("--draw")) {
@ -445,7 +432,7 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu
exit(0);
}
else if(argis("-gencells")) {
PHASE(3); shift();
PHASEFROM(2); shift(); start_game();
printf("Generating %d cells...\n", argi());
celllister cl(cwt.c, 50, argi(), NULL);
printf("Cells generated: %d\n", size(cl.lst));
@ -480,7 +467,7 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu
}
#if CAP_SDL
else if(argis("-pngshot")) {
PHASE(3); shift();
PHASE(3); shift(); start_game();
printf("saving PNG screenshot to %s\n", argcs());
saveHighQualityShot(argcs());
}
@ -503,7 +490,7 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu
shift(); svg::gamma = argf();
}
else if(argis("-svgshot")) {
PHASE(3); shift();
PHASE(3); shift(); start_game();
printf("saving SVG screenshot to %s\n", argcs());
svg::render(argcs());
}
@ -531,6 +518,10 @@ else if(args()[0] == '-' && args()[1] == x && args()[2] == '0') { showstartmenu
}
// informational
else if(argis("--version") || argis("-v")) {
printf("HyperRogue version " VER "\n");
exit(0);
}
else if(argis("-fi")) {
fieldpattern::info();
exit(0);

View File

@ -306,22 +306,22 @@ bool have_current_settings() {
void resetModes(char leave) {
popAllGames();
firstland = laIce; specialland = laIce; vid.scfg.players = 1;
if(shmup::on != (leave == rg::shmup)) restartGame(rg::shmup);
if(inv::on != (leave == rg::inv)) restartGame(rg::inv);
if(chaosmode != (leave == rg::chaos)) restartGame(rg::chaos);
if(gp::on != (leave == rg::gp)) restartGame(rg::gp);
if(nonbitrunc != (leave == rg::bitrunc)) restartGame(rg::bitrunc);
if(peace::on != (leave == rg::peace)) restartGame(rg::peace);
if(shmup::on != (leave == rg::shmup)) stop_game_and_switch_mode(rg::shmup);
if(inv::on != (leave == rg::inv)) stop_game_and_switch_mode(rg::inv);
if(chaosmode != (leave == rg::chaos)) stop_game_and_switch_mode(rg::chaos);
if(gp::on != (leave == rg::gp)) stop_game_and_switch_mode(rg::gp);
if(nonbitrunc != (leave == rg::bitrunc)) stop_game_and_switch_mode(rg::bitrunc);
if(peace::on != (leave == rg::peace)) stop_game_and_switch_mode(rg::peace);
#if CAP_TOUR
if(tour::on != (leave == rg::tour)) restartGame(rg::tour);
if(tour::on != (leave == rg::tour)) stop_game_and_switch_mode(rg::tour);
#endif
if(yendor::on != (leave == rg::yendor)) restartGame(rg::yendor);
if(tactic::on != (leave == rg::tactic)) restartGame(rg::tactic);
if(randomPatternsMode != (leave == rg::randpattern)) restartGame(rg::randpattern);
if(yendor::on != (leave == rg::yendor)) stop_game_and_switch_mode(rg::yendor);
if(tactic::on != (leave == rg::tactic)) stop_game_and_switch_mode(rg::tactic);
if(randomPatternsMode != (leave == rg::randpattern)) stop_game_and_switch_mode(rg::randpattern);
if(geometry != gNormal && leave != rg::geometry) {
targetgeometry = gNormal;
restartGame(rg::geometry);
stop_game_and_switch_mode(rg::geometry);
}
pmodel = mdDisk; vid.alpha = 1; vid.scale = 1;
@ -332,6 +332,7 @@ void resetModes(char leave) {
vid.monmode = DEFAULT_MONMODE;
vid.wallmode = DEFAULT_WALLMODE;
start_game();
}
#if CAP_CONFIG

View File

@ -365,8 +365,6 @@ void handleKeyNormal(int sym, int uni) {
if(sym == SDLK_KP5 && DEFAULTCONTROL) movepcto(-1, 1);
// if(sym == SDLK_F4) restartGameSwitchEuclid();
if(sym == SDLK_F5) {
#if CAP_DAILY
if(daily::on) daily::handleQuit(1);
@ -374,7 +372,7 @@ void handleKeyNormal(int sym, int uni) {
#endif
if(needConfirmation())
pushScreen(showMission);
else restartGame();
else restart_game();
}
if(sym == SDLK_ESCAPE) {

View File

@ -71,14 +71,16 @@ void showQuotientConfig() {
else if(uni == 'p')
nextPrime(gxcur);
else if(uni == 'x' || uni == '\n') {
targetgeometry = gxcur.base; restartGame(rg::geometry);
targetgeometry = gxcur.base; stop_game_and_switch_mode(rg::geometry);
enableFieldChange();
targetgeometry = gQuotient2; restartGame(rg::geometry);
targetgeometry = gQuotient2; stop_game_and_switch_mode(rg::geometry);
start_game();
}
else if(uni == 'c') {
targetgeometry = gEuclid; restartGame(rg::geometry);
targetgeometry = gEuclid; stop_game_and_switch_mode(rg::geometry);
fieldpattern::quotient_field_changed = false;
targetgeometry = gQuotient2; restartGame(rg::geometry);
targetgeometry = gQuotient2; stop_game_and_switch_mode(rg::geometry);
start_game();
}
else if(doexiton(sym, uni))
popScreen();
@ -184,22 +186,24 @@ void showTorusConfig() {
else if(uni == 't')
torus_bitrunc = !torus_bitrunc;
else if((uni == 'a' || uni == '\n') && torusconfig::newqty >= 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);

View File

@ -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);

15
hyper.h
View File

@ -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<int, int> cell_to_pair(cell *c);
extern bool nohud, nofps;
@ -3400,3 +3398,12 @@ void handle_event(SDL_Event& ev);
#ifndef XPRINTF
template<class...T> 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

View File

@ -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;
}
};

View File

@ -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;

View File

@ -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) {

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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<cell*> allcells;

View File

@ -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);
}
}
};

View File

@ -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) {

View File

@ -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<ittypes; i++) items[i] = 0;
lastkills = 0; for(int i=0; i<motypes; i++) kills[i] = 0;
for(int i=0; i<10; i++) explore[i] = 0;
for(int i=0; i<10; i++) for(int l=0; l<landtypes; l++)
exploreland[i][l] = 0;
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i))
multi::deaths[i]++;
#if CAP_SAVE
anticheat::tampered = false;
#endif
achievementsReceived.clear();
princess::saved = false;
princess::nodungeon = false;
princess::reviveAt = 0;
princess::forceVizier = false;
princess::forceMouse = false;
knighted = 0;
// items[itGreenStone] = 100;
clearMemory();
}
void stop_game() {
if(!game_active) return;
achievement_final(true);
#if CAP_SAVE
saveStats();
#endif
for(int i=0; i<ittypes; i++) items[i] = 0;
lastkills = 0; for(int i=0; i<motypes; i++) kills[i] = 0;
for(int i=0; i<10; i++) explore[i] = 0;
for(int i=0; i<10; i++) for(int l=0; l<landtypes; l++)
exploreland[i][l] = 0;
for(int i=0; i<numplayers(); i++)
if(multi::playerActive(i))
multi::deaths[i]++;
#if CAP_SAVE
anticheat::tampered = false;
#endif
achievementsReceived.clear();
princess::saved = false;
princess::nodungeon = false;
princess::reviveAt = 0;
princess::forceVizier = false;
princess::forceMouse = false;
knighted = 0;
// items[itGreenStone] = 100;
clearMemory();
game_active = false;
#if CAP_DAILY
if(daily::on && !among(switchWhat, rg::daily, rg::daily_off))
daily::turnoff();
#endif
if(switchWhat == rg::peace) {
peace::on = !peace::on;
tactic::on = yendor::on = princess::challenge =
randomPatternsMode = inv::on = false;
}
if(switchWhat == rg::inv) {
inv::on = !inv::on;
if(tactic::on) firstland = laIce;
tactic::on = yendor::on = princess::challenge =
randomPatternsMode = peace::on = false;
}
if(switchWhat == rg::chaos) {
if(euclid || sphere || quotient)
geometry = gNormal;
if(tactic::on) firstland = laIce;
yendor::on = tactic::on = princess::challenge = false;
resetGeometry();
chaosmode = !chaosmode;
}
#if CAP_TOUR
if(switchWhat == rg::tour) {
geometry = gNormal;
yendor::on = tactic::on = princess::challenge = peace::on = inv::on = false;
chaosmode = nonbitrunc = randomPatternsMode = false;
shmup::on = false;
resetGeometry();
tour::on = !tour::on;
}
#endif
if(switchWhat == rg::bitrunc || switchWhat == rg::gp) {
if(euclid6) geometry = gNormal;
nonbitrunc = !nonbitrunc;
gp::on = (switchWhat == rg::gp && !gp::on);
resetGeometry();
#if CAP_TEXTURE
if(texture::config.tstate == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
if(texture::config.tstate_max == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
#endif
}
if(switchWhat == rg::geometry) {
if(geometry == targetgeometry) geometry = gNormal;
else geometry = targetgeometry;
if(chaosmode && (euclid || sphere || quotient)) chaosmode = false;
if(nonbitrunc && euclid6) nonbitrunc = false;
if(gp::on && (S3 != 3 || elliptic)) gp::on = false;
}
resetGeometry();
#if CAP_TEXTURE
if(texture::config.tstate == texture::tsActive)
texture::config.tstate = texture::tsOff;
if(texture::config.tstate_max == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
#endif
}
if(switchWhat == rg::yendor) {
yendor::on = !yendor::on;
tactic::on = false;
peace::on = false;
inv::on = false;
princess::challenge = false;
randomPatternsMode = false;
chaosmode = false;
if(!yendor::on) firstland = laIce;
}
if(switchWhat == rg::tactic) {
tactic::on = !tactic::on;
yendor::on = false;
peace::on = false;
inv::on = false;
randomPatternsMode = false;
princess::challenge = false;
chaosmode = false;
if(!tactic::on) firstland = laIce;
}
if(switchWhat == rg::shmup) {
shmup::on = !shmup::on;
princess::challenge = false;
}
if(switchWhat == rg::randpattern) {
randomPatternsMode = !randomPatternsMode;
tactic::on = false;
yendor::on = false;
peace::on = false;
inv::on = false;
princess::challenge = false;
}
#if CAP_DAILY
if(switchWhat == rg::daily)
daily::setup();
if(switchWhat == rg::daily_off)
daily::turnoff();
void push_game() {
gamestack::push();
pd_from = NULL;
centerover.c = NULL;
game_active = false;
}
void switch_game_mode(char switchWhat) {
switch(switchWhat) {
case rg::peace:
peace::on = !peace::on;
tactic::on = yendor::on = princess::challenge =
randomPatternsMode = inv::on = false;
break;
case rg::inv:
inv::on = !inv::on;
if(tactic::on) firstland = laIce;
tactic::on = yendor::on = princess::challenge =
randomPatternsMode = peace::on = false;
break;
case rg::chaos:
if(euclid || sphere || quotient)
geometry = gNormal;
if(tactic::on) firstland = laIce;
yendor::on = tactic::on = princess::challenge = false;
need_reset_geometry = true;
chaosmode = !chaosmode;
break;
#if CAP_TOUR
case rg::tour:
geometry = gNormal;
yendor::on = tactic::on = princess::challenge = peace::on = inv::on = false;
chaosmode = nonbitrunc = randomPatternsMode = false;
shmup::on = false;
need_reset_geometry = true;
tour::on = !tour::on;
break;
#endif
case rg::bitrunc:
case rg::gp:
if(euclid6) geometry = gNormal;
nonbitrunc = !nonbitrunc;
gp::on = (switchWhat == rg::gp && !gp::on);
need_reset_geometry = true;
#if CAP_TEXTURE
if(texture::config.tstate == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
if(texture::config.tstate_max == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
#endif
break;
case rg::geometry:
if(geometry == targetgeometry) geometry = gNormal;
else geometry = targetgeometry;
if(chaosmode && (euclid || sphere || quotient)) chaosmode = false;
if(nonbitrunc && euclid6) nonbitrunc = false;
if(gp::on && (S3 != 3 || elliptic)) gp::on = false;
need_reset_geometry = true;
#if CAP_TEXTURE
if(texture::config.tstate == texture::tsActive)
texture::config.tstate = texture::tsOff;
if(texture::config.tstate_max == texture::tsActive)
texture::config.tstate = texture::tsAdjusting;
#endif
break;
case rg::yendor:
yendor::on = !yendor::on;
tactic::on = false;
peace::on = false;
inv::on = false;
princess::challenge = false;
randomPatternsMode = false;
chaosmode = false;
if(!yendor::on) firstland = laIce;
break;
case rg::tactic:
tactic::on = !tactic::on;
yendor::on = false;
peace::on = false;
inv::on = false;
randomPatternsMode = false;
princess::challenge = false;
chaosmode = false;
if(!tactic::on) firstland = laIce;
break;
case rg::shmup:
shmup::on = !shmup::on;
princess::challenge = false;
break;
case rg::randpattern:
randomPatternsMode = !randomPatternsMode;
tactic::on = false;
yendor::on = false;
peace::on = false;
inv::on = false;
princess::challenge = false;
break;
case rg::princess:
princess::challenge = !princess::challenge;
firstland = princess::challenge ? laPalace : laIce;
shmup::on = false;
tactic::on = false;
yendor::on = false;
chaosmode = false;
inv::on = false;
break;
#if CAP_DAILY
case rg::daily:
daily::setup();
break;
case rg::daily_off:
daily::turnoff();
break;
#endif
if(switchWhat == rg::princess) {
princess::challenge = !princess::challenge;
firstland = princess::challenge ? laPalace : laIce;
shmup::on = false;
tactic::on = false;
yendor::on = false;
chaosmode = false;
inv::on = false;
}
}
void start_game() {
if(game_active) return;
game_active = true;
if(need_reset_geometry) resetGeometry();
initcells();
if(randomPatternsMode) {
@ -1237,7 +1265,20 @@ void restartGame(char switchWhat, bool push, bool keep_screens) {
resetmusic();
resetmusic();
}
void restart_game(char switchWhat) {
popScreenAll();
popAllGames();
stop_game();
switch_game_mode(switchWhat);
start_game();
}
void stop_game_and_switch_mode(char switchWhat) {
stop_game();
switch_game_mode(switchWhat);
}
purehookset clearmemory;
void clearMemory() {

View File

@ -875,14 +875,16 @@ bool texture_config::load() {
dynamicval<int> 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);

View File

@ -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);
}
}
};

View File

@ -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();