diff --git a/src/common/gamecode/monster.c b/src/common/gamecode/monster.c index f5f6377a6..d5cd96014 100644 --- a/src/common/gamecode/monster.c +++ b/src/common/gamecode/monster.c @@ -594,40 +594,40 @@ monster_attacks(unit * u) static void eaten_by_monster(unit * u) { - int n = 0; - int horse = 0; + int n = 0; + int horse = 0; - switch (old_race(u->race)) { - case RC_FIREDRAGON: - n = rng_int()%80 * u->number; - horse = get_item(u, I_HORSE); - break; - case RC_DRAGON: - n = rng_int()%200 * u->number; - horse = get_item(u, I_HORSE); - break; - case RC_WYRM: - n = rng_int()%500 * u->number; - horse = get_item(u, I_HORSE); - break; - default: - n = rng_int()%(u->number/20+1); - } + switch (old_race(u->race)) { + case RC_FIREDRAGON: + n = rng_int()%80 * u->number; + horse = get_item(u, I_HORSE); + break; + case RC_DRAGON: + n = rng_int()%200 * u->number; + horse = get_item(u, I_HORSE); + break; + case RC_WYRM: + n = rng_int()%500 * u->number; + horse = get_item(u, I_HORSE); + break; + default: + n = rng_int()%(u->number/20+1); + } - if (n > 0) { - n = lovar(n); - n = MIN(rpeasants(u->region), n); + if (n > 0) { + n = lovar(n); + n = MIN(rpeasants(u->region), n); - if (n > 0) { - deathcounts(u->region, n); - rsetpeasants(u->region, rpeasants(u->region) - n); - ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); - } - } - if (horse > 0) { - set_item(u, I_HORSE, 0); + if (n > 0) { + deathcounts(u->region, n); + rsetpeasants(u->region, rpeasants(u->region) - n); + ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n)); + } + } + if (horse > 0) { + set_item(u, I_HORSE, 0); ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); - } + } } static void diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index 2587b9082..756b0a5fc 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -1124,7 +1124,7 @@ leave_cmd(unit * u, struct order * ord) cmistake(u, ord, 11, MSG_MOVE); return 0; } - if(get_item(u, I_HORSE)) { + if (has_horses(u)) { cmistake(u, ord, 231, MSG_MOVE); return 0; } diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index c43396b18..ab0bed052 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -2504,6 +2504,15 @@ lifestyle(const unit * u) return need; } +boolean has_horses(const struct unit * u) +{ + item * itm = u->items; + for (;itm;itm=itm->next) { + if (itm->type->flags&ITF_ANIMAL) return true; + } + return false; +} + boolean hunger(int number, unit * u) { diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index d70fcc121..762e672eb 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -335,6 +335,7 @@ extern boolean hunger(int number, struct unit * u); extern int lifestyle(const struct unit*); extern int besieged(const struct unit * u); extern int maxworkingpeasants(const struct region * r); +extern boolean has_horses(const struct unit * u); extern int wage(const struct region *r, const struct faction *f, const struct race * rc); extern int maintenance_cost(const struct unit * u); diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index e2227c9ca..7a08a36d8 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -288,6 +288,7 @@ destroyfaction(faction * f) if ((rc->ec_flags & ECF_REC_ETHEREAL)==0) { int p = rpeasants(u->region); int h = rhorses(u->region); + item * itm; /* Personen gehen nur an die Bauern, wenn sie auch von dort * stammen */ @@ -298,7 +299,11 @@ destroyfaction(faction * f) } else { p += u->number; } - h += get_item(u, I_HORSE); + for (itm=u->items;itm;itm=itm->next) { + if (itm->type->flags&ITF_ANIMAL) { + h += itm->number; + } + } rsetpeasants(r, p); rsethorses(r, h); } diff --git a/src/common/kernel/move.c b/src/common/kernel/move.c index 784e6fc70..4b5058d31 100644 --- a/src/common/kernel/move.c +++ b/src/common/kernel/move.c @@ -416,22 +416,38 @@ canswim(unit *u) static int canride(unit * u) { - int pferde, maxpferde, unicorns, maxunicorns; + int horses = 0, maxhorses, unicorns = 0, maxunicorns; int skill = effskill(u, SK_RIDING); + item * itm; + static const item_type * it_horse = 0; + static const item_type * it_elvenhorse = 0; + static const item_type * it_charger = 0; + + if (it_horse==0) { + it_horse = it_find("horse"); + it_elvenhorse = it_find("elvenhorse"); + it_charger = it_find("charger"); + } + + for (itm=u->items;itm;itm=itm->next) { + if (itm->type==it_horse || itm->type==it_charger) { + horses += itm->number; + } else if (itm->type==it_elvenhorse) { + unicorns += itm->number; + } + } - unicorns = get_item(u, I_ELVENHORSE); - pferde = get_item(u, I_HORSE); maxunicorns = (skill/5) * u->number; - maxpferde = skill * u->number * 2; + maxhorses = skill * u->number * 2; if(!(u->race->flags & RCF_HORSE) - && ((pferde == 0 && unicorns == 0) - || pferde > maxpferde || unicorns > maxunicorns)) { + && ((horses == 0 && unicorns == 0) + || horses > maxhorses || unicorns > maxunicorns)) { return 0; } if (ridingcapacity(u) - eff_weight(u) >= 0) { - if(pferde == 0 && unicorns >= u->number && !(u->race->flags & RCF_HORSE)) { + if (horses == 0 && unicorns >= u->number && !(u->race->flags & RCF_HORSE)) { return 2; } return 1; @@ -1403,7 +1419,7 @@ travel_route(unit * u, const region_list * route_begin, const region_list * rout if (fval(current->terrain, SEA_REGION) || fval(next->terrain, SEA_REGION)) { /* trying to enter or exit ocean with horses, are we? */ - if (get_item(u, I_HORSE) > 0 || get_item(u, I_ELVENHORSE) > 0) { + if (has_horses(u)) { /* tries to do it with horses */ if (ord!=NULL) cmistake(u, ord, 67, MSG_MOVE); break; diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index c1d8b5cc1..f0d209a67 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -827,7 +827,7 @@ can_survive(const unit *u, const region *r) { static const curse_type * ctype = NULL; - if (get_item(u, I_HORSE) && !fval(r->terrain, WALK_INTO)) + if (has_horses(u) && !fval(r->terrain, WALK_INTO)) return false; if (!ctype) ctype = ct_find("holyground"); diff --git a/src/common/modules/gmcmd.c b/src/common/modules/gmcmd.c index 9b75abef7..f496f013c 100644 --- a/src/common/modules/gmcmd.c +++ b/src/common/modules/gmcmd.c @@ -669,7 +669,6 @@ gm_addfaction(const char * email, plane * p, region * r) { attrib * a; unit * u; - int i; faction * f = calloc(1, sizeof(faction)); assert(p!=NULL); @@ -713,9 +712,6 @@ gm_addfaction(const char * email, plane * p, region * r) } a_add(&ap, make_atgmcreate(resource2item(r_silver))); - for (i=0;i<=I_HORSE;++i) { - a_add(&ap, make_atgmcreate(olditemtype[i])); - } a->data.v = ap; } diff --git a/src/common/modules/museum.c b/src/common/modules/museum.c index 6607e051b..c5d1d4d53 100644 --- a/src/common/modules/museum.c +++ b/src/common/modules/museum.c @@ -357,7 +357,7 @@ use_museumticket(unit *u, const struct item_type *itype, int amount, order * ord cmistake(u, ord, 267, MSG_MAGIC); return 0; } - if(get_item(u, I_HORSE)) { + if (has_horses(u)) { cmistake(u, ord, 272, MSG_MAGIC); return 0; } diff --git a/src/res/asgard/items.xml b/src/res/asgard/items.xml index 569a7ac9f..1c6bc6699 100644 --- a/src/res/asgard/items.xml +++ b/src/res/asgard/items.xml @@ -113,7 +113,7 @@ - +