diff --git a/CMakeSettings.json b/CMakeSettings.json index 934963e60..8bf3c23fc 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -1,11 +1,11 @@ -{ +{ "configurations": [ { "name": "x64-Debug", "generator": "Ninja", "configurationType": "Debug", "inheritEnvironments": [ "msvc_x64_x64" ], - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", + "buildRoot": "${projectDir}\\out\\build\\${name}", "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "cmakeCommandArgs": "", "buildCommandArgs": "-v", @@ -36,4 +36,4 @@ "variables": [] } ] -} +} \ No newline at end of file diff --git a/src/economy.c b/src/economy.c index e638afff5..016d09ff8 100644 --- a/src/economy.c +++ b/src/economy.c @@ -393,10 +393,15 @@ void economics(region * r) for (u = r->units; u; u = u->next) { order *ord; if (u->number > 0) { + order* transfer = NULL; for (ord = u->orders; ord; ord = ord->next) { keyword_t kwd = getkeyword(ord); if (kwd == K_GIVE) { - give_cmd(u, ord); + param_t p = give_cmd(u, ord); + /* deal with GIVE UNIT later */ + if (p == P_UNIT && !transfer) { + transfer = ord; + } } else if (kwd == K_FORGET) { forget_cmd(u, ord); @@ -405,6 +410,15 @@ void economics(region * r) break; } } + if (transfer) { + for (ord = transfer; ord; ord = ord->next) { + keyword_t kwd = getkeyword(ord); + if (kwd == K_GIVE) { + give_unit_cmd(u, ord); + break; + } + } + } } } } diff --git a/src/give.c b/src/give.c index bf9bba95e..8b2e5feb2 100644 --- a/src/give.c +++ b/src/give.c @@ -813,9 +813,42 @@ static void give_all_items(unit *u, unit *u2, order *ord) { } } -void give_cmd(unit * u, order * ord) +void give_unit_cmd(unit* u, order* ord) { - char token[128]; + char token[64]; + unit* u2; + message* msg = NULL; + keyword_t kwd; + int err; + + kwd = init_order(ord, NULL); + assert(kwd == K_GIVE); + err = getunit(u->region, u->faction, &u2); + + if (err == GET_NOTFOUND || (err != GET_PEASANTS && !can_give_to(u, u2))) { + msg = msg_feedback(u, ord, "feedback_unit_not_found", ""); + } + else { + msg = check_give(u, u2, ord); + } + + if (msg) { + ADDMSG(&u->faction->msgs, msg); + } + else if (!(u_race(u)->ec_flags & ECF_GIVEUNIT)) { + cmistake(u, ord, 167, MSG_COMMERCE); + } + else { + param_t p = findparam(gettoken(token, sizeof(token)), u->faction->locale); + if (p == P_UNIT) { + give_unit(u, u2, ord); + } + } +} + +param_t give_cmd(unit * u, order * ord) +{ + char token[64]; region *r = u->region; unit *u2; const char *s; @@ -828,41 +861,44 @@ void give_cmd(unit * u, order * ord) kwd = init_order(ord, NULL); assert(kwd == K_GIVE); + err = getunit(r, u->faction, &u2); s = gettoken(token, sizeof(token)); n = s ? atoip(s) : 0; p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale); - /* first, do all the ones that do not require HELP_GIVE or CONTACT */ - if (p == P_CONTROL) { - /* handled in give_control_cmd */ - return; - } - else if (p == P_SHIP) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "give_number_missing", "resource", "ship_p")); - return; - } - else if (p == P_PERSON) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "give_number_missing", "resource", "person_p")); - return; + /* quick exit before any errors are generated: */ + if (p == P_UNIT || p == P_CONTROL) { + /* handled in give_unit_cmd */ + return p; } if (err == GET_NOTFOUND || (err != GET_PEASANTS && !can_give_to(u, u2))) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", "")); - return; + return NOPARAM; } if (u == u2) { cmistake(u, ord, 8, MSG_COMMERCE); - return; + return NOPARAM; + } + + /* first, do all the ones that do not require HELP_GIVE or CONTACT */ + if (p == P_SHIP) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "give_number_missing", "resource", "ship_p")); + return p; + } + else if (p == P_PERSON) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "give_number_missing", "resource", "person_p")); + return p; } msg = check_give(u, u2, ord); if (msg) { ADDMSG(&u->faction->msgs, msg); - return; + return p; } /* UFL_TAKEALL ist ein grober Hack. Generalisierung tut not, ist aber nicht @@ -870,12 +906,12 @@ void give_cmd(unit * u, order * ord) pl = rplane(r); if (pl && fval(pl, PFL_NOGIVE) && (!u2 || !fval(u2, UFL_TAKEALL))) { cmistake(u, ord, 268, MSG_COMMERCE); - return; + return p; } if (u2 && !alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) { cmistake(u, ord, 40, MSG_COMMERCE); - return; + return p; } else if (p == NOPARAM) { /* the most likely case: giving items to someone. @@ -886,17 +922,15 @@ void give_cmd(unit * u, order * ord) bool given = false; if (!can_give(u, u2, NULL, GIVE_HERBS)) { feedback_give_not_allowed(u, ord); - return; } - if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { + else if (u2 && !(u_race(u2)->ec_flags & ECF_GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); - return; } - if (u->items) { - item **itmp = &u->items; + else if (u->items) { + item** itmp = &u->items; while (*itmp) { - item *itm = *itmp; + item* itm = *itmp; if (fval(itm->type, ITF_HERB) && itm->number > 0) { /* give_item aendert im fall,das man alles uebergibt, die * item-liste der unit, darum continue vor pointerumsetzten */ @@ -907,38 +941,27 @@ void give_cmd(unit * u, order * ord) } itmp = &itm->next; } + if (!given) { + cmistake(u, ord, 38, MSG_COMMERCE); + } } - if (!given) { - cmistake(u, ord, 38, MSG_COMMERCE); - } - return; + return p; } else if (p == P_ZAUBER) { cmistake(u, ord, 7, MSG_COMMERCE); /* geht nimmer */ - return; + return p; } - - else if (p == P_UNIT) { /* Einheiten uebergeben */ - if (!(u_race(u)->ec_flags & ECF_GIVEUNIT)) { - cmistake(u, ord, 167, MSG_COMMERCE); - return; - } - - give_unit(u, u2, ord); - return; - } - else if (p == P_ANY) { give_all_items(u, u2, ord); - return; + return p; } else if (p == P_EACH) { if (u2 == NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "peasants_give_invalid", "")); - return; + return p; } s = gettoken(token, sizeof(token)); /* skip one ahead to get the amount. */ n = s ? atoip(s) : 0; /* n: Anzahl */ @@ -948,59 +971,59 @@ void give_cmd(unit * u, order * ord) if (s == NULL) { cmistake(u, ord, 113, MSG_COMMERCE); - return; } - - p = findparam(s, u->faction->locale); - if (p == P_SHIP) { - if (u->ship) { - message * msg; - if (n > u->ship->number) { - n = u->ship->number; + else { + p = findparam(s, u->faction->locale); + if (p == P_SHIP) { + if (u->ship) { + message* msg; + if (n > u->ship->number) { + n = u->ship->number; + } + msg = give_ship(u, u2, n, ord); + if (msg) { + ADDMSG(&u->faction->msgs, msg); + } } - msg = give_ship(u, u2, n, ord); - if (msg) { - ADDMSG(&u->faction->msgs, msg); + else { + cmistake(u, ord, 144, MSG_COMMERCE); } } - else { - cmistake(u, ord, 144, MSG_COMMERCE); + else if (p == P_PERSON) { + if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { + ADDMSG(&u->faction->msgs, + msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); + } + else { + if (n > u->number) { + n = u->number; + } + msg = u2 ? give_men(n, u, u2, ord) : disband_men(n, u, ord); + if (msg) { + ADDMSG(&u->faction->msgs, msg); + } + } } - return; - } - else if (p == P_PERSON) { - if (!(u_race(u)->ec_flags & ECF_GIVEPERSON)) { - ADDMSG(&u->faction->msgs, - msg_feedback(u, ord, "race_noregroup", "race", u_race(u))); - return; - } - if (n > u->number) n = u->number; - msg = u2 ? give_men(n, u, u2, ord) : disband_men(n, u, ord); - if (msg) { - ADDMSG(&u->faction->msgs, msg); - } - return; - } - - if (u2 != NULL) { - if (!(u_race(u2)->ec_flags & ECF_GETITEM)) { + else if (u2 != NULL && !(u_race(u2)->ec_flags & ECF_GETITEM)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_notake", "race", u_race(u2))); - return; - } - } - - itype = finditemtype(s, u->faction->locale); - if (itype != NULL) { - if (can_give(u, u2, itype, 0)) { - give_item(n, itype, u, u2, ord); } else { - feedback_give_not_allowed(u, ord); + itype = finditemtype(s, u->faction->locale); + if (itype != NULL) { + if (can_give(u, u2, itype, 0)) { + give_item(n, itype, u, u2, ord); + } + else { + feedback_give_not_allowed(u, ord); + } + } + else { + cmistake(u, ord, 123, MSG_COMMERCE); + } } - return; } - cmistake(u, ord, 123, MSG_COMMERCE); + return p; } message *check_give(const unit *u, const unit *u2, order * ord) { diff --git a/src/give.h b/src/give.h index b0edc58a9..8c6fbaa52 100644 --- a/src/give.h +++ b/src/give.h @@ -11,6 +11,7 @@ extern "C" { struct order; struct unit; struct message; + enum param_t; int give_item(int want, const struct item_type *itype, struct unit *src, struct unit *dest, struct order *ord); @@ -19,7 +20,8 @@ extern "C" { struct order *ord); int give_unit_allowed(const struct unit * u); void give_unit(struct unit *u, struct unit *u2, struct order *ord); - void give_cmd(struct unit * u, struct order * ord); + void give_unit_cmd(struct unit* u, struct order* ord); + enum param_t give_cmd(struct unit * u, struct order * ord); struct message * check_give(const struct unit * u, const struct unit * u2, struct order *ord); bool can_give_to(struct unit *u, struct unit *u2); bool rule_transfermen(void); diff --git a/src/util/param.c b/src/util/param.c index 38a33d322..d3501dbaf 100644 --- a/src/util/param.c +++ b/src/util/param.c @@ -65,7 +65,7 @@ param_t findparam(const char *s, const struct locale * lang) { param_t result = NOPARAM; char buffer[64]; - char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : 0; + char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : NULL; if (str && str[0] && str[1]) { int i; diff --git a/tests/runtests.bat b/tests/runtests.bat index 5925f07e3..c8b4ec03b 100644 --- a/tests/runtests.bat +++ b/tests/runtests.bat @@ -1,11 +1,4 @@ @ECHO OFF -IF EXIST ..\build-vs10 SET BUILD=..\build-vs10\Debug -IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\\Debug -IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\Debug -IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\Debug -IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\Debug -IF EXIST ..\build-vs16 SET BUILD=..\build-vs16\Debug -IF EXIST ..\out\build\x86-Debug\eressea.exe SET BUILD=..\out\build\x86-Debug IF EXIST ..\out\build\x64-Debug\eressea.exe SET BUILD=..\out\build\x64-Debug SET SERVER=%BUILD%\eressea.exe