Merge pull request #842 from ennorehling/master

FIX_STARTLEVEL_VERSION
This commit is contained in:
Enno Rehling 2019-03-24 21:37:11 +01:00 committed by GitHub
commit 2ec6021278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -41,8 +41,9 @@
#define CRYPT_VERSION 363 /* passwords are encrypted */
#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 RELEASE_VERSION FAMILIAR_FIXSPELLBOOK_VERSION /* current datafile */
#define RELEASE_VERSION FIX_STARTLEVEL_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 */

View File

@ -613,6 +613,27 @@ static void read_regioninfo(gamedata *data, const region *r, char *info, size_t
}
}
static void fix_baselevel(region *r) {
struct terrain_production *p;
for (p = r->terrain->production; p->type; ++p) {
char *end;
long start = (int)strtol(p->startlevel, &end, 10);
if (*end == '\0') {
rawmaterial *res;
for (res = r->resources; res; res = res->next) {
if (p->type == res->rtype) {
if (start != res->startlevel) {
log_debug("setting resource start level for %s in %s to %d",
res->rtype->_name, regionname(r, NULL), start);
res->startlevel = start;
}
}
}
}
}
}
static region *readregion(gamedata *data, int x, int y)
{
region *r;
@ -781,6 +802,11 @@ 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);
}
return r;
}