diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index e4ae939f9..18efbd994 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -150,10 +150,9 @@ static int tolua_make_island(lua_State * L) int x = (int)tolua_tonumber(L, 1, 0); int y = (int)tolua_tonumber(L, 2, 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); - lua_pushinteger(L, n); + s = build_island_e3(x, y, s, NULL, 0); + lua_pushinteger(L, s); return 1; } diff --git a/src/gmtool.c b/src/gmtool.c index 6db857ad9..d9afd738e 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -912,15 +912,15 @@ static void handlekey(state * st, int c) break; case 'B': cnormalize(&st->cursor, &nx, &ny); - minpop = config_get_int("editor.population.min", 8); - maxpop = config_get_int("editor.population.max", minpop); + minpop = config_get_int("editor.island.min", 8); + maxpop = config_get_int("editor.island.max", minpop); if (maxpop > minpop) { n = rng_int() % (maxpop - minpop) + minpop; } else { n = minpop; } - build_island_e3(&new_players, nx, ny, n, n * 3); + build_island_e3(nx, ny, n, NULL, 0); st->modified = 1; st->wnd_info->update |= 1; st->wnd_status->update |= 1; diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index 66013149c..ad8eb6731 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -780,25 +780,29 @@ const terrain_type *random_terrain_e3(direction_t dir) return random_terrain(terrainarr, distribution, GEOMAX); } -int +static int random_neighbours(region * r, region_list ** rlist, -const terrain_type * (*terraformer) (direction_t)) +const terrain_type * (*terraformer) (direction_t), int n) { int nsize = 0; direction_t dir; for (dir = 0; dir != MAXDIRECTIONS; ++dir) { region *rn = rconnect(r, dir); - if (rn == NULL) { + if (rn == NULL || (!rn->units && !rn->land)) { const terrain_type *terrain = terraformer(dir); - plane *pl = rplane(r); - int x = r->x + delta_x[dir]; - int y = r->y + delta_y[dir]; - pnormalize(&x, &y, pl); - rn = new_region(x, y, pl, 0); + if (!rn) { + plane *pl = rplane(r); + int x = r->x + delta_x[dir]; + int y = r->y + delta_y[dir]; + pnormalize(&x, &y, pl); + rn = new_region(x, y, pl, 0); + } terraform_region(rn, terrain); regionqueue_push(rlist, rn); if (rn->land) { - ++nsize; + if (++nsize >= n) { + break; + } } } } @@ -908,7 +912,7 @@ static void starting_region(newfaction ** players, region * r, region * rn[]) } /* 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 int nfactions = 0; @@ -919,9 +923,10 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi int nsize = 1; 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); - assert(!r->units); + } do { terraform_region(r, random_terrain_e3(NODIRECTION)); } while (!r->land); @@ -930,10 +935,10 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi fset(r, RF_MARK); if (r->land) { if (nsize < minsize) { - nsize += random_neighbours(r, &rlist, &random_terrain_e3); + nsize += random_neighbours(r, &rlist, &random_terrain_e3, minsize-nsize); } else { - nsize += random_neighbours(r, &rlist, &get_ocean); + nsize += random_neighbours(r, &rlist, &get_ocean, minsize - nsize); } } regionqueue_push(&island, r); @@ -950,7 +955,7 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi get_neighbours(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); minq = MIN(minq, q); maxq = MAX(maxq, q); @@ -965,7 +970,7 @@ int build_island_e3(newfaction ** players, int x, int y, int numfactions, int mi region *rn[MAXDIRECTIONS]; get_neighbours(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); minq = MIN(minq, q); maxq = MAX(maxq, q); diff --git a/src/modules/autoseed.h b/src/modules/autoseed.h index 06ce646c2..65bdccb7f 100644 --- a/src/modules/autoseed.h +++ b/src/modules/autoseed.h @@ -38,8 +38,7 @@ extern "C" { extern const struct terrain_type *random_terrain(const struct terrain_type *terrains[], int distribution[], int size); - extern int seed_adamantium(struct region *r, int base); - extern int build_island_e3(newfaction **players, int x, int y, int numfactions, int minsize); + extern int build_island_e3(int x, int y, int minsize, newfaction **players, int numfactions); #ifdef __cplusplus }