diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index ba53cf20..0c7eaad4 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -61,7 +61,7 @@ bool changemapserv(char *name, int mode, int download, int revision) // f else { defformatstring(msg)("map '%s' revision: local %d, provided by server %d", name, hdr.maprevision, revision); - alias("__getmaprevisions", msg); + alias("__getmaprevisions", msg, true); showmenu("getmap"); } } diff --git a/source/src/command.cpp b/source/src/command.cpp index f8ca73b3..afbdf60a 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -117,13 +117,14 @@ void delalias(const char *name) } COMMAND(delalias, "s"); -void alias(const char *name, const char *action, bool constant) +void alias(const char *name, const char *action, bool temp, bool constant) { ident *b = idents->access(name); if(!b) { - ident b(ID_ALIAS, newstring(name), newstring(action), persistidents && !constant, execcontext); + ident b(ID_ALIAS, newstring(name), newstring(action), persistidents && !constant && !temp, execcontext); b.isconst = constant; + b.istemp = temp; idents->access(b.name, b); return; } @@ -144,12 +145,14 @@ void alias(const char *name, const char *action, bool constant) } b->isconst = constant; + if(temp) b->istemp = true; if(!constant || (action && action[0])) { if(b->action!=b->executing) delete[] b->action; b->action = newstring(action); b->persist = persistidents != 0; } + if(b->istemp) b->persist = false; } else { @@ -158,8 +161,9 @@ void alias(const char *name, const char *action, bool constant) } } -COMMANDF(alias, "ss", (const char *name, const char *action) { alias(name, action, false); }); -COMMANDF(const, "ss", (const char *name, const char *action) { alias(name, action, true); }); +COMMANDF(alias, "ss", (const char *name, const char *action) { alias(name, action, false, false); }); +COMMANDF(tempalias, "ss", (const char *name, const char *action) { alias(name, action, true, false); }); +COMMANDF(const, "ss", (const char *name, const char *action) { alias(name, action, false, true); }); COMMANDF(checkalias, "s", (const char *name) { intret(getalias(name) ? 1 : 0); }); COMMANDF(isconst, "s", (const char *name) { ident *id = idents->access(name); intret(id && id->isconst ? 1 : 0); }); diff --git a/source/src/command.h b/source/src/command.h index bd34bc25..8de574f0 100644 --- a/source/src/command.h +++ b/source/src/command.h @@ -11,7 +11,6 @@ struct ident { int type; // one of ID_* above const char *name; - bool isconst; union { int minval; // ID_VAR @@ -42,39 +41,41 @@ struct ident int defaultval; // ID_VAR float defaultvalf; // ID_FVAR }; - short context; - bool persist; + short context; // one of IEXC_* below + bool persist; // if true, value gets written to saved.cfg on exit; set to true, if it's an ID_ALIAS and the value gets changed + bool isconst; // ID_ALIAS: value may not be overwritten + bool istemp; // ID_ALIAS: if value is changed, "persist" will not be set true ident() {} // ID_VAR ident(int type, const char *name, int minval, int maxval, int *i, int defval, void (*fun)(), bool persist, int context) - : type(type), name(name), isconst(false), minval(minval), maxval(maxval), fun(fun), - sig(NULL), action(NULL), defaultval(defval), context(context), persist(persist) + : type(type), name(name), minval(minval), maxval(maxval), fun(fun), + sig(NULL), action(NULL), defaultval(defval), context(context), persist(persist), isconst(false), istemp(false) { storage.i = i; } // ID_FVAR ident(int type, const char *name, float minval, float maxval, float *f, float defval, void (*fun)(), bool persist, int context) - : type(type), name(name), isconst(false), minvalf(minval), maxvalf(maxval), fun(fun), - sig(NULL), action(NULL), defaultvalf(defval), context(context), persist(persist) + : type(type), name(name), minvalf(minval), maxvalf(maxval), fun(fun), + sig(NULL), action(NULL), defaultvalf(defval), context(context), persist(persist), isconst(false), istemp(false) { storage.f = f; } // ID_SVAR ident(int type, const char *name, char **s, void (*fun)(), void (*getfun)(), bool persist, int context) - : type(type), name(name), isconst(false), minval(0), maxval(0), fun(fun), - sig(NULL), action(NULL), getfun(getfun), context(context), persist(persist) + : type(type), name(name), minval(0), maxval(0), fun(fun), + sig(NULL), action(NULL), getfun(getfun), context(context), persist(persist), isconst(false), istemp(false) { storage.s = s; } // ID_ALIAS ident(int type, const char *name, char *action, bool persist, int context) - : type(type), name(name), isconst(false), minval(0), maxval(0), stack(0), - sig(NULL), action(action), executing(NULL), context(context), persist(persist) + : type(type), name(name), minval(0), maxval(0), stack(0), + sig(NULL), action(action), executing(NULL), context(context), persist(persist), isconst(false), istemp(false) { storage.i = NULL; } // ID_COMMAND ident(int type, const char *name, void (*fun)(), const char *sig, int context) - : type(type), name(name), isconst(false), minval(0), maxval(0), fun(fun), - sig(sig), action(NULL), executing(NULL), context(context), persist(false) + : type(type), name(name), minval(0), maxval(0), fun(fun), + sig(sig), action(NULL), executing(NULL), context(context), persist(false), isconst(false), istemp(false) { storage.i = NULL; } }; diff --git a/source/src/main.cpp b/source/src/main.cpp index 38fb2d01..ae532e49 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -29,9 +29,10 @@ VAR(resetcfg, 0, 0, 1); void quit() // normal exit { - const char *mapstartonce = getalias("mapstartonce"), *onquit = getalias("onQuit"); - if(mapstartonce && mapstartonce[0]) alias("mapstartonce", ""); - if(onquit && onquit[0]) { execute(onquit); alias("onQuit", ""); } + const char *onquit = getalias("onQuit"); + if(onquit && onquit[0]) execute(onquit); + alias("onQuit", ""); + alias("mapstartonce", ""); extern void writeinitcfg(); writeinitcfg(); writeservercfg(); diff --git a/source/src/protos.h b/source/src/protos.h index 9b250b8c..ee4f13ec 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -835,7 +835,7 @@ extern void resetcomplete(); extern void complete(char *s, bool reversedirection); extern void push(const char *name, const char *action); extern void pop(const char *name); -extern void alias(const char *name, const char *action, bool constant = false); +extern void alias(const char *name, const char *action, bool temp = false, bool constant = false); extern const char *getalias(const char *name); extern void writecfg(); extern void deletecfg(); diff --git a/source/src/world.cpp b/source/src/world.cpp index 5fe702ce..9e334663 100644 --- a/source/src/world.cpp +++ b/source/src/world.cpp @@ -580,7 +580,7 @@ void newmap(int *i) exechook(HOOK_SP_MP, "onNewMap", ""); } defformatstring(startmillis)("%d", millis_()); - alias("gametimestart", startmillis); + alias("gametimestart", startmillis, true); } COMMAND(mapenlarge, ""); diff --git a/source/src/worldio.cpp b/source/src/worldio.cpp index 97868f03..1eedbebf 100644 --- a/source/src/worldio.cpp +++ b/source/src/worldio.cpp @@ -754,7 +754,7 @@ bool load_world(char *mname) // still supports all map formats that have c2skeepalive(); defformatstring(startmillis)("%d", millis_()); - alias("gametimestart", startmillis); + alias("gametimestart", startmillis, true); startmap(mname); return true; }