diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index fdb7e768c..efab59d62 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -1530,12 +1530,14 @@ static int display_cmd(unit * u, struct order *ord) { building *b = u->building; char **s = NULL; + const char *str; region *r = u->region; init_tokens(ord); skip_token(); - switch (getparam(u->faction->locale)) { + str = getstrtoken(); + switch (findparam_ex(str, u->faction->locale)) { case P_BUILDING: case P_GEBAEUDE: if (!b) { @@ -1695,14 +1697,17 @@ static int name_cmd(unit * u, struct order *ord) char **s = NULL; param_t p; boolean foreign = false; + const char *str; init_tokens(ord); skip_token(); - p = getparam(u->faction->locale); + str = getstrtoken(); + p = findparam_ex(str, u->faction->locale); if (p == P_FOREIGN) { + str = getstrtoken(); foreign = true; - p = getparam(u->faction->locale); + p = findparam_ex(str, u->faction->locale); } switch (p) { @@ -1951,7 +1956,7 @@ static int mail_cmd(unit * u, struct order *ord) do { cont = 0; - switch (findparam(s, u->faction->locale)) { + switch (findparam_ex(s, u->faction->locale)) { case P_REGION: /* können alle Einheiten in der Region sehen */ s = getstrtoken(); @@ -2991,7 +2996,7 @@ static int renumber_cmd(unit * u, order * ord) init_tokens(ord); skip_token(); s = getstrtoken(); - switch (findparam(s, u->faction->locale)) { + switch (findparam_ex(s, u->faction->locale)) { case P_FACTION: s = getstrtoken(); @@ -3374,7 +3379,7 @@ static void new_units(void) if (get_keyword(makeord) == K_MAKE) { init_tokens(makeord); skip_token(); - if (getparam(u->faction->locale) == P_TEMP) { + if (isparam(getstrtoken(), u->faction->locale, P_TEMP)) { const char *token; char *name = NULL; int alias; diff --git a/src/gamecode/study.c b/src/gamecode/study.c index ae057dec0..a317d4b4d 100644 --- a/src/gamecode/study.c +++ b/src/gamecode/study.c @@ -416,13 +416,13 @@ int teach_cmd(unit * u, struct order *ord) token = getstrtoken(); /* Beginne die Fehlermeldung */ - if (findparam(token, u->faction->locale) != P_TEMP) { - uid = token; - } else { + if (isparam(token, u->faction->locale, P_TEMP)) { token = getstrtoken(); sprintf(tbuf, "%s %s", LOC(u->faction->locale, parameters[P_TEMP]), token); uid = tbuf; + } else { + uid = token; } ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unitnotfound_id", "id", uid)); diff --git a/src/kernel/build.c b/src/kernel/build.c index 805c5ad32..8ad6caaeb 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -1341,10 +1341,12 @@ void do_misc(region * r, boolean lasttry) param_t p; int id; unit *ulast = NULL; + const char * s; init_tokens(ord); skip_token(); - p = getparam(u->faction->locale); + s = getstrtoken(); + p = findparam_ex(s, u->faction->locale); id = getid(); switch (p) { diff --git a/src/kernel/config.c b/src/kernel/config.c index 1de9d135d..1e90fc778 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1494,25 +1494,44 @@ keyword_t findkeyword(const char *s, const struct locale * lang) param_t findparam(const char *s, const struct locale * lang) { - void **tokens = get_translations(lang, UT_PARAMS); - int i; param_t result = NOPARAM; - const void * match; char buffer[64]; char * str = transliterate(buffer, sizeof(buffer)-sizeof(int), s); - critbit_tree *cb = (critbit_tree *)*tokens; - if (str && cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { - cb_get_kv(match, &i, sizeof(int)); - result = (param_t)i; - } else { + if (str) { + int i; + const void * match; + void **tokens = get_translations(lang, UT_PARAMS); + critbit_tree *cb = (critbit_tree *)*tokens; + if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { + cb_get_kv(match, &i, sizeof(int)); + result = (param_t)i; + } + } + return result; +} + +param_t findparam_ex(const char *s, const struct locale * lang) +{ + param_t result = findparam(s, lang); + + if (result==NOPARAM) { const building_type *btype = findbuildingtype(s, lang); if (btype != NULL) - return (param_t) P_GEBAEUDE; + return P_GEBAEUDE; } return (result == P_BUILDING) ? P_GEBAEUDE : result; } +int isparam(const char *s, const struct locale * lang, param_t param) +{ + if (s[0]>'@') { + param_t p = (param==P_GEBAEUDE) ? findparam_ex(s, lang) : findparam(s, lang); + return p==param; + } + return 0; +} + param_t getparam(const struct locale * lang) { return findparam(getstrtoken(), lang); @@ -1588,18 +1607,17 @@ static int read_newunitid(const faction * f, const region * r) int read_unitid(const faction * f, const region * r) { const char *s = getstrtoken(); - param_t param; /* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der * paramliste. machen wir das nicht, dann wird getnewunit in s nach der * nummer suchen, doch dort steht bei temp-units nur "temp" drinnen! */ - param = findparam(s, f->locale); - if (param == P_TEMP) { + if (!s || *s == 0) { + return -1; + } + if (isparam(s, f->locale, P_TEMP)) { return read_newunitid(f, r); } - if (!s || *s == 0) - return -1; return atoi36((const char *)s); } diff --git a/src/kernel/config.h b/src/kernel/config.h index 8d6715fd6..36731c1f5 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -179,8 +179,10 @@ extern "C" { extern keyword_t findkeyword(const char *s, const struct locale *lang); - extern param_t findparam(const char *s, const struct locale *lang); - extern param_t getparam(const struct locale *lang); + param_t findparam(const char *s, const struct locale *lang); + param_t findparam_ex(const char *s, const struct locale * lang); + int isparam(const char *s, const struct locale * lang, param_t param); + param_t getparam(const struct locale *lang); extern int getid(void); #define unitid(x) itoa36((x)->no) diff --git a/src/kernel/magic.c b/src/kernel/magic.c index e871a14e8..5da9bc57f 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -1922,7 +1922,7 @@ addparam_unit(const char *const param[], spllprm ** spobjp, const unit * u, sppobj_t otype = SPP_UNIT; *spobjp = NULL; - if (findparam(param[0], u->faction->locale) == P_TEMP) { + if (isparam(param[0], u->faction->locale, P_TEMP)) { if (param[1] == NULL) { /* Fehler: Ziel vergessen */ cmistake(u, ord, 203, MSG_MAGIC); @@ -1981,7 +1981,6 @@ static spellparameter *add_spellparameter(region * target_r, unit * u, while (!fail && *c && i < size && param[i] != NULL) { spllprm *spobj = NULL; - param_t pword; int j = -1; switch (*c) { case '?': @@ -2028,8 +2027,7 @@ static spellparameter *add_spellparameter(region * target_r, unit * u, break; case 'k': ++c; - pword = findparam(param[i++], u->faction->locale); - switch (pword) { + switch (findparam_ex(param[i++], u->faction->locale)) { case P_REGION: spobj = (spllprm *)malloc(sizeof(spllprm)); spobj->flag = 0; diff --git a/src/kernel/order.c b/src/kernel/order.c index d595ebf18..9547d4446 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -373,12 +373,12 @@ order *parse_order(const char *s, const struct locale * lang) * \return true if the order is long * \sa is_exclusive(), is_repeated(), is_persistent() */ -boolean is_repeated(const order * ord) +int is_repeated(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); const struct locale *lang = ORD_LOCALE(ord); const char * s; - param_t param; + int result = 0; switch (kwd) { case K_CAST: @@ -399,7 +399,8 @@ boolean is_repeated(const order * ord) case K_BREED: case K_PIRACY: case K_PLANT: - return true; + result = 1; + break; case K_FOLLOW: /* FOLLOW is only a long order if we are following a ship. */ @@ -407,13 +408,8 @@ boolean is_repeated(const order * ord) init_tokens(ord); skip_token(); s = getstrtoken(); - if (s[0]>'9') { - param = findparam(s, lang); - parser_popstate(); - if (param == P_SHIP) { - return true; - } - } + result = isparam(s, lang, P_SHIP); + parser_popstate(); break; case K_MAKE: @@ -426,16 +422,13 @@ boolean is_repeated(const order * ord) init_tokens(ord); /* initialize token-parser */ skip_token(); s = getstrtoken(); - if (s[0]>'9') { - param = findparam(s, lang); - parser_popstate(); - return param != P_TEMP; - } + result = !isparam(s, lang, P_TEMP); + parser_popstate(); break; default: - return false; + result = 0; } - return false; + return result; } /** @@ -446,11 +439,11 @@ boolean is_repeated(const order * ord) * \return true if the order is long * \sa is_exclusive(), is_repeated(), is_persistent() */ -boolean is_exclusive(const order * ord) +int is_exclusive(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); const struct locale *lang = ORD_LOCALE(ord); - param_t param; + int result = 0; switch (kwd) { case K_MOVE: @@ -471,18 +464,16 @@ boolean is_exclusive(const order * ord) case K_BREED: case K_PIRACY: case K_PLANT: - return true; + result = 1; + break; case K_FOLLOW: /* FOLLOW is only a long order if we are following a ship. */ parser_pushstate(); init_tokens(ord); skip_token(); - param = getparam(lang); + result = isparam(getstrtoken(), lang, P_SHIP); parser_popstate(); - - if (param == P_SHIP) - return true; break; case K_MAKE: @@ -494,16 +485,13 @@ boolean is_exclusive(const order * ord) parser_pushstate(); init_tokens(ord); /* initialize token-parser */ skip_token(); - param = getparam(lang); + result = !isparam(getstrtoken(), lang, P_TEMP); parser_popstate(); - - if (param != P_TEMP) - return true; break; default: - return false; + result = 0; } - return false; + return result; } /** @@ -514,11 +502,11 @@ boolean is_exclusive(const order * ord) * \return true if the order is long * \sa is_exclusive(), is_repeated(), is_persistent() */ -boolean is_long(const order * ord) +int is_long(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); const struct locale *lang = ORD_LOCALE(ord); - param_t param; + int result = 0; switch (kwd) { case K_CAST: @@ -548,11 +536,8 @@ boolean is_long(const order * ord) parser_pushstate(); init_tokens(ord); skip_token(); - param = getparam(lang); + result = isparam(getstrtoken(), lang, P_SHIP); parser_popstate(); - - if (param == P_SHIP) - return true; break; case K_MAKE: @@ -564,16 +549,13 @@ boolean is_long(const order * ord) parser_pushstate(); init_tokens(ord); /* initialize token-parser */ skip_token(); - param = getparam(lang); + result = !isparam(getstrtoken(), lang, P_TEMP); parser_popstate(); - - if (param != P_TEMP) - return true; break; default: - return false; + result = 0; } - return false; + return result; } /** @@ -585,10 +567,10 @@ boolean is_long(const order * ord) * \return true if the order is persistent * \sa is_exclusive(), is_repeated(), is_persistent() */ -boolean is_persistent(const order * ord) +int is_persistent(const order * ord) { keyword_t kwd = ORD_KEYWORD(ord); - boolean persist = ord->_persistent != 0; + int persist = ord->_persistent != 0; switch (kwd) { case K_MOVE: case K_WEREWOLF: diff --git a/src/kernel/order.h b/src/kernel/order.h index 3dd97bcae..9e0ebeef5 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -51,10 +51,10 @@ extern "C" { extern keyword_t get_keyword(const order * ord); extern void set_order(order ** destp, order * src); extern char *getcommand(const order * ord); - extern boolean is_persistent(const order * ord); - extern boolean is_exclusive(const order * ord); - extern boolean is_repeated(const order * ord); - extern boolean is_long(const order * ord); + extern int is_persistent(const order * ord); + extern int is_exclusive(const order * ord); + extern int is_repeated(const order * ord); + extern int is_long(const order * ord); extern char *write_order(const order * ord, char *buffer, size_t size); diff --git a/src/kernel/save.c b/src/kernel/save.c index fcfc02291..a05445ab1 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -291,7 +291,7 @@ static unit *unitorders(FILE * F, int enc, struct faction *f) if (s == NULL) break; - if (s[0]) { + if (s[0] && s[0]!='@') { const char *stok = s; stok = parse_token(&stok); @@ -436,7 +436,7 @@ int readorders(const char *filename) b = getbuf(F, enc_gamedata); if (!b) break; - p = igetparam(b, lang); + p = (b[0]=='@') ? NOPARAM : igetparam(b, lang); } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT && p != P_GAMENAME); break;