From b2c5e2d807160e955f7abc2e999136e78a6c1271 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 28 Jun 2013 14:07:44 +0000 Subject: [PATCH] Mapster32/Lunatic: ask when a =4))) - SaveBoard(NULL, 0); + SaveBoard(NULL, M32_SB_ASKOV); while (keystatus[1] || keystatus[0x2e]) { @@ -7992,7 +7995,7 @@ static void SaveBoardAndPrintMessage(const char *fn) _printmessage16("Saving board..."); showframe(1); - f = SaveBoard(fn, 0); + f = SaveBoard(fn, M32_SB_ASKOV); if (f) { @@ -8004,11 +8007,14 @@ static void SaveBoardAndPrintMessage(const char *fn) } else { - if (saveboard_fixedsprites) - message("^13SAVING BOARD FAILED (changed sectnums of %d sprites).", - saveboard_fixedsprites); - else - message("^13SAVING BOARD FAILED."); + if (!saveboard_canceled) + { + if (saveboard_fixedsprites) + message("^13SAVING BOARD FAILED (changed sectnums of %d sprites).", + saveboard_fixedsprites); + else + message("^13SAVING BOARD FAILED."); + } } } @@ -8026,17 +8032,36 @@ const char *GetSaveBoardFilename(const char *fn) return getbasefn(fn); } -// flags: 1:no ExtSaveMap (backup.map) and no taglabels saving +// flags: see enum SaveBoardFlags. +// returns: NULL on failure, file name on success. const char *SaveBoard(const char *fn, uint32_t flags) { int32_t ret; const char *f = GetSaveBoardFilename(fn); - saveboard_savedtags = 0; + saveboard_canceled = 0; +#ifdef NEW_MAP_FORMAT + if ((flags&M32_SB_ASKOV) && mapversion>=10 && + g_loadedMapVersion != -1 && g_loadedMapVersion < mapversion) + { + char question[128]; + Bsnprintf(question, sizeof(question), "Are you sure to overwrite a version " + "V%d map with a V%d map-text one?", g_loadedMapVersion, mapversion); + if (AskIfSure(question)) + { + message("Cancelled saving board"); + saveboard_canceled = 1; + return NULL; + } + } +#endif + + saveboard_savedtags = 0; saveboard_fixedsprites = ExtPreSaveMap(); + ret = saveboard(f, &startpos, startang, startsectnum); - if ((flags&1)==0) + if ((flags&M32_SB_NOEXT)==0) { ExtSaveMap(f); saveboard_savedtags = !taglab_save(f); @@ -8047,6 +8072,9 @@ const char *SaveBoard(const char *fn, uint32_t flags) // flags: 1: for running on Mapster32 init // 4: passed to loadboard flags (no polymer_loadboard); implies no maphack loading +// returns: +// 0 on success, +// <0 on failure. int32_t LoadBoard(const char *filename, uint32_t flags) { int32_t i, tagstat; @@ -8055,9 +8083,6 @@ int32_t LoadBoard(const char *filename, uint32_t flags) if (!filename) filename = selectedboardfilename; - if (filename != boardfilename) - Bstrcpy(boardfilename, filename); - editorzrange[0] = INT32_MIN; editorzrange[1] = INT32_MAX; @@ -8072,6 +8097,10 @@ int32_t LoadBoard(const char *filename, uint32_t flags) return i; } + // Success, so copy the file name. + if (filename != boardfilename) + Bstrcpy(boardfilename, filename); + mkonwinvalid(); highlightcnt = -1; @@ -8099,7 +8128,8 @@ int32_t LoadBoard(const char *filename, uint32_t flags) else Bstrcpy(msgtail, "successfully"); - message("Loaded V%d map %s%s %s", mapversion, boardfilename, tagstat==0?" w/tags":"", msgtail); + message("Loaded V%d map %s%s %s", g_loadedMapVersion, + boardfilename, tagstat==0?" w/tags":"", msgtail); } startpos = pos; //this is same diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index c71c6fd39..1f7136092 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -80,6 +80,7 @@ float debug1, debug2; #endif int32_t mapversion=7; // JBF 20040211: default mapversion to 7 +int32_t g_loadedMapVersion = -1; // -1: none (e.g. started new) static int32_t get_mapversion(void); @@ -10037,6 +10038,8 @@ skip_reading_mapbin: check_sprite(i); } + // Back up the map version of the *loaded* map. Must be before yax_update(). + g_loadedMapVersion = mapversion; #ifdef YAX_ENABLE yax_update(mapversion<9); if (editstatus) diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 092e08155..b7226238a 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -2987,7 +2987,7 @@ static void m32_showmouse(void) pop_nofog(); } -static int32_t AskIfSure(const char *text) +int32_t AskIfSure(const char *text) { int32_t retval=1; @@ -3027,7 +3027,7 @@ static int32_t AskIfSure(const char *text) if (PRESSED_KEYSC(ESC)) retval = 1; - return(retval); + return retval; } static int32_t IsValidTile(int32_t idTile) @@ -10513,7 +10513,7 @@ void app_crashhandler(void) if (levelname[0]) { append_ext_UNSAFE(levelname, "_crash.map"); - SaveBoard(levelname, 1); + SaveBoard(levelname, M32_SB_NOEXT); } } @@ -11099,11 +11099,12 @@ static void Keys2d3d(void) Bsprintf(tempbuf, "Save to %s?", levelname); if (!AskIfSure(tempbuf)) { - SaveBoard(levelname, 0); - - message("Board saved to %s", levelname); - asksave = 0; - lastsave=totalclock; + if (SaveBoard(levelname, M32_SB_ASKOV) != NULL) + { + message("Board saved to %s", levelname); + asksave = 0; + lastsave=totalclock; + } } } else @@ -11284,13 +11285,13 @@ void ExtCheckKeys(void) { if (CheckMapCorruption(5, 0)>=4) { - SaveBoard("autosave_corrupt.map", 1); - message("Board autosaved to AUTOSAVE_CORRUPT.MAP"); + if (SaveBoard("autosave_corrupt.map", M32_SB_NOEXT) != NULL) + message("Board autosaved to AUTOSAVE_CORRUPT.MAP"); } else { - SaveBoard("autosave.map", 0); - message("Board autosaved to AUTOSAVE.MAP"); + if (SaveBoard("autosave.map", 0) != NULL) + message("Board autosaved to AUTOSAVE.MAP"); } asksave++;