implementation of "EACH":

GIVE abcd EACH 1 sword
  GIB abcd JE[DEM] 1 schwert
This commit is contained in:
Enno Rehling 2006-10-03 12:02:27 +00:00
parent 31b8b57b77
commit 79134609a2
5 changed files with 70 additions and 41 deletions

View file

@ -563,6 +563,7 @@ give_cmd(unit * u, order * ord)
int i, n; int i, n;
const item_type * itype; const item_type * itype;
int notfound_error = 63; int notfound_error = 63;
param_t p;
init_tokens(ord); init_tokens(ord);
skip_token(); skip_token();
@ -591,8 +592,9 @@ give_cmd(unit * u, order * ord)
} }
s = getstrtoken(); s = getstrtoken();
p = findparam(s, u->faction->locale);
if (findparam(s, u->faction->locale) == P_CONTROL) { if (p == P_CONTROL) {
if (!u2) { if (!u2) {
cmistake(u, ord, notfound_error, MSG_EVENT); cmistake(u, ord, notfound_error, MSG_EVENT);
return; return;
@ -629,19 +631,20 @@ give_cmd(unit * u, order * ord)
} }
return; return;
} }
if (u2 && u2->race == new_race[RC_SPELL]) {
else if (u2 && u2->race == new_race[RC_SPELL]) {
cmistake(u, ord, notfound_error, MSG_COMMERCE); cmistake(u, ord, notfound_error, MSG_COMMERCE);
return; return;
} }
/* if ((u->race->ec_flags & NOGIVE) || fval(u,UFL_LOCKED)) {*/ /* if ((u->race->ec_flags & NOGIVE) || fval(u,UFL_LOCKED)) {*/
if (u->race->ec_flags & NOGIVE && u2!=NULL) { else if (u->race->ec_flags & NOGIVE && u2!=NULL) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_nogive", "race", u->race)); msg_feedback(u, ord, "race_nogive", "race", u->race));
return; return;
} }
/* sperrt hier auch personenübergaben! /* sperrt hier auch personenübergaben!
if (u2 && !(u2->race->ec_flags & GETITEM)) { else if (u2 && !(u2->race->ec_flags & GETITEM)) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_notake", "race", u2->race)); msg_feedback(u, ord, "race_notake", "race", u2->race));
return; return;
@ -649,7 +652,7 @@ give_cmd(unit * u, order * ord)
*/ */
/* Übergabe aller Kräuter */ /* Übergabe aller Kräuter */
if (findparam(s, u->faction->locale) == P_HERBS) { else if (p == P_HERBS) {
boolean given = false; boolean given = false;
if (!(u->race->ec_flags & GIVEITEM) && u2!=NULL) { if (!(u->race->ec_flags & GIVEITEM) && u2!=NULL) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
@ -685,12 +688,14 @@ give_cmd(unit * u, order * ord)
if (!given) cmistake(u, ord, 38, MSG_COMMERCE); if (!given) cmistake(u, ord, 38, MSG_COMMERCE);
return; return;
} }
if (findparam(s, u->faction->locale) == 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;
} }
if (findparam(s, u->faction->locale) == P_UNIT) { /* Einheiten uebergeben */
else if (p == P_UNIT) { /* Einheiten uebergeben */
if (!(u->race->ec_flags & GIVEUNIT)) { if (!(u->race->ec_flags & GIVEUNIT)) {
cmistake(u, ord, 167, MSG_COMMERCE); cmistake(u, ord, 167, MSG_COMMERCE);
return; return;
@ -703,15 +708,18 @@ give_cmd(unit * u, order * ord)
give_unit(u, u2, ord); give_unit(u, u2, ord);
return; return;
} }
if (findparam(s, u->faction->locale) == P_ANY) { /* Alle Gegenstände übergeben */
else if (p==P_ANY) {
const char * s = getstrtoken(); const char * s = getstrtoken();
if (u2 && !alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) { if (*s == 0) { /* Alle Gegenstände übergeben */
cmistake(u, ord, 40, MSG_COMMERCE);
return;
}
if (*s == 0) { if (u2 && !alliedunit(u2, u->faction, HELP_GIVE) && !ucontact(u2, u)) {
cmistake(u, ord, 40, MSG_COMMERCE);
return;
}
/* do these checks once, not for each item we have: */
if (!(u->race->ec_flags & GIVEITEM) && u2!=NULL) { if (!(u->race->ec_flags & GIVEITEM) && u2!=NULL) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_nogive", "race", u->race)); msg_feedback(u, ord, "race_nogive", "race", u->race));
@ -724,7 +732,7 @@ give_cmd(unit * u, order * ord)
} }
/* für alle items einmal prüfen, ob wir mehr als von diesem Typ /* für alle items einmal prüfen, ob wir mehr als von diesem Typ
* reserviert ist besitzen und diesen Teil dann übergeben */ * reserviert ist besitzen und diesen Teil dann übergeben */
if (u->items) { if (u->items) {
item **itmp=&u->items; item **itmp=&u->items;
while (*itmp) { while (*itmp) {
@ -739,41 +747,54 @@ give_cmd(unit * u, order * ord)
} }
return; return;
} }
i = findparam(s, u->faction->locale); else {
if (i == P_PERSON) { param_t p2 = findparam(s, u->faction->locale);
if (!(u->race->ec_flags & GIVEPERSON)) {
if (p2 == P_PERSON) {
if (!(u->race->ec_flags & GIVEPERSON)) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_noregroup", "race", u->race));
return;
}
n = u->number;
give_men(n, u, u2, ord);
return;
}
if (!(u->race->ec_flags & GIVEITEM) && u2!=NULL) {
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_noregroup", "race", u->race)); msg_feedback(u, ord, "race_nogive", "race", u->race));
return; return;
} }
n = u->number; if (u2 && !(u2->race->ec_flags & GETITEM)) {
give_men(n, u, u2, ord); ADDMSG(&u->faction->msgs,
return; msg_feedback(u, ord, "race_notake", "race", u2->race));
}
if (!(u->race->ec_flags & GIVEITEM) && u2!=NULL) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_nogive", "race", u->race));
return;
}
if (u2 && !(u2->race->ec_flags & GETITEM)) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "race_notake", "race", u2->race));
return;
}
itype = finditemtype(s, u->faction->locale);
if (itype!=NULL) {
item * i = *i_find(&u->items, itype);
if (i!=NULL) {
n = i->number - get_reservation(u, itype->rtype);
give_item(n, itype, u, u2, ord);
return; return;
} }
itype = finditemtype(s, u->faction->locale);
if (itype!=NULL) {
item * i = *i_find(&u->items, itype);
if (i!=NULL) {
n = i->number - get_reservation(u, itype->rtype);
give_item(n, itype, u, u2, ord);
return;
}
}
} }
} else if (p==P_EACH) {
if (u2==NULL) {
ADDMSG(&u->faction->msgs,
msg_feedback(u, ord, "peasants_give_invalid", ""));
return;
}
s = getstrtoken(); /* skip one ahead to get the amount. */
} }
n = atoip(s); /* n: anzahl */ n = atoip(s); /* n: anzahl */
if (p==P_EACH) {
n *= u2->number;
}
s = getstrtoken(); s = getstrtoken();
if (s == NULL) { if (s == NULL) {

View file

@ -280,6 +280,7 @@ const char *parameters[MAXPARAMS] =
{ {
"LOCALE", "LOCALE",
"ALLES", "ALLES",
"JEDEM",
"BAUERN", "BAUERN",
"BURG", "BURG",
"EINHEIT", "EINHEIT",

View file

@ -450,7 +450,8 @@ enum {
typedef unsigned char param_t; typedef unsigned char param_t;
enum { enum {
P_LOCALE, P_LOCALE,
P_ANY, P_ANY,
P_EACH,
P_PEASANT, P_PEASANT,
P_BUILDING, P_BUILDING,
P_UNIT, P_UNIT,

View file

@ -1825,6 +1825,9 @@
<string name="AGGRESSIV"> <string name="AGGRESSIV">
<text locale="de">AGGRESSIV</text> <text locale="de">AGGRESSIV</text>
</string> </string>
<string name="JEDEM">
<text locale="de">JEDEM</text>
</string>
<string name="ALLES"> <string name="ALLES">
<text locale="de">ALLES</text> <text locale="de">ALLES</text>
</string> </string>

View file

@ -1157,6 +1157,9 @@
<string name="ALLES"> <string name="ALLES">
<text locale="en">ALL</text> <text locale="en">ALL</text>
</string> </string>
<string name="JEDEM">
<text locale="en">EACH</text>
</string>
<string name="ANZAHL"> <string name="ANZAHL">
<text locale="en">NUMBER</text> <text locale="en">NUMBER</text>
</string> </string>