Merge branch 'develop' of github.com:eressea/server into develop

This commit is contained in:
Enno Rehling 2021-03-06 21:31:16 +01:00
commit 1d6825f179
6 changed files with 132 additions and 100 deletions

View File

@ -1,11 +1,11 @@
{ {
"configurations": [ "configurations": [
{ {
"name": "x64-Debug", "name": "x64-Debug",
"generator": "Ninja", "generator": "Ninja",
"configurationType": "Debug", "configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ], "inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", "buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
"cmakeCommandArgs": "", "cmakeCommandArgs": "",
"buildCommandArgs": "-v", "buildCommandArgs": "-v",
@ -36,4 +36,4 @@
"variables": [] "variables": []
} }
] ]
} }

View File

@ -393,10 +393,15 @@ void economics(region * r)
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
order *ord; order *ord;
if (u->number > 0) { if (u->number > 0) {
order* transfer = NULL;
for (ord = u->orders; ord; ord = ord->next) { for (ord = u->orders; ord; ord = ord->next) {
keyword_t kwd = getkeyword(ord); keyword_t kwd = getkeyword(ord);
if (kwd == K_GIVE) { 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) { else if (kwd == K_FORGET) {
forget_cmd(u, ord); forget_cmd(u, ord);
@ -405,6 +410,15 @@ void economics(region * r)
break; 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;
}
}
}
} }
} }
} }

View File

@ -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; region *r = u->region;
unit *u2; unit *u2;
const char *s; const char *s;
@ -828,41 +861,44 @@ void give_cmd(unit * u, order * ord)
kwd = init_order(ord, NULL); kwd = init_order(ord, NULL);
assert(kwd == K_GIVE); assert(kwd == K_GIVE);
err = getunit(r, u->faction, &u2); err = getunit(r, u->faction, &u2);
s = gettoken(token, sizeof(token)); s = gettoken(token, sizeof(token));
n = s ? atoip(s) : 0; n = s ? atoip(s) : 0;
p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale); p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale);
/* first, do all the ones that do not require HELP_GIVE or CONTACT */ /* quick exit before any errors are generated: */
if (p == P_CONTROL) { if (p == P_UNIT || p == P_CONTROL) {
/* handled in give_control_cmd */ /* handled in give_unit_cmd */
return; return p;
}
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;
} }
if (err == GET_NOTFOUND || (err != GET_PEASANTS && !can_give_to(u, u2))) { if (err == GET_NOTFOUND || (err != GET_PEASANTS && !can_give_to(u, u2))) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "feedback_unit_not_found", "")); msg_feedback(u, ord, "feedback_unit_not_found", ""));
return; return NOPARAM;
} }
if (u == u2) { if (u == u2) {
cmistake(u, ord, 8, MSG_COMMERCE); 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); msg = check_give(u, u2, ord);
if (msg) { if (msg) {
ADDMSG(&u->faction->msgs, msg); ADDMSG(&u->faction->msgs, msg);
return; return p;
} }
/* UFL_TAKEALL ist ein grober Hack. Generalisierung tut not, ist aber nicht /* 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); pl = rplane(r);
if (pl && fval(pl, PFL_NOGIVE) && (!u2 || !fval(u2, UFL_TAKEALL))) { if (pl && fval(pl, PFL_NOGIVE) && (!u2 || !fval(u2, UFL_TAKEALL))) {
cmistake(u, ord, 268, MSG_COMMERCE); cmistake(u, ord, 268, MSG_COMMERCE);
return; return p;
} }
if (u2 && !alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) { if (u2 && !alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) {
cmistake(u, ord, 40, MSG_COMMERCE); cmistake(u, ord, 40, MSG_COMMERCE);
return; return p;
} }
else if (p == NOPARAM) { else if (p == NOPARAM) {
/* the most likely case: giving items to someone. /* the most likely case: giving items to someone.
@ -886,17 +922,15 @@ void give_cmd(unit * u, order * ord)
bool given = false; bool given = false;
if (!can_give(u, u2, NULL, GIVE_HERBS)) { if (!can_give(u, u2, NULL, GIVE_HERBS)) {
feedback_give_not_allowed(u, ord); 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, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_notake", "race", u_race(u2))); msg_feedback(u, ord, "race_notake", "race", u_race(u2)));
return;
} }
if (u->items) { else if (u->items) {
item **itmp = &u->items; item** itmp = &u->items;
while (*itmp) { while (*itmp) {
item *itm = *itmp; item* itm = *itmp;
if (fval(itm->type, ITF_HERB) && itm->number > 0) { if (fval(itm->type, ITF_HERB) && itm->number > 0) {
/* give_item aendert im fall,das man alles uebergibt, die /* give_item aendert im fall,das man alles uebergibt, die
* item-liste der unit, darum continue vor pointerumsetzten */ * item-liste der unit, darum continue vor pointerumsetzten */
@ -907,38 +941,27 @@ void give_cmd(unit * u, order * ord)
} }
itmp = &itm->next; itmp = &itm->next;
} }
if (!given) {
cmistake(u, ord, 38, MSG_COMMERCE);
}
} }
if (!given) { return p;
cmistake(u, ord, 38, MSG_COMMERCE);
}
return;
} }
else if (p == P_ZAUBER) { else if (p == P_ZAUBER) {
cmistake(u, ord, 7, MSG_COMMERCE); cmistake(u, ord, 7, MSG_COMMERCE);
/* geht nimmer */ /* 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) { else if (p == P_ANY) {
give_all_items(u, u2, ord); give_all_items(u, u2, ord);
return; return p;
} }
else if (p == P_EACH) { else if (p == P_EACH) {
if (u2 == NULL) { if (u2 == NULL) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "peasants_give_invalid", "")); msg_feedback(u, ord, "peasants_give_invalid", ""));
return; return p;
} }
s = gettoken(token, sizeof(token)); /* skip one ahead to get the amount. */ s = gettoken(token, sizeof(token)); /* skip one ahead to get the amount. */
n = s ? atoip(s) : 0; /* n: Anzahl */ n = s ? atoip(s) : 0; /* n: Anzahl */
@ -948,59 +971,59 @@ void give_cmd(unit * u, order * ord)
if (s == NULL) { if (s == NULL) {
cmistake(u, ord, 113, MSG_COMMERCE); cmistake(u, ord, 113, MSG_COMMERCE);
return;
} }
else {
p = findparam(s, u->faction->locale); p = findparam(s, u->faction->locale);
if (p == P_SHIP) { if (p == P_SHIP) {
if (u->ship) { if (u->ship) {
message * msg; message* msg;
if (n > u->ship->number) { if (n > u->ship->number) {
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); else {
if (msg) { cmistake(u, ord, 144, MSG_COMMERCE);
ADDMSG(&u->faction->msgs, msg);
} }
} }
else { else if (p == P_PERSON) {
cmistake(u, ord, 144, MSG_COMMERCE); 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 (u2 != NULL && !(u_race(u2)->ec_flags & ECF_GETITEM)) {
}
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)) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_notake", "race", u_race(u2))); 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 { 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) { message *check_give(const unit *u, const unit *u2, order * ord) {

View File

@ -11,6 +11,7 @@ extern "C" {
struct order; struct order;
struct unit; struct unit;
struct message; struct message;
enum param_t;
int give_item(int want, const struct item_type *itype, int give_item(int want, const struct item_type *itype,
struct unit *src, struct unit *dest, struct order *ord); struct unit *src, struct unit *dest, struct order *ord);
@ -19,7 +20,8 @@ extern "C" {
struct order *ord); struct order *ord);
int give_unit_allowed(const struct unit * u); int give_unit_allowed(const struct unit * u);
void give_unit(struct unit *u, struct unit *u2, struct order *ord); 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); 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 can_give_to(struct unit *u, struct unit *u2);
bool rule_transfermen(void); bool rule_transfermen(void);

View File

@ -65,7 +65,7 @@ param_t findparam(const char *s, const struct locale * lang)
{ {
param_t result = NOPARAM; param_t result = NOPARAM;
char buffer[64]; 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]) { if (str && str[0] && str[1]) {
int i; int i;

View File

@ -1,11 +1,4 @@
@ECHO OFF @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 IF EXIST ..\out\build\x64-Debug\eressea.exe SET BUILD=..\out\build\x64-Debug
SET SERVER=%BUILD%\eressea.exe SET SERVER=%BUILD%\eressea.exe