indentation + whitespace changes

This commit is contained in:
Enno Rehling 2014-08-08 01:03:46 +02:00
parent bf4bda36a2
commit 1918f56990
6 changed files with 7236 additions and 7054 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,11 +2,11 @@
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de> | (c) 1998 - 2014 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
@ -53,379 +53,408 @@
static int GiveRestriction(void) static int GiveRestriction(void)
{ {
static int value = -1; static int value = -1;
if (value < 0) { if (value < 0) {
const char *str = get_param(global.parameters, "GiveRestriction"); const char *str = get_param(global.parameters, "GiveRestriction");
value = str ? atoi(str) : 0; value = str ? atoi(str) : 0;
} }
return value; return value;
} }
static void static void
add_give(unit * u, unit * u2, int given, int received, add_give(unit * u, unit * u2, int given, int received,
const resource_type * rtype, struct order *ord, int error) const resource_type * rtype, struct order *ord, int error)
{ {
if (error) { if (error) {
cmistake(u, ord, error, MSG_COMMERCE); cmistake(u, ord, error, MSG_COMMERCE);
} else if (u2 == NULL) { }
ADDMSG(&u->faction->msgs, else if (u2 == NULL) {
msg_message("give_peasants", "unit resource amount", u, rtype, given)); ADDMSG(&u->faction->msgs,
} else if (u2->faction != u->faction) { msg_message("give_peasants", "unit resource amount", u, rtype, given));
message *msg; }
else if (u2->faction != u->faction) {
message *msg;
msg = msg =
msg_message("give", "unit target resource amount", u, u2, rtype, given); msg_message("give", "unit target resource amount", u, u2, rtype, given);
add_message(&u->faction->msgs, msg); add_message(&u->faction->msgs, msg);
msg_release(msg); msg_release(msg);
msg = msg =
msg_message("receive", "unit target resource amount", u, u2, rtype, msg_message("receive", "unit target resource amount", u, u2, rtype,
received); received);
add_message(&u2->faction->msgs, msg); add_message(&u2->faction->msgs, msg);
msg_release(msg); msg_release(msg);
} }
} }
static bool limited_give(const item_type * type) static bool limited_give(const item_type * type)
{ {
/* trade only money 2:1, if at all */ /* trade only money 2:1, if at all */
return (type->rtype == get_resourcetype(R_SILVER)); return (type->rtype == get_resourcetype(R_SILVER));
} }
int give_quota(const unit * src, const unit * dst, const item_type * type, int give_quota(const unit * src, const unit * dst, const item_type * type,
int n) int n)
{ {
float divisor; float divisor;
if (!limited_give(type)) { if (!limited_give(type)) {
return n;
}
if (dst && src && src->faction != dst->faction) {
divisor = get_param_flt(global.parameters, "rules.items.give_divisor", 1);
assert(divisor == 0 || divisor >= 1);
if (divisor >= 1) {
/* predictable > correct: */
int x = (int)(n / divisor);
return x;
}
}
return n; return n;
}
if (dst && src && src->faction != dst->faction) {
divisor = get_param_flt(global.parameters, "rules.items.give_divisor", 1);
assert(divisor == 0 || divisor >= 1);
if (divisor >= 1) {
/* predictable > correct: */
int x = (int)(n / divisor);
return x;
}
}
return n;
} }
int int
give_item(int want, const item_type * itype, unit * src, unit * dest, give_item(int want, const item_type * itype, unit * src, unit * dest,
struct order *ord) struct order *ord)
{ {
short error = 0; short error = 0;
int n, r; int n, r;
assert(itype != NULL); assert(itype != NULL);
n = get_pooled(src, item2resource(itype), GET_SLACK | GET_POOLED_SLACK, want); n = get_pooled(src, item2resource(itype), GET_SLACK | GET_POOLED_SLACK, want);
n = _min(want, n); n = _min(want, n);
r = n; r = n;
if (dest && src->faction != dest->faction if (dest && src->faction != dest->faction
&& src->faction->age < GiveRestriction()) { && src->faction->age < GiveRestriction()) {
if (ord != NULL) { if (ord != NULL) {
ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "giverestriction", ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "giverestriction",
"turns", GiveRestriction())); "turns", GiveRestriction()));
}
return -1;
} }
return -1; else if (n == 0) {
} else if (n == 0) { int reserve = get_reservation(src, itype->rtype);
int reserve = get_reservation(src, itype->rtype); if (reserve) {
if (reserve) { msg_feedback(src, ord, "nogive_reserved", "resource reservation",
msg_feedback(src, ord, "nogive_reserved", "resource reservation", itype->rtype, reserve);
itype->rtype, reserve); return -1;
return -1; }
error = 36;
} }
error = 36; else if (itype->flags & ITF_CURSED) {
} else if (itype->flags & ITF_CURSED) { error = 25;
error = 25; }
} else if (itype->give == NULL || itype->give(src, dest, itype, n, ord) != 0) { else if (itype->give == NULL || itype->give(src, dest, itype, n, ord) != 0) {
int use = use_pooled(src, item2resource(itype), GET_SLACK, n); int use = use_pooled(src, item2resource(itype), GET_SLACK, n);
if (use < n) if (use < n)
use += use +=
use_pooled(src, item2resource(itype), GET_POOLED_SLACK, use_pooled(src, item2resource(itype), GET_POOLED_SLACK,
n - use); n - use);
if (dest) { if (dest) {
r = give_quota(src, dest, itype, n); r = give_quota(src, dest, itype, n);
i_change(&dest->items, itype, r); i_change(&dest->items, itype, r);
#ifdef RESERVE_GIVE #ifdef RESERVE_GIVE
#ifdef RESERVE_DONATIONS #ifdef RESERVE_DONATIONS
change_reservation(dest, item2resource(itype), r); change_reservation(dest, item2resource(itype), r);
#else #else
if (src->faction == dest->faction) { if (src->faction == dest->faction) {
change_reservation(dest, item2resource(itype), r); change_reservation(dest, item2resource(itype), r);
} }
#endif #endif
#endif #endif
#if MUSEUM_MODULE && defined(TODO) #if MUSEUM_MODULE && defined(TODO)
/* TODO: use a trigger for the museum warden! */ /* TODO: use a trigger for the museum warden! */
if (a_find(dest->attribs, &at_warden)) { if (a_find(dest->attribs, &at_warden)) {
warden_add_give(src, dest, itype, r); warden_add_give(src, dest, itype, r);
} }
#endif #endif
handle_event(dest->attribs, "receive", src); handle_event(dest->attribs, "receive", src);
}
handle_event(src->attribs, "give", dest);
} }
handle_event(src->attribs, "give", dest); add_give(src, dest, n, r, item2resource(itype), ord, error);
} if (error)
add_give(src, dest, n, r, item2resource(itype), ord, error); return -1;
if (error) return 0;
return -1;
return 0;
} }
void give_men(int n, unit * u, unit * u2, struct order *ord) void give_men(int n, unit * u, unit * u2, struct order *ord)
{ {
ship *sh; ship *sh;
int k = 0; int k = 0;
int error = 0; int error = 0;
if (u2 && u->faction != u2->faction && u->faction->age < GiveRestriction()) { if (u2 && u->faction != u2->faction && u->faction->age < GiveRestriction()) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "giverestriction", ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "giverestriction",
"turns", GiveRestriction())); "turns", GiveRestriction()));
return; return;
} else if (u == u2) {
error = 10;
}
else if (!u2 && u_race(u) == get_race(RC_SNOTLING)) {
/* snotlings may not be given to the peasants. */
error = 307;
} else if (u2 && u2->number && (fval(u, UFL_HERO) != fval(u2, UFL_HERO))) {
/* heroes may not be given to non-heroes and vice versa */
error = 75;
} else if (unit_has_cursed_item(u) || (u2 && unit_has_cursed_item(u2))) {
error = 78;
} else if (fval(u, UFL_LOCKED) || is_cursed(u->attribs, C_SLAVE, 0)) {
error = 74;
} else if (u2 && fval(u, UFL_HUNGER)) {
/* hungry people cannot be given away */
error = 73;
} else if (u2 && (fval(u2, UFL_LOCKED) || is_cursed(u2->attribs, C_SLAVE, 0))) {
error = 75;
} else if (u2 && !ucontact(u2, u)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact",
"target", u2));
error = -1;
} else if (u2 && (has_skill(u, SK_MAGIC) || has_skill(u2, SK_MAGIC))) {
/* cannot give units to and from magicians */
error = 158;
} else if (u2 && (fval(u, UFL_WERE) != fval(u2, UFL_WERE))) {
/* werewolves can't be given to non-werewolves and vice-versa */
error = 312;
} else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) {
log_warning("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name[0], u_race(u2)->_name[1]);
error = 139;
} else if (u2 != NULL && (get_racename(u2->attribs)
|| get_racename(u->attribs))) {
error = 139;
} else if (u2 && u2->faction != u->faction && !rule_transfermen()) {
error = 74;
} else {
if (n > u->number)
n = u->number;
if (u2 && n + u2->number > UNIT_MAXSIZE) {
n = UNIT_MAXSIZE - u2->number;
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_unit_size",
"maxsize", UNIT_MAXSIZE));
assert(n >= 0);
} }
if (n == 0) { else if (u == u2) {
error = 96; error = 10;
} else if (u2 && u->faction != u2->faction) { }
if (u2->faction->newbies + n > MAXNEWBIES) { else if (!u2 && u_race(u) == get_race(RC_SNOTLING)) {
error = 129; /* snotlings may not be given to the peasants. */
} else if (u_race(u) != u2->faction->race) { error = 307;
if (u2->faction->race != get_race(RC_HUMAN)) { }
error = 120; else if (u2 && u2->number && (fval(u, UFL_HERO) != fval(u2, UFL_HERO))) {
} else if (count_migrants(u2->faction) + n > /* heroes may not be given to non-heroes and vice versa */
count_maxmigrants(u2->faction)) { error = 75;
error = 128; }
} else if (has_limited_skills(u) || has_limited_skills(u2)) { else if (unit_has_cursed_item(u) || (u2 && unit_has_cursed_item(u2))) {
error = 154; error = 78;
} else if (u2->number != 0) { }
error = 139; else if (fval(u, UFL_LOCKED) || is_cursed(u->attribs, C_SLAVE, 0)) {
error = 74;
}
else if (u2 && fval(u, UFL_HUNGER)) {
/* hungry people cannot be given away */
error = 73;
}
else if (u2 && (fval(u2, UFL_LOCKED) || is_cursed(u2->attribs, C_SLAVE, 0))) {
error = 75;
}
else if (u2 && !ucontact(u2, u)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact",
"target", u2));
error = -1;
}
else if (u2 && (has_skill(u, SK_MAGIC) || has_skill(u2, SK_MAGIC))) {
/* cannot give units to and from magicians */
error = 158;
}
else if (u2 && (fval(u, UFL_WERE) != fval(u2, UFL_WERE))) {
/* werewolves can't be given to non-werewolves and vice-versa */
error = 312;
}
else if (u2 && u2->number != 0 && u_race(u2) != u_race(u)) {
log_warning("faction %s attempts to give %s to %s.\n", itoa36(u->faction->no), u_race(u)->_name[0], u_race(u2)->_name[1]);
error = 139;
}
else if (u2 != NULL && (get_racename(u2->attribs)
|| get_racename(u->attribs))) {
error = 139;
}
else if (u2 && u2->faction != u->faction && !rule_transfermen()) {
error = 74;
}
else {
if (n > u->number)
n = u->number;
if (u2 && n + u2->number > UNIT_MAXSIZE) {
n = UNIT_MAXSIZE - u2->number;
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_unit_size",
"maxsize", UNIT_MAXSIZE));
assert(n >= 0);
}
if (n == 0) {
error = 96;
}
else if (u2 && u->faction != u2->faction) {
if (u2->faction->newbies + n > MAXNEWBIES) {
error = 129;
}
else if (u_race(u) != u2->faction->race) {
if (u2->faction->race != get_race(RC_HUMAN)) {
error = 120;
}
else if (count_migrants(u2->faction) + n >
count_maxmigrants(u2->faction)) {
error = 128;
}
else if (has_limited_skills(u) || has_limited_skills(u2)) {
error = 154;
}
else if (u2->number != 0) {
error = 139;
}
}
} }
}
}
}
if (u2 && (has_skill(u, SK_ALCHEMY) || has_skill(u2, SK_ALCHEMY))) {
k = count_skill(u2->faction, SK_ALCHEMY);
/* Falls die Zieleinheit keine Alchemisten sind, werden sie nun
* welche. */
if (!has_skill(u2, SK_ALCHEMY) && has_skill(u, SK_ALCHEMY))
k += u2->number;
/* Wenn in eine Alchemisteneinheit Personen verschoben werden */
if (has_skill(u2, SK_ALCHEMY) && !has_skill(u, SK_ALCHEMY))
k += n;
/* Wenn Parteigrenzen überschritten werden */
if (u2->faction != u->faction)
k += n;
/* wird das Alchemistenmaximum ueberschritten ? */
if (k > skill_limit(u2->faction, SK_ALCHEMY)) {
error = 156;
}
}
if (error == 0) {
if (u2 && u2->number == 0) {
set_racename(&u2->attribs, get_racename(u->attribs));
u_setrace(u2, u_race(u));
u2->irace = u->irace;
if (fval(u, UFL_HERO))
fset(u2, UFL_HERO);
else
freset(u2, UFL_HERO);
} }
if (u2) { if (u2 && (has_skill(u, SK_ALCHEMY) || has_skill(u2, SK_ALCHEMY))) {
/* Einheiten von Schiffen können nicht NACH in von k = count_skill(u2->faction, SK_ALCHEMY);
* Nicht-alliierten bewachten Regionen ausführen */
sh = leftship(u); /* Falls die Zieleinheit keine Alchemisten sind, werden sie nun
if (sh) { * welche. */
set_leftship(u2, sh); if (!has_skill(u2, SK_ALCHEMY) && has_skill(u, SK_ALCHEMY))
} k += u2->number;
transfermen(u, u2, n);
if (u->faction != u2->faction) { /* Wenn in eine Alchemisteneinheit Personen verschoben werden */
u2->faction->newbies += n; if (has_skill(u2, SK_ALCHEMY) && !has_skill(u, SK_ALCHEMY))
} k += n;
} else {
if (getunitpeasants) { /* Wenn Parteigrenzen überschritten werden */
if (u2->faction != u->faction)
k += n;
/* wird das Alchemistenmaximum ueberschritten ? */
if (k > skill_limit(u2->faction, SK_ALCHEMY)) {
error = 156;
}
}
if (error == 0) {
if (u2 && u2->number == 0) {
set_racename(&u2->attribs, get_racename(u->attribs));
u_setrace(u2, u_race(u));
u2->irace = u->irace;
if (fval(u, UFL_HERO))
fset(u2, UFL_HERO);
else
freset(u2, UFL_HERO);
}
if (u2) {
/* Einheiten von Schiffen können nicht NACH in von
* Nicht-alliierten bewachten Regionen ausführen */
sh = leftship(u);
if (sh) {
set_leftship(u2, sh);
}
transfermen(u, u2, n);
if (u->faction != u2->faction) {
u2->faction->newbies += n;
}
}
else {
if (getunitpeasants) {
#ifdef ORCIFICATION #ifdef ORCIFICATION
if (u_race(u) == get_race(RC_SNOTLING) && !fval(u->region, RF_ORCIFIED)) { if (u_race(u) == get_race(RC_SNOTLING) && !fval(u->region, RF_ORCIFIED)) {
attrib *a = a_find(u->region->attribs, &at_orcification); attrib *a = a_find(u->region->attribs, &at_orcification);
if (!a) if (!a)
a = a_add(&u->region->attribs, a_new(&at_orcification)); a = a_add(&u->region->attribs, a_new(&at_orcification));
a->data.i += n; a->data.i += n;
} }
#endif #endif
transfermen(u, NULL, n); transfermen(u, NULL, n);
} else { }
error = 159; else {
} error = 159;
}
}
}
if (error > 0) {
cmistake(u, ord, error, MSG_COMMERCE);
}
else if (!u2) {
ADDMSG(&u->faction->msgs,
msg_message("give_person_peasants", "unit amount", u, n));
}
else if (u2->faction != u->faction) {
message *msg = msg_message("give_person", "unit target amount", u, u2, n);
add_message(&u->faction->msgs, msg);
add_message(&u2->faction->msgs, msg);
msg_release(msg);
} }
}
if (error > 0) {
cmistake(u, ord, error, MSG_COMMERCE);
} else if (!u2) {
ADDMSG(&u->faction->msgs,
msg_message("give_person_peasants", "unit amount", u, n));
} else if (u2->faction != u->faction) {
message *msg = msg_message("give_person", "unit target amount", u, u2, n);
add_message(&u->faction->msgs, msg);
add_message(&u2->faction->msgs, msg);
msg_release(msg);
}
} }
void give_unit(unit * u, unit * u2, order * ord) void give_unit(unit * u, unit * u2, order * ord)
{ {
region *r = u->region; region *r = u->region;
int n = u->number; int n = u->number;
if (!rule_transfermen() && u->faction != u2->faction) { if (!rule_transfermen() && u->faction != u2->faction) {
cmistake(u, ord, 74, MSG_COMMERCE); cmistake(u, ord, 74, MSG_COMMERCE);
return; return;
} }
if (u && unit_has_cursed_item(u)) { if (u && unit_has_cursed_item(u)) {
cmistake(u, ord, 78, MSG_COMMERCE); cmistake(u, ord, 78, MSG_COMMERCE);
return; return;
} }
if (fval(u, UFL_HERO)) { if (fval(u, UFL_HERO)) {
cmistake(u, ord, 75, MSG_COMMERCE); cmistake(u, ord, 75, MSG_COMMERCE);
return; return;
} }
if (fval(u, UFL_LOCKED) || fval(u, UFL_HUNGER)) { if (fval(u, UFL_LOCKED) || fval(u, UFL_HUNGER)) {
cmistake(u, ord, 74, MSG_COMMERCE); cmistake(u, ord, 74, MSG_COMMERCE);
return; return;
} }
if (u2 == NULL) { if (u2 == NULL) {
if (fval(r->terrain, SEA_REGION)) { if (fval(r->terrain, SEA_REGION)) {
cmistake(u, ord, 152, MSG_COMMERCE); cmistake(u, ord, 152, MSG_COMMERCE);
} else if (getunitpeasants) {
unit *u3;
for (u3 = r->units; u3; u3 = u3->next)
if (u3->faction == u->faction && u != u3)
break;
if (u3) {
while (u->items) {
item *iold = i_remove(&u->items, u->items);
item *inew = *i_find(&u3->items, iold->type);
if (inew == NULL)
i_add(&u3->items, iold);
else {
inew->number += iold->number;
i_free(iold);
}
} }
} else if (getunitpeasants) {
give_men(u->number, u, NULL, ord); unit *u3;
cmistake(u, ord, 153, MSG_COMMERCE);
} else {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
""));
}
return;
}
if (!alliedunit(u2, u->faction, HELP_GIVE) && ucontact(u2, u) == 0) { for (u3 = r->units; u3; u3 = u3->next)
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact", if (u3->faction == u->faction && u != u3)
"target", u2)); break;
return;
} if (u3) {
if (u->number == 0) { while (u->items) {
cmistake(u, ord, 105, MSG_COMMERCE); item *iold = i_remove(&u->items, u->items);
return; item *inew = *i_find(&u3->items, iold->type);
} if (inew == NULL)
if (u2->faction->newbies + n > MAXNEWBIES) { i_add(&u3->items, iold);
cmistake(u, ord, 129, MSG_COMMERCE); else {
return; inew->number += iold->number;
} i_free(iold);
if (u_race(u) != u2->faction->race) { }
if (u2->faction->race != get_race(RC_HUMAN)) { }
cmistake(u, ord, 120, MSG_COMMERCE); }
return; give_men(u->number, u, NULL, ord);
cmistake(u, ord, 153, MSG_COMMERCE);
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
""));
}
return;
} }
if (count_migrants(u2->faction) + u->number >
count_maxmigrants(u2->faction)) { if (!alliedunit(u2, u->faction, HELP_GIVE) && ucontact(u2, u) == 0) {
cmistake(u, ord, 128, MSG_COMMERCE); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact",
return; "target", u2));
return;
} }
if (has_limited_skills(u)) { if (u->number == 0) {
cmistake(u, ord, 154, MSG_COMMERCE); cmistake(u, ord, 105, MSG_COMMERCE);
return; return;
} }
} if (u2->faction->newbies + n > MAXNEWBIES) {
if (has_skill(u, SK_MAGIC)) { cmistake(u, ord, 129, MSG_COMMERCE);
sc_mage *mage; return;
if (count_skill(u2->faction, SK_MAGIC) + u->number >
skill_limit(u2->faction, SK_MAGIC)) {
cmistake(u, ord, 155, MSG_COMMERCE);
return;
} }
mage = get_mage(u); if (u_race(u) != u2->faction->race) {
if (!mage || u2->faction->magiegebiet != mage->magietyp) { if (u2->faction->race != get_race(RC_HUMAN)) {
cmistake(u, ord, 157, MSG_COMMERCE); cmistake(u, ord, 120, MSG_COMMERCE);
return; return;
}
if (count_migrants(u2->faction) + u->number >
count_maxmigrants(u2->faction)) {
cmistake(u, ord, 128, MSG_COMMERCE);
return;
}
if (has_limited_skills(u)) {
cmistake(u, ord, 154, MSG_COMMERCE);
return;
}
} }
} if (has_skill(u, SK_MAGIC)) {
if (has_skill(u, SK_ALCHEMY) sc_mage *mage;
&& count_skill(u2->faction, SK_ALCHEMY) + u->number > if (count_skill(u2->faction, SK_MAGIC) + u->number >
skill_limit(u2->faction, SK_ALCHEMY)) { skill_limit(u2->faction, SK_MAGIC)) {
cmistake(u, ord, 156, MSG_COMMERCE); cmistake(u, ord, 155, MSG_COMMERCE);
return; return;
} }
add_give(u, u2, 1, 1, get_resourcetype(R_UNIT), ord, 0); mage = get_mage(u);
u_setfaction(u, u2->faction); if (!mage || u2->faction->magiegebiet != mage->magietyp) {
u2->faction->newbies += n; cmistake(u, ord, 157, MSG_COMMERCE);
return;
}
}
if (has_skill(u, SK_ALCHEMY)
&& count_skill(u2->faction, SK_ALCHEMY) + u->number >
skill_limit(u2->faction, SK_ALCHEMY)) {
cmistake(u, ord, 156, MSG_COMMERCE);
return;
}
add_give(u, u2, 1, 1, get_resourcetype(R_UNIT), ord, 0);
u_setfaction(u, u2->faction);
u2->faction->newbies += n;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +1,14 @@
/* vi: set ts=2: /* vi: set ts=2:
+-------------------+ +-------------------+
| | Christian Schlittchen <corwin@amber.kn-bremen.de> | | Christian Schlittchen <corwin@amber.kn-bremen.de>
| Eressea PBEM host | Enno Rehling <enno@eressea.de> | Eressea PBEM host | Enno Rehling <enno@eressea.de>
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de> | (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
| | | |
+-------------------+ +-------------------+
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
@ -35,58 +35,58 @@
# define ORD_STRING(ord) (ord)->data->_str # define ORD_STRING(ord) (ord)->data->_str
typedef struct locale_data { typedef struct locale_data {
struct order_data *short_orders[MAXKEYWORDS]; struct order_data *short_orders[MAXKEYWORDS];
struct order_data *study_orders[MAXSKILLS]; struct order_data *study_orders[MAXSKILLS];
const struct locale *lang; const struct locale *lang;
} locale_data; } locale_data;
static struct locale_data *locale_array[16]; static struct locale_data *locale_array[16];
static int nlocales = 0; static int nlocales = 0;
typedef struct order_data { typedef struct order_data {
char *_str; char *_str;
# ifdef LOMEM # ifdef LOMEM
int _refcount:20; int _refcount:20;
int _lindex:4; int _lindex:4;
# else # else
int _refcount; int _refcount;
int _lindex; int _lindex;
# endif # endif
keyword_t _keyword; keyword_t _keyword;
} order_data; } order_data;
static void release_data(order_data * data) static void release_data(order_data * data)
{ {
if (data) { if (data) {
if (--data->_refcount == 0) { if (--data->_refcount == 0) {
if (data->_str) if (data->_str)
free(data->_str); free(data->_str);
free(data); free(data);
}
} }
}
} }
void replace_order(order ** dlist, order * orig, const order * src) void replace_order(order ** dlist, order * orig, const order * src)
{ {
while (*dlist != NULL) { while (*dlist != NULL) {
order *dst = *dlist; order *dst = *dlist;
if (dst->data == orig->data) { if (dst->data == orig->data) {
order *cpy = copy_order(src); order *cpy = copy_order(src);
*dlist = cpy; *dlist = cpy;
cpy->next = dst->next; cpy->next = dst->next;
dst->next = 0; dst->next = 0;
free_order(dst); free_order(dst);
}
dlist = &(*dlist)->next;
} }
dlist = &(*dlist)->next;
}
} }
keyword_t getkeyword(const order * ord) keyword_t getkeyword(const order * ord)
{ {
if (ord == NULL) { if (ord == NULL) {
return NOKEYWORD; return NOKEYWORD;
} }
return ORD_KEYWORD(ord); return ORD_KEYWORD(ord);
} }
/** returns a plain-text representation of the order. /** returns a plain-text representation of the order.
@ -103,7 +103,8 @@ static char* get_command(const order *ord, char *sbuffer, size_t size) {
if (size > 0) { if (size > 0) {
*bufp++ = '@'; *bufp++ = '@';
--size; --size;
} else { }
else {
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
} }
@ -116,7 +117,8 @@ static char* get_command(const order *ord, char *sbuffer, size_t size) {
bytes = (int)strlcpy(bufp, str, size); bytes = (int)strlcpy(bufp, str, size);
if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER();
if (text) *bufp++ = ' '; if (text) *bufp++ = ' ';
} else { }
else {
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
} }
} }
@ -141,205 +143,208 @@ static char* get_command(const order *ord, char *sbuffer, size_t size) {
char *getcommand(const order * ord) char *getcommand(const order * ord)
{ {
char sbuffer[DISPLAYSIZE * 2]; char sbuffer[DISPLAYSIZE * 2];
return _strdup(get_command(ord, sbuffer, sizeof(sbuffer))); return _strdup(get_command(ord, sbuffer, sizeof(sbuffer)));
} }
void free_order(order * ord) void free_order(order * ord)
{ {
if (ord != NULL) { if (ord != NULL) {
assert(ord->next == 0); assert(ord->next == 0);
release_data(ord->data); release_data(ord->data);
free(ord); free(ord);
} }
} }
order *copy_order(const order * src) order *copy_order(const order * src)
{ {
if (src != NULL) { if (src != NULL) {
order *ord = (order *) malloc(sizeof(order)); order *ord = (order *)malloc(sizeof(order));
ord->next = NULL; ord->next = NULL;
ord->_persistent = src->_persistent; ord->_persistent = src->_persistent;
ord->data = src->data; ord->data = src->data;
++ord->data->_refcount; ++ord->data->_refcount;
return ord; return ord;
} }
return NULL; return NULL;
} }
void set_order(struct order **destp, struct order *src) void set_order(struct order **destp, struct order *src)
{ {
if (*destp == src) if (*destp == src)
return; return;
free_order(*destp); free_order(*destp);
*destp = src; *destp = src;
} }
void free_orders(order ** olist) void free_orders(order ** olist)
{ {
while (*olist) { while (*olist) {
order *ord = *olist; order *ord = *olist;
*olist = ord->next; *olist = ord->next;
ord->next = NULL; ord->next = NULL;
free_order(ord); free_order(ord);
} }
} }
static order_data *create_data(keyword_t kwd, const char *sptr, int lindex) static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
{ {
const char *s = sptr; const char *s = sptr;
order_data *data; order_data *data;
const struct locale *lang = locale_array[lindex]->lang; const struct locale *lang = locale_array[lindex]->lang;
if (kwd != NOKEYWORD) if (kwd != NOKEYWORD)
s = (*sptr) ? sptr : NULL; s = (*sptr) ? sptr : NULL;
/* learning, only one order_data per skill required */ /* learning, only one order_data per skill required */
if (kwd == K_STUDY) { if (kwd == K_STUDY) {
skill_t sk = get_skill(parse_token(&sptr), lang); skill_t sk = get_skill(parse_token(&sptr), lang);
switch (sk) { switch (sk) {
case NOSKILL: /* fehler */ case NOSKILL: /* fehler */
break; break;
case SK_MAGIC: /* kann parameter haben */ case SK_MAGIC: /* kann parameter haben */
if (*sptr != 0) if (*sptr != 0)
break; break;
default: /* nur skill als Parameter, keine extras */ default: /* nur skill als Parameter, keine extras */
data = locale_array[lindex]->study_orders[sk]; data = locale_array[lindex]->study_orders[sk];
if (data == NULL) { if (data == NULL) {
const char *skname = skillname(sk, lang); const char *skname = skillname(sk, lang);
data = (order_data *) malloc(sizeof(order_data)); data = (order_data *)malloc(sizeof(order_data));
locale_array[lindex]->study_orders[sk] = data; locale_array[lindex]->study_orders[sk] = data;
data->_keyword = kwd; data->_keyword = kwd;
data->_lindex = lindex; data->_lindex = lindex;
assert(data->_lindex>=0); assert(data->_lindex >= 0);
if (strchr(skname, ' ') != NULL) { if (strchr(skname, ' ') != NULL) {
size_t len = strlen(skname); size_t len = strlen(skname);
data->_str = malloc(len + 3); data->_str = malloc(len + 3);
data->_str[0] = '\"'; data->_str[0] = '\"';
memcpy(data->_str + 1, skname, len); memcpy(data->_str + 1, skname, len);
data->_str[len + 1] = '\"'; data->_str[len + 1] = '\"';
data->_str[len + 2] = '\0'; data->_str[len + 2] = '\0';
} else { }
data->_str = _strdup(skname); else {
data->_str = _strdup(skname);
}
data->_refcount = 1;
}
++data->_refcount;
return data;
} }
data->_refcount = 1;
}
++data->_refcount;
return data;
} }
}
/* orders with no parameter, only one order_data per order required */ /* orders with no parameter, only one order_data per order required */
else if (kwd != NOKEYWORD && *sptr == 0) { else if (kwd != NOKEYWORD && *sptr == 0) {
data = locale_array[lindex]->short_orders[kwd]; data = locale_array[lindex]->short_orders[kwd];
if (data == NULL) { if (data == NULL) {
data = (order_data *) malloc(sizeof(order_data)); data = (order_data *)malloc(sizeof(order_data));
locale_array[lindex]->short_orders[kwd] = data; locale_array[lindex]->short_orders[kwd] = data;
data->_keyword = kwd; data->_keyword = kwd;
data->_lindex = lindex; data->_lindex = lindex;
assert(data->_lindex>=0); assert(data->_lindex >= 0);
data->_str = NULL; data->_str = NULL;
data->_refcount = 1; data->_refcount = 1;
}
++data->_refcount;
return data;
} }
++data->_refcount; data = (order_data *)malloc(sizeof(order_data));
data->_keyword = kwd;
data->_lindex = lindex;
assert(data->_lindex >= 0);
data->_str = s ? _strdup(s) : NULL;
data->_refcount = 1;
return data; return data;
}
data = (order_data *) malloc(sizeof(order_data));
data->_keyword = kwd;
data->_lindex = lindex;
assert(data->_lindex>=0);
data->_str = s ? _strdup(s) : NULL;
data->_refcount = 1;
return data;
} }
static order *create_order_i(keyword_t kwd, const char *sptr, int persistent, static order *create_order_i(keyword_t kwd, const char *sptr, int persistent,
const struct locale *lang) const struct locale *lang)
{ {
order *ord = NULL; order *ord = NULL;
int lindex; int lindex;
/* if this is just nonsense, then we skip it. */ /* if this is just nonsense, then we skip it. */
if (lomem) { if (lomem) {
switch (kwd) { switch (kwd) {
case K_KOMMENTAR: case K_KOMMENTAR:
case NOKEYWORD: case NOKEYWORD:
return NULL; return NULL;
default: default:
break; break;
}
} }
}
for (lindex = 0; lindex != nlocales; ++lindex) { for (lindex = 0; lindex != nlocales; ++lindex) {
if (locale_array[lindex]->lang == lang) if (locale_array[lindex]->lang == lang)
break; break;
} }
if (lindex == nlocales) { if (lindex == nlocales) {
locale_array[nlocales] = (locale_data *) calloc(1, sizeof(locale_data)); locale_array[nlocales] = (locale_data *)calloc(1, sizeof(locale_data));
locale_array[nlocales]->lang = lang; locale_array[nlocales]->lang = lang;
++nlocales; ++nlocales;
} }
ord = (order *) malloc(sizeof(order)); ord = (order *)malloc(sizeof(order));
ord->_persistent = persistent; ord->_persistent = persistent;
ord->next = NULL; ord->next = NULL;
ord->data = create_data(kwd, sptr, lindex); ord->data = create_data(kwd, sptr, lindex);
return ord; return ord;
} }
order *create_order(keyword_t kwd, const struct locale * lang, order *create_order(keyword_t kwd, const struct locale * lang,
const char *params, ...) const char *params, ...)
{ {
char zBuffer[DISPLAYSIZE]; char zBuffer[DISPLAYSIZE];
if (params) { if (params) {
char *bufp = zBuffer; char *bufp = zBuffer;
int bytes; int bytes;
size_t size = sizeof(zBuffer) - 1; size_t size = sizeof(zBuffer) - 1;
va_list marker; va_list marker;
va_start(marker, params); va_start(marker, params);
while (*params) { while (*params) {
if (*params == '%') { if (*params == '%') {
int i; int i;
const char *s; const char *s;
++params; ++params;
switch (*params) { switch (*params) {
case 's': case 's':
s = va_arg(marker, const char *); s = va_arg(marker, const char *);
bytes = (int)strlcpy(bufp, s, size); bytes = (int)strlcpy(bufp, s, size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
case 'd': case 'd':
i = va_arg(marker, int); i = va_arg(marker, int);
bytes = (int)strlcpy(bufp, itoa10(i), size); bytes = (int)strlcpy(bufp, itoa10(i), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
case 'i': case 'i':
i = va_arg(marker, int); i = va_arg(marker, int);
bytes = (int)strlcpy(bufp, itoa36(i), size); bytes = (int)strlcpy(bufp, itoa36(i), size);
if (wrptr(&bufp, &size, bytes) != 0) if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER(); WARN_STATIC_BUFFER();
break; break;
default: default:
assert(!"unknown format-character in create_order"); assert(!"unknown format-character in create_order");
}
}
else if (size > 0) {
*bufp++ = *params;
--size;
}
++params;
} }
} else if (size > 0) { va_end(marker);
*bufp++ = *params; *bufp = 0;
--size;
}
++params;
} }
va_end(marker); else {
*bufp = 0; zBuffer[0] = 0;
} else { }
zBuffer[0] = 0; return create_order_i(kwd, zBuffer, 0, lang);
}
return create_order_i(kwd, zBuffer, 0, lang);
} }
order *parse_order(const char *s, const struct locale * lang) order *parse_order(const char *s, const struct locale * lang)
@ -352,7 +357,7 @@ order *parse_order(const char *s, const struct locale * lang)
if (*s != 0) { if (*s != 0) {
keyword_t kwd; keyword_t kwd;
const char *sptr; const char *sptr;
int persistent = 0; int persistent = 0;
while (*s == '@') { while (*s == '@') {
persistent = 1; persistent = 1;
@ -379,50 +384,50 @@ order *parse_order(const char *s, const struct locale * lang)
*/ */
bool is_repeated(const order * ord) bool is_repeated(const order * ord)
{ {
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
const struct locale *lang = ORD_LOCALE(ord); const struct locale *lang = ORD_LOCALE(ord);
const char * s; const char * s;
int result = 0; int result = 0;
switch (kwd) { switch (kwd) {
case K_CAST: case K_CAST:
case K_BUY: case K_BUY:
case K_SELL: case K_SELL:
case K_ROUTE: case K_ROUTE:
case K_DRIVE: case K_DRIVE:
case K_WORK: case K_WORK:
case K_BESIEGE: case K_BESIEGE:
case K_ENTERTAIN: case K_ENTERTAIN:
case K_TAX: case K_TAX:
case K_RESEARCH: case K_RESEARCH:
case K_SPY: case K_SPY:
case K_STEAL: case K_STEAL:
case K_SABOTAGE: case K_SABOTAGE:
case K_STUDY: case K_STUDY:
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
case K_PLANT: case K_PLANT:
result = 1; result = 1;
break; break;
case K_MAKE: case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen /* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden * Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case * behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl) * K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */ * abgespeichert). */
parser_pushstate(); parser_pushstate();
init_tokens(ord); /* initialize token-parser */ init_tokens(ord); /* initialize token-parser */
skip_token(); skip_token();
s = getstrtoken(); s = getstrtoken();
result = !isparam(s, lang, P_TEMP); result = !isparam(s, lang, P_TEMP);
parser_popstate(); parser_popstate();
break; break;
default: default:
result = 0; result = 0;
} }
return result; return result;
} }
/** /**
@ -435,46 +440,46 @@ bool is_repeated(const order * ord)
*/ */
bool is_exclusive(const order * ord) bool is_exclusive(const order * ord)
{ {
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
const struct locale *lang = ORD_LOCALE(ord); const struct locale *lang = ORD_LOCALE(ord);
int result = 0; int result = 0;
switch (kwd) { switch (kwd) {
case K_MOVE: case K_MOVE:
case K_ROUTE: case K_ROUTE:
case K_DRIVE: case K_DRIVE:
case K_WORK: case K_WORK:
case K_BESIEGE: case K_BESIEGE:
case K_ENTERTAIN: case K_ENTERTAIN:
case K_TAX: case K_TAX:
case K_RESEARCH: case K_RESEARCH:
case K_SPY: case K_SPY:
case K_STEAL: case K_STEAL:
case K_SABOTAGE: case K_SABOTAGE:
case K_STUDY: case K_STUDY:
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
case K_PLANT: case K_PLANT:
result = 1; result = 1;
break; break;
case K_MAKE: case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen /* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden * Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case * behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl) * K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */ * abgespeichert). */
parser_pushstate(); parser_pushstate();
init_tokens(ord); /* initialize token-parser */ init_tokens(ord); /* initialize token-parser */
skip_token(); skip_token();
result = !isparam(getstrtoken(), lang, P_TEMP); result = !isparam(getstrtoken(), lang, P_TEMP);
parser_popstate(); parser_popstate();
break; break;
default: default:
result = 0; result = 0;
} }
return result; return result;
} }
/** /**
@ -487,48 +492,48 @@ bool is_exclusive(const order * ord)
*/ */
bool is_long(const order * ord) bool is_long(const order * ord)
{ {
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
const struct locale *lang = ORD_LOCALE(ord); const struct locale *lang = ORD_LOCALE(ord);
bool result = false; bool result = false;
switch (kwd) { switch (kwd) {
case K_CAST: case K_CAST:
case K_BUY: case K_BUY:
case K_SELL: case K_SELL:
case K_MOVE: case K_MOVE:
case K_ROUTE: case K_ROUTE:
case K_DRIVE: case K_DRIVE:
case K_WORK: case K_WORK:
case K_BESIEGE: case K_BESIEGE:
case K_ENTERTAIN: case K_ENTERTAIN:
case K_TAX: case K_TAX:
case K_RESEARCH: case K_RESEARCH:
case K_SPY: case K_SPY:
case K_STEAL: case K_STEAL:
case K_SABOTAGE: case K_SABOTAGE:
case K_STUDY: case K_STUDY:
case K_TEACH: case K_TEACH:
case K_BREED: case K_BREED:
case K_PIRACY: case K_PIRACY:
case K_PLANT: case K_PLANT:
return true; return true;
case K_MAKE: case K_MAKE:
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen /* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
* Arten von MACHE zaehlen aber als neue defaults und werden * Arten von MACHE zaehlen aber als neue defaults und werden
* behandelt wie die anderen (deswegen kein break nach case * behandelt wie die anderen (deswegen kein break nach case
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl) * K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
* abgespeichert). */ * abgespeichert). */
parser_pushstate(); parser_pushstate();
init_tokens(ord); /* initialize token-parser */ init_tokens(ord); /* initialize token-parser */
skip_token(); skip_token();
result = !isparam(getstrtoken(), lang, P_TEMP); result = !isparam(getstrtoken(), lang, P_TEMP);
parser_popstate(); parser_popstate();
break; break;
default: default:
result = false; result = false;
} }
return result; return result;
} }
/** /**
@ -542,48 +547,50 @@ bool is_long(const order * ord)
*/ */
bool is_persistent(const order * ord) bool is_persistent(const order * ord)
{ {
keyword_t kwd = ORD_KEYWORD(ord); keyword_t kwd = ORD_KEYWORD(ord);
int persist = ord->_persistent != 0; int persist = ord->_persistent != 0;
switch (kwd) { switch (kwd) {
case K_MOVE: case K_MOVE:
case NOKEYWORD: case NOKEYWORD:
/* lang, aber niemals persistent! */ /* lang, aber niemals persistent! */
return false; return false;
case K_KOMMENTAR: case K_KOMMENTAR:
return true; return true;
default: default:
return persist || is_repeated(ord); return persist || is_repeated(ord);
} }
} }
char *write_order(const order * ord, char *buffer, size_t size) char *write_order(const order * ord, char *buffer, size_t size)
{ {
if (ord == 0) { if (ord == 0) {
buffer[0] = 0; buffer[0] = 0;
} else {
keyword_t kwd = ORD_KEYWORD(ord);
if (kwd == NOKEYWORD) {
const char *text = ORD_STRING(ord);
strlcpy(buffer, (const char *)text, size);
} else {
get_command(ord, buffer, size);
} }
} else {
return buffer; keyword_t kwd = ORD_KEYWORD(ord);
if (kwd == NOKEYWORD) {
const char *text = ORD_STRING(ord);
strlcpy(buffer, (const char *)text, size);
}
else {
get_command(ord, buffer, size);
}
}
return buffer;
} }
void push_order(order ** ordp, order * ord) void push_order(order ** ordp, order * ord)
{ {
while (*ordp) while (*ordp)
ordp = &(*ordp)->next; ordp = &(*ordp)->next;
*ordp = ord; *ordp = ord;
} }
void init_tokens(const struct order *ord) void init_tokens(const struct order *ord)
{ {
char *cmd = getcommand(ord); char *cmd = getcommand(ord);
init_tokens_str(cmd, cmd); init_tokens_str(cmd, cmd);
} }

View File

@ -1,5 +1,6 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2014,
Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>