From 3524cb59d2c96f678443a7e0cdded273bbd52e6a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Nov 2005 00:42:32 +0000 Subject: [PATCH] random_terrain() function --- src/common/modules/autoseed.c | 30 ++++++++++++++++++++++++++---- src/common/modules/autoseed.h | 1 + src/mapper/mapper.c | 14 +------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/common/modules/autoseed.c b/src/common/modules/autoseed.c index 14d204db0..33df6c6c1 100644 --- a/src/common/modules/autoseed.c +++ b/src/common/modules/autoseed.c @@ -37,6 +37,28 @@ #include #include +const terrain_type * +random_terrain(unsigned int flags) +{ + static int nterrains; + const terrain_type * terrain; + int n; + if (nterrains==0) { + for (terrain=terrains();terrain;terrain=terrain->next) { + if (fval(terrain, flags)==flags) { + ++nterrains; + } + } + } + n = rand() % nterrains; + for (terrain=terrains();n;terrain=terrain->next) { + if (fval(terrain, flags)==flags) { + --n; + } + } + return terrain; +} + static int count_demand(const region *r) @@ -622,7 +644,7 @@ autoseed(newfaction ** players, int nsize, boolean new_island) --isize; if (psize>=PLAYERS_PER_ISLAND) break; } else { - terraform(r, (terrain_t)((rand() % T_GLACIER)+1)); + terraform_region(r, random_terrain(NORMAL_TERRAIN)); --isize; } } @@ -655,15 +677,15 @@ autoseed(newfaction ** players, int nsize, boolean new_island) for (d=0;d!=MAXDIRECTIONS;++d) { region * rn = rconnect(r, d); if (rn==NULL) { - terrain_t terrain = T_OCEAN; + const struct terrain_type * terrain = newterrain(T_OCEAN); rn = new_region(r->x + delta_x[d], r->y + delta_y[d]); if (rand() % SPECIALCHANCE < special) { - terrain = (terrain_t)(1 + rand() % T_GLACIER); + terrain = random_terrain(NORMAL_TERRAIN); special = SPECIALCHANCE / 3; /* 33% chance auf noch eines */ } else { special = 1; } - terraform(rn, terrain); + terraform_region(rn, terrain); /* the new region has an extra 15% chance to have laen */ if (rand() % 100 < 15) rsetlaen(r, 5 + rand() % 5); /* the new region has an extra 20% chance to have mallorn */ diff --git a/src/common/modules/autoseed.h b/src/common/modules/autoseed.h index a9bd156c7..e7d522fba 100644 --- a/src/common/modules/autoseed.h +++ b/src/common/modules/autoseed.h @@ -36,6 +36,7 @@ extern int autoseed(newfaction ** players, int nsize, boolean new_island); extern newfaction * read_newfactions(const char * filename); extern void get_island(struct region * root, struct region_list ** rlist); extern int fix_demand(struct region *r); +extern const struct terrain_type * random_terrain(unsigned int flags); #ifdef __cplusplus } diff --git a/src/mapper/mapper.c b/src/mapper/mapper.c index 967568e74..79022d7cf 100644 --- a/src/mapper/mapper.c +++ b/src/mapper/mapper.c @@ -1153,19 +1153,7 @@ movearound(short rx, short ry) { case 'I': a=map_input(0,0,0,"Wieviele Regionen?",0,500,0); if (a) { - const terrain_type * terrain; - int nterrains; - for (terrain=terrains();terrain;terrain=terrain->next) { - if (fval(terrain, NORMAL_TERRAIN)) { - ++nterrains; - } - } - nterrains = rand() % nterrains; - for (terrain=terrains();nterrains;terrain=terrain->next) { - if (fval(terrain, NORMAL_TERRAIN)) { - --nterrains; - } - } + const terrain_type * terrain = random_terrain(NORMAL_TERRAIN); create_island(r, a, terrain); modified=1; }