forked from github/server
orders in messages parsen
This commit is contained in:
parent
f3244cd6c8
commit
a2640fa4e5
|
@ -380,7 +380,8 @@ void
|
||||||
creport_init(void)
|
creport_init(void)
|
||||||
{
|
{
|
||||||
tsf_register("report", &cr_ignore);
|
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("int", &cr_int);
|
||||||
tsf_register("unit", &cr_unit);
|
tsf_register("unit", &cr_unit);
|
||||||
tsf_register("region", &cr_region);
|
tsf_register("region", &cr_region);
|
||||||
|
|
|
@ -3610,6 +3610,14 @@ eval_int36(struct opstack ** stack, const void * userdata)
|
||||||
unused(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
|
void
|
||||||
report_init(void)
|
report_init(void)
|
||||||
{
|
{
|
||||||
|
@ -3622,6 +3630,7 @@ report_init(void)
|
||||||
add_function("faction", &eval_faction);
|
add_function("faction", &eval_faction);
|
||||||
add_function("ship", &eval_ship);
|
add_function("ship", &eval_ship);
|
||||||
add_function("unit", &eval_unit);
|
add_function("unit", &eval_unit);
|
||||||
|
add_function("order", &eval_string);
|
||||||
add_function("unit.name", &eval_unitname);
|
add_function("unit.name", &eval_unitname);
|
||||||
add_function("unit.id", &eval_unitid);
|
add_function("unit.id", &eval_unitid);
|
||||||
add_function("building", &eval_building);
|
add_function("building", &eval_building);
|
||||||
|
|
|
@ -50,15 +50,18 @@ typedef struct item {
|
||||||
#define NMF_PLURAL 0x01
|
#define NMF_PLURAL 0x01
|
||||||
#define NMF_APPEARANCE 0x02
|
#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 {
|
typedef struct resource_type {
|
||||||
/* --- constants --- */
|
/* --- constants --- */
|
||||||
const char * _name[2]; /* wie es heißt */
|
const char * _name[2]; /* wie es heißt */
|
||||||
const char * _appearance[2]; /* wie es für andere aussieht */
|
const char * _appearance[2]; /* wie es für andere aussieht */
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
/* --- functions --- */
|
/* --- functions --- */
|
||||||
int (*uchange)(struct unit * user, const struct resource_type * rtype, int delta);
|
rtype_uchange uchange;
|
||||||
int (*uget)(const struct unit * user, const struct resource_type * rtype);
|
rtype_uget uget;
|
||||||
char * (*name)(const struct resource_type * rtype, int flags);
|
rtype_name name;
|
||||||
/* --- pointers --- */
|
/* --- pointers --- */
|
||||||
struct attrib * attribs;
|
struct attrib * attribs;
|
||||||
struct resource_type * next;
|
struct resource_type * next;
|
||||||
|
@ -85,9 +88,11 @@ extern const resource_type * findresourcetype(const char * name, const struct lo
|
||||||
|
|
||||||
/* resource-limits for regions */
|
/* resource-limits for regions */
|
||||||
extern struct attrib_type at_resourcelimit;
|
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 {
|
typedef struct resource_limit {
|
||||||
int (*limit)(const struct region * r, const struct resource_type * rtype);
|
rlimit_limit limit;
|
||||||
void (*use)(struct region * r, const struct resource_type * rtype, int n);
|
rlimit_use use;
|
||||||
int value;
|
int value;
|
||||||
} resource_limit;
|
} resource_limit;
|
||||||
|
|
||||||
|
|
|
@ -545,6 +545,7 @@ parse_resources(xmlDocPtr doc)
|
||||||
resource_type * rtype;
|
resource_type * rtype;
|
||||||
unsigned int flags = RTF_NONE;
|
unsigned int flags = RTF_NONE;
|
||||||
xmlXPathObjectPtr result;
|
xmlXPathObjectPtr result;
|
||||||
|
int k;
|
||||||
|
|
||||||
if (xml_bvalue(node, "pooled", false)) flags |= RTF_POOLED;
|
if (xml_bvalue(node, "pooled", false)) flags |= RTF_POOLED;
|
||||||
|
|
||||||
|
@ -569,6 +570,77 @@ parse_resources(xmlDocPtr doc)
|
||||||
free(names[0]);
|
free(names[0]);
|
||||||
free(names[1]);
|
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 */
|
/* reading eressea/resources/resource/item */
|
||||||
xpath->node = node;
|
xpath->node = node;
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "item", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "item", xpath);
|
||||||
|
|
Loading…
Reference in New Issue