2010-08-08 10:06:34 +02:00
|
|
|
|
#include <platform.h>
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
#include "items.h"
|
|
|
|
|
|
|
|
|
|
#include "study.h"
|
2014-08-27 06:40:18 +02:00
|
|
|
|
#include "move.h"
|
2014-11-01 12:57:01 +01:00
|
|
|
|
#include "magic.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
#include <kernel/curse.h>
|
|
|
|
|
#include <kernel/building.h>
|
|
|
|
|
#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/plane.h>
|
|
|
|
|
#include <kernel/pool.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
|
#include <kernel/spell.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
|
|
|
|
|
#include <items/demonseye.h>
|
|
|
|
|
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
#include <util/parser.h>
|
|
|
|
|
#include <util/rand.h>
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#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
|
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
|
if (init_order(u->thisorder) == 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
|
|
|
|
}
|
2014-08-23 09:17:58 +02:00
|
|
|
|
teach->value += amount * 30;
|
|
|
|
|
if (teach->value > MAXGAIN * 30) {
|
|
|
|
|
teach->value = MAXGAIN * 30;
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
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
|
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
|
curse *c;
|
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;
|
|
|
|
|
c =
|
|
|
|
|
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, effect,
|
|
|
|
|
0);
|
|
|
|
|
c_setflag(c, CURSE_NOAGE);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
const resource_type *rt_crystal = NULL;
|
|
|
|
|
int i;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
if (rt_crystal == NULL) {
|
|
|
|
|
rt_crystal = rt_find("antimagic");
|
|
|
|
|
assert(rt_crystal != NULL);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
2014-08-23 09:17:58 +02:00
|
|
|
|
for (i = 0; i != amount; ++i) {
|
|
|
|
|
int effect, duration = 2;
|
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;
|
|
|
|
|
unused_arg(ord);
|
|
|
|
|
assert(sp);
|
|
|
|
|
|
|
|
|
|
/* Reduziert die St<53>rke jedes Spruchs um effect */
|
|
|
|
|
effect = 5;
|
|
|
|
|
|
|
|
|
|
/* H<>lt Spr<70>che bis zu einem summierten Gesamtlevel von power aus.
|
|
|
|
|
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
|
|
|
|
|
* um seine Stufe */
|
2015-05-15 19:08:44 +02:00
|
|
|
|
force = effect * 20; /* Stufe 5 =~ 100 */
|
2014-08-23 09:17:58 +02:00
|
|
|
|
|
|
|
|
|
/* Regionszauber aufl<66>sen */
|
|
|
|
|
while (*ap && force > 0) {
|
|
|
|
|
curse *c;
|
|
|
|
|
attrib *a = *ap;
|
|
|
|
|
if (!fval(a->type, ATF_CURSE)) {
|
|
|
|
|
do {
|
|
|
|
|
ap = &(*ap)->next;
|
|
|
|
|
} while (*ap && a->type == (*ap)->type);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
c = (curse *)a->data.v;
|
|
|
|
|
|
|
|
|
|
/* Immunit<69>t pr<70>fen */
|
|
|
|
|
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) {
|
2015-05-15 19:08:44 +02:00
|
|
|
|
create_curse(u, &r->attribs, ct_find("antimagiczone"), force, duration,
|
|
|
|
|
effect, 0);
|
2014-08-23 09:17:58 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
use_pooled(u, rt_crystal, GET_DEFAULT, amount);
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("use_antimagiccrystal",
|
|
|
|
|
"unit region", u, r));
|
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_instantartsculpture(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
|
|
|
|
building *b;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
if (u->region->land == NULL) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
b = new_building(bt_find("artsculpture"), u->region, u->faction->locale);
|
|
|
|
|
b->size = 100;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region",
|
|
|
|
|
u, u->region));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_instantartacademy(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
|
|
|
|
building *b;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
if (u->region->land == NULL) {
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
b = new_building(bt_find("artacademy"), u->region, u->faction->locale);
|
|
|
|
|
b->size = 100;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
ADDMSG(&u->region->msgs, msg_message("artacademy_create", "unit region", u,
|
|
|
|
|
u->region));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define BAGPIPEFRACTION dice_rand("2d4+2")
|
|
|
|
|
#define BAGPIPEDURATION dice_rand("2d10+4")
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
if (get_curse(u->region->attribs, ct_find("depression"))) {
|
|
|
|
|
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
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
create_curse(u, &u->region->attribs, ct_find("depression"),
|
|
|
|
|
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
|
|
|
|
|
2014-08-23 09:17:58 +02:00
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("aurapotion50",
|
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void register_itemfunctions(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-08-23 09:17:58 +02:00
|
|
|
|
register_demonseye();
|
|
|
|
|
register_item_use(use_antimagiccrystal, "use_antimagiccrystal");
|
|
|
|
|
register_item_use(use_instantartsculpture, "use_instantartsculpture");
|
|
|
|
|
register_item_use(use_studypotion, "use_studypotion");
|
|
|
|
|
register_item_use(use_speedsail, "use_speedsail");
|
|
|
|
|
register_item_use(use_instantartacademy, "use_instantartacademy");
|
|
|
|
|
register_item_use(use_bagpipeoffear, "use_bagpipeoffear");
|
|
|
|
|
register_item_use(use_aurapotion50, "use_aurapotion50");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|