server/src/items.c

276 lines
6.7 KiB
C
Raw Normal View History

2010-08-08 10:06:34 +02:00
#include <platform.h>
#include <kernel/config.h>
#include "items.h"
#include "study.h"
#include <kernel/curse.h>
#include <kernel/building.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/magic.h>
#include <kernel/message.h>
#include <kernel/move.h>
#include <kernel/order.h>
#include <kernel/plane.h>
#include <kernel/pool.h>
#include <kernel/region.h>
#include <kernel/ship.h>
#include <kernel/skill.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,
struct order *ord)
2010-08-08 10:06:34 +02:00
{
if (get_keyword(u->thisorder) == K_STUDY) {
skill_t sk;
2011-03-07 08:02:35 +01:00
skill *sv;
2010-08-08 10:06:34 +02:00
init_tokens(u->thisorder);
skip_token();
sk = findskill(getstrtoken(), u->faction->locale);
sv = get_skill(u, sk);
if (sv && sv->level > 2) {
/* TODO: message */
2011-03-07 08:02:35 +01:00
} else if (study_cost(u, sk) > 0) {
2010-08-08 10:06:34 +02:00
/* TODO: message */
} else {
2011-03-07 08:02:35 +01:00
attrib *a = a_find(u->attribs, &at_learning);
teaching_info *teach;
if (a == NULL) {
2010-08-08 10:06:34 +02:00
a = a_add(&u->attribs, a_new(&at_learning));
}
2011-03-07 08:02:35 +01:00
teach = (teaching_info *) a->data.v;
if (amount > MAXGAIN)
amount = MAXGAIN;
2010-08-08 10:06:34 +02:00
teach->value += amount * 30;
if (teach->value > MAXGAIN * 30) {
teach->value = MAXGAIN * 30;
}
i_change(&u->items, itype, -amount);
return 0;
}
}
return EUNUSABLE;
}
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,
struct order *ord)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
curse *c;
float effect;
2011-03-07 08:02:35 +01:00
ship *sh = u->ship;
2010-08-08 10:06:34 +02:00
if (!sh) {
cmistake(u, ord, 20, MSG_MOVE);
return -1;
}
effect = SPEEDSAIL_EFFECT;
2011-03-07 08:02:35 +01:00
c =
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, effect,
0);
2010-08-08 10:06:34 +02:00
c_setflag(c, CURSE_NOAGE);
2011-03-07 08:02:35 +01:00
ADDMSG(&u->faction->msgs, msg_message("use_speedsail", "unit speed", u,
SPEEDSAIL_EFFECT));
2010-08-08 10:06:34 +02:00
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
return 0;
}
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,
struct order *ord)
2010-08-08 10:06:34 +02:00
{
2011-03-07 08:02:35 +01:00
region *r = u->region;
const resource_type *rt_crystal = NULL;
2010-08-08 10:06:34 +02:00
int i;
if (rt_crystal == NULL) {
rt_crystal = rt_find("antimagic");
2011-03-07 08:02:35 +01:00
assert(rt_crystal != NULL);
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
for (i = 0; i != amount; ++i) {
2010-08-08 10:06:34 +02:00
int effect, duration = 2;
float force;
spell *sp = find_spell("antimagiczone");
2011-03-07 08:02:35 +01:00
attrib **ap = &r->attribs;
unused_arg(ord);
2010-08-08 10:06:34 +02:00
assert(sp);
/* Reduziert die St<53>rke jedes Spruchs um effect */
effect = 5;
2010-08-08 10:06:34 +02:00
/* H<>lt Spr<70>che bis zu einem summierten Gesamtlevel von power aus.
2011-03-07 08:02:35 +01:00
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
* um seine Stufe */
force = (float)effect * 20; /* Stufe 5 =~ 100 */
2010-08-08 10:06:34 +02:00
/* Regionszauber aufl<66>sen */
while (*ap && force > 0) {
2011-03-07 08:02:35 +01:00
curse *c;
attrib *a = *ap;
2010-08-08 10:06:34 +02:00
if (!fval(a->type, ATF_CURSE)) {
2011-03-07 08:02:35 +01:00
do {
ap = &(*ap)->next;
} while (*ap && a->type == (*ap)->type);
2010-08-08 10:06:34 +02:00
continue;
}
2011-03-07 08:02:35 +01:00
c = (curse *) a->data.v;
2010-08-08 10:06:34 +02:00
/* Immunit<69>t pr<70>fen */
if (c_flags(c) & CURSE_IMMUNE) {
2011-03-07 08:02:35 +01:00
do {
ap = &(*ap)->next;
} while (*ap && a->type == (*ap)->type);
2010-08-08 10:06:34 +02:00
continue;
}
force = destr_curse(c, effect, force);
2011-03-07 08:02:35 +01:00
if (c->vigour <= 0) {
2010-08-08 10:06:34 +02:00
a_remove(&r->attribs, a);
}
2011-03-07 08:02:35 +01:00
if (*ap)
ap = &(*ap)->next;
2010-08-08 10:06:34 +02:00
}
if (force > 0) {
create_curse(u, &r->attribs, ct_find("antimagiczone"), (float)force, duration,
(float)effect, 0);
2010-08-08 10:06:34 +02:00
}
}
use_pooled(u, rt_crystal, GET_DEFAULT, amount);
2011-03-07 08:02:35 +01:00
ADDMSG(&u->faction->msgs, msg_message("use_antimagiccrystal",
"unit region", u, r));
2010-08-08 10:06:34 +02:00
return 0;
}
static int
2011-03-07 08:02:35 +01:00
use_instantartsculpture(struct unit *u, const struct item_type *itype,
int amount, struct order *ord)
2010-08-08 10:06:34 +02:00
{
building *b;
2011-03-07 08:02:35 +01:00
if (u->region->land == NULL) {
2010-08-08 10:06:34 +02:00
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
return -1;
}
b = new_building(bt_find("artsculpture"), u->region, u->faction->locale);
b->size = 100;
2011-03-07 08:02:35 +01:00
ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region",
u, u->region));
2010-08-08 10:06:34 +02:00
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
return 0;
}
static int
2011-03-07 08:02:35 +01:00
use_instantartacademy(struct unit *u, const struct item_type *itype,
int amount, struct order *ord)
2010-08-08 10:06:34 +02:00
{
building *b;
2011-03-07 08:02:35 +01:00
if (u->region->land == NULL) {
2010-08-08 10:06:34 +02:00
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
return -1;
}
b = new_building(bt_find("artacademy"), u->region, u->faction->locale);
b->size = 100;
2011-03-07 08:02:35 +01:00
ADDMSG(&u->region->msgs, msg_message("artacademy_create", "unit region", u,
u->region));
2010-08-08 10:06:34 +02:00
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
return 0;
}
#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,
int amount, struct order *ord)
2010-08-08 10:06:34 +02:00
{
int money;
if (get_curse(u->region->attribs, ct_find("depression"))) {
cmistake(u, ord, 58, MSG_MAGIC);
return -1;
}
2011-03-07 08:02:35 +01:00
money = entertainmoney(u->region) / BAGPIPEFRACTION;
2010-08-08 10:06:34 +02:00
change_money(u, money);
rsetmoney(u->region, rmoney(u->region) - money);
create_curse(u, &u->region->attribs, ct_find("depression"),
20, BAGPIPEDURATION, 0.0, 0);
ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction",
2011-03-07 08:02:35 +01:00
"unit region command money", u, u->region, ord, money));
2010-08-08 10:06:34 +02:00
ADDMSG(&u->region->msgs, msg_message("bagpipeoffear_region",
2011-03-07 08:02:35 +01:00
"unit money", u, money));
2010-08-08 10:06:34 +02:00
return 0;
}
static int
2011-03-07 08:02:35 +01:00
use_aurapotion50(struct unit *u, const struct item_type *itype,
int amount, struct order *ord)
2010-08-08 10:06:34 +02:00
{
if (!is_mage(u)) {
cmistake(u, ord, 214, MSG_MAGIC);
return -1;
}
change_spellpoints(u, 50);
ADDMSG(&u->faction->msgs, msg_message("aurapotion50",
2011-03-07 08:02:35 +01:00
"unit region command", u, u->region, ord));
2010-08-08 10:06:34 +02:00
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
return 0;
}
2011-03-07 08:02:35 +01:00
void register_itemfunctions(void)
2010-08-08 10:06:34 +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");
}