From e5dc754c2551e88c79653696d59d7d7a9ea57ec8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 24 Oct 2016 13:54:53 +0200 Subject: [PATCH] fix demand in broken regions, after load. --- src/kernel/region.c | 14 ++++++++++++++ src/kernel/region.h | 1 + src/kernel/save.c | 3 +++ src/modules/autoseed.c | 14 -------------- src/modules/autoseed.h | 1 - 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/kernel/region.c b/src/kernel/region.c index bda362dc5..a92a87291 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1009,6 +1009,20 @@ void setluxuries(region * r, const luxury_type * sale) } } +int fix_demand(region * rd) { + luxury_type * ltype; + int maxluxuries = get_maxluxuries(); + if (maxluxuries > 0) { + int sale = rng_int() % maxluxuries; + for (ltype = luxurytypes; sale != 0 && ltype; ltype = ltype->next) { + --sale; + } + setluxuries(rd, ltype); + return 0; + } + return -1; +} + void terraform_region(region * r, const terrain_type * terrain) { /* Resourcen, die nicht mehr vorkommen können, löschen */ diff --git a/src/kernel/region.h b/src/kernel/region.h index 6e231529d..5efd416f6 100644 --- a/src/kernel/region.h +++ b/src/kernel/region.h @@ -160,6 +160,7 @@ extern "C" { #define reg_hashkey(r) (r->index) + extern int fix_demand(struct region *r); int distance(const struct region *, const struct region *); int koor_distance(int ax, int ay, int bx, int by); struct region *findregion(int x, int y); diff --git a/src/kernel/save.c b/src/kernel/save.c index 2373d60a0..0b0ea222d 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -1096,6 +1096,9 @@ static region *readregion(struct gamedata *data, int x, int y) READ_INT(data->store, &n); r_setdemand(r, rtype->ltype, n); } + if (!r->land->demands) { + fix_demand(r); + } read_items(data->store, &r->land->items); if (data->version >= REGIONOWNER_VERSION) { READ_INT(data->store, &n); diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index e8855683e..3bcf36848 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -132,20 +132,6 @@ static bool f_nolux(const region * r) return (r->land && count_demand(r) != get_maxluxuries()); } -int fix_demand(region * rd) { - luxury_type * ltype; - int maxluxuries = get_maxluxuries(); - if (maxluxuries > 0) { - int sale = rng_int() % maxluxuries; - for (ltype = luxurytypes; sale != 0 && ltype; ltype = ltype->next) { - --sale; - } - setluxuries(rd, ltype); - return 0; - } - return -1; -} - int fix_all_demand(region *rd) { region_list *rl, *rlist = NULL; recurse_regions(rd, &rlist, f_nolux); diff --git a/src/modules/autoseed.h b/src/modules/autoseed.h index 3cfe6225c..06ce646c2 100644 --- a/src/modules/autoseed.h +++ b/src/modules/autoseed.h @@ -35,7 +35,6 @@ extern "C" { extern int autoseed(newfaction ** players, int nsize, int max_agediff); extern newfaction *read_newfactions(const char *filename); - extern int fix_demand(struct region *r); extern const struct terrain_type *random_terrain(const struct terrain_type *terrains[], int distribution[], int size);