diff --git a/src/economy.c b/src/economy.c index 542253ca8..71900a38c 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1297,7 +1297,8 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) allocation *al; attrib *a = a_find(rtype->attribs, &at_resourcelimit); resource_limit *rdata = (resource_limit *) a->data.v; - int amount, skill; + const resource_type *rring; + int amount, skill; /* momentan kann man keine ressourcen abbauen, wenn man dafür * Materialverbrauch hat: */ @@ -1347,7 +1348,7 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) * Als magische Wesen 'sehen' Bergwächter alles und werden durch * Belagerung nicht aufgehalten. (Ansonsten wie oben bei Elfen anpassen). */ - if (itype == olditemtype[I_IRON] || itype == olditemtype[I_LAEN]) { + if (itype->rtype && (itype->rtype==get_resourcetype(R_IRON) || itype->rtype==rt_find("laen"))) { unit *u2; for (u2 = r->units; u2; u2 = u2->next) { if (is_guard(u, GUARD_MINING) @@ -1397,16 +1398,18 @@ static void allocate_resource(unit * u, const resource_type * rtype, int want) /* nun ist amount die Gesamtproduktion der Einheit (in punkten) */ /* mit Flinkfingerring verzehnfacht sich die Produktion */ - amount += - skill * _min(u->number, get_item(u, - I_RING_OF_NIMBLEFINGER)) * (roqf_factor() - 1); + rring = get_resourcetype(R_RING_OF_NIMBLEFINGER); + if (rring) { + int dm = i_get(u->items, rring->itype); + amount += skill * _min(u->number, dm) * (roqf_factor() - 1); + } - /* Schaffenstrunk: */ - if ((dm = get_effect(u, oldpotiontype[P_DOMORE])) != 0) { - dm = _min(dm, u->number); - change_effect(u, oldpotiontype[P_DOMORE], -dm); - amount += dm * skill; /* dm Personen produzieren doppelt */ - } + /* Schaffenstrunk: */ + if ((dm = get_effect(u, oldpotiontype[P_DOMORE])) != 0) { + dm = _min(dm, u->number); + change_effect(u, oldpotiontype[P_DOMORE], -dm); + amount += dm * skill; /* dm Personen produzieren doppelt */ + } amount /= itype->construction->minskill; @@ -2601,32 +2604,32 @@ static void breedtrees(region * r, unit * u, int raw) /* züchte pferde */ static void breedhorses(region * r, unit * u) { - int n, c; - int gezuechtet = 0; - struct building *b = inside_building(u); - const struct building_type *btype = b ? b->type : NULL; + int n, c, breed = 0; + struct building *b = inside_building(u); + const struct building_type *btype = b ? b->type : NULL; + const struct item_type *ihorse = it_find("horse"); - if (btype != bt_find("stables")) { - cmistake(u, u->thisorder, 122, MSG_PRODUCE); - return; - } - if (get_item(u, I_HORSE) < 2) { - cmistake(u, u->thisorder, 107, MSG_PRODUCE); - return; - } - n = _min(u->number * eff_skill(u, SK_HORSE_TRAINING, r), get_item(u, I_HORSE)); - - for (c = 0; c < n; c++) { - if (rng_int() % 100 < eff_skill(u, SK_HORSE_TRAINING, r)) { - i_change(&u->items, olditemtype[I_HORSE], 1); - gezuechtet++; + assert(ihorse); + if (btype != bt_find("stables")) { + cmistake(u, u->thisorder, 122, MSG_PRODUCE); + return; } - } + if (i_get(u->items, ihorse) < 2) { + cmistake(u, u->thisorder, 107, MSG_PRODUCE); + return; + } + n = _min(u->number * eff_skill(u, SK_HORSE_TRAINING, r), i_get(u->items, ihorse)); - produceexp(u, SK_HORSE_TRAINING, u->number); + for (c = 0; c < n; c++) { + if (rng_int() % 100 < eff_skill(u, SK_HORSE_TRAINING, r)) { + i_change(&u->items, ihorse, 1); + ++breed; + } + } - ADDMSG(&u->faction->msgs, msg_message("raised", - "unit amount", u, gezuechtet)); + produceexp(u, SK_HORSE_TRAINING, u->number); + + ADDMSG(&u->faction->msgs, msg_message("raised", "unit amount", u, breed)); } static void breed_cmd(unit * u, struct order *ord) @@ -2753,6 +2756,7 @@ static int max_skill(region * r, faction * f, skill_t sk) static void steal_cmd(unit * u, struct order *ord, request ** stealorders) { + const resource_type *rring = get_resourcetype(R_RING_OF_NIMBLEFINGER); int n, i, id; bool goblin = false; request *o; @@ -2842,7 +2846,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) } } - i = _min(u->number, get_item(u, I_RING_OF_NIMBLEFINGER)); + i = _min(u->number, i_get(u->items, rring->itype)); if (i > 0) { n *= STEALINCOME * (u->number + i * (roqf_factor() - 1)); } else { diff --git a/src/kernel/battle.c b/src/kernel/battle.c index 9a5facbb2..bdd9d5226 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -839,15 +839,17 @@ static const armor_type *select_armor(troop t, bool shield) * - Artefakt I_TROLLBELT gibt Rüstung +1 * - Zauber Rindenhaut gibt Rüstung +3 */ +static int trollbelts(const unit *u) { + const struct item_type *belt = it_find("trollbelt"); + return belt ? i_get(u->items, belt) : 0; +} + int select_magicarmor(troop t) { unit *u = t.fighter->unit; - int geschuetzt = 0; int ma = 0; - geschuetzt = _min(get_item(u, I_TROLLBELT), u->number); - - if (geschuetzt > t.index) /* unser Kandidat wird geschuetzt */ + if (trollbelts(u) > t.index) /* unser Kandidat wird geschuetzt */ ma += 1; return ma; @@ -3252,7 +3254,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) /* change_effect wird in ageing gemacht */ /* Effekte von Artefakten */ - strongmen = _min(fig->unit->number, get_item(u, I_TROLLBELT)); + strongmen = _min(fig->unit->number, trollbelts(u)); /* Hitpoints, Attack- und Defence-Boni für alle Personen */ for (i = 0; i < fig->alive; i++) { @@ -3371,15 +3373,15 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) fig->horses = fig->unit->number; fig->elvenhorses = 0; } else { - static const item_type *it_charger = 0; - if (it_charger == 0) { - it_charger = it_find("charger"); - if (!it_charger) { - it_charger = it_find("horse"); - } + const item_type *it_horse = 0; + const item_type *it_elvenhorse = 0; + it_elvenhorse = it_find("elvenhorse"); + it_horse = it_find("charger"); + if (!it_horse) { + it_horse = it_find("horse"); } - fig->horses = i_get(u->items, it_charger); - fig->elvenhorses = get_item(u, I_ELVENHORSE); + fig->horses = i_get(u->items, it_horse); + fig->elvenhorses = i_get(u->items, it_elvenhorse); } if (u_race(u)->battle_flags & BF_EQUIPMENT) { diff --git a/src/kernel/battle.test.c b/src/kernel/battle.test.c index cd57eb147..1719ff516 100644 --- a/src/kernel/battle.test.c +++ b/src/kernel/battle.test.c @@ -31,7 +31,7 @@ static void test_make_fighter(CuTest * tc) set_level(au, SK_MAGIC, 3); set_level(au, SK_RIDING, 3); au->status = ST_BEHIND; - set_item(au, I_HORSE, 1); + i_change(&au->items, it_find("horse"), 1); b = make_battle(r); as = make_side(b, au->faction, 0, 0, 0); diff --git a/src/kernel/build.c b/src/kernel/build.c index f24b17f81..86b390755 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -326,7 +326,8 @@ void build_road(region * r, unit * u, int size, direction_t d) /* n = maximum by skill. try to maximize it */ n = u->number * eff_skill(u, SK_ROAD_BUILDING, r); if (n < left) { - item *itm = *i_find(&u->items, olditemtype[I_RING_OF_NIMBLEFINGER]); + const resource_type *ring = get_resourcetype(R_RING_OF_NIMBLEFINGER); + item *itm = ring ? *i_find(&u->items, ring->itype) : 0; if (itm != NULL && itm->number > 0) { int rings = _min(u->number, itm->number); n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; @@ -516,10 +517,9 @@ int build(unit * u, const construction * ctype, int completed, int want) /* Flinkfingerring wirkt nicht auf Mengenbegrenzte (magische) * Talente */ if (skill_limit(u->faction, type->skill) == INT_MAX) { - int i = 0; - item *itm = *i_find(&u->items, olditemtype[I_RING_OF_NIMBLEFINGER]); - if (itm != NULL) - i = itm->number; + const resource_type *ring = get_resourcetype(R_RING_OF_NIMBLEFINGER); + item *itm = ring ? *i_find(&u->items, ring->itype) : 0; + int i = itm ? itm->number : 0; if (i > 0) { int rings = _min(u->number, i); n = n * ((roqf_factor() - 1) * rings + u->number) / u->number; diff --git a/src/kernel/config.c b/src/kernel/config.c index 155b82d39..b0e904320 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -2120,7 +2120,7 @@ int weight(const unit * u) n += u->number * u_race(u)->weight; - w = get_item(u, I_BAG_OF_HOLDING) * BAGCAPACITY; + w = i_get(u->items, it_find("magicbag")) * BAGCAPACITY; if (w > in_bag) w = in_bag; n -= w; diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 67018796e..7f028b512 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -99,6 +99,12 @@ void free_faction(faction * f) freelist(f->ursprung); } +void set_show_item(faction * f, const struct item_type *itype) +{ + attrib *a = a_add(&f->attribs, a_new(&at_showitem)); + a->data.v = (void *)itype; +} + faction *get_monsters(void) { static faction *monsters; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index e00ceac01..77a8ba167 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -54,10 +54,9 @@ extern "C" { #define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_NOTIMEOUT|FFL_DBENTRY|FFL_NOIDLEOUT) - struct faction *get_monsters(void); #define is_monsters(f) ((f)->flags&FFL_NPC) - typedef struct faction { +typedef struct faction { struct faction *next; struct faction *nexthash; @@ -110,20 +109,21 @@ extern "C" { struct item *items; /* items this faction can claim */ struct seen_region **seen; struct quicklist *seen_factions; - } faction; +} faction; - extern struct faction *factions; +extern struct faction *factions; - int max_magicians(const faction * f); +struct faction *get_monsters(void); +int max_magicians(const faction * f); +void set_show_item(faction * f, const struct item_type *itype); - extern const struct unit *random_unit_in_faction(const struct faction *f); - extern const char *factionname(const struct faction *f); - extern struct unit *addplayer(struct region *r, faction * f); - extern struct faction *addfaction(const char *email, const char *password, +const struct unit *random_unit_in_faction(const struct faction *f); +const char *factionname(const struct faction *f); +struct unit *addplayer(struct region *r, faction * f); +struct faction *addfaction(const char *email, const char *password, const struct race *frace, const struct locale *loc, int subscription); - extern bool checkpasswd(const faction * f, const char *passwd, - bool shortp); - extern void destroyfaction(faction * f); +bool checkpasswd(const faction * f, const char *passwd, bool shortp); +void destroyfaction(faction * f); extern void set_alliance(struct faction *a, struct faction *b, int status); extern int get_alliance(const struct faction *a, const struct faction *b); diff --git a/src/kernel/item.c b/src/kernel/item.c index 9a4f57a9c..2a06337d0 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -399,12 +399,12 @@ item **i_find(item ** i, const item_type * it) return i; } -item *const *i_findc(item * const *i, const item_type * it) +item *const* i_findc(item *const* iter, const item_type * it) { - while (*i && (*i)->type != it) { - i = &(*i)->next; + while (*iter && (*iter)->type != it) { + iter = &(*iter)->next; } - return i; + return iter; } int i_get(const item * i, const item_type * it) @@ -597,7 +597,6 @@ give_money(unit * s, unit * d, const item_type * itype, int n, #define LASTLUXURY (I_INCENSE +1) #define MAXLUXURIES (LASTLUXURY - FIRSTLUXURY) -const item_type *olditemtype[MAXITEMS + 1]; const potion_type *oldpotiontype[MAXPOTIONS + 1]; /*** alte items ***/ @@ -607,7 +606,7 @@ const char *itemnames[MAX_RESOURCES] = { "aots", "roi", "rop", "ao_chastity", "laen", "fairyboot", "aoc", "pegasus", "elvenhorse", "dolphin", "roqf", "trollbelt", - "presspass", "aurafocus", "sphereofinv", "magicbag", + "aurafocus", "sphereofinv", "magicbag", "magicherbbag", "dreameye", "money", "aura", "permaura" }; @@ -616,24 +615,21 @@ const resource_type *get_resourcetype(resource_t type) { return rtype; } -int get_item(const unit * u, item_t it) +int get_item(const unit * u, const item_type *itype) { - const item_type *type = olditemtype[it]; - const item *i = *i_findc(&u->items, type); - if (i) - assert(i->number >= 0); + const item *i = *i_findc(&u->items, itype); + assert(!i || i->number >= 0); return i ? i->number : 0; } -int set_item(unit * u, item_t it, int value) +int set_item(unit * u, const item_type *itype, int value) { - const item_type *type = olditemtype[it]; item *i; - assert(type); - i = *i_find(&u->items, type); + assert(itype); + i = *i_find(&u->items, itype); if (!i) { - i = i_add(&u->items, i_new(type, value)); + i = i_add(&u->items, i_new(itype, value)); } else { i->number = value; assert(i->number >= 0); @@ -731,20 +727,6 @@ mod_dwarves_only(const unit * u, const region * r, skill_t sk, int value) return -118; } -static void init_olditems(void) -{ - item_t i; - - for (i = 0; i != MAXITEMS; ++i) { - /* item is defined in XML file, but IT_XYZ enum still in use */ - const item_type *itype = it_find(itemnames[i]); - - if (itype) { - olditemtype[i] = itype; - } - } -} - static int heal(unit * user, int effect) { int req = unit_max_hp(user) * user->number - user->hp; @@ -1006,7 +988,6 @@ void init_resources(void) rt_register(r_unit); /* alte typen registrieren: */ - init_olditems(); init_oldpotions(); } @@ -1211,7 +1192,6 @@ void test_clear_resources(void) { int i; - memset((void *)olditemtype, 0, sizeof(olditemtype)); memset((void *)oldpotiontype, 0, sizeof(oldpotiontype)); cb_foreach(&cb_items, "", 0, free_itype_cb, 0); diff --git a/src/kernel/item.h b/src/kernel/item.h index 349f2e300..5e56bb8bb 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -291,7 +291,6 @@ extern "C" { I_DOLPHIN, I_RING_OF_NIMBLEFINGER, I_TROLLBELT, - I_PRESSCARD, I_AURAKULUM, I_SPHERE_OF_INVISIBILITY, I_BAG_OF_HOLDING, @@ -318,7 +317,6 @@ extern "C" { R_DOLPHIN, R_RING_OF_NIMBLEFINGER, R_TROLLBELT, - R_PRESSCARD, R_AURAKULUM, R_SPHERE_OF_INVISIBILITY, R_BAG_OF_HOLDING, @@ -335,11 +333,7 @@ extern "C" { } resource_t; extern const struct potion_type *oldpotiontype[]; - extern const struct item_type *olditemtype[]; - const struct resource_type *get_resourcetype(resource_t type); - - int get_item(const struct unit *, item_t); - int set_item(struct unit *, item_t, int); + const struct resource_type *get_resourcetype(resource_t rt); int get_money(const struct unit *); int set_money(struct unit *, int); diff --git a/src/kernel/item.test.c b/src/kernel/item.test.c index e78799a79..db4acff26 100644 --- a/src/kernel/item.test.c +++ b/src/kernel/item.test.c @@ -31,7 +31,7 @@ void test_change_item(CuTest * tc) test_create_world(); u = test_create_unit(0, 0); - test_uchange(tc, u, olditemtype[I_IRON]->rtype); + test_uchange(tc, u, get_resourcetype(R_IRON)); } void test_change_person(CuTest * tc) diff --git a/src/kernel/magic.c b/src/kernel/magic.c index 1299666d3..d95519687 100644 --- a/src/kernel/magic.c +++ b/src/kernel/magic.c @@ -723,7 +723,7 @@ int max_spellpoints(const region * r, const unit * u) sk = eff_skill(u, SK_MAGIC, r); msp = u_race(u)->maxaura * (pow(sk, potenz) / divisor + 1) + get_spchange(u); - if (get_item(u, I_AURAKULUM) > 0) { + if (i_get(u->items, it_find("aurafocus")) > 0) { msp += use_item_aura(r, u); } n = get_curseeffect(u->attribs, C_AURA, 0); @@ -1022,7 +1022,7 @@ spellpower(region * r, unit * u, const spell * sp, int cast_level, ++force; } - if (get_item(u, I_RING_OF_POWER) > 0) + if (i_get(u->items, it_find("rop")) > 0) ++force; if (elf_power < 0) { elf_power = get_param_int(global.parameters, "rules.magic.elfpower", 0); @@ -1125,7 +1125,7 @@ double magic_resistance(unit * target) } /* Unicorn +10 */ - n = get_item(target, I_ELVENHORSE); + n = i_get(target->items, it_find("elvenhorse")); if (n) probability += n * 0.1 / target->number; diff --git a/src/kernel/move.c b/src/kernel/move.c index b6c8ef1d7..1c5ebc5d6 100644 --- a/src/kernel/move.c +++ b/src/kernel/move.c @@ -270,10 +270,12 @@ static int ridingcapacity(unit * u) int walkingcapacity(const struct unit *u) { - int n, tmp, people, pferde_fuer_wagen; + int n, people, pferde_fuer_wagen; int wagen_ohne_pferde, wagen_mit_pferden, wagen_mit_trollen; int vehicles = 0, vcap = 0; int animals = 0, acap = 0; + const struct item_type *ihorse = it_find("horse"); + const struct item_type *ibelt = it_find("trollbelt"); get_transporters(u->items, &animals, &acap, &vehicles, &vcap); @@ -309,16 +311,20 @@ int walkingcapacity(const struct unit *u) n += animals * acap; n += people * personcapacity(u); /* Goliathwasser */ - tmp = get_effect(u, oldpotiontype[P_STRONG]); - if (tmp > 0) { - int horsecap = olditemtype[I_HORSE]->capacity; - if (tmp > people) - tmp = people; - n += tmp * (horsecap - personcapacity(u)); + if (ihorse) { + int tmp = get_effect(u, oldpotiontype[P_STRONG]); + if (tmp > 0) { + int horsecap = ihorse->capacity; + if (tmp > people) { + tmp = people; + } + n += tmp * (horsecap - personcapacity(u)); + } + } + if (ibelt) { + int tmp = i_get(u->items, ibelt); + n += _min(people, tmp) * (STRENGTHMULTIPLIER - 1) * personcapacity(u); } - /* change_effect wird in ageing gemacht */ - tmp = get_item(u, I_TROLLBELT); - n += _min(people, tmp) * (STRENGTHMULTIPLIER - 1) * personcapacity(u); return n; } @@ -372,7 +378,7 @@ static int canwalk(unit * u) bool canfly(unit * u) { - if (get_item(u, I_PEGASUS) >= u->number && effskill(u, SK_RIDING) >= 4) + if (i_get(u->items, it_find("pegasus")) >= u->number && effskill(u, SK_RIDING) >= 4) return true; if (fval(u_race(u), RCF_FLY)) @@ -386,7 +392,7 @@ bool canfly(unit * u) bool canswim(unit * u) { - if (get_item(u, I_DOLPHIN) >= u->number && effskill(u, SK_RIDING) >= 4) + if (i_get(u->items, it_find("dolphin")) >= u->number && effskill(u, SK_RIDING) >= 4) return true; if (u_race(u)->flags & RCF_FLY) @@ -860,7 +866,7 @@ static unit *bewegung_blockiert_von(unit * reisender, region * r) if (!contact && guard) { double prob = 0.3; /* 30% base chance */ prob += 0.1 * (perception - eff_stealth(reisender, r)); - prob += 0.1 * _min(guard->number, get_item(guard, I_AMULET_OF_TRUE_SEEING)); + prob += 0.1 * _min(guard->number, i_get(guard->items, it_find("aots"))); if (chance(prob)) { return guard; @@ -1375,7 +1381,7 @@ static int movement_speed(unit * u) } /* unicorn in inventory */ - if (u->number <= get_item(u, I_FEENSTIEFEL)) { + if (u->number <= i_get(u->items, it_find("fairyboot"))) { mp *= 2; } diff --git a/src/kernel/pool.c b/src/kernel/pool.c index 15f56d330..bc61c0969 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -39,8 +39,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. int get_resource(const unit * u, const resource_type * rtype) { - const item_type *itype = resource2item(rtype); - assert(rtype); if (rtype->uget) { /* this resource is probably special */ @@ -54,16 +52,13 @@ int get_resource(const unit * u, const resource_type * rtype) if (i >= 0) return i; } - if (itype != NULL) { - if (itype == olditemtype[R_STONE] && (u_race(u)->flags & RCF_STONEGOLEM)) { + if (rtype->itype) { + if (rtype == rt_find("stone") && (u_race(u)->flags & RCF_STONEGOLEM)) { return u->number * GOLEM_STONE; - } else if (itype == olditemtype[R_IRON] && (u_race(u)->flags & RCF_IRONGOLEM)) { + } else if (rtype->itype == it_find("iron") && (u_race(u)->flags & RCF_IRONGOLEM)) { return u->number * GOLEM_IRON; } else { - const item *i = *i_findc(&u->items, itype); - if (i) - return i->number; - return 0; + return i_get(u->items, rtype->itype); } } if (rtype == get_resourcetype(R_AURA)) diff --git a/src/kernel/race.c b/src/kernel/race.c index 65fbabf10..b61d5dc87 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -193,12 +193,6 @@ extern void add_raceprefix(const char *prefix) /* "den Zwergen", "Halblingsparteien" */ -void set_show_item(faction * f, item_t i) -{ - attrib *a = a_add(&f->attribs, a_new(&at_showitem)); - a->data.v = (void *)olditemtype[i]; -} - bool r_insectstalled(const region * r) { return fval(r->terrain, ARCTIC_REGION); diff --git a/src/kernel/reports.h b/src/kernel/reports.h index ffd4ee42c..b01af4ff8 100644 --- a/src/kernel/reports.h +++ b/src/kernel/reports.h @@ -57,10 +57,6 @@ extern "C" { extern const struct unit *ucansee(const struct faction *f, const struct unit *u, const struct unit *x); - int hat_in_region(item_t itm, struct region *r, struct faction *f); - -/* für fast_region und neuen CR: */ - enum { see_none, see_neighbour, diff --git a/src/kernel/types.h b/src/kernel/types.h index 4693c4b58..29ee07924 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -131,9 +131,6 @@ typedef enum { P_GROUP, P_FACTIONSTEALTH, P_TREES, - P_XEPOTION, - P_XEBALLOON, - P_XELAEN, P_ALLIANCE, MAXPARAMS, NOPARAM = -1 diff --git a/src/kernel/unit.c b/src/kernel/unit.c index b267136aa..6cda1943d 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -303,13 +303,14 @@ int gift_items(unit * u, int flags) if (flags & GIFT_PEASANTS) { if (!fval(u->region->terrain, SEA_REGION)) { - if (itm->type == olditemtype[I_HORSE]) { - rsethorses(r, rhorses(r) + itm->number); - itm->number = 0; - } else if (itm->type == i_silver) { + if (itm->type == i_silver) { rsetmoney(r, rmoney(r) + itm->number); itm->number = 0; } + else if (itm->type == it_find("horse")) { + rsethorses(r, rhorses(r) + itm->number); + itm->number = 0; + } } } if (itm->number > 0 && (itm->type->flags & ITF_NOTLOST)) { @@ -1210,23 +1211,17 @@ bool has_skill(const unit * u, skill_t sk) static int item_modification(const unit * u, skill_t sk, int val) { - /* Presseausweis: *2 Spionage, 0 Tarnung */ - if (sk == SK_SPY && get_item(u, I_PRESSCARD) >= u->number) { - val = val * 2; - } else if (sk == SK_STEALTH) { + if (sk == SK_STEALTH) { #if NEWATSROI == 1 - if (get_item(u, I_RING_OF_INVISIBILITY) - + 100 * get_item(u, I_SPHERE_OF_INVISIBILITY) >= u->number) { + if (i_get(u->items, it_find("roi")) + + 100 * i_get(u->items, it_find("sphereofinv")) >= u->number) { val += ROIBONUS; } #endif - if (get_item(u, I_PRESSCARD) >= u->number) { - val = 0; - } } #if NEWATSROI == 1 if (sk == SK_PERCEPTION) { - if (get_item(u, I_AMULET_OF_TRUE_SEEING) >= u->number) { + if (i_get(u->items, it_find("aots")) >= u->number) { val += ATSBONUS; } } @@ -1364,12 +1359,13 @@ int invisible(const unit * target, const unit * viewer) return 0; else { int hidden = - get_item(target, I_RING_OF_INVISIBILITY) + 100 * get_item(target, - I_SPHERE_OF_INVISIBILITY); + i_get(target->items, it_find("roi")) + 100 * i_get(target->items, + it_find("sphereofinv")); if (hidden) { hidden = _min(hidden, target->number); - if (viewer) - hidden -= get_item(viewer, I_AMULET_OF_TRUE_SEEING); + if (viewer) { + hidden -= i_get(viewer->items, it_find("aots")); + } } return hidden; } diff --git a/src/laws.c b/src/laws.c index 39dcdebb4..c9a08ed30 100755 --- a/src/laws.c +++ b/src/laws.c @@ -3257,6 +3257,7 @@ static building *age_building(building * b) { const struct building_type *bt_blessed; const struct curse_type *ct_astralblock; + const struct item_type *itype = it_find("elvenhorse"); bt_blessed = bt_find("blessedstonecircle"); ct_astralblock = ct_find("astralblock"); @@ -3268,7 +3269,7 @@ static building *age_building(building * b) * * TODO: this would be nicer in a btype->age function, but we don't have it. */ - if (ct_astralblock && bt_blessed && b->type == bt_blessed) { + if (itype && ct_astralblock && bt_blessed && b->type == bt_blessed) { region *r = b->region; region *rt = r_standard_to_astral(r); unit *u, *mage = NULL; @@ -3281,13 +3282,13 @@ static building *age_building(building * b) int n, unicorns = 0; for (n = 0; n != u->number; ++n) { if (chance(0.02)) { - i_change(&u->items, olditemtype[I_ELVENHORSE], 1); + i_change(&u->items, itype, 1); ++unicorns; } if (unicorns) { ADDMSG(&u->faction->msgs, msg_message("scunicorn", "unit amount rtype", - u, unicorns, olditemtype[I_ELVENHORSE]->rtype)); + u, unicorns, itype->rtype)); } } } diff --git a/src/monster.c b/src/monster.c index 222ee6be5..0c49f1239 100644 --- a/src/monster.c +++ b/src/monster.c @@ -78,47 +78,46 @@ bool monster_is_waiting(const unit * u) static void eaten_by_monster(unit * u) { - /* adjustment for smaller worlds */ - static double multi = 0.0; - int n = 0; - int horse = 0; - - if (multi == 0.0) { - multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; - } - - switch (old_race(u_race(u))) { - 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); - } - - n = (int)(n * multi); - 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)); + /* adjustment for smaller worlds */ + static double multi = 0.0; + int n = 0; + int horse = -1; + + if (multi == 0.0) { + multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0; + } + + switch (old_race(u_race(u))) { + case RC_FIREDRAGON: + n = rng_int() % 80 * u->number; + break; + case RC_DRAGON: + n = rng_int() % 200 * u->number; + break; + case RC_WYRM: + n = rng_int() % 500 * u->number; + break; + default: + n = rng_int() % (u->number / 20 + 1); + horse = 0; + } + horse = horse ? i_get(u->items, it_find("horse")) : 0; + + n = (int)(n * multi); + 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) { + i_change(&u->items, it_find("horse"), -horse); + ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); } - } - if (horse > 0) { - set_item(u, I_HORSE, 0); - ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse)); - } } static void absorbed_by_monster(unit * u) diff --git a/src/races/races.c b/src/races/races.c index af253b3ad..95a6cc5b9 100644 --- a/src/races/races.c +++ b/src/races/races.c @@ -48,22 +48,16 @@ static void oldfamiliars(unit * u) equip_unit(u, get_equipment(fname)); } -static void set_show_item(faction * f, item_t i) -{ - attrib *a = a_add(&f->attribs, a_new(&at_showitem)); - a->data.v = (void *)olditemtype[i]; -} - static void equip_newunits(const struct equipment *eq, struct unit *u) { struct region *r = u->region; switch (old_race(u_race(u))) { case RC_ELF: - set_show_item(u->faction, I_FEENSTIEFEL); + set_show_item(u->faction, it_find("fairyboot")); break; case RC_GOBLIN: - set_show_item(u->faction, I_RING_OF_INVISIBILITY); + set_show_item(u->faction, it_find("roi")); set_number(u, 10); break; case RC_HUMAN: @@ -78,7 +72,7 @@ static void equip_newunits(const struct equipment *eq, struct unit *u) } break; case RC_CAT: - set_show_item(u->faction, I_RING_OF_INVISIBILITY); + set_show_item(u->faction, it_find("roi")); break; case RC_AQUARIAN: { diff --git a/src/randenc.c b/src/randenc.c index 322201147..0e40c4c93 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -1079,8 +1079,12 @@ static void orc_growth(void) int increase = 0; int num = get_cursedmen(u, c); double prob = curse_geteffect(c); + const item_type * it_chastity = it_find("ao_chastity"); - for (n = (num - get_item(u, I_CHASTITY_BELT)); n > 0; n--) { + if (it_chastity) { + num -= i_get(u->items, it_chastity); + } + for (n = num; n > 0; n--) { if (chance(prob)) { ++increase; } @@ -1169,41 +1173,41 @@ static void icebergs(void) #ifdef HERBS_ROT static void rotting_herbs(void) { - static int rule_rot = -1; - region *r; + static int rule_rot = -1; + region *r; - if (rule_rot < 0) { - rule_rot = - get_param_int(global.parameters, "rules.economy.herbrot", HERBROTCHANCE); - } - if (rule_rot == 0) - return; - - for (r = regions; r; r = r->next) { - unit *u; - for (u = r->units; u; u = u->next) { - item **itmp = &u->items; - item *hbag = *i_find(itmp, olditemtype[I_SACK_OF_CONSERVATION]); - int rot_chance = rule_rot; - - if (hbag) - rot_chance = (rot_chance * 2) / 5; - while (*itmp) { - item *itm = *itmp; - int n = itm->number; - double k = n * rot_chance / 100.0; - if (fval(itm->type, ITF_HERB)) { - double nv = normalvariate(k, k / 4); - int inv = (int)nv; - int delta = _min(n, inv); - if (i_change(itmp, itm->type, -delta) == NULL) { - continue; - } - } - itmp = &itm->next; - } + if (rule_rot < 0) { + rule_rot = + get_param_int(global.parameters, "rules.economy.herbrot", HERBROTCHANCE); + } + if (rule_rot == 0) return; + + for (r = regions; r; r = r->next) { + unit *u; + for (u = r->units; u; u = u->next) { + const struct item_type *it_bag = it_find("magicherbbag"); + item **itmp = &u->items; + int rot_chance = rule_rot; + + if (it_bag && *i_find(itmp, it_bag)) { + rot_chance = (rot_chance * 2) / 5; + } + while (*itmp) { + item *itm = *itmp; + int n = itm->number; + double k = n * rot_chance / 100.0; + if (fval(itm->type, ITF_HERB)) { + double nv = normalvariate(k, k / 4); + int inv = (int)nv; + int delta = _min(n, inv); + if (!i_change(itmp, itm->type, -delta)) { + continue; + } + } + itmp = &itm->next; + } + } } - } } #endif diff --git a/src/report.c b/src/report.c index 660a58074..6215c4e1c 100644 --- a/src/report.c +++ b/src/report.c @@ -547,18 +547,6 @@ void sparagraph(strlist ** SP, const char *s, int indent, char mark) } } -int hat_in_region(item_t it, region * r, faction * f) -{ - unit *u; - - for (u = r->units; u; u = u->next) { - if (u->faction == f && get_item(u, it) > 0) { - return 1; - } - } - return 0; -} - static void nr_curses(FILE * F, const faction * viewer, const void *obj, objtype_t typ, int indent) diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index 0b5561e89..2864e31a1 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -1527,6 +1527,10 @@ static int count_healable(battle * b, fighter * df) } return healable; } +static bool has_ao_healing(const unit *u) { + item *const* iter = i_findc(&u->items, it_find("ao_healing")); + return (*iter && (*iter)->number>0); +} /* wiederbeleben */ int sp_reanimate(struct castorder * co) @@ -1539,7 +1543,7 @@ int sp_reanimate(struct castorder * co) int healable, j = 0; double c = 0.50 + 0.02 * power; double k = EFFECT_HEALING_SPELL * power; - bool use_item = get_item(mage, I_AMULET_OF_HEALING) > 0; + bool use_item = has_ao_healing(mage); message *msg; if (use_item) { @@ -1658,7 +1662,7 @@ int sp_healing(struct castorder * co) int healhp = (int)power * 200; quicklist *fgs; message *msg; - bool use_item = get_item(mage, I_AMULET_OF_HEALING) > 0; + bool use_item = has_ao_healing(mage); /* bis zu 11 Personen pro Stufe (einen HP müssen sie ja noch * haben, sonst wären sie tot) können geheilt werden */ diff --git a/src/summary.c b/src/summary.c index ef7a49bbc..0b4bebbcb 100644 --- a/src/summary.c +++ b/src/summary.c @@ -310,10 +310,11 @@ void report_summary(summary * s, summary * o, bool full) summary *make_summary(void) { - faction *f; - region *r; - unit *u; - summary *s = calloc(1, sizeof(summary)); + faction *f; + region *r; + unit *u; + summary *s = calloc(1, sizeof(summary)); + const struct item_type *ihorse = it_find("horse"); for (f = factions; f; f = f->next) { const struct locale *lang = f->locale; @@ -383,7 +384,7 @@ summary *make_summary(void) if (u->flags & UFL_HERO) { s->heroes += u->number; } - s->spielerpferde += get_item(u, I_HORSE); + s->spielerpferde += i_get(u->items, ihorse); s->playermoney += get_money(u); s->armed_men += armedmen(u, true); for (itm = u->items; itm; itm = itm->next) { @@ -395,7 +396,7 @@ summary *make_summary(void) } } - s->spielerpferde += get_item(u, I_HORSE); + s->spielerpferde += i_get(u->items, ihorse); for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { skill_t sk = sv->id; diff --git a/src/tests.c b/src/tests.c index c95d30fbe..84c1595aa 100644 --- a/src/tests.c +++ b/src/tests.c @@ -136,11 +136,10 @@ void test_create_world(void) get_or_create_locale("de"); init_resources(); - assert(!olditemtype[I_HORSE]); - olditemtype[I_HORSE] = test_create_itemtype(names+0); - olditemtype[I_IRON] = test_create_itemtype(names+4); - olditemtype[I_STONE] = test_create_itemtype(names+6); + test_create_itemtype(names+0); + test_create_itemtype(names+4); + test_create_itemtype(names+6); t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION); t_plain->size = 1000;