diff --git a/src/alchemy.c b/src/alchemy.c index 166cde00b..8b8220136 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -122,61 +122,86 @@ static void end_potion(unit * u, const potion_type * ptype, int amount) "unit potion", u, ptype->itype->rtype)); } +static int potion_water_of_life(unit * u, int amount) { + region *r = u->region; + int wood = 0; + int tree_type = config_get_int("rules.magic.wol_type", 1); + int tree_count = config_get_int("rules.magic.wol_effect", 10); + /* mallorn is required to make mallorn forests, wood for regular ones */ + if (fval(r, RF_MALLORN)) { + wood = use_pooled(u, rt_find("mallorn"), + GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount); + } + else { + wood = use_pooled(u, rt_find("log"), + GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount); + } + if (r->land == 0) + wood = 0; + if (wood < tree_count * amount) { + int x = wood / tree_count; + if (wood % tree_count) + ++x; + if (x < amount) + amount = x; + } + rsettrees(r, tree_type, rtrees(r, tree_type) + wood); + ADDMSG(&u->faction->msgs, msg_message("growtree_effect", + "mage amount", u, wood)); + return amount; +} + +static int potion_healing(unit * u, int amount) { + u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount); + return amount; +} + +static int potion_luck(unit *u, attrib_type *atype, int amount) { + region *r = u->region; + attrib *a = (attrib *)a_find(r->attribs, atype); + if (!a) { + a = a_add(&r->attribs, a_new(atype)); + } + a->data.i += amount; + return amount; +} + +static int potion_truth(unit *u) { + fset(u, UFL_DISBELIEVES); + return 1; +} + +static int potion_power(unit *u, int amount) { + int use = u->number / 10; + if (use < amount) { + if (u->number % 10 > 0) ++use; + amount = use; + } + /* Verfünffacht die HP von max. 10 Personen in der Einheit */ + u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4; + return amount; +} + static int do_potion(unit * u, region *r, const potion_type * ptype, int amount) { + assert(r == u->region); // TODO: is r an unnecessary argument? if (ptype == oldpotiontype[P_LIFE]) { - int holz = 0; - static int tree_type = -1; - static int tree_count = -1; - if (tree_type < 0) { - tree_type = config_get_int("rules.magic.wol_type", 1); - tree_count = - config_get_int("rules.magic.wol_effect", 10); - } - /* mallorn is required to make mallorn forests, wood for regular ones */ - if (fval(r, RF_MALLORN)) { - holz = use_pooled(u, rt_find("mallorn"), - GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount); - } - else { - holz = use_pooled(u, rt_find("log"), - GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount); - } - if (r->land == 0) - holz = 0; - if (holz < tree_count * amount) { - int x = holz / tree_count; - if (holz % tree_count) - ++x; - if (x < amount) - amount = x; - } - rsettrees(r, tree_type, rtrees(r, tree_type) + holz); - ADDMSG(&u->faction->msgs, msg_message("growtree_effect", - "mage amount", u, holz)); + return potion_water_of_life(u, amount); } else if (ptype == oldpotiontype[P_HEILWASSER]) { - u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount); + return potion_healing(u, amount); } else if (ptype == oldpotiontype[P_PEOPLE]) { - attrib *a = (attrib *)a_find(r->attribs, &at_peasantluck); - if (!a) - a = a_add(&r->attribs, a_new(&at_peasantluck)); - a->data.i += amount; + return potion_luck(u, &at_peasantluck, amount); } else if (ptype == oldpotiontype[P_HORSE]) { - attrib *a = (attrib *)a_find(r->attribs, &at_horseluck); - if (!a) - a = a_add(&r->attribs, a_new(&at_horseluck)); - a->data.i += amount; + return potion_luck(u, &at_horseluck, amount); } else if (ptype == oldpotiontype[P_WAHRHEIT]) { - fset(u, UFL_DISBELIEVES); - amount = 1; + return potion_truth(u); } else if (ptype == oldpotiontype[P_MACHT]) { - /* Verfünffacht die HP von max. 10 Personen in der Einheit */ - u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4; + return potion_power(u, amount); } else { change_effect(u, ptype, 10 * amount);