forked from github/server
read callback fucntions for resources and weapons.
This commit is contained in:
parent
46f5fa0211
commit
e86f3e7589
3 changed files with 34 additions and 3 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "kernel/race.h"
|
#include "kernel/race.h"
|
||||||
#include "kernel/resources.h"
|
#include "kernel/resources.h"
|
||||||
|
|
||||||
|
#include "util/functions.h"
|
||||||
#include "util/log.h"
|
#include "util/log.h"
|
||||||
#include "util/strings.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);
|
handle_item(ud, el, attr);
|
||||||
}
|
}
|
||||||
else if (xml_strcmp(el, "function") == 0) {
|
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);
|
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;
|
++ud->errors;
|
||||||
/* TODO */
|
/* TODO */
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
||||||
struct gamedata;
|
struct gamedata;
|
||||||
struct rawmaterial_type;
|
struct rawmaterial_type;
|
||||||
struct resource_mod;
|
struct resource_mod;
|
||||||
|
struct weapon_type;
|
||||||
|
|
||||||
typedef struct item {
|
typedef struct item {
|
||||||
struct item *next;
|
struct item *next;
|
||||||
|
@ -66,9 +67,12 @@ extern "C" {
|
||||||
|
|
||||||
void item_done(void);
|
void item_done(void);
|
||||||
|
|
||||||
|
typedef bool(*wtype_attack)(const struct troop *,
|
||||||
|
const struct weapon_type *, int *);
|
||||||
typedef int(*rtype_uchange) (struct unit * user,
|
typedef int(*rtype_uchange) (struct unit * user,
|
||||||
const struct resource_type * rtype, int delta);
|
const struct resource_type * rtype, int delta);
|
||||||
typedef char *(*rtype_name) (const struct resource_type * rtype, int flags);
|
typedef char *(*rtype_name) (const struct resource_type * rtype, int flags);
|
||||||
|
|
||||||
typedef struct resource_type {
|
typedef struct resource_type {
|
||||||
/* --- constants --- */
|
/* --- constants --- */
|
||||||
char *_name; /* wie es hei<65>t */
|
char *_name; /* wie es hei<65>t */
|
||||||
|
|
|
@ -654,9 +654,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype)
|
||||||
}
|
}
|
||||||
assert(propValue != NULL);
|
assert(propValue != NULL);
|
||||||
if (strcmp((const char *)propValue, "attack") == 0) {
|
if (strcmp((const char *)propValue, "attack") == 0) {
|
||||||
wtype->attack =
|
wtype->attack = (wtype_attack)fun;
|
||||||
(bool(*)(const struct troop *, const struct weapon_type *,
|
|
||||||
int *))fun;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name);
|
log_error("unknown function type '%s' for item '%s'\n", (const char *)propValue, itype->rtype->_name);
|
||||||
|
|
Loading…
Reference in a new issue