diff --git a/src/items.c b/src/items.c index bb5009038..cae5ea642 100644 --- a/src/items.c +++ b/src/items.c @@ -1,6 +1,7 @@ #include #include "items.h" +#include "alchemy.h" #include "study.h" #include "economy.h" #include "move.h" @@ -14,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -21,9 +23,15 @@ #include +/* triggers includes */ +#include +#include + #include +#include #include #include +#include #include #include @@ -125,15 +133,15 @@ struct order *ord) UNUSED_ARG(ord); assert(sp); - /* Reduziert die Stärke jedes Spruchs um effect */ + /* Reduziert die St�rke jedes Spruchs um effect */ effect = 5; - /* Hält Sprüche bis zu einem summierten Gesamtlevel von power aus. + /* H�lt Spr�che bis zu einem summierten Gesamtlevel von power aus. * Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone * um seine Stufe */ force = effect * 20; /* Stufe 5 =~ 100 */ - /* Regionszauber auflösen */ + /* Regionszauber aufl�sen */ while (*ap && force > 0) { curse *c; attrib *a = *ap; @@ -145,7 +153,7 @@ struct order *ord) } c = (curse *)a->data.v; - /* Immunität prüfen */ + /* Immunit�t pr�fen */ if (c_flags(c) & CURSE_IMMUNE) { do { ap = &(*ap)->next; @@ -264,6 +272,118 @@ int amount, struct order *ord) return 0; } +static int +use_birthdayamulet(unit * u, const struct item_type *itype, int amount, +struct order *ord) +{ + direction_t d; + message *msg = msg_message("meow", ""); + + UNUSED_ARG(ord); + UNUSED_ARG(amount); + UNUSED_ARG(itype); + + add_message(&u->region->msgs, msg); + for (d = 0; d < MAXDIRECTIONS; d++) { + region *tr = rconnect(u->region, d); + if (tr) + add_message(&tr->msgs, msg); + } + msg_release(msg); + return 0; +} + +static int use_foolpotion(unit *u, const item_type *itype, int amount, + struct order *ord) +{ + int targetno = read_unitid(u->faction, u->region); + unit *target = findunit(targetno); + if (target == NULL || u->region != target->region) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", + "")); + return ECUSTOM; + } + if (effskill(u, SK_STEALTH, 0) <= effskill(target, SK_PERCEPTION, 0)) { + cmistake(u, ord, 64, MSG_EVENT); + return ECUSTOM; + } + ADDMSG(&u->faction->msgs, msg_message("givedumb", + "unit recipient amount", u, target, amount)); + + change_effect(target, itype->rtype->ptype, amount); + use_pooled(u, itype->rtype, GET_DEFAULT, amount); + return 0; +} + +static int +use_bloodpotion(struct unit *u, const struct item_type *itype, int amount, +struct order *ord) +{ + if (u->number == 0 || u_race(u) == get_race(RC_DAEMON)) { + change_effect(u, itype->rtype->ptype, 100 * amount); + } + else { + const race *irace = u_irace(u); + if (irace == u_race(u)) { + const race *rcfailure = rc_find("smurf"); + if (!rcfailure) { + rcfailure = rc_find("toad"); + } + if (rcfailure) { + trigger *trestore = trigger_changerace(u, u_race(u), irace); + if (trestore) { + int duration = 2 + rng_int() % 8; + + add_trigger(&u->attribs, "timer", trigger_timeout(duration, + trestore)); + u->irace = NULL; + u_setrace(u, rcfailure); + } + } + } + } + use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, + amount); + usetpotionuse(u, itype->rtype->ptype); + + ADDMSG(&u->faction->msgs, msg_message("usepotion", + "unit potion", u, itype->rtype)); + return 0; +} + +static int heal(unit * user, int effect) +{ + int req = unit_max_hp(user) * user->number - user->hp; + if (req > 0) { + req = MIN(req, effect); + effect -= req; + user->hp += req; + } + return effect; +} + +static int +use_healingpotion(struct unit *user, const struct item_type *itype, int amount, +struct order *ord) +{ + int effect = amount * 400; + unit *u = user->region->units; + effect = heal(user, effect); + while (effect > 0 && u != NULL) { + if (u->faction == user->faction) { + effect = heal(u, effect); + } + u = u->next; + } + use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, + amount); + usetpotionuse(user, itype->rtype->ptype); + + ADDMSG(&user->faction->msgs, msg_message("usepotion", + "unit potion", user, itype->rtype)); + return 0; +} + void register_itemfunctions(void) { register_demonseye(); @@ -274,4 +394,10 @@ void register_itemfunctions(void) register_item_use(use_instantartacademy, "use_instantartacademy"); register_item_use(use_bagpipeoffear, "use_bagpipeoffear"); register_item_use(use_aurapotion50, "use_aurapotion50"); + + /* have tests: */ + register_item_use(use_birthdayamulet, "use_aoc"); + register_item_use(use_foolpotion, "use_p7"); + register_item_use(use_bloodpotion, "use_peasantblood"); + register_item_use(use_healingpotion, "use_ointment"); } diff --git a/src/kernel/item.c b/src/kernel/item.c index e0f8f64cc..ecad829ca 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -34,23 +34,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "terrain.h" #include "unit.h" -/* triggers includes */ -#include -#include - /* util includes */ #include #include -#include -#include #include #include #include #include #include -#include #include +#include +#include #include /* libc includes */ @@ -675,27 +670,6 @@ int set_item(unit * u, const item_type *itype, int value) return value; } -static int -use_birthdayamulet(unit * u, const struct item_type *itype, int amount, -struct order *ord) -{ - direction_t d; - message *msg = msg_message("meow", ""); - - UNUSED_ARG(ord); - UNUSED_ARG(amount); - UNUSED_ARG(itype); - - add_message(&u->region->msgs, msg); - for (d = 0; d < MAXDIRECTIONS; d++) { - region *tr = rconnect(u->region, d); - if (tr) - add_message(&tr->msgs, msg); - } - msg_release(msg); - return 0; -} - /* t_item::flags */ #define FL_ITEM_CURSED (1<<0) #define FL_ITEM_NOTLOST (1<<1) @@ -766,17 +740,6 @@ mod_dwarves_only(const unit * u, const region * r, skill_t sk, int value) return -118; } -static int heal(unit * user, int effect) -{ - int req = unit_max_hp(user) * user->number - user->hp; - if (req > 0) { - req = MIN(req, effect); - effect -= req; - user->hp += req; - } - return effect; -} - void register_item_give(int(*foo) (struct unit *, struct unit *, const struct item_type *, int, struct order *), const char *name) @@ -791,35 +754,6 @@ struct order *), const char *name) register_function((pf_generic)foo, name); } -void -register_item_useonother(int(*foo) (struct unit *, int, -const struct item_type *, int, struct order *), const char *name) -{ - register_function((pf_generic)foo, name); -} - -static int -use_healingpotion(struct unit *user, const struct item_type *itype, int amount, -struct order *ord) -{ - int effect = amount * 400; - unit *u = user->region->units; - effect = heal(user, effect); - while (effect > 0 && u != NULL) { - if (u->faction == user->faction) { - effect = heal(u, effect); - } - u = u->next; - } - use_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, - amount); - usetpotionuse(user, itype->rtype->ptype); - - ADDMSG(&user->faction->msgs, msg_message("usepotion", - "unit potion", user, itype->rtype)); - return 0; -} - static int use_warmthpotion(unit *u, const item_type *itype, int amount, struct order *ord) { @@ -840,64 +774,6 @@ static int use_warmthpotion(unit *u, const item_type *itype, return 0; } -static int use_foolpotion(unit *u, const item_type *itype, int amount, - struct order *ord) -{ - int targetno = read_unitid(u->faction, u->region); - unit *target = findunit(targetno); - if (target == NULL || u->region != target->region) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", - "")); - return ECUSTOM; - } - if (effskill(u, SK_STEALTH, 0) <= effskill(target, SK_PERCEPTION, 0)) { - cmistake(u, ord, 64, MSG_EVENT); - return ECUSTOM; - } - ADDMSG(&u->faction->msgs, msg_message("givedumb", - "unit recipient amount", u, target, amount)); - - change_effect(target, itype->rtype->ptype, amount); - use_pooled(u, itype->rtype, GET_DEFAULT, amount); - return 0; -} - -static int -use_bloodpotion(struct unit *u, const struct item_type *itype, int amount, -struct order *ord) -{ - if (u->number == 0 || u_race(u) == get_race(RC_DAEMON)) { - change_effect(u, itype->rtype->ptype, 100 * amount); - } - else { - const race *irace = u_irace(u); - if (irace == u_race(u)) { - const race *rcfailure = rc_find("smurf"); - if (!rcfailure) { - rcfailure = rc_find("toad"); - } - if (rcfailure) { - trigger *trestore = trigger_changerace(u, u_race(u), irace); - if (trestore) { - int duration = 2 + rng_int() % 8; - - add_trigger(&u->attribs, "timer", trigger_timeout(duration, - trestore)); - u->irace = NULL; - u_setrace(u, rcfailure); - } - } - } - } - use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, - amount); - usetpotionuse(u, itype->rtype->ptype); - - ADDMSG(&u->faction->msgs, msg_message("usepotion", - "unit potion", u, itype->rtype)); - return 0; -} - #include static int use_mistletoe(struct unit *user, const struct item_type *itype, int amount, @@ -1288,12 +1164,8 @@ void register_resources(void) register_function((pf_generic)res_changeaura, "changeaura"); register_item_use(use_potion_delayed, "use_p2"); - register_item_use(use_tacticcrystal, "use_tacticcrystal"); - register_item_use(use_birthdayamulet, "use_aoc"); register_item_use(use_warmthpotion, "use_nestwarmth"); - register_item_use(use_bloodpotion, "use_peasantblood"); - register_item_use(use_healingpotion, "use_ointment"); - register_item_use(use_foolpotion, "use_p7"); + register_item_use(use_tacticcrystal, "use_tacticcrystal"); register_item_use(use_mistletoe, "usemistletoe"); register_item_use(use_magicboost, "usemagicboost"); register_item_use(use_snowball, "usesnowball");