2018-01-01 08:23:52 +01:00
|
|
|
|
#ifdef _MSC_VER
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <platform.h>
|
2018-01-01 08:23:52 +01:00
|
|
|
|
#endif
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "items.h"
|
|
|
|
|
|
2017-02-27 14:10:12 +01:00
|
|
|
|
#include "alchemy.h"
|
2017-12-29 11:44:14 +01:00
|
|
|
|
#include "skill.h"
|
|
|
|
|
#include "direction.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include "study.h"
|
2016-11-22 12:22:07 +01:00
|
|
|
|
#include "economy.h"
|
2014-11-01 12:57:01 +01:00
|
|
|
|
#include "magic.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2017-08-21 20:18:19 +02:00
|
|
|
|
#include <spells/shipcurse.h>
|
|
|
|
|
#include <spells/unitcurse.h>
|
|
|
|
|
#include <spells/regioncurse.h>
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/curse.h>
|
2018-02-15 20:25:58 +01:00
|
|
|
|
#include <kernel/config.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/item.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
|
#include <kernel/messages.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/order.h>
|
|
|
|
|
#include <kernel/pool.h>
|
2017-02-27 14:10:12 +01:00
|
|
|
|
#include <kernel/race.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
|
#include <kernel/spell.h>
|
2017-12-29 11:44:14 +01:00
|
|
|
|
#include <kernel/skills.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
2017-02-27 14:10:12 +01:00
|
|
|
|
/* triggers includes */
|
|
|
|
|
#include <triggers/changerace.h>
|
|
|
|
|
#include <triggers/timeout.h>
|
|
|
|
|
|
2018-09-29 11:37:17 +02:00
|
|
|
|
#include <kernel/attrib.h>
|
|
|
|
|
#include <kernel/event.h>
|
2018-09-29 18:13:32 +02:00
|
|
|
|
#include <util/keyword.h>
|
2017-12-29 06:13:28 +01:00
|
|
|
|
#include <util/macros.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <util/parser.h>
|
|
|
|
|
#include <util/rand.h>
|
2017-02-27 14:10:12 +01:00
|
|
|
|
#include <util/rng.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
2017-12-29 11:44:14 +01:00
|
|
|
|
#include <stddef.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
|
|
/* BEGIN studypotion */
|
|
|
|
|
#define MAXGAIN 15
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
2014-08-23 09:17:58 +02:00
|
|
|
|
struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2017-10-09 20:33:47 +02:00
|
|
|
|
if (u->thisorder && init_order(u->thisorder, u->faction->locale) == K_STUDY) {
|
2014-12-22 16:28:17 +01:00
|
|
|
|
char token[128];
|
2014-09-21 16:43:17 +02:00
|
|
|
|
skill_t sk = NOSKILL;
|
|
|
|
|
skill *sv = 0;
|
2014-12-22 16:28:17 +01:00
|
|
|
|
const char * s = gettoken(token, sizeof(token));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
2014-09-21 16:43:17 +02:00
|
|
|
|
if (s) {
|
|
|
|
|
sk = get_skill(s, u->faction->locale);
|
|
|
|
|
sv = unit_skill(u, sk);
|
|
|
|
|
}
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
|
|
|
|
if (sv && sv->level > 2) {
|
|
|
|
|
/* TODO: message */
|
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
|
else if (sk != NOSKILL && study_cost(u, sk) > 0) {
|
2014-08-23 09:17:58 +02:00
|
|
|
|
/* TODO: message */
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attrib *a = a_find(u->attribs, &at_learning);
|
|
|
|
|
teaching_info *teach;
|
|
|
|
|
if (a == NULL) {
|
|
|
|
|
a = a_add(&u->attribs, a_new(&at_learning));
|
|
|
|
|
}
|
|
|
|
|
teach = (teaching_info *)a->data.v;
|
2014-09-21 16:43:17 +02:00
|
|
|
|
if (amount > MAXGAIN) {
|
2014-08-23 09:17:58 +02:00
|
|
|
|
amount = MAXGAIN;
|
2014-09-21 16:43:17 +02:00
|
|
|
|
}
|
2017-09-02 15:50:03 +02:00
|
|
|
|
teach->days += amount * STUDYDAYS;
|
|
|
|
|
if (teach->days > MAXGAIN * STUDYDAYS) {
|
|
|
|
|
teach->days = MAXGAIN * STUDYDAYS;
|
2014-08-23 09:17:58 +02:00
|
|
|
|
}
|
|
|
|
|
i_change(&u->items, itype, -amount);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-08-23 09:17:58 +02:00
|
|
|
|
return EUNUSABLE;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
/* END studypotion */
|
|
|
|
|
|
|
|
|
|
/* BEGIN speedsail */
|
|
|
|
|
#define SPEEDSAIL_EFFECT 1
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_speedsail(struct unit *u, const struct item_type *itype, int amount,
|
2014-08-23 09:17:58 +02:00
|
|
|
|
struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2015-05-15 19:08:44 +02:00
|
|
|
|
double effect;
|
2014-08-23 09:17:58 +02:00
|
|
|
|
ship *sh = u->ship;
|
|
|
|
|
if (!sh) {
|
|
|
|
|
cmistake(u, ord, 20, MSG_MOVE);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
effect = SPEEDSAIL_EFFECT;
|
2017-08-18 19:48:34 +02:00
|
|
|
|
create_curse(u, &sh->attribs, &ct_shipspeedup, 20, INT_MAX, effect, 0);
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_speedsail", "unit speed", u,
|
|
|
|
|
SPEEDSAIL_EFFECT));
|
|
|
|
|
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* END speedsail */
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
/* Kann auch von Nichtmagiern benutzt werden, erzeugt eine
|
|
|
|
|
* Antimagiezone, die zwei Runden bestehen bleibt */
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_antimagiccrystal(unit * u, const struct item_type *itype, int amount,
|
2014-08-23 09:17:58 +02:00
|
|
|
|
struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
|
region *r = u->region;
|
2018-02-25 17:58:45 +01:00
|
|
|
|
const resource_type *rt_crystal;
|
2014-08-23 09:17:58 +02:00
|
|
|
|
int i;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2016-11-20 19:08:39 +01:00
|
|
|
|
rt_crystal = rt_find("antimagic");
|
|
|
|
|
assert(rt_crystal != NULL);
|
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
for (i = 0; i != amount; ++i) {
|
2018-02-25 17:58:45 +01:00
|
|
|
|
int effect;
|
2015-05-15 19:08:44 +02:00
|
|
|
|
double force;
|
2014-08-23 09:17:58 +02:00
|
|
|
|
spell *sp = find_spell("antimagiczone");
|
|
|
|
|
attrib **ap = &r->attribs;
|
2017-01-10 16:31:05 +01:00
|
|
|
|
UNUSED_ARG(ord);
|
2014-08-23 09:17:58 +02:00
|
|
|
|
assert(sp);
|
|
|
|
|
|
2017-02-27 14:10:12 +01:00
|
|
|
|
/* Reduziert die St<53>rke jedes Spruchs um effect */
|
2014-08-23 09:17:58 +02:00
|
|
|
|
effect = 5;
|
|
|
|
|
|
2017-02-27 14:10:12 +01:00
|
|
|
|
/* H<>lt Spr<70>che bis zu einem summierten Gesamtlevel von power aus.
|
2014-08-23 09:17:58 +02:00
|
|
|
|
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
|
|
|
|
|
* um seine Stufe */
|
2018-12-15 19:38:40 +01:00
|
|
|
|
force = effect * 20.0; /* Stufe 5 =~ 100 */
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
2017-02-27 14:10:12 +01:00
|
|
|
|
/* Regionszauber aufl<66>sen */
|
2014-08-23 09:17:58 +02:00
|
|
|
|
while (*ap && force > 0) {
|
|
|
|
|
curse *c;
|
|
|
|
|
attrib *a = *ap;
|
2017-08-25 21:11:01 +02:00
|
|
|
|
if (a->type != &at_curse) {
|
2014-08-23 09:17:58 +02:00
|
|
|
|
do {
|
|
|
|
|
ap = &(*ap)->next;
|
|
|
|
|
} while (*ap && a->type == (*ap)->type);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
c = (curse *)a->data.v;
|
|
|
|
|
|
2017-02-27 14:10:12 +01:00
|
|
|
|
/* Immunit<69>t pr<70>fen */
|
2014-08-23 09:17:58 +02:00
|
|
|
|
if (c_flags(c) & CURSE_IMMUNE) {
|
|
|
|
|
do {
|
|
|
|
|
ap = &(*ap)->next;
|
|
|
|
|
} while (*ap && a->type == (*ap)->type);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
force = destr_curse(c, effect, force);
|
|
|
|
|
if (c->vigour <= 0) {
|
|
|
|
|
a_remove(&r->attribs, a);
|
|
|
|
|
}
|
|
|
|
|
if (*ap)
|
|
|
|
|
ap = &(*ap)->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (force > 0) {
|
2018-02-25 17:58:45 +01:00
|
|
|
|
int duration = 2;
|
2017-08-21 20:18:19 +02:00
|
|
|
|
create_curse(u, &r->attribs, &ct_antimagiczone, force, duration,
|
2015-05-15 19:08:44 +02:00
|
|
|
|
effect, 0);
|
2014-08-23 09:17:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
use_pooled(u, rt_crystal, GET_DEFAULT, amount);
|
2017-02-03 21:48:03 +01:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("use_antimagiccrystal", "unit", u));
|
2014-08-23 09:17:58 +02:00
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 06:28:12 +01:00
|
|
|
|
#define BAGPIPEFRACTION (dice(2,4)+2)
|
|
|
|
|
#define BAGPIPEDURATION (dice(2,10)+4)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_bagpipeoffear(struct unit *u, const struct item_type *itype,
|
2014-08-23 09:17:58 +02:00
|
|
|
|
int amount, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
|
int money;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2017-08-21 20:18:19 +02:00
|
|
|
|
if (get_curse(u->region->attribs, &ct_depression)) {
|
2014-08-23 09:17:58 +02:00
|
|
|
|
cmistake(u, ord, 58, MSG_MAGIC);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
money = entertainmoney(u->region) / BAGPIPEFRACTION;
|
|
|
|
|
change_money(u, money);
|
|
|
|
|
rsetmoney(u->region, rmoney(u->region) - money);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2017-08-21 20:18:19 +02:00
|
|
|
|
create_curse(u, &u->region->attribs, &ct_depression,
|
2014-08-23 09:17:58 +02:00
|
|
|
|
20, BAGPIPEDURATION, 0.0, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction",
|
|
|
|
|
"unit region command money", u, u->region, ord, money));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("bagpipeoffear_region",
|
|
|
|
|
"unit money", u, money));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_aurapotion50(struct unit *u, const struct item_type *itype,
|
2014-08-23 09:17:58 +02:00
|
|
|
|
int amount, struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
|
if (!is_mage(u)) {
|
|
|
|
|
cmistake(u, ord, 214, MSG_MAGIC);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
change_spellpoints(u, 50);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2018-05-17 19:03:49 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("aurapotion50_effect",
|
2014-08-23 09:17:58 +02:00
|
|
|
|
"unit region command", u, u->region, ord));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 14:10:12 +01:00
|
|
|
|
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));
|
|
|
|
|
|
2018-01-12 09:17:01 +01:00
|
|
|
|
change_effect(target, itype, amount);
|
2017-02-27 14:10:12 +01:00
|
|
|
|
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)) {
|
2018-01-12 09:17:01 +01:00
|
|
|
|
change_effect(u, itype, 100 * amount);
|
2017-02-27 14:10:12 +01:00
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
2018-02-17 15:30:38 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_item",
|
|
|
|
|
"unit amount item", u, amount, itype->rtype));
|
2017-02-27 14:10:12 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 18:50:48 +01:00
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
/* Kann auch von Nichtmagier benutzt werden, modifiziert Taktik fuer diese
|
|
|
|
|
* Runde um -1 - 4 Punkte. */
|
|
|
|
|
static int
|
|
|
|
|
use_tacticcrystal(unit * u, const struct item_type *itype, int amount,
|
|
|
|
|
struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2017-02-27 18:50:48 +01:00
|
|
|
|
int i;
|
|
|
|
|
for (i = 0; i != amount; ++i) {
|
2017-02-27 19:35:14 +01:00
|
|
|
|
int duration = 1; /* wirkt nur in dieser Runde */
|
2017-02-27 18:50:48 +01:00
|
|
|
|
curse *c;
|
|
|
|
|
float effect;
|
|
|
|
|
float power = 5; /* Widerstand gegen Antimagiesprueche, ist in diesem
|
|
|
|
|
Fall egal, da der curse fuer den Kampf gelten soll,
|
|
|
|
|
der vor den Antimagiezaubern passiert */
|
|
|
|
|
|
|
|
|
|
effect = (float)(rng_int() % 6 - 1);
|
2017-08-21 20:18:19 +02:00
|
|
|
|
c = create_curse(u, &u->attribs, &ct_skillmod, power,
|
2017-02-27 18:50:48 +01:00
|
|
|
|
duration, effect, u->number);
|
|
|
|
|
c->data.i = SK_TACTICS;
|
|
|
|
|
UNUSED_ARG(ord);
|
|
|
|
|
}
|
|
|
|
|
use_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_tacticcrystal",
|
|
|
|
|
"unit region", u, u->region));
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2017-02-27 14:10:12 +01:00
|
|
|
|
|
2017-02-27 19:35:14 +01:00
|
|
|
|
static int
|
|
|
|
|
use_mistletoe(struct unit *user, const struct item_type *itype, int amount,
|
|
|
|
|
struct order *ord)
|
|
|
|
|
{
|
2018-01-21 18:07:49 +01:00
|
|
|
|
int mtoes = get_pooled(user, itype->rtype,
|
|
|
|
|
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, amount);
|
|
|
|
|
if (mtoes < amount) {
|
|
|
|
|
amount = mtoes;
|
|
|
|
|
}
|
|
|
|
|
if (amount > 0) {
|
|
|
|
|
use_pooled(user, itype->rtype,
|
|
|
|
|
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, amount);
|
|
|
|
|
change_effect(user, itype, amount);
|
|
|
|
|
ADDMSG(&user->faction->msgs,
|
|
|
|
|
msg_message("use_item", "unit amount item", user, amount, itype->rtype));
|
2017-02-27 19:35:14 +01:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 20:26:48 +01:00
|
|
|
|
static int use_warmthpotion(unit *u, const item_type *itype,
|
|
|
|
|
int amount, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
if (u->faction->race == get_race(RC_INSECT)) {
|
|
|
|
|
u->flags |= UFL_WARMTH;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* nur fuer insekten: */
|
|
|
|
|
cmistake(u, ord, 163, MSG_EVENT);
|
|
|
|
|
return ECUSTOM;
|
|
|
|
|
}
|
2018-02-15 20:25:58 +01:00
|
|
|
|
use_pooled(u, itype->rtype, GET_DEFAULT, amount);
|
2017-02-27 20:26:48 +01:00
|
|
|
|
|
2018-02-17 15:30:38 +01:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_item",
|
|
|
|
|
"unit amount item", u, amount, itype->rtype));
|
2017-02-27 20:26:48 +01:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 10:39:23 +01:00
|
|
|
|
static int potion_water_of_life(unit * u, region *r, int amount) {
|
|
|
|
|
static int config;
|
|
|
|
|
static int tree_type, tree_count;
|
|
|
|
|
int wood = 0;
|
|
|
|
|
|
|
|
|
|
if (config_changed(&config)) {
|
|
|
|
|
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)) {
|
|
|
|
|
wood = use_pooled(u, rt_find("mallorn"), GET_DEFAULT, tree_count * amount);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
wood = use_pooled(u, rt_find("log"), GET_DEFAULT, 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 use_water_of_life(unit *u, const item_type *itype,
|
|
|
|
|
int amount, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
return potion_water_of_life(u, u->region, amount);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 18:51:11 +01:00
|
|
|
|
static int heal(unit * user, int effect)
|
|
|
|
|
{
|
|
|
|
|
int req = unit_max_hp(user) * user->number - user->hp;
|
|
|
|
|
if (req > 0) {
|
|
|
|
|
if (req > effect) req = effect;
|
|
|
|
|
effect -= req;
|
|
|
|
|
user->hp += req;
|
|
|
|
|
}
|
|
|
|
|
return effect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int potion_healing(struct unit *user, int amount)
|
|
|
|
|
{
|
|
|
|
|
int effect = amount * 400;
|
|
|
|
|
unit *u = user->region->units;
|
|
|
|
|
effect = heal(u, effect);
|
|
|
|
|
while (effect > 0 && u != NULL) {
|
|
|
|
|
if (u->faction == user->faction) {
|
|
|
|
|
effect = heal(u, effect);
|
|
|
|
|
}
|
|
|
|
|
u = u->next;
|
|
|
|
|
}
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int use_healing_potion(unit *u, const item_type *itype,
|
|
|
|
|
int amount, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_item",
|
|
|
|
|
"unit amount item", u, amount, itype->rtype));
|
|
|
|
|
return potion_healing(u, amount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int potion_ointment(unit * u, int amount) {
|
|
|
|
|
int effect = amount * 400;
|
|
|
|
|
effect = heal(u, effect);
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int use_ointment(unit *u, const item_type *itype,
|
|
|
|
|
int amount, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_item",
|
|
|
|
|
"unit amount item", u, amount, itype->rtype));
|
|
|
|
|
return potion_ointment(u, amount);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-17 19:02:02 +01:00
|
|
|
|
static int potion_power(unit *u, int amount) {
|
|
|
|
|
int hp = 10 * amount;
|
|
|
|
|
|
|
|
|
|
if (hp > u->number) {
|
|
|
|
|
hp = u->number;
|
|
|
|
|
amount = (hp + 9) % 10;
|
|
|
|
|
}
|
|
|
|
|
u->hp += hp * unit_max_hp(u) * 4;
|
|
|
|
|
return amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int use_power_elixir(unit *u, const item_type *itype,
|
|
|
|
|
int amount, struct order *ord)
|
|
|
|
|
{
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_item",
|
|
|
|
|
"unit amount item", u, amount, itype->rtype));
|
|
|
|
|
return potion_power(u, amount);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-27 18:50:48 +01:00
|
|
|
|
void register_itemfunctions(void)
|
|
|
|
|
{
|
2017-02-27 14:10:12 +01:00
|
|
|
|
/* have tests: */
|
2018-02-17 10:45:56 +01:00
|
|
|
|
register_item_use(use_water_of_life, "use_lifepotion");
|
2017-02-27 19:35:14 +01:00
|
|
|
|
register_item_use(use_mistletoe, "use_mistletoe");
|
2017-02-27 18:50:48 +01:00
|
|
|
|
register_item_use(use_tacticcrystal, "use_dreameye");
|
2017-02-27 18:21:41 +01:00
|
|
|
|
register_item_use(use_studypotion, "use_studypotion");
|
2017-02-27 15:14:52 +01:00
|
|
|
|
register_item_use(use_antimagiccrystal, "use_antimagic");
|
|
|
|
|
register_item_use(use_speedsail, "use_speedsail");
|
|
|
|
|
register_item_use(use_bagpipeoffear, "use_bagpipeoffear");
|
2017-02-27 14:17:38 +01:00
|
|
|
|
register_item_use(use_aurapotion50, "use_aurapotion50");
|
2017-02-27 14:10:12 +01:00
|
|
|
|
register_item_use(use_birthdayamulet, "use_aoc");
|
|
|
|
|
register_item_use(use_foolpotion, "use_p7");
|
|
|
|
|
register_item_use(use_bloodpotion, "use_peasantblood");
|
2018-02-17 18:51:11 +01:00
|
|
|
|
register_item_use(use_ointment, "use_ointment");
|
2018-02-17 20:35:00 +01:00
|
|
|
|
register_item_use(use_healing_potion, "use_healing");
|
2018-02-17 19:02:02 +01:00
|
|
|
|
register_item_use(use_power_elixir, "use_p13");
|
2017-02-27 20:26:48 +01:00
|
|
|
|
register_item_use(use_warmthpotion, "use_nestwarmth");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|