diff --git a/src/kernel/item.c b/src/kernel/item.c index 5beac7189..9bc321fdb 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -1242,6 +1242,9 @@ void free_rtype(resource_type *rtype) { if (rtype->itype) { free_itype(rtype->itype); } + if (rtype->raw) { + free(rtype->raw); + } free(rtype->_name); free(rtype); } diff --git a/src/kernel/resources.c b/src/kernel/resources.c index d02153e8f..1261417f1 100644 --- a/src/kernel/resources.c +++ b/src/kernel/resources.c @@ -183,14 +183,13 @@ struct rawmaterial *rm_get(region * r, const struct resource_type *rtype) return rm; } -struct rawmaterial_type *rawmaterialtypes = 0; - struct rawmaterial_type *rmt_find(const char *str) { - rawmaterial_type *rmt = rawmaterialtypes; - while (rmt && strcmp(rmt->name, str) != 0) - rmt = rmt->next; - return rmt; + resource_type *rtype = rt_find(str); + if (!rtype && strncmp(str, "rm_", 3) == 0) { + rtype = rt_find(str+3); + } + return rtype ? rtype->raw : NULL; } struct rawmaterial_type *rmt_get(const struct resource_type *rtype) @@ -205,13 +204,10 @@ struct rawmaterial_type *rmt_create(struct resource_type *rtype, assert(!rtype->raw); rmtype = rtype->raw = malloc(sizeof(rawmaterial_type)); - rmtype->name = strdup(name); rmtype->rtype = rtype; rmtype->terraform = terraform_default; rmtype->update = NULL; rmtype->use = use_default; rmtype->visible = visible_default; - rmtype->next = rawmaterialtypes; - rawmaterialtypes = rmtype; return rmtype; } diff --git a/src/kernel/resources.h b/src/kernel/resources.h index dd4cfd664..9d248c0f8 100644 --- a/src/kernel/resources.h +++ b/src/kernel/resources.h @@ -63,16 +63,12 @@ extern "C" { } resource_limit; typedef struct rawmaterial_type { - char *name; const struct resource_type *rtype; void(*terraform) (struct rawmaterial *, const struct region *); void(*update) (struct rawmaterial *, const struct region *); void(*use) (struct rawmaterial *, const struct region *, int amount); int(*visible) (const struct rawmaterial *, int skilllevel); - - /* no initialization required */ - struct rawmaterial_type *next; } rawmaterial_type; extern struct rawmaterial_type *rawmaterialtypes; diff --git a/src/kernel/save.c b/src/kernel/save.c index d4045d05f..21ec98e76 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1068,7 +1068,7 @@ void writeregion(struct gamedata *data, const region * r) WRITE_INT(data->store, rhorses(r)); while (res) { - WRITE_TOK(data->store, res->type->name); + WRITE_TOK(data->store, res->type->rtype->_name); WRITE_INT(data->store, res->level); WRITE_INT(data->store, res->amount); WRITE_INT(data->store, res->startlevel); diff --git a/src/reports.c b/src/reports.c index a49957b9d..a70219b0b 100644 --- a/src/reports.c +++ b/src/reports.c @@ -412,32 +412,32 @@ const faction * viewer, bool see_unit) if (money) { if (n >= size) return -1; - report_resource(result + n, "rm_money", money, -1); + report_resource(result + n, "money", money, -1); ++n; } if (peasants) { if (n >= size) return -1; - report_resource(result + n, "rm_peasant", peasants, -1); + report_resource(result + n, "peasant", peasants, -1); ++n; } if (horses) { if (n >= size) return -1; - report_resource(result + n, "rm_horse", horses, -1); + report_resource(result + n, "horse", horses, -1); ++n; } if (saplings) { if (n >= size) return -1; - report_resource(result + n, mallorn ? "rm_mallornsapling" : "rm_sapling", + report_resource(result + n, mallorn ? "mallornsapling" : "sapling", saplings, -1); ++n; } if (trees) { if (n >= size) return -1; - report_resource(result + n, mallorn ? "rm_mallorn" : "rm_tree", trees, + report_resource(result + n, mallorn ? "mallorn" : "tree", trees, -1); ++n; } @@ -469,7 +469,7 @@ const faction * viewer, bool see_unit) if (level >= 0 && visible >= 0) { if (n >= size) return -1; - report_resource(result + n, res->type->name, visible, level); + report_resource(result + n, res->type->rtype->_name, visible, level); n++; } res = res->next;