forked from github/server
random_terrain() function
This commit is contained in:
parent
b086e9f93a
commit
3524cb59d2
3 changed files with 28 additions and 17 deletions
|
@ -37,6 +37,28 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
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
|
static int
|
||||||
count_demand(const region *r)
|
count_demand(const region *r)
|
||||||
|
@ -622,7 +644,7 @@ autoseed(newfaction ** players, int nsize, boolean new_island)
|
||||||
--isize;
|
--isize;
|
||||||
if (psize>=PLAYERS_PER_ISLAND) break;
|
if (psize>=PLAYERS_PER_ISLAND) break;
|
||||||
} else {
|
} else {
|
||||||
terraform(r, (terrain_t)((rand() % T_GLACIER)+1));
|
terraform_region(r, random_terrain(NORMAL_TERRAIN));
|
||||||
--isize;
|
--isize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -655,15 +677,15 @@ autoseed(newfaction ** players, int nsize, boolean new_island)
|
||||||
for (d=0;d!=MAXDIRECTIONS;++d) {
|
for (d=0;d!=MAXDIRECTIONS;++d) {
|
||||||
region * rn = rconnect(r, d);
|
region * rn = rconnect(r, d);
|
||||||
if (rn==NULL) {
|
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]);
|
rn = new_region(r->x + delta_x[d], r->y + delta_y[d]);
|
||||||
if (rand() % SPECIALCHANCE < special) {
|
if (rand() % SPECIALCHANCE < special) {
|
||||||
terrain = (terrain_t)(1 + rand() % T_GLACIER);
|
terrain = random_terrain(NORMAL_TERRAIN);
|
||||||
special = SPECIALCHANCE / 3; /* 33% chance auf noch eines */
|
special = SPECIALCHANCE / 3; /* 33% chance auf noch eines */
|
||||||
} else {
|
} else {
|
||||||
special = 1;
|
special = 1;
|
||||||
}
|
}
|
||||||
terraform(rn, terrain);
|
terraform_region(rn, terrain);
|
||||||
/* the new region has an extra 15% chance to have laen */
|
/* the new region has an extra 15% chance to have laen */
|
||||||
if (rand() % 100 < 15) rsetlaen(r, 5 + rand() % 5);
|
if (rand() % 100 < 15) rsetlaen(r, 5 + rand() % 5);
|
||||||
/* the new region has an extra 20% chance to have mallorn */
|
/* the new region has an extra 20% chance to have mallorn */
|
||||||
|
|
|
@ -36,6 +36,7 @@ extern int autoseed(newfaction ** players, int nsize, boolean new_island);
|
||||||
extern newfaction * read_newfactions(const char * filename);
|
extern newfaction * read_newfactions(const char * filename);
|
||||||
extern void get_island(struct region * root, struct region_list ** rlist);
|
extern void get_island(struct region * root, struct region_list ** rlist);
|
||||||
extern int fix_demand(struct region *r);
|
extern int fix_demand(struct region *r);
|
||||||
|
extern const struct terrain_type * random_terrain(unsigned int flags);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -1153,19 +1153,7 @@ movearound(short rx, short ry) {
|
||||||
case 'I':
|
case 'I':
|
||||||
a=map_input(0,0,0,"Wieviele Regionen?",0,500,0);
|
a=map_input(0,0,0,"Wieviele Regionen?",0,500,0);
|
||||||
if (a) {
|
if (a) {
|
||||||
const terrain_type * terrain;
|
const terrain_type * terrain = random_terrain(NORMAL_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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
create_island(r, a, terrain);
|
create_island(r, a, terrain);
|
||||||
modified=1;
|
modified=1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue