2010-08-08 10:06:34 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include "xerewards.h"
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/skill.h>
|
|
|
|
#include <kernel/curse.h>
|
|
|
|
#include <kernel/message.h>
|
|
|
|
#include <kernel/magic.h>
|
2012-05-26 01:15:21 +02:00
|
|
|
#include <kernel/pool.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
/* util includes */
|
|
|
|
#include <util/functions.h>
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
use_skillpotion(struct unit *u, const struct item_type *itype, int amount,
|
|
|
|
struct order *ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
|
|
|
/* the problem with making this a lua function is that there's no way
|
|
|
|
* to get the list of skills for a unit. and with the way skills are
|
|
|
|
* currently saved, it doesn't look likely (can't make eressea::list
|
|
|
|
* from them)
|
|
|
|
*/
|
|
|
|
int n;
|
2011-03-07 08:02:35 +01:00
|
|
|
for (n = 0; n != amount; ++n) {
|
|
|
|
skill *sv = u->skills;
|
|
|
|
while (sv != u->skills + u->skill_size) {
|
2010-08-08 10:06:34 +02:00
|
|
|
int i;
|
2011-03-07 08:02:35 +01:00
|
|
|
for (i = 0; i != 3; ++i)
|
2012-06-17 20:08:48 +02:00
|
|
|
learn_skill(u, (skill_t)sv->id, 1.0);
|
2010-08-08 10:06:34 +02:00
|
|
|
++sv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("skillpotion_use", "unit", u));
|
|
|
|
|
2012-05-26 01:15:21 +02:00
|
|
|
change_resource(u, itype->rtype, -amount);
|
2010-08-08 10:06:34 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
use_manacrystal(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
|
|
|
int i, sp = 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
if (!is_mage(u)) {
|
|
|
|
cmistake(u, u->thisorder, 295, MSG_EVENT);
|
|
|
|
return -1;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
for (i = 0; i != amount; ++i) {
|
|
|
|
sp += MAX(25, max_spellpoints(u->region, u) / 2);
|
|
|
|
change_spellpoints(u, sp);
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("manacrystal_use", "unit aura", u, sp));
|
|
|
|
|
2012-05-26 01:15:21 +02:00
|
|
|
change_resource(u, itype->rtype, -amount);
|
2011-03-07 08:02:35 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void register_xerewards(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
|
|
|
register_item_use(use_skillpotion, "use_skillpotion");
|
|
|
|
register_item_use(use_manacrystal, "use_manacrystal");
|
|
|
|
}
|