study potion. To use this potion, you must have:

- a level < 2 in the skill
- a STUDY order for a no-fee skill
Each potion adds 1 study attempt, up to a maximum of 15 attempts
This commit is contained in:
Enno Rehling 2005-01-19 21:57:37 +00:00
parent 13172a28af
commit 31b609b7b9
10 changed files with 155 additions and 40 deletions

View File

@ -24,6 +24,7 @@
#include <config.h>
#include "eressea.h"
#include "study.h"
#include "alchemy.h"
#include "building.h"
@ -97,8 +98,8 @@ magic_lowskill(unit *u)
/* ------------------------------------------------------------- */
static int
study_cost(unit *u, int talent)
int
study_cost(unit *u, skill_t talent)
{
int stufe, k = 50;
@ -122,12 +123,6 @@ study_cost(unit *u, int talent)
/* ------------------------------------------------------------- */
#define MAXTEACHERS 4
typedef struct teaching_info {
unit * teachers[MAXTEACHERS];
int value;
} teaching_info;
static void
init_learning(struct attrib * a)
{
@ -140,7 +135,7 @@ done_learning(struct attrib * a)
free(a->data.v);
}
static const attrib_type at_learning = {
const attrib_type at_learning = {
"learning",
init_learning, done_learning, NULL, NULL, NULL,
ATF_UNIQUE

View File

@ -8,6 +8,7 @@ SubDirHdrs $(SUBDIR)/.. ;
SubDirHdrs $(SUBDIR)/../.. ;
SOURCES =
artrewards.c
birthday_firework.c
catapultammo.c
demonseye.c
@ -15,10 +16,10 @@ SOURCES =
questkeys.c
racespoils.c
seed.c
speedsail.c
studypotion.c
weapons.c
xerewards.c
artrewards.c
speedsail.c
;
Library items : $(SOURCES) ;

View File

@ -20,6 +20,7 @@
#include "artrewards.h"
#include "weapons.h"
#include "speedsail.h"
#include "studypotion.h"
#include "racespoils.h"
#if GROWING_TREES
# include "seed.h"
@ -44,6 +45,7 @@ register_items(void)
register_racespoils();
register_artrewards();
register_speedsail();
register_studypotion();
}
void

View File

@ -181,6 +181,12 @@
<File
RelativePath=".\speedsail.h">
</File>
<File
RelativePath=".\studypotion.c">
</File>
<File
RelativePath=".\studypotion.h">
</File>
<File
RelativePath=".\weapons.c">
</File>

View File

@ -17,17 +17,17 @@
#include "speedsail.h"
/* kernel includes */
#include <faction.h>
#include <item.h>
#include <message.h>
#include <movement.h>
#include <plane.h>
#include <region.h>
#include <ship.h>
#include <unit.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/message.h>
#include <kernel/movement.h>
#include <kernel/plane.h>
#include <kernel/region.h>
#include <kernel/ship.h>
#include <kernel/unit.h>
/* util includes */
#include <functions.h>
#include <util/functions.h>
/* libc includes */
#include <assert.h>
@ -61,25 +61,8 @@ use_speedsail(struct unit * u, const struct item_type * itype, int amount, struc
return EUNUSABLE;
}
static resource_type rt_speedsail = {
{ "speedsail", "speedsail_p" },
{ "speedsail", "speedsail_p" },
RTF_ITEM,
&res_changeitem
};
item_type it_speedsail = {
&rt_speedsail, /* resourcetype */
0, 0, 0, /* flags, weight, capacity */
NULL, /* construction */
&use_speedsail,
NULL,
NULL
};
void
register_speedsail(void)
{
it_register(&it_speedsail);
register_function((pf_generic)use_speedsail, "use_speedsail");
}

View File

@ -0,0 +1,58 @@
#include <config.h>
#include <kernel/eressea.h>
#include "studypotion.h"
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/order.h>
#include <kernel/skill.h>
#include <kernel/study.h>
#include <kernel/unit.h>
#include <util/attrib.h>
#include <util/functions.h>
/* BEGIN it_studypotion */
#define MAXGAIN 15
static int
use_studypotion(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
{
if (get_keyword(u->thisorder) == K_STUDY) {
skill_t sk;
skill * sv;
init_tokens(u->thisorder);
skip_token();
sk = findskill(getstrtoken(), u->faction->locale);
sv = get_skill(u, sk);
if (sv && sv->level > 2) {
/* TODO: message */
} else if (study_cost(u, sk)>0) {
/* 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;
if (amount>MAXGAIN) amount = MAXGAIN;
teach->value += amount * 30;
if (teach->value > MAXGAIN * 30) {
teach->value = MAXGAIN * 30;
}
i_change(&u->items, itype, -amount);
return 0;
}
}
return EUNUSABLE;
}
void
register_studypotion(void)
{
register_function((pf_generic)use_studypotion, "use_studypotion");
}
/* END it_studypotion */

View File

@ -0,0 +1,26 @@
/* vi: set ts=2:
*
*
* Eressea PB(E)M host Copyright (C) 1998-2003
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
*/
#ifndef H_ITM_STUDYPOTION
#define H_ITM_STUDYPOTION
#ifdef __cplusplus
extern "C" {
#endif
extern void register_studypotion(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -12,8 +12,30 @@
* prior permission by the authors of Eressea.
*/
void teaching(void);
void learn(void);
#ifndef H_KRNL_STUDY
#define H_KRNL_STUDY
#ifdef __cplusplus
extern "C" {
#endif
extern void teaching(void);
extern void learn(void);
extern magic_t getmagicskill(void);
extern boolean is_migrant(struct unit *u);
extern int study_cost(struct unit *u, skill_t talent);
#define MAXTEACHERS 4
typedef struct teaching_info {
struct unit * teachers[MAXTEACHERS];
int value;
} teaching_info;
extern const struct attrib_type at_learning;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -6034,4 +6034,14 @@
<text locale="en">grails</text>
</string>
<string name="studypotion">
<text locale="de">Lerntrank</text>
<text locale="en">brain boost</text>
</string>
<string name="studypotion_p">
<text locale="de">Lerntränke</text>
<text locale="en">brain boosts</text>
</string>
</strings>

View File

@ -21,6 +21,18 @@
</item>
</resource>
<resource name="studypotion">
<item weight="0">
<function name="use" value="use_studypotion"/>
</item>
</resource>
<resource name="speedsail">
<item weight="0">
<function name="use" value="use_speedsail"/>
</item>
</resource>
<resource name="snowman">
<!-- xmas gimmik -->
<item notlost="yes" weight="1"/>