orders in messages parsen

This commit is contained in:
Enno Rehling 2004-04-12 00:57:09 +00:00
parent f3244cd6c8
commit a2640fa4e5
4 changed files with 93 additions and 6 deletions

View File

@ -381,6 +381,7 @@ creport_init(void)
{
tsf_register("report", &cr_ignore);
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);

View File

@ -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);

View File

@ -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;

View File

@ -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);