From 8c0fc4bd918610edabded2bb2da3c92f164aeaa2 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 30 Apr 2019 18:56:37 +0200 Subject: [PATCH] 2577: Fix resource values, again. --- src/kernel/gamedata.h | 3 ++- src/kernel/save.c | 35 +++++++++++++++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/kernel/gamedata.h b/src/kernel/gamedata.h index 986b13d1d..64732b7fc 100644 --- a/src/kernel/gamedata.h +++ b/src/kernel/gamedata.h @@ -42,8 +42,9 @@ #define FAMILIAR_FIXMAGE_VERSION 364 /* familiar links are fixed */ #define FAMILIAR_FIXSPELLBOOK_VERSION 365 /* familiar spells are fixed */ #define FIX_STARTLEVEL_VERSION 366 /* fixing resource startlevels */ +#define FIX_RES_BASE_VERSION 367 /* fixing resource base */ -#define RELEASE_VERSION FIX_STARTLEVEL_VERSION /* current datafile */ +#define RELEASE_VERSION FIX_RES_BASE_VERSION /* current datafile */ #define MIN_VERSION UIDHASH_VERSION /* minimal datafile we support */ #define MAX_VERSION RELEASE_VERSION /* change this if we can need to read the future datafile, and we can do so */ diff --git a/src/kernel/save.c b/src/kernel/save.c index 0b3ade593..f5e66162b 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -613,7 +613,7 @@ static void read_regioninfo(gamedata *data, const region *r, char *info, size_t } } -static void fix_baselevel(region *r) { +static void fix_resource_levels(region *r) { struct terrain_production *p; for (p = r->terrain->production; p->type; ++p) { char *end; @@ -634,6 +634,27 @@ static void fix_baselevel(region *r) { } } +static void fix_resource_bases(region *r) { + struct terrain_production *p; + for (p = r->terrain->production; p->type; ++p) { + char *end; + long base = (int)strtol(p->base, &end, 10); + if (*end == '\0') { + rawmaterial *res; + for (res = r->resources; res; res = res->next) { + if (p->type == res->rtype) { + if (base != res->base) { + log_debug("setting resource base for %s in %s to %d", + res->rtype->_name, regionname(r, NULL), base); + res->base = base; + } + } + } + } + + } +} + static region *readregion(gamedata *data, int x, int y) { region *r; @@ -803,9 +824,15 @@ static region *readregion(gamedata *data, int x, int y) } read_attribs(data, &r->attribs, r); - if (r->resources && data->version < FIX_STARTLEVEL_VERSION) { - /* we had some badly made rawmaterials before this */ - fix_baselevel(r); + if (r->resources) { + if (data->version < FIX_STARTLEVEL_VERSION) { + /* we had some badly made rawmaterials before this */ + fix_resource_levels(r); + } + if (data->version < FIX_RES_BASE_VERSION) { + /* we had some badly made rawmaterials before this */ + fix_resource_bases(r); + } } return r; }