From 2b2a79620c87257a9061b11c924c5b5f9bf21c93 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 12 Jan 2018 10:01:06 +0100 Subject: [PATCH] compiles, test fails, xmlreader includes need fixing --- src/alchemy.c | 14 ++++++++++++++ src/alchemy.h | 5 ++++- src/kernel/item.c | 15 +++++++++++++++ src/kernel/item.h | 6 ++++-- src/kernel/xmlreader.c | 9 +++++---- src/laws.c | 32 ++++---------------------------- 6 files changed, 46 insertions(+), 35 deletions(-) diff --git a/src/alchemy.c b/src/alchemy.c index 29db8ce85..cf3d2b376 100644 --- a/src/alchemy.c +++ b/src/alchemy.c @@ -434,3 +434,17 @@ int change_effect(unit * u, const item_type * effect, int delta) log_error("change effect with delta==0 for unit %s\n", itoa36(u->no)); return 0; } + +bool display_potions(struct unit *u) +{ + int skill = effskill(u, SK_ALCHEMY, 0); + int c = 0; + const potion_type *ptype; + for (ptype = potiontypes; ptype != NULL; ptype = ptype->next) { + if (ptype->level * 2 <= skill) { + show_item(u, ptype->itype); + ++c; + } + } + return (c > 0); +} diff --git a/src/alchemy.h b/src/alchemy.h index f8cebd3db..d183cacd0 100644 --- a/src/alchemy.h +++ b/src/alchemy.h @@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_ALCHEMY_H #define H_KRNL_ALCHEMY_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -68,8 +70,9 @@ extern "C" { int get_effect(const struct unit *u, const struct item_type *effect); int change_effect(struct unit *u, const struct item_type *effect, int value); + bool display_potions(struct unit *u); - /* rausnehmen, sobald man attribute splitten kann: */ + /* TODO: rausnehmen, sobald man attribute splitten kann: */ typedef struct effect_data { const struct item_type *type; int value; diff --git a/src/kernel/item.c b/src/kernel/item.c index f7ce28835..74951895a 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -980,3 +980,18 @@ void register_resources(void) register_function((pf_generic)res_changehp, "changehp"); register_function((pf_generic)res_changeaura, "changeaura"); } + +void show_item(unit * u, const item_type * itype) +{ + faction * f = u->faction; + attrib *a; + + a = a_find(f->attribs, &at_showitem); + while (a && a->data.v != itype) + a = a->next; + if (!a) { + a = a_add(&f->attribs, a_new(&at_showitem)); + a->data.v = (void *)itype; + } +} + diff --git a/src/kernel/item.h b/src/kernel/item.h index c289005df..e7bfef7cc 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -276,6 +276,10 @@ extern "C" { } resource_t; extern const struct item_type *oldpotiontype[]; + extern struct attrib_type at_showitem; /* show this potion's description */ + + void show_item(struct unit * u, const struct item_type * itype); + const struct resource_type *get_resourcetype(resource_t rt); struct item *item_spoil(const struct race *rc, int size); @@ -285,8 +289,6 @@ extern "C" { int set_money(struct unit *, int); int change_money(struct unit *, int); - extern struct attrib_type at_showitem; /* show this potion's description */ - void register_resources(void); void init_resources(void); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index f086af3ef..1ef17b2e7 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -32,6 +32,8 @@ without prior permission by the authors of Eressea. #include "prefix.h" #include "move.h" +/* TODO: core code should not include these files: */ +#include "alchemy.h" #include "vortex.h" #include @@ -483,12 +485,11 @@ static int parse_ships(xmlDocPtr doc) return 0; } -static potion_type *xml_readpotion(xmlXPathContextPtr xpath, item_type * itype) +static void xml_readpotion(xmlXPathContextPtr xpath, item_type * itype) { int level = xml_ivalue(xpath->node, "level", 0); - assert(level > 0); - return new_potiontype(itype, level); + new_potiontype(itype, level); } static luxury_type *xml_readluxury(xmlXPathContextPtr xpath, item_type * itype) @@ -741,7 +742,7 @@ static item_type *xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype) itype->flags |= ITF_CANUSE; } xpath->node = result->nodesetval->nodeTab[0]; - rtype->ptype = xml_readpotion(xpath, itype); + xml_readpotion(xpath, itype); } xmlXPathFreeObject(result); diff --git a/src/laws.c b/src/laws.c index faf680272..47577d461 100644 --- a/src/laws.c +++ b/src/laws.c @@ -2234,6 +2234,10 @@ int send_cmd(unit * u, struct order *ord) return 0; } +static void display_potion(unit * u, const item_type * itype) { + show_item(u, itype); +} + static void display_item(unit * u, const item_type * itype) { faction * f = u->faction; @@ -2252,20 +2256,6 @@ static void display_item(unit * u, const item_type * itype) itype->weight, itype->rtype, info)); } -static void display_potion(unit * u, const item_type * itype) -{ - faction * f = u->faction; - attrib *a; - - a = a_find(f->attribs, &at_showitem); - while (a && a->data.v != itype) - a = a->next; - if (!a) { - a = a_add(&f->attribs, a_new(&at_showitem)); - a->data.v = (void *)itype; - } -} - static void display_race(unit * u, const race * rc) { faction * f = u->faction; @@ -2466,20 +2456,6 @@ static void reshow_other(unit * u, struct order *ord, const char *s) { cmistake(u, ord, err, MSG_EVENT); } -bool display_potions(unit *u) -{ - int skill = effskill(u, SK_ALCHEMY, 0); - int c = 0; - const potion_type *ptype; - for (ptype = potiontypes; ptype != NULL; ptype = ptype->next) { - if (ptype->level * 2 <= skill) { - display_potion(u, ptype); - ++c; - } - } - return (c > 0); -} - static void reshow(unit * u, struct order *ord, const char *s, param_t p) { switch (p) {