From a2640fa4e57e93bb436b22027b3e2da15a13d760 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 12 Apr 2004 00:57:09 +0000 Subject: [PATCH] orders in messages parsen --- src/common/gamecode/creport.c | 3 +- src/common/gamecode/report.c | 9 +++++ src/common/kernel/item.h | 15 +++++--- src/common/kernel/xmlreader.c | 72 +++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+), 6 deletions(-) diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index ffc73d7f0..087c99a03 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -380,7 +380,8 @@ void creport_init(void) { tsf_register("report", &cr_ignore); - tsf_register("string", &cr_string); + tsf_register("string", &cr_string); + tsf_register("order", &cr_string); tsf_register("int", &cr_int); tsf_register("unit", &cr_unit); tsf_register("region", &cr_region); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 239d0848b..6cb5e4d66 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -3610,6 +3610,14 @@ eval_int36(struct opstack ** stack, const void * userdata) unused(userdata); } +static void +eval_string(struct opstack ** stack, const void * userdata) +{ + const char * c = opop(stack, const char*); + opush(stack, strcpy(balloc(strlen(c)+1), c)); + unused(userdata); +} + void report_init(void) { @@ -3622,6 +3630,7 @@ report_init(void) add_function("faction", &eval_faction); add_function("ship", &eval_ship); add_function("unit", &eval_unit); + add_function("order", &eval_string); add_function("unit.name", &eval_unitname); add_function("unit.id", &eval_unitid); add_function("building", &eval_building); diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index 2ca254d20..5a2e2a7a5 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -50,15 +50,18 @@ typedef struct item { #define NMF_PLURAL 0x01 #define NMF_APPEARANCE 0x02 +typedef int (*rtype_uchange)(struct unit * user, const struct resource_type * rtype, int delta); +typedef int (*rtype_uget)(const struct unit * user, const struct resource_type * rtype); +typedef char * (*rtype_name)(const struct resource_type * rtype, int flags); typedef struct resource_type { /* --- constants --- */ const char * _name[2]; /* wie es heißt */ const char * _appearance[2]; /* wie es für andere aussieht */ unsigned int flags; /* --- functions --- */ - int (*uchange)(struct unit * user, const struct resource_type * rtype, int delta); - int (*uget)(const struct unit * user, const struct resource_type * rtype); - char * (*name)(const struct resource_type * rtype, int flags); + rtype_uchange uchange; + rtype_uget uget; + rtype_name name; /* --- pointers --- */ struct attrib * attribs; struct resource_type * next; @@ -85,9 +88,11 @@ extern const resource_type * findresourcetype(const char * name, const struct lo /* resource-limits for regions */ extern struct attrib_type at_resourcelimit; +typedef int (*rlimit_limit)(const struct region * r, const struct resource_type * rtype); +typedef void (*rlimit_use)(struct region * r, const struct resource_type * rtype, int n); typedef struct resource_limit { - int (*limit)(const struct region * r, const struct resource_type * rtype); - void (*use)(struct region * r, const struct resource_type * rtype, int n); + rlimit_limit limit; + rlimit_use use; int value; } resource_limit; diff --git a/src/common/kernel/xmlreader.c b/src/common/kernel/xmlreader.c index c64636e46..450ef4ff8 100644 --- a/src/common/kernel/xmlreader.c +++ b/src/common/kernel/xmlreader.c @@ -545,6 +545,7 @@ parse_resources(xmlDocPtr doc) resource_type * rtype; unsigned int flags = RTF_NONE; xmlXPathObjectPtr result; + int k; if (xml_bvalue(node, "pooled", false)) flags |= RTF_POOLED; @@ -569,6 +570,77 @@ parse_resources(xmlDocPtr doc) free(names[0]); free(names[1]); + /* reading eressea/resources/resource/function */ + xpath->node = node; + result = xmlXPathEvalExpression(BAD_CAST "function", xpath); + for (k=0;k!=result->nodesetval->nodeNr;++k) { + xmlNodePtr node = result->nodesetval->nodeTab[k]; + pf_generic fun; + + property = xmlGetProp(node, BAD_CAST "value"); + assert(property!=NULL); + fun = get_function((const char*)property); + if (fun==NULL) { + log_error(("unknown function name '%s' for resource %s\n", + (const char*)property, rtype->_name[0])); + xmlFree(property); + continue; + } + xmlFree(property); + + property = xmlGetProp(node, BAD_CAST "name"); + assert(property!=NULL); + if (strcmp((const char*)property, "change")==0) { + rtype->uchange = (rtype_uchange)fun; + } else if (strcmp((const char*)property, "get")==0) { + rtype->uget = (rtype_uget)fun; + } else if (strcmp((const char*)property, "name")==0) { + rtype->name = (rtype_name)fun; + } else { + log_error(("unknown function type '%s' for resource %s\n", + (const char*)property, rtype->_name[0])); + } + xmlFree(property); + } + xmlXPathFreeObject(result); + + /* reading eressea/resources/resource/resourcelimit/function */ + xpath->node = node; + result = xmlXPathEvalExpression(BAD_CAST "resourcelimit/function", xpath); + for (k=0;k!=result->nodesetval->nodeNr;++k) { + attrib * a = a_find(rtype->attribs, &at_resourcelimit); + xmlNodePtr node = result->nodesetval->nodeTab[k]; + pf_generic fun; + + property = xmlGetProp(node, BAD_CAST "value"); + assert(property!=NULL); + fun = get_function((const char*)property); + if (fun==NULL) { + log_error(("unknown limit '%s' for resource %s\n", + (const char*)property, rtype->_name[0])); + xmlFree(property); + continue; + } + xmlFree(property); + + if (a==NULL) a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); + + property = xmlGetProp(node, BAD_CAST "name"); + assert(property!=NULL); + if (strcmp((const char*)property, "use")==0) { + resource_limit * rdata = (resource_limit*)a->data.v; + rdata->use = (rlimit_use)fun; + } else if (strcmp((const char*)property, "limit")==0) { + resource_limit * rdata = (resource_limit*)a->data.v; + rdata->limit = (rlimit_limit)fun; + } else { + log_error(("unknown limit '%s' for resource %s\n", + (const char*)property, rtype->_name[0])); + } + xmlFree(property); + } + xmlXPathFreeObject(result); + /* reading eressea/resources/resource/item */ xpath->node = node; result = xmlXPathEvalExpression(BAD_CAST "item", xpath);