Merge pull request #713 from ennorehling/master

gmtool island building
This commit is contained in:
Enno Rehling 2017-07-27 16:48:06 +02:00 committed by GitHub
commit 133b49f087
4 changed files with 27 additions and 24 deletions

View File

@ -150,10 +150,9 @@ static int tolua_make_island(lua_State * L)
int x = (int)tolua_tonumber(L, 1, 0); int x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0); int y = (int)tolua_tonumber(L, 2, 0);
int s = (int)tolua_tonumber(L, 3, 0); int s = (int)tolua_tonumber(L, 3, 0);
int n = (int)tolua_tonumber(L, 4, s / 3);
n = build_island_e3(NULL, x, y, n, s); s = build_island_e3(x, y, s, NULL, 0);
lua_pushinteger(L, n); lua_pushinteger(L, s);
return 1; return 1;
} }

View File

@ -912,15 +912,15 @@ static void handlekey(state * st, int c)
break; break;
case 'B': case 'B':
cnormalize(&st->cursor, &nx, &ny); cnormalize(&st->cursor, &nx, &ny);
minpop = config_get_int("editor.population.min", 8); minpop = config_get_int("editor.island.min", 8);
maxpop = config_get_int("editor.population.max", minpop); maxpop = config_get_int("editor.island.max", minpop);
if (maxpop > minpop) { if (maxpop > minpop) {
n = rng_int() % (maxpop - minpop) + minpop; n = rng_int() % (maxpop - minpop) + minpop;
} }
else { else {
n = minpop; n = minpop;
} }
build_island_e3(&new_players, nx, ny, n, n * 3); build_island_e3(nx, ny, n, NULL, 0);
st->modified = 1; st->modified = 1;
st->wnd_info->update |= 1; st->wnd_info->update |= 1;
st->wnd_status->update |= 1; st->wnd_status->update |= 1;

View File

@ -776,25 +776,29 @@ const terrain_type *random_terrain_e3(direction_t dir)
return random_terrain(terrainarr, distribution, GEOMAX); return random_terrain(terrainarr, distribution, GEOMAX);
} }
int static int
random_neighbours(region * r, region_list ** rlist, random_neighbours(region * r, region_list ** rlist,
const terrain_type * (*terraformer) (direction_t)) const terrain_type * (*terraformer) (direction_t), int n)
{ {
int nsize = 0; int nsize = 0;
direction_t dir; direction_t dir;
for (dir = 0; dir != MAXDIRECTIONS; ++dir) { for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
region *rn = rconnect(r, dir); region *rn = rconnect(r, dir);
if (rn == NULL) { if (rn == NULL || (!rn->units && !rn->land)) {
const terrain_type *terrain = terraformer(dir); const terrain_type *terrain = terraformer(dir);
if (!rn) {
plane *pl = rplane(r); plane *pl = rplane(r);
int x = r->x + delta_x[dir]; int x = r->x + delta_x[dir];
int y = r->y + delta_y[dir]; int y = r->y + delta_y[dir];
pnormalize(&x, &y, pl); pnormalize(&x, &y, pl);
rn = new_region(x, y, pl, 0); rn = new_region(x, y, pl, 0);
}
terraform_region(rn, terrain); terraform_region(rn, terrain);
regionqueue_push(rlist, rn); regionqueue_push(rlist, rn);
if (rn->land) { if (rn->land) {
++nsize; if (++nsize >= n) {
break;
}
} }
} }
} }
@ -904,7 +908,7 @@ static void starting_region(newfaction ** players, region * r, region * rn[])
} }
/* E3A island generation */ /* E3A island generation */
int build_island_e3(newfaction ** players, int x, int y, int numfactions, int minsize) int build_island_e3(int x, int y, int minsize, newfaction ** players, int numfactions)
{ {
#define MIN_QUALITY 1000 #define MIN_QUALITY 1000
int nfactions = 0; int nfactions = 0;
@ -915,9 +919,10 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi
int nsize = 1; int nsize = 1;
int q, maxq = INT_MIN, minq = INT_MAX; int q, maxq = INT_MIN, minq = INT_MAX;
if (!r) if (r && r->units) return 0;
if (!r) {
r = new_region(x, y, pl, 0); r = new_region(x, y, pl, 0);
assert(!r->units); }
do { do {
terraform_region(r, random_terrain_e3(NODIRECTION)); terraform_region(r, random_terrain_e3(NODIRECTION));
} while (!r->land); } while (!r->land);
@ -926,10 +931,10 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi
fset(r, RF_MARK); fset(r, RF_MARK);
if (r->land) { if (r->land) {
if (nsize < minsize) { if (nsize < minsize) {
nsize += random_neighbours(r, &rlist, &random_terrain_e3); nsize += random_neighbours(r, &rlist, &random_terrain_e3, minsize-nsize);
} }
else { else {
nsize += random_neighbours(r, &rlist, &get_ocean); nsize += random_neighbours(r, &rlist, &get_ocean, minsize - nsize);
} }
} }
regionqueue_push(&island, r); regionqueue_push(&island, r);
@ -946,7 +951,7 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi
get_neighbours(r, rn); get_neighbours(r, rn);
q = region_quality(r, rn); q = region_quality(r, rn);
if (q >= MIN_QUALITY && nfactions < numfactions && *players) { if (q >= MIN_QUALITY && nfactions < numfactions && players && *players) {
starting_region(players, r, rn); starting_region(players, r, rn);
minq = MIN(minq, q); minq = MIN(minq, q);
maxq = MAX(maxq, q); maxq = MAX(maxq, q);
@ -961,7 +966,7 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi
region *rn[MAXDIRECTIONS]; region *rn[MAXDIRECTIONS];
get_neighbours(r, rn); get_neighbours(r, rn);
q = region_quality(r, rn); q = region_quality(r, rn);
if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) { if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && players && *players) {
starting_region(players, r, rn); starting_region(players, r, rn);
minq = MIN(minq, q); minq = MIN(minq, q);
maxq = MAX(maxq, q); maxq = MAX(maxq, q);

View File

@ -38,8 +38,7 @@ extern "C" {
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);
extern int seed_adamantium(struct region *r, int base); extern int build_island_e3(int x, int y, int minsize, newfaction **players, int numfactions);
extern int build_island_e3(newfaction **players, int x, int y, int numfactions, int minsize);
#ifdef __cplusplus #ifdef __cplusplus
} }