fix rmt_find for trees

This commit is contained in:
Enno Rehling 2017-02-23 08:02:24 +01:00
parent f4dc88c3be
commit be42137833
4 changed files with 16 additions and 7 deletions

View File

@ -382,7 +382,7 @@ static void test_make_item(CuTest *tc) {
free(itype->construction->materials); free(itype->construction->materials);
itype->construction->materials = 0; itype->construction->materials = 0;
rtype->flags |= RTF_LIMITED; rtype->flags |= RTF_LIMITED;
rmt = rmt_create(rtype, "rm_stone"); rmt = rmt_create(rtype);
rdata = rtype->limit = calloc(1, sizeof(resource_limit)); rdata = rtype->limit = calloc(1, sizeof(resource_limit));
rdata->value = 0; rdata->value = 0;
add_resource(u->region, 1, 300, 150, rtype); add_resource(u->region, 1, 300, 150, rtype);

View File

@ -185,10 +185,21 @@ struct rawmaterial *rm_get(region * r, const struct resource_type *rtype)
struct rawmaterial_type *rmt_find(const char *str) struct rawmaterial_type *rmt_find(const char *str)
{ {
const char * replace[] = { "rm_tree", "log", NULL };
resource_type *rtype = rt_find(str); resource_type *rtype = rt_find(str);
if (!rtype && strncmp(str, "rm_", 3) == 0) { if (!rtype && strncmp(str, "rm_", 3) == 0) {
int i;
for (i = 0; replace[i]; i+=2) {
if (strcmp(replace[i], str) == 0) {
rtype = rt_find(replace[i+1]);
break;
}
}
if (!rtype) {
rtype = rt_find(str+3); rtype = rt_find(str+3);
} }
}
assert(rtype);
return rtype ? rtype->raw : NULL; return rtype ? rtype->raw : NULL;
} }
@ -197,8 +208,7 @@ struct rawmaterial_type *rmt_get(const struct resource_type *rtype)
return rtype->raw; return rtype->raw;
} }
struct rawmaterial_type *rmt_create(struct resource_type *rtype, struct rawmaterial_type *rmt_create(struct resource_type *rtype)
const char *name)
{ {
rawmaterial_type *rmtype; rawmaterial_type *rmtype;

View File

@ -82,8 +82,7 @@ extern "C" {
void add_resource(struct region *r, int level, int base, int divisor, void add_resource(struct region *r, int level, int base, int divisor,
const struct resource_type *rtype); const struct resource_type *rtype);
struct rawmaterial_type *rmt_create(struct resource_type *rtype, struct rawmaterial_type *rmt_create(struct resource_type *rtype);
const char *name);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -983,7 +983,7 @@ static int parse_resources(xmlDocPtr doc)
name = xmlGetProp(node, BAD_CAST "material"); name = xmlGetProp(node, BAD_CAST "material");
if (name) { if (name) {
rmt_create(rtype, (const char *)name); rmt_create(rtype);
xmlFree(name); xmlFree(name);
} }