diff --git a/source/src/console.cpp b/source/src/console.cpp index 21f4e851..520a1d7a 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -347,7 +347,7 @@ void mapmsg(char *s) filterrichtext(text, s); filterservdesc(text, text); copystring(hdr.maptitle, text, 128); - unsavededits = 1; + if(editmode) unsavededits++; } void getmapmsg(void) diff --git a/source/src/editing.cpp b/source/src/editing.cpp index c9254eb0..69d17f53 100644 --- a/source/src/editing.cpp +++ b/source/src/editing.cpp @@ -324,7 +324,7 @@ void makeundo(block &sel) storeposition(sel.p); undos.add(blockcopy(sel)); pruneundos(undomegs<<20); - unsavededits = 1; + unsavededits++; } void restoreposition(short p[]) @@ -352,7 +352,7 @@ void editundo() if(editmetakeydown) restoreposition(*p); blockpaste(*p); freeblock(p); - unsavededits = 1; + unsavededits++; } void editredo() @@ -364,7 +364,7 @@ void editredo() if(editmetakeydown) restoreposition(*p); blockpaste(*p); freeblock(p); - unsavededits = 1; + unsavededits++; } extern int worldiodebug; @@ -611,7 +611,7 @@ void edittex(int type, int dir) edittexxy(type, t, sels[i]); addmsg(SV_EDITT, "ri6", sels[i].x, sels[i].y, sels[i].xs, sels[i].ys, type, t); } - unsavededits = 1; + unsavededits++; } void settex(int texture, int type) @@ -635,7 +635,7 @@ void settex(int texture, int type) edittexxy(type, t, sels[i]); addmsg(SV_EDITT, "ri6", sels[i].x, sels[i].y, sels[i].xs, sels[i].ys, type, t); } - unsavededits = 1; + unsavededits++; } void replace() @@ -654,7 +654,7 @@ void replace() } block b = { 0, 0, ssize, ssize }; remip(b); - unsavededits = 1; + unsavededits++; } void edittypexy(int type, block &sel) @@ -856,7 +856,7 @@ void movemap(int xo, int yo, int zo) // move whole map entinmap(player1); calclight(); resetmap(false); - unsavededits = 1; + unsavededits++; } void selfliprotate(block &sel, int dir) @@ -972,7 +972,7 @@ void transformclipentities() // transforms all clip entities to tag clips, if t while(thisrun); loopi(ssize) loopj(ssize) { sqr *s = S(i,j); if(s->tag & TAGCLIP) s->tag &= ~TAGPLCLIP; } conoutf("changed %d clip entities to tagged clip areas", total); - unsavededits = 1; + if(total) unsavededits++; } COMMAND(transformclipentities, ""); diff --git a/source/src/water.cpp b/source/src/water.cpp index 2b665cfe..9b980b95 100644 --- a/source/src/water.cpp +++ b/source/src/water.cpp @@ -4,7 +4,7 @@ int wx1, wy1, wx2, wy2; float wsx1, wsy1, wsx2, wsy2; VARP(watersubdiv, 1, 4, 64); -VARF(waterlevel, -128, -128, 127, if(!noteditmode("waterlevel")) { hdr.waterlevel = waterlevel; unsavededits = 1; }); +VARF(waterlevel, -128, -128, 127, if(!noteditmode("waterlevel")) { hdr.waterlevel = waterlevel; unsavededits++; }); void setwatercolor(const char *r, const char *g, const char *b, const char *a) { @@ -22,7 +22,7 @@ void setwatercolor(const char *r, const char *g, const char *b, const char *a) hdr.watercolor[2] = 20; hdr.watercolor[3] = 178; } - unsavededits = 1; + if(editmode) unsavededits++; } COMMANDN(watercolour, setwatercolor, "ssss"); diff --git a/source/src/world.cpp b/source/src/world.cpp index 12bde3a6..817db875 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -191,7 +191,7 @@ void entproperty(int prop, int amount) loc->drop(); } if(changedents.find(n) == -1) changedents.add(n); // apply ent changes later (reduces network traffic) - unsavededits = 1; + unsavededits++; } hashtable mapinfo, &resdata = mapinfo; @@ -247,7 +247,7 @@ void delent() { case LIGHT: calclight(); break; } - unsavededits = 1; + unsavededits++; } int findtype(char *what) @@ -312,7 +312,7 @@ entity *newentity(int index, int x, int y, int z, char *what, int v1, int v2, in case LIGHT: calclight(); break; case SOUND: audiomgr.preloadmapsound(e); break; } - unsavededits = 1; + unsavededits++; return index<0 ? &ents.last() : &ents[index]; } @@ -332,16 +332,17 @@ void clearents(char *name) { int type = findtype(name); if(noteditmode("clearents") || multiplayer()) return; + bool found = false; loopv(ents) { entity &e = ents[i]; - if(e.type==type) e.type = NOTUSED; - unsavededits = 1; + if(e.type==type) { e.type = NOTUSED; found = true; } } switch(type) { case LIGHT: calclight(); break; } + if(found) unsavededits++; } COMMAND(clearents, "s"); @@ -369,7 +370,7 @@ void scalelights(int f, int intens) scalecomp(e.attr3, intens); scalecomp(e.attr4, intens); } - unsavededits = 1; + unsavededits++; } calclight(); } @@ -752,7 +753,7 @@ void mapmrproper(bool manual) conoutf("before: %d / %d / %d / %d / %d / %d / %d", sta[0], sta[1], sta[2], sta[3], sta[4], sta[5], sta[6]); conoutf("idealized: %d / %d / %d / %d / %d / %d / %d", stb[0], stb[1], stb[2], stb[3], stb[4], stb[5], stb[6]); conoutf("final count: %d / %d / %d / %d / %d / %d / %d", stc[0], stc[1], stc[2], stc[3], stc[4], stc[5], stc[6]); - unsavededits = 1; + unsavededits++; } } COMMANDF(mapmrproper, "", () { mapmrproper(true); }); diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index f5755db3..4f3ae6e3 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -858,7 +858,7 @@ struct xmap persistent_entity &e = ents[i]; f->printf("restorexmap ent %d %d %d %d %d %d %d %d // %s\n", e.type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4, e.type >= 0 && e.type < MAXENTTYPES ? entnames[e.type] : "unknown"); } - f->printf("restorexmap position %d %d %d %d %d // EOF, don't touch this\n\n", position[0], position[1], position[2], position[3], position[4]); + f->printf("restorexmap position %d %d %d %d %d // EOF, don't touch this\n\n", int(position[0]), int(position[1]), int(position[2]), int(position[3]), int(position[4])); } }; @@ -868,6 +868,8 @@ static xmap *bak, *xmjigsaw; // only bak needs to #define SPEDIT if(noteditmode("xmap") || multiplayer()) return // only allowed in non-coop editmode #define SPEDITDIFF if(noteditmode("xmap") || multiplayer() || nodiff()) return // only allowed in non-coop editmode after xmap_diff +bool validxmapname(const char *nick) { if(validmapname(nick)) return true; conoutf("sry, %s is not a valid xmap nickname", nick); return false; } + void xmapdelete(xmap *&xm) // make sure, we don't point to deleted xmaps { DELETEP(xm); @@ -915,8 +917,7 @@ COMMANDF(xmap_list, "", () // list xmaps (and status) COMMANDF(xmap_store, "s", (const char *nick) // store current map in an xmap buffer { if(noteditmode("xmap_store")) return; // (may also be used in coopedit) - if(!*nick) return; - if(!validmapname(nick)) { conoutf("sry, %s is not a valid xmap nickname", nick); return; } + if(!*nick || !validxmapname(nick)) return; int i; if(getxmapbynick(nick, &i, false)) { xmap *xm = xmaps.remove(i); xmapdelete(xm); } // overwrite existing same nick xmaps.add(new xmap(nick)); @@ -936,6 +937,31 @@ COMMANDF(xmap_delete, "s", (const char *nick) // delete xmap buffer } } ); +COMMANDF(xmap_delete_backup, "", () { if(bak) { xmapdelete(bak); conoutf("deleted backup xmap"); }} ); + +COMMANDF(xmap_keep_backup, "s", (const char *nick) // move backup xmap to more permanent position +{ + if(!bak) { conoutf("no backup xmap available"); return ; } + defformatstring(bakdesc)("%s", bak->nick); + if(*nick) + { + if(validxmapname(nick)) copystring(bak->nick, nick); + else return; + } + loopi(42) if(getxmapbynick(bak->nick, NULL, false)) concatstring(bak->nick, "_"); // evade existing nicknames + xmaps.add(bak); + bak = NULL; + conoutf("stored backup xmap \"%s\" as xmap %s", bakdesc, xmapdescstring(xmaps.last())); +} ); + +COMMANDF(xmap_rename, "ss", (const char *oldnick, const char *newnick) // rename xmap buffer +{ + if(!*oldnick || !*newnick) return; + xmap *xm = getxmapbynick(oldnick); + if(!xm || !validxmapname(newnick) || getxmapbynick(newnick, NULL, false)) return; + copystring(xm->nick, newnick); +} ); + COMMANDF(xmap_restore, "s", (const char *nick) // use xmap as current map { SPEDIT; @@ -1025,14 +1051,17 @@ void restorexmap(char **args, int numargs) // read an xmap from a cubescript f } COMMAND(restorexmap, "v"); -static const char *bakprefix = "__.backup.__", *xmapspath = "mapediting/xmaps"; -char *xmapfilename(const char *nick, const char *prefix = "") { static defformatstring(fn)("%s/%s%s.xmap", xmapspath, prefix, nick); return fn; } +static const char *bakprefix = "(backup)", *xmapspath = "mapediting/xmaps"; +char *xmapfilename(const char *nick, const char *prefix = "") { static defformatstring(fn)("%s/%s%s.xmap", xmapspath, prefix, nick); return path(fn); } void writexmap(xmap *xm, const char *prefix = "") { stream *f = openfile(xmapfilename(xm->nick, prefix), "w"); - xm->write(f); - delete f; + if(f) + { + xm->write(f); + delete f; + } } void writeallxmaps() // at game exit, write all xmaps to cubescript files in mapediting/xmaps diff --git a/source/src/worldlight.cpp b/source/src/worldlight.cpp index 4b722e94..c4be3e24 100644 --- a/source/src/worldlight.cpp +++ b/source/src/worldlight.cpp @@ -174,7 +174,7 @@ void fullbrightlight(int level) lastcalclight = totalmillis; } -VARF(ambient, 0, 0, 0xFFFFFF, if(!noteditmode("ambient")) { hdr.ambient = ambient; calclight(); unsavededits = 1;}); +VARF(ambient, 0, 0, 0xFFFFFF, if(!noteditmode("ambient")) { hdr.ambient = ambient; calclight(); unsavededits++;}); void calclight() {