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 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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(NULL, 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;
|
||||||
|
|
|
@ -776,15 +776,15 @@ 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 || !rn->land) {
|
if (rn == NULL || (!rn->units && !rn->land)) {
|
||||||
const terrain_type *terrain = terraformer(dir);
|
const terrain_type *terrain = terraformer(dir);
|
||||||
if (!rn) {
|
if (!rn) {
|
||||||
plane *pl = rplane(r);
|
plane *pl = rplane(r);
|
||||||
|
@ -796,7 +796,9 @@ const terrain_type * (*terraformer) (direction_t))
|
||||||
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -906,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;
|
||||||
|
@ -917,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);
|
||||||
|
@ -928,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);
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue