fix demand in broken regions, after load.

This commit is contained in:
Enno Rehling 2016-10-24 13:54:53 +02:00
parent cd69936922
commit e5dc754c25
5 changed files with 18 additions and 15 deletions

View File

@ -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) void terraform_region(region * r, const terrain_type * terrain)
{ {
/* Resourcen, die nicht mehr vorkommen können, löschen */ /* Resourcen, die nicht mehr vorkommen können, löschen */

View File

@ -160,6 +160,7 @@ extern "C" {
#define reg_hashkey(r) (r->index) #define reg_hashkey(r) (r->index)
extern int fix_demand(struct region *r);
int distance(const struct region *, const struct region *); int distance(const struct region *, const struct region *);
int koor_distance(int ax, int ay, int bx, int by); int koor_distance(int ax, int ay, int bx, int by);
struct region *findregion(int x, int y); struct region *findregion(int x, int y);

View File

@ -1096,6 +1096,9 @@ static region *readregion(struct gamedata *data, int x, int y)
READ_INT(data->store, &n); READ_INT(data->store, &n);
r_setdemand(r, rtype->ltype, n); r_setdemand(r, rtype->ltype, n);
} }
if (!r->land->demands) {
fix_demand(r);
}
read_items(data->store, &r->land->items); read_items(data->store, &r->land->items);
if (data->version >= REGIONOWNER_VERSION) { if (data->version >= REGIONOWNER_VERSION) {
READ_INT(data->store, &n); READ_INT(data->store, &n);

View File

@ -132,20 +132,6 @@ static bool f_nolux(const region * r)
return (r->land && count_demand(r) != get_maxluxuries()); 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) { int fix_all_demand(region *rd) {
region_list *rl, *rlist = NULL; region_list *rl, *rlist = NULL;
recurse_regions(rd, &rlist, f_nolux); recurse_regions(rd, &rlist, f_nolux);

View File

@ -35,7 +35,6 @@ extern "C" {
extern int autoseed(newfaction ** players, int nsize, int max_agediff); extern int autoseed(newfaction ** players, int nsize, int max_agediff);
extern newfaction *read_newfactions(const char *filename); 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 extern const struct terrain_type *random_terrain(const struct terrain_type
*terrains[], int distribution[], int size); *terrains[], int distribution[], int size);