From fc80f2bd8c5c6e05df7270ff8bab6a6445c3192e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 9 Oct 2017 20:33:47 +0200 Subject: [PATCH] hackish optimization for STUDY orders --- src/battle.c | 2 +- src/bind_order.c | 2 +- src/economy.c | 24 +++++++++--------- src/give.c | 2 +- src/items.c | 2 +- src/kernel/alliance.c | 10 ++++---- src/kernel/build.c | 2 +- src/kernel/command.c | 2 +- src/kernel/config.test.c | 24 +++++++++--------- src/kernel/order.c | 31 ++++++++++++++++++----- src/kernel/order.h | 3 ++- src/kernel/order.test.c | 52 +++++++++++++++++++++++++++++++++----- src/laws.c | 54 ++++++++++++++++++++-------------------- src/magic.c | 2 +- src/move.c | 22 ++++++++-------- src/move.test.c | 2 +- src/piracy.c | 4 +-- src/renumber.c | 2 +- src/spy.c | 8 +++--- src/study.c | 18 +++++++------- 20 files changed, 164 insertions(+), 104 deletions(-) diff --git a/src/battle.c b/src/battle.c index ad1c0f8da..8139456cc 100644 --- a/src/battle.c +++ b/src/battle.c @@ -3841,7 +3841,7 @@ static bool start_battle(region * r, battle ** bp) /* Ende Fehlerbehandlung Angreifer */ - init_order(ord); + init_order_depr(ord); /* attackierte Einheit ermitteln */ getunit(r, u->faction, &u2); diff --git a/src/bind_order.c b/src/bind_order.c index 84399deec..cfbe51d16 100644 --- a/src/bind_order.c +++ b/src/bind_order.c @@ -13,7 +13,7 @@ static int tolua_order_get_token(lua_State *L) { order *ord = (order *)tolua_tousertype(L, 1, 0); int n = (int)tolua_tonumber(L, 2, 0); const char * str = 0; - init_order(ord); + init_order_depr(ord); while (n-->0) { str = getstrtoken(); if (!str) { diff --git a/src/economy.c b/src/economy.c index 7c4b0efd3..1de4f7e4e 100644 --- a/src/economy.c +++ b/src/economy.c @@ -441,7 +441,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders) const char *str; int n; - init_order(ord); + init_order_depr(ord); n = getint(); if (n <= 0) { syntax_error(u, ord); @@ -598,7 +598,7 @@ int give_control_cmd(unit * u, order * ord) unit *u2; const char *s; - init_order(ord); + init_order_depr(ord); getunit(r, u->faction, &u2); s = gettoken(token, sizeof(token)); @@ -657,7 +657,7 @@ static int forget_cmd(unit * u, order * ord) return 0; } - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); sk = get_skill(s, u->faction->locale); @@ -1303,7 +1303,7 @@ int make_cmd(unit * u, struct order *ord) char ibuf[16]; keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_MAKE); s = gettoken(token, sizeof(token)); @@ -1582,7 +1582,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord) /* Im Augenblick kann man nur 1 Produkt kaufen. expandbuying ist aber * schon daf�r ausger�stet, mehrere Produkte zu kaufen. */ - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_BUY); n = getint(); if (n <= 0) { @@ -1896,7 +1896,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord) /* sellorders sind KEIN array, weil f�r alle items DIE SELBE resource * (das geld der region) aufgebraucht wird. */ - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_SELL); s = gettoken(token, sizeof(token)); @@ -2287,7 +2287,7 @@ static void breed_cmd(unit * u, struct order *ord) } /* z�chte [] */ - (void)init_order(ord); + (void)init_order_depr(ord); s = gettoken(token, sizeof(token)); m = s ? atoip(s) : 0; @@ -2354,7 +2354,7 @@ static void research_cmd(unit * u, struct order *ord) region *r = u->region; keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_RESEARCH); if (effskill(u, SK_HERBALISM, 0) < 7) { @@ -2430,7 +2430,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) message * msg; keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_STEAL); assert(skill_enabled(SK_PERCEPTION) && skill_enabled(SK_STEALTH)); @@ -2568,7 +2568,7 @@ void entertain_cmd(unit * u, struct order *ord) static int entertainperlevel = 0; keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_ENTERTAIN); if (!entertainbase) { const char *str = config_get("entertain.base"); @@ -2778,7 +2778,7 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders) taxperlevel = config_get_int("taxing.perlevel", 0); } - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_TAX); if (!humanoidrace(u_race(u)) && !is_monsters(u->faction)) { @@ -2847,7 +2847,7 @@ void loot_cmd(unit * u, struct order *ord, request ** lootorders) request *o; keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_LOOT); if (config_get_int("rules.enable_loot", 0) == 0 && !is_monsters(u->faction)) { diff --git a/src/give.c b/src/give.c index da75e56c5..84e2765a6 100644 --- a/src/give.c +++ b/src/give.c @@ -634,7 +634,7 @@ void give_cmd(unit * u, order * ord) message *msg; keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_GIVE); err = getunit(r, u->faction, &u2); s = gettoken(token, sizeof(token)); diff --git a/src/items.c b/src/items.c index 8a6328d91..fe59ffa15 100644 --- a/src/items.c +++ b/src/items.c @@ -47,7 +47,7 @@ static int use_studypotion(struct unit *u, const struct item_type *itype, int amount, struct order *ord) { - if (u->thisorder && init_order(u->thisorder) == K_STUDY) { + if (u->thisorder && init_order(u->thisorder, u->faction->locale) == K_STUDY) { char token[128]; skill_t sk = NOSKILL; skill *sv = 0; diff --git a/src/kernel/alliance.c b/src/kernel/alliance.c index 910670d10..e4fd7c3b5 100644 --- a/src/kernel/alliance.c +++ b/src/kernel/alliance.c @@ -171,7 +171,7 @@ static void perform_kick(void) if (al && alliance_get_leader(al) == ta->u->faction) { faction *f; - init_order(ta->ord); + init_order_depr(ta->ord); skip_token(); f = getfaction(); if (f && f_get_alliance(f) == al) { @@ -192,7 +192,7 @@ static void perform_new(void) int id; faction *f = ta->u->faction; - init_order(ta->ord); + init_order_depr(ta->ord); skip_token(); id = getid(); @@ -227,7 +227,7 @@ static void perform_transfer(void) if (al && alliance_get_leader(al) == ta->u->faction) { faction *f; - init_order(ta->ord); + init_order_depr(ta->ord); skip_token(); f = getfaction(); if (f && f_get_alliance(f) == al) { @@ -264,7 +264,7 @@ static void perform_join(void) faction *fj = ta->u->faction; int aid; - init_order(ta->ord); + init_order_depr(ta->ord); skip_token(); aid = getid(); if (aid) { @@ -276,7 +276,7 @@ static void perform_join(void) faction *fi = ti->u->faction; if (fi && f_get_alliance(fi) == al) { int fid; - init_order(ti->ord); + init_order_depr(ti->ord); skip_token(); fid = getid(); if (fid == fj->no) { diff --git a/src/kernel/build.c b/src/kernel/build.c index 1f4e143df..2746fa406 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -161,7 +161,7 @@ int destroy_cmd(unit * u, struct order *ord) return 52; } - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); if (s && *s) { diff --git a/src/kernel/command.c b/src/kernel/command.c index a6a036fe9..8b2a7e5e8 100644 --- a/src/kernel/command.c +++ b/src/kernel/command.c @@ -105,7 +105,7 @@ static int do_command_i(const struct tnode *keys, struct unit *u, struct order * void do_command(const struct tnode *keys, struct unit *u, struct order *ord) { - init_order(ord); + init_order_depr(ord); if (do_command_i(keys, u, ord) != E_TOK_SUCCESS) { char cmd[ORDERSIZE]; get_command(ord, u->faction->locale, cmd, sizeof(cmd)); diff --git a/src/kernel/config.test.c b/src/kernel/config.test.c index ac35b85a3..610c2d4b3 100644 --- a/src/kernel/config.test.c +++ b/src/kernel/config.test.c @@ -32,28 +32,28 @@ static void test_read_unitid(CuTest *tc) { a->data.i = atoi36("42"); /* this unit is also TEMP 42 */ ord = create_order(K_GIVE, lang, "TEMP 42"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, u->no, read_unitid(u->faction, u->region)); free_order(ord); ord = create_order(K_GIVE, lang, "8"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, 8, read_unitid(u->faction, u->region)); free_order(ord); ord = create_order(K_GIVE, lang, ""); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region)); free_order(ord); ord = create_order(K_GIVE, lang, "TEMP"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region)); free_order(ord); /* bug https://bugs.eressea.de/view.php?id=1685 */ ord = create_order(K_GIVE, lang, "##"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, -1, read_unitid(u->faction, u->region)); free_order(ord); @@ -78,42 +78,42 @@ static void test_getunit(CuTest *tc) { r = test_create_region(1, 0, t_plain); ord = create_order(K_GIVE, lang, itoa36(u->no)); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, GET_UNIT, getunit(u->region, u->faction, &u2)); CuAssertPtrEquals(tc, u, u2); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, GET_NOTFOUND, getunit(r, u->faction, &u2)); CuAssertPtrEquals(tc, NULL, u2); free_order(ord); ord = create_order(K_GIVE, lang, itoa36(u->no + 1)); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2)); CuAssertPtrEquals(tc, NULL, u2); free_order(ord); ord = create_order(K_GIVE, lang, "0"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, GET_PEASANTS, getunit(u->region, u->faction, &u2)); CuAssertPtrEquals(tc, NULL, u2); free_order(ord); /* bug https://bugs.eressea.de/view.php?id=1685 */ ord = create_order(K_GIVE, lang, "TEMP ##"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2)); CuAssertPtrEquals(tc, NULL, u2); free_order(ord); /* bug https://bugs.eressea.de/view.php?id=1685 */ ord = create_order(K_GIVE, lang, "##"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, GET_NOTFOUND, getunit(u->region, u->faction, &u2)); CuAssertPtrEquals(tc, NULL, u2); free_order(ord); ord = create_order(K_GIVE, lang, "TEMP 42"); - init_order(ord); + init_order_depr(ord); CuAssertIntEquals(tc, GET_UNIT, getunit(u->region, u->faction, &u2)); CuAssertPtrEquals(tc, u, u2); free_order(ord); diff --git a/src/kernel/order.c b/src/kernel/order.c index 4124651c9..7cdb2961d 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -155,7 +155,7 @@ char* get_command(const order *ord, const struct locale *lang, char *sbuffer, si } if (ord->id < 0) { - skill_t sk = (skill_t)(100-ord->id); + skill_t sk = (skill_t)(100+ord->id); assert(kwd == K_STUDY && sk != SK_MAGIC); text = skillname(sk, lang); } else { @@ -569,7 +569,7 @@ void push_order(order ** ordp, order * ord) static order_data *parser_od; -keyword_t init_order(const struct order *ord) +keyword_t init_order(const struct order *ord, const struct locale *lang) { if (!ord) { release_data(parser_od); @@ -577,19 +577,38 @@ keyword_t init_order(const struct order *ord) return NOKEYWORD; } else { + keyword_t kwd = ORD_KEYWORD(ord); if (parser_od) { /* TODO: warning */ release_data(parser_od); + parser_od = NULL; } - parser_od = load_data(ord->id); - init_tokens_str(OD_STRING(parser_od)); - return ORD_KEYWORD(ord); + if (ord->id < 0) { + skill_t sk = (skill_t)(100 + ord->id); + assert(lang); + assert(kwd == K_STUDY); + init_tokens_str(skillname(sk, lang)); + } + else { + parser_od = load_data(ord->id); + init_tokens_str(OD_STRING(parser_od)); + } + return kwd; } } +keyword_t init_order_depr(const struct order *ord) +{ + if (ord) { + keyword_t kwd = ORD_KEYWORD(ord); + assert(kwd != K_STUDY); + } + return init_order(ord, NULL); +} + void close_orders(void) { if (parser_od) { - init_order(NULL); + (void)init_order(NULL, NULL); } free_data(); } diff --git a/src/kernel/order.h b/src/kernel/order.h index 916055379..0cbe4989c 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -69,7 +69,8 @@ extern "C" { char *write_order(const order * ord, const struct locale *lang, char *buffer, size_t size); - keyword_t init_order(const struct order *ord); + keyword_t init_order_depr(const struct order *ord); + keyword_t init_order(const struct order *ord, const struct locale *lang); void close_orders(void); diff --git a/src/kernel/order.test.c b/src/kernel/order.test.c index 675cd90cf..c892e7e54 100644 --- a/src/kernel/order.test.c +++ b/src/kernel/order.test.c @@ -2,6 +2,8 @@ #include #include "order.h" +#include + #include #include @@ -22,7 +24,7 @@ static void test_create_order(CuTest *tc) { CuAssertIntEquals(tc, K_MOVE, getkeyword(ord)); CuAssertStrEquals(tc, "move NORTH", get_command(ord, lang, cmd, sizeof(cmd))); - CuAssertIntEquals(tc, K_MOVE, init_order(ord)); + CuAssertIntEquals(tc, K_MOVE, init_order_depr(ord)); CuAssertStrEquals(tc, "NORTH", getstrtoken()); free_order(ord); test_cleanup(); @@ -42,7 +44,7 @@ static void test_parse_order(CuTest *tc) { CuAssertIntEquals(tc, K_MOVE, getkeyword(ord)); CuAssertStrEquals(tc, "move NORTH", get_command(ord, lang, cmd, sizeof(cmd))); - CuAssertIntEquals(tc, K_MOVE, init_order(ord)); + CuAssertIntEquals(tc, K_MOVE, init_order_depr(ord)); CuAssertStrEquals(tc, "NORTH", getstrtoken()); free_order(ord); @@ -100,7 +102,7 @@ static void test_parse_make(CuTest *tc) { CuAssertIntEquals(tc, K_MAKE, getkeyword(ord)); CuAssertStrEquals(tc, "MAKE hurrdurr", get_command(ord, lang, cmd, sizeof(cmd))); - CuAssertIntEquals(tc, K_MAKE, init_order(ord)); + CuAssertIntEquals(tc, K_MAKE, init_order_depr(ord)); CuAssertStrEquals(tc, "hurrdurr", getstrtoken()); free_order(ord); test_cleanup(); @@ -123,7 +125,7 @@ static void test_parse_make_temp(CuTest *tc) { CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord)); CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, lang, cmd, sizeof(cmd))); - CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord)); + CuAssertIntEquals(tc, K_MAKETEMP, init_order_depr(ord)); CuAssertStrEquals(tc, "herp", getstrtoken()); free_order(ord); test_cleanup(); @@ -146,7 +148,7 @@ static void test_parse_maketemp(CuTest *tc) { CuAssertPtrNotNull(tc, ord); CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, lang, cmd, sizeof(cmd))); CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord)); - CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord)); + CuAssertIntEquals(tc, K_MAKETEMP, init_order_depr(ord)); CuAssertStrEquals(tc, "herp", getstrtoken()); free_order(ord); test_cleanup(); @@ -160,7 +162,7 @@ static void test_init_order(CuTest *tc) { lang = get_or_create_locale("en"); ord = create_order(K_MAKETEMP, lang, "hurr durr"); - CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord)); + CuAssertIntEquals(tc, K_MAKETEMP, init_order_depr(ord)); CuAssertStrEquals(tc, "hurr", getstrtoken()); CuAssertStrEquals(tc, "durr", getstrtoken()); free_order(ord); @@ -292,10 +294,48 @@ static void test_is_silent(CuTest *tc) { test_cleanup(); } + +static void test_study_orders(CuTest *tc) { + order *ord; + struct locale *lang; + const char *s; + char token[16]; + + test_setup(); + lang = test_create_locale(); + + ord = create_order(K_STUDY, lang, skillname(SK_CROSSBOW, lang)); + CuAssertIntEquals(tc, K_STUDY, getkeyword(ord)); + CuAssertIntEquals(tc, K_STUDY, init_order(ord, lang)); + s = gettoken(token, sizeof(token)); + CuAssertStrEquals(tc, skillname(SK_CROSSBOW, lang), s); + CuAssertPtrEquals(tc, NULL, (void *)getstrtoken()); + free_order(ord); + + ord = create_order(K_STUDY, lang, skillname(SK_MAGIC, lang)); + CuAssertIntEquals(tc, K_STUDY, getkeyword(ord)); + CuAssertIntEquals(tc, K_STUDY, init_order(ord, lang)); + s = gettoken(token, sizeof(token)); + CuAssertStrEquals(tc, skillname(SK_MAGIC, lang), s); + CuAssertPtrEquals(tc, NULL, (void *)getstrtoken()); + free_order(ord); + + ord = create_order(K_STUDY, lang, "%s 100", skillname(SK_MAGIC, lang)); + CuAssertIntEquals(tc, K_STUDY, getkeyword(ord)); + CuAssertIntEquals(tc, K_STUDY, init_order(ord, lang)); + s = gettoken(token, sizeof(token)); + CuAssertStrEquals(tc, skillname(SK_MAGIC, lang), s); + CuAssertIntEquals(tc, 100, getint()); + free_order(ord); + + test_cleanup(); +} + CuSuite *get_order_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_create_order); + SUITE_ADD_TEST(suite, test_study_orders); SUITE_ADD_TEST(suite, test_parse_order); SUITE_ADD_TEST(suite, test_parse_make); SUITE_ADD_TEST(suite, test_parse_make_temp); diff --git a/src/laws.c b/src/laws.c index 7da40f83f..dec35ef8c 100644 --- a/src/laws.c +++ b/src/laws.c @@ -910,7 +910,7 @@ int contact_cmd(unit * u, order * ord) unit *u2; int n; - init_order(ord); + init_order_depr(ord); n = read_unitid(u->faction, u->region); u2 = findunit(n); @@ -960,7 +960,7 @@ int quit_cmd(unit * u, struct order *ord) const char *passwd; keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_QUIT); passwd = gettoken(token, sizeof(token)); if (checkpasswd(f, (const char *)passwd)) { @@ -1146,7 +1146,7 @@ void do_enter(struct region *r, bool is_final_attempt) unit *ulast = NULL; const char * s; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); p = findparam_ex(s, u->faction->locale); id = getid(); @@ -1306,7 +1306,7 @@ int ally_cmd(unit * u, struct order *ord) int keyword, not_kw; const char *s; - init_order(ord); + init_order_depr(ord); f = getfaction(); if (f == NULL || is_monsters(f)) { @@ -1473,7 +1473,7 @@ int prefix_cmd(unit * u, struct order *ord) for (in = pnames; in->lang != lang; in = in->next); } - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); if (!s || !*s) { @@ -1517,7 +1517,7 @@ int display_cmd(unit * u, struct order *ord) const char *str; region *r = u->region; - init_order(ord); + init_order_depr(ord); str = gettoken(token, sizeof(token)); switch (findparam_ex(str, u->faction->locale)) { @@ -1690,7 +1690,7 @@ int name_cmd(struct unit *u, struct order *ord) bool foreign = false; const char *str; - init_order(ord); + init_order_depr(ord); str = gettoken(token, sizeof(token)); p = findparam_ex(str, u->faction->locale); @@ -1948,7 +1948,7 @@ int mail_cmd(unit * u, struct order *ord) const char *s; int n, cont; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); /* Falls kein Parameter, ist das eine Einheitsnummer; @@ -2105,7 +2105,7 @@ int banner_cmd(unit * u, struct order *ord) const char * s; free(u->faction->banner); - init_order(ord); + init_order_depr(ord); s = getstrtoken(); u->faction->banner = s ? strdup(s) : 0; add_message(&u->faction->msgs, msg_message("changebanner", "value", @@ -2118,7 +2118,7 @@ int email_cmd(unit * u, struct order *ord) { const char *s; - init_order(ord); + init_order_depr(ord); s = getstrtoken(); if (!s || !s[0]) { @@ -2144,7 +2144,7 @@ int password_cmd(unit * u, struct order *ord) const char *s; bool pwok = true; - init_order(ord); + init_order_depr(ord); s = gettoken(pwbuf, sizeof(pwbuf)); if (!s || !*s) { @@ -2177,7 +2177,7 @@ int send_cmd(unit * u, struct order *ord) const char *s; int option; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); option = findoption(s, u->faction->locale); @@ -2512,7 +2512,7 @@ int group_cmd(unit * u, struct order *ord) { keyword_t kwd; - kwd = init_order(ord); + kwd = init_order_depr(ord); assert(kwd == K_GROUP); join_group(u, getstrtoken()); return 0; @@ -2522,7 +2522,7 @@ int origin_cmd(unit * u, struct order *ord) { short px, py; - init_order(ord); + init_order_depr(ord); px = (short)getint(); py = (short)getint(); @@ -2534,7 +2534,7 @@ int origin_cmd(unit * u, struct order *ord) int guard_off_cmd(unit * u, struct order *ord) { assert(getkeyword(ord) == K_GUARD); - init_order(ord); + init_order_depr(ord); if (getparam(u->faction->locale) == P_NOT) { setguard(u, false); @@ -2548,7 +2548,7 @@ int reshow_cmd(unit * u, struct order *ord) const char *s; param_t p = NOPARAM; - init_order(ord); + init_order_depr(ord); s = gettoken(lbuf, sizeof(lbuf)); if (s && isparam(s, u->faction->locale, P_ANY)) { @@ -2565,7 +2565,7 @@ int status_cmd(unit * u, struct order *ord) char token[128]; const char *s; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); switch (findparam(s, u->faction->locale)) { case P_NOT: @@ -2613,7 +2613,7 @@ int combatspell_cmd(unit * u, struct order *ord) int level = 0; spell *sp = 0; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); /* KAMPFZAUBER [NICHT] löscht alle gesetzten Kampfzauber */ @@ -2658,7 +2658,7 @@ int guard_on_cmd(unit * u, struct order *ord) assert(u); assert(u->faction); - init_order(ord); + init_order_depr(ord); /* GUARD NOT is handled in goard_off_cmd earlier in the turn */ if (getparam(u->faction->locale) == P_NOT) { @@ -2739,7 +2739,7 @@ void restack_units(void) int id; unit *v; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); p = findparam(s, u->faction->locale); id = getid(); @@ -3049,7 +3049,7 @@ void maketemp_cmd(unit *u, order **olist) unit *u2; order **ordp, **oinsert; #ifndef NDEBUG - keyword_t kwd = init_order(makeord); + keyword_t kwd = init_order_depr(makeord); assert(kwd == K_MAKETEMP); #endif alias = getid(); @@ -3347,7 +3347,7 @@ void defaultorders(void) char lbuf[8192]; order *new_order = 0; const char *s; - init_order(ord); + init_order_depr(ord); s = gettoken(lbuf, sizeof(lbuf)); if (s) { new_order = parse_order(s, u->faction->locale); @@ -3463,7 +3463,7 @@ int use_cmd(unit * u, struct order *ord) int n, err = ENOITEM; const item_type *itype; - init_order(ord); + init_order_depr(ord); t = gettoken(token, sizeof(token)); if (!t) { @@ -3518,7 +3518,7 @@ int pay_cmd(unit * u, struct order *ord) param_t p; int id; - init_order(ord); + init_order_depr(ord); p = getparam(u->faction->locale); id = getid(); if (p == P_NOT) { @@ -3572,7 +3572,7 @@ static int reserve_i(unit * u, struct order *ord, int flags) const item_type *itype; const char *s; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); count = s ? atoip(s) : 0; para = findparam(s, u->faction->locale); @@ -3615,7 +3615,7 @@ int claim_cmd(unit * u, struct order *ord) int n = 1; const item_type *itype = 0; - init_order(ord); + init_order_depr(ord); t = gettoken(token, sizeof(token)); if (t) { @@ -3909,7 +3909,7 @@ int siege_cmd(unit * u, order * ord) resource_type *rt_catapultammo = NULL; resource_type *rt_catapult = NULL; - init_order(ord); + init_order_depr(ord); b = getbuilding(r); if (!b) { diff --git a/src/magic.c b/src/magic.c index f83e31a7d..c8f1b83c3 100644 --- a/src/magic.c +++ b/src/magic.c @@ -2514,7 +2514,7 @@ static castorder *cast_cmd(unit * u, order * ord) } level = effskill(u, SK_MAGIC, 0); - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); param = findparam(s, u->faction->locale); /* für Syntax ' STUFE x REGION y z ' */ diff --git a/src/move.c b/src/move.c index 3f899ac22..5a9e51b43 100644 --- a/src/move.c +++ b/src/move.c @@ -1067,7 +1067,7 @@ static void cycle_route(order * ord, unit * u, int gereist) return; tail[0] = '\0'; - init_order(ord); + init_order_depr(ord); neworder[0] = 0; for (cm = 0;; ++cm) { @@ -1144,7 +1144,7 @@ static bool transport(unit * ut, unit * u) for (ord = ut->orders; ord; ord = ord->next) { if (getkeyword(ord) == K_TRANSPORT) { unit *u2; - init_order(ord); + init_order_depr(ord); getunit(ut->region, ut->faction, &u2); if (u2 == u) { return true; @@ -1178,7 +1178,7 @@ static void init_transportation(void) && !fval(u, UFL_NOTMOVING) && !LongHunger(u)) { unit *ut = 0; - init_order(u->thisorder); + init_order_depr(u->thisorder); if (getunit(r, u->faction, &ut) != GET_UNIT) { ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "feedback_unit_not_found", "")); @@ -1207,7 +1207,7 @@ static void init_transportation(void) for (ord = u->orders; ord; ord = ord->next) { if (getkeyword(ord) == K_TRANSPORT) { - init_order(ord); + init_order_depr(ord); for (;;) { unit *ut = 0; @@ -1218,7 +1218,7 @@ static void init_transportation(void) can_move(ut) && !fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) { unit *u2; - init_order(ut->thisorder); + init_order_depr(ut->thisorder); getunit(r, ut->faction, &u2); if (u2 == u) { w += weight(ut); @@ -2062,7 +2062,7 @@ static const region_list *travel_i(unit * u, const region_list * route_begin, if (getkeyword(ord) != K_TRANSPORT) continue; - init_order(ord); + init_order_depr(ord); if (getunit(r, u->faction, &ut) == GET_UNIT) { if (getkeyword(ut->thisorder) == K_DRIVE) { if (ut->building && !can_leave(ut)) { @@ -2077,7 +2077,7 @@ static const region_list *travel_i(unit * u, const region_list * route_begin, if (!fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) { unit *u2; - init_order(ut->thisorder); + init_order_depr(ut->thisorder); getunit(u->region, ut->faction, &u2); if (u2 == u) { const region_list *route_to = @@ -2363,7 +2363,7 @@ static void move_hunters(void) if (getkeyword(ord) == K_FOLLOW) { param_t p; - init_order(ord); + init_order_depr(ord); p = getparam(u->faction->locale); if (p != P_SHIP) { if (p != P_UNIT) { @@ -2485,13 +2485,13 @@ void movement(void) else { if (ships) { if (u->ship && ship_owner(u->ship) == u) { - init_order(u->thisorder); + init_order_depr(u->thisorder); move_cmd(u, u->thisorder); } } else { if (!u->ship || ship_owner(u->ship) != u) { - init_order(u->thisorder); + init_order_depr(u->thisorder); move_cmd(u, u->thisorder); } } @@ -2548,7 +2548,7 @@ void follow_unit(unit * u) if (getkeyword(ord) == K_FOLLOW) { int id; param_t p; - init_order(ord); + init_order_depr(ord); p = getparam(lang); if (p == P_UNIT) { id = read_unitid(u->faction, r); diff --git a/src/move.test.c b/src/move.test.c index c8fdb2436..908da0bb7 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -462,7 +462,7 @@ static void test_follow_ship_msg(CuTest * tc) { mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order", 0)); - init_order(ord); + init_order_depr(ord); getstrtoken(); follow_ship(u, ord); diff --git a/src/piracy.c b/src/piracy.c index 3025d484c..b74a0b363 100644 --- a/src/piracy.c +++ b/src/piracy.c @@ -86,7 +86,7 @@ int *parse_ids(const order *ord) { const char *s; int *il = NULL; - init_order(ord); + init_order_depr(ord); s = getstrtoken(); if (s != NULL && *s) { il = intlist_init(); @@ -211,7 +211,7 @@ void piracy_cmd(unit * u) ord = create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[target_dir])); /* Bewegung ausführen */ - init_order(ord); + init_order_depr(ord); move_cmd(u, ord); free_order(ord); } diff --git a/src/renumber.c b/src/renumber.c index 30769403f..ec9d61c66 100644 --- a/src/renumber.c +++ b/src/renumber.c @@ -80,7 +80,7 @@ int renumber_cmd(unit * u, order * ord) int i = 0; faction *f = u->faction; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); switch (findparam_ex(s, u->faction->locale)) { diff --git a/src/spy.c b/src/spy.c index ae01656bf..ff1f6da4e 100644 --- a/src/spy.c +++ b/src/spy.c @@ -126,7 +126,7 @@ int spy_cmd(unit * u, struct order *ord) double spychance, observechance; region *r = u->region; - init_order(ord); + init_order_depr(ord); getunit(r, u->faction, &target); if (!target) { @@ -219,7 +219,7 @@ int setstealth_cmd(unit * u, struct order *ord) const char *s; int level; - init_order(ord); + init_order_depr(ord); s = gettoken(token, sizeof(token)); /* Tarne ohne Parameter: Setzt maximale Tarnung */ @@ -494,10 +494,10 @@ int sabotage_cmd(unit * u, struct order *ord) assert(u); assert(ord); - init_order(ord); + init_order_depr(ord); s = getstrtoken(); p = findparam(s, u->faction->locale); - init_order(NULL); + init_order_depr(NULL); switch (p) { case P_SHIP: diff --git a/src/study.c b/src/study.c index a66efd662..9264f9060 100644 --- a/src/study.c +++ b/src/study.c @@ -283,7 +283,7 @@ int teach_cmd(unit * teacher, struct order *ord) count = 0; - init_order(ord); + init_order_depr(ord); #if TEACH_ALL if (getparam(teacher->faction->locale) == P_ANY) { @@ -304,7 +304,7 @@ int teach_cmd(unit * teacher, struct order *ord) else if (student->faction == teacher->faction) { if (getkeyword(student->thisorder) == K_STUDY) { /* Input ist nun von student->thisorder !! */ - init_order(student->thisorder); + init_order(student->thisorder, student->faction->locale); sk = getskill(student->faction->locale); if (sk != NOSKILL && teachskill[0] != NOSKILL) { for (t = 0; teachskill[t] != NOSKILL; ++t) { @@ -324,7 +324,7 @@ int teach_cmd(unit * teacher, struct order *ord) else if (alliedunit(teacher, student->faction, HELP_GUARD)) { if (getkeyword(student->thisorder) == K_STUDY) { /* Input ist nun von student->thisorder !! */ - init_order(student->thisorder); + init_order(student->thisorder, student->faction->locale); sk = getskill(student->faction->locale); if (sk != NOSKILL && effskill_study(teacher, sk, 0) - TEACHDIFFERENCE >= effskill(student, sk, 0)) { @@ -343,7 +343,7 @@ int teach_cmd(unit * teacher, struct order *ord) order *new_order; zOrder[0] = '\0'; - init_order(ord); + init_order_depr(ord); while (!parser_end()) { skill_t sk; @@ -361,7 +361,7 @@ int teach_cmd(unit * teacher, struct order *ord) const char *token; /* Finde den string, der den Fehler verursacht hat */ parser_pushstate(); - init_order(ord); + init_order_depr(ord); for (j = 0; j != count - 1; ++j) { /* skip over the first 'count' units */ @@ -406,7 +406,7 @@ int teach_cmd(unit * teacher, struct order *ord) /* Input ist nun von student->thisorder !! */ parser_pushstate(); - init_order(student->thisorder); + init_order(student->thisorder, student->faction->locale); sk = getskill(student->faction->locale); parser_popstate(); @@ -448,7 +448,7 @@ int teach_cmd(unit * teacher, struct order *ord) if (academy_students > 0 && sk_academy!=NOSKILL) { academy_teaching_bonus(teacher, sk_academy, academy_students); } - init_order(NULL); + init_order_depr(NULL); return 0; } @@ -557,7 +557,7 @@ int study_cmd(unit * u, order * ord) return 0; } - init_order(ord); + (void)init_order(ord, u->faction->locale); sk = getskill(u->faction->locale); if (sk < 0) { @@ -785,7 +785,7 @@ int study_cmd(unit * u, order * ord) mage = create_mage(u, u->faction->magiegebiet); } } - init_order(NULL); + init_order_depr(NULL); return 0; }