forked from github/server
limit island size from configuration, deal with existing units.
This commit is contained in:
parent
822292c99a
commit
847e6f3e43
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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(NULL, 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;
|
||||
|
|
|
@ -776,15 +776,15 @@ 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 || !rn->land) {
|
||||
if (rn == NULL || (!rn->units && !rn->land)) {
|
||||
const terrain_type *terrain = terraformer(dir);
|
||||
if (!rn) {
|
||||
plane *pl = rplane(r);
|
||||
|
@ -796,7 +796,9 @@ const terrain_type * (*terraformer) (direction_t))
|
|||
terraform_region(rn, terrain);
|
||||
regionqueue_push(rlist, rn);
|
||||
if (rn->land) {
|
||||
++nsize;
|
||||
if (++nsize >= n) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -906,7 +908,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;
|
||||
|
@ -917,9 +919,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);
|
||||
|
@ -928,10 +931,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);
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue