refactoring: sprout methods for all special-action potions

remove static caches for WOL configuration
This commit is contained in:
Enno Rehling 2015-11-22 14:28:15 +01:00
parent 35e7a0bc79
commit c6bac1e49e
1 changed files with 67 additions and 42 deletions

View File

@ -122,61 +122,86 @@ static void end_potion(unit * u, const potion_type * ptype, int amount)
"unit potion", u, ptype->itype->rtype));
}
static int do_potion(unit * u, region *r, const potion_type * ptype, int amount)
{
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);
}
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)) {
holz = use_pooled(u, rt_find("mallorn"),
wood = use_pooled(u, rt_find("mallorn"),
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
}
else {
holz = use_pooled(u, rt_find("log"),
wood = 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)
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) + holz);
rsettrees(r, tree_type, rtrees(r, tree_type) + wood);
ADDMSG(&u->faction->msgs, msg_message("growtree_effect",
"mage amount", u, holz));
"mage amount", u, wood));
return amount;
}
else if (ptype == oldpotiontype[P_HEILWASSER]) {
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));
}
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 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;
}
else if (ptype == oldpotiontype[P_WAHRHEIT]) {
static int potion_truth(unit *u) {
fset(u, UFL_DISBELIEVES);
amount = 1;
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;
}
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 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]) {
return potion_water_of_life(u, amount);
}
else if (ptype == oldpotiontype[P_HEILWASSER]) {
return potion_healing(u, amount);
}
else if (ptype == oldpotiontype[P_PEOPLE]) {
return potion_luck(u, &at_peasantluck, amount);
}
else if (ptype == oldpotiontype[P_HORSE]) {
return potion_luck(u, &at_horseluck, amount);
}
else if (ptype == oldpotiontype[P_WAHRHEIT]) {
return potion_truth(u);
}
else if (ptype == oldpotiontype[P_MACHT]) {
return potion_power(u, amount);
}
else {
change_effect(u, ptype, 10 * amount);