read callback fucntions for resources and weapons.

This commit is contained in:
Enno Rehling 2018-04-28 21:46:01 +02:00
parent 46f5fa0211
commit e86f3e7589
3 changed files with 34 additions and 3 deletions

View File

@ -8,6 +8,7 @@
#include "kernel/race.h"
#include "kernel/resources.h"
#include "util/functions.h"
#include "util/log.h"
#include "util/strings.h"
@ -250,7 +251,35 @@ static void XMLCALL start_resources(userdata *ud, const XML_Char *el, const XML_
handle_item(ud, el, attr);
}
else if (xml_strcmp(el, "function") == 0) {
const XML_Char *name = NULL;
pf_generic fun = NULL;
int i;
for (i = 0; attr[i]; i += 2) {
if (xml_strcmp(attr[i], "name") == 0) {
name = attr[i + 1];
}
else if (xml_strcmp(attr[i], "value") == 0) {
fun = get_function((const char *)attr[i + 1]);
}
else {
handle_bad_input(ud, el, attr[i]);
}
}
assert(rtype);
if (name && fun) {
if (xml_strcmp(name, "change") == 0) {
rtype->uchange = (rtype_uchange)fun;
}
else if (xml_strcmp(name, "name") == 0) {
rtype->name = (rtype_name)fun;
}
else if (xml_strcmp(name, "attack") == 0) {
assert(rtype->wtype);
rtype->wtype->attack = (wtype_attack)fun;
}
}
++ud->errors;
/* TODO */
}

View File

@ -40,6 +40,7 @@ extern "C" {
struct gamedata;
struct rawmaterial_type;
struct resource_mod;
struct weapon_type;
typedef struct item {
struct item *next;
@ -66,9 +67,12 @@ extern "C" {
void item_done(void);
typedef bool(*wtype_attack)(const struct troop *,
const struct weapon_type *, int *);
typedef int(*rtype_uchange) (struct unit * user,
const struct resource_type * rtype, int delta);
typedef char *(*rtype_name) (const struct resource_type * rtype, int flags);
typedef struct resource_type {
/* --- constants --- */
char *_name; /* wie es hei<65>t */

View File

@ -654,9 +654,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
}
assert(propValue != NULL);
if (strcmp((const char *)propValue, "attack") == 0) {
wtype->attack =
(bool(*)(const struct troop *, const struct weapon_type *,
int *))fun;
wtype->attack = (wtype_attack)fun;
}
else {
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name);