From 0de5d698de0316c6a301053df32a7f55f11c2cf4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 2 Jun 2015 15:29:21 +0200 Subject: [PATCH] Fix the 'B' island generation to use the newfactions file, for use by new GMs. configurable island size. --- conf/e2/config.xml | 3 +++ conf/e3/config.xml | 2 ++ src/bind_gmtool.c | 2 +- src/creport.c | 2 +- src/gmtool.c | 39 +++++++++++++++++++++++++-------------- src/gmtool.h | 3 ++- src/modules/autoseed.c | 23 +++++++++++++++-------- src/modules/autoseed.h | 2 +- 8 files changed, 50 insertions(+), 26 deletions(-) diff --git a/conf/e2/config.xml b/conf/e2/config.xml index 92b09b86c..914fd2796 100644 --- a/conf/e2/config.xml +++ b/conf/e2/config.xml @@ -93,6 +93,9 @@ + + + diff --git a/conf/e3/config.xml b/conf/e3/config.xml index c17cec6f8..dac778015 100644 --- a/conf/e3/config.xml +++ b/conf/e3/config.xml @@ -116,6 +116,8 @@ + + diff --git a/src/bind_gmtool.c b/src/bind_gmtool.c index 3a07cfc6b..ec2535e16 100644 --- a/src/bind_gmtool.c +++ b/src/bind_gmtool.c @@ -152,7 +152,7 @@ static int tolua_make_island(lua_State * L) int s = (int)tolua_tonumber(L, 3, 0); int n = (int)tolua_tonumber(L, 4, s / 3); - n = build_island_e3(x, y, n, s); + n = build_island_e3(NULL, x, y, n, s); tolua_pushnumber(L, n); return 1; } diff --git a/src/creport.c b/src/creport.c index 890513c8a..f33d29c1c 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1500,7 +1500,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) FILE *F = fopen(filename, "wt"); if (era < 0) { - era = get_param_int(global.parameters, "world.era", 2); + era = get_param_int(global.parameters, "world.era", 1); } if (F == NULL) { perror(filename); diff --git a/src/gmtool.c b/src/gmtool.c index 920d02a30..f009f6dbf 100644 --- a/src/gmtool.c +++ b/src/gmtool.c @@ -65,6 +65,7 @@ static int g_quit; int force_color = 0; +newfaction * new_players = 0; state *current_state = NULL; @@ -793,7 +794,7 @@ static void handlekey(state * st, int c) region *r; char sbuffer[80]; static char kbuffer[80]; - int n, nx, ny; + int n, nx, ny, minpop, maxpop; switch (c) { case FAST_RIGHT: @@ -846,12 +847,20 @@ static void handlekey(state * st, int c) loaddata(st); break; case 'B': - /* - make_block(st->cursor.x, st->cursor.y, 6, select_terrain(st, NULL)); - */ + if (!new_players) { + sprintf(sbuffer, "%s/newfactions", basepath()); + new_players = read_newfactions(sbuffer); + } cnormalize(&st->cursor, &nx, &ny); - n = rng_int() % 8 + 8; - build_island_e3(nx, ny, n, n * 3); + minpop = get_param_int(global.parameters, "seed.population.min", 8); + maxpop = get_param_int(global.parameters, "seed.population.max", minpop); + if (maxpop > minpop) { + n = rng_int() % (maxpop - minpop) + minpop; + } + else { + n = minpop; + } + build_island_e3(&new_players, nx, ny, n, n * 3); st->modified = 1; st->wnd_info->update |= 1; st->wnd_status->update |= 1; @@ -1052,8 +1061,11 @@ static void handlekey(state * st, int c) tag_region(st->selected, nx, ny); break; case 'A': - sprintf(sbuffer, "%s/newfactions", basepath()); - seed_players(sbuffer, false); + if (!new_players) { + sprintf(sbuffer, "%s/newfactions", basepath()); + new_players = read_newfactions(sbuffer); + } + seed_players(&new_players, false); st->wnd_map->update |= 1; break; case '/': @@ -1332,15 +1344,14 @@ const char *prompt) return buffer[0] != 0; } -void seed_players(const char *filename, bool new_island) +void seed_players(newfaction **players, bool new_island) { - newfaction *players = read_newfactions(filename); - if (players != NULL) { - while (players) { - int n = listlen(players); + if (players) { + while (*players) { + int n = listlen(*players); int k = (n + ISLANDSIZE - 1) / ISLANDSIZE; k = n / k; - n = autoseed(&players, k, new_island ? 0 : TURNS_PER_ISLAND); + n = autoseed(players, k, new_island ? 0 : TURNS_PER_ISLAND); if (n == 0) { break; } diff --git a/src/gmtool.h b/src/gmtool.h index ae2cea39a..d5396a615 100644 --- a/src/gmtool.h +++ b/src/gmtool.h @@ -20,6 +20,7 @@ extern "C" { struct state; struct region; struct terrain_type; + struct newfaction; int gmmain(int argc, char *argv[]); int curses_readline(struct lua_State *L, char *buffer, size_t size, @@ -35,7 +36,7 @@ extern "C" { void state_close(struct state *); void make_block(int x, int y, int radius, const struct terrain_type *terrain); - void seed_players(const char *filename, bool new_island); + void seed_players(struct newfaction **players, bool new_island); #ifdef __cplusplus } diff --git a/src/modules/autoseed.c b/src/modules/autoseed.c index eac860185..dd73943f2 100644 --- a/src/modules/autoseed.c +++ b/src/modules/autoseed.c @@ -904,10 +904,9 @@ static void smooth_island(region_list * island) } } -static void starting_region(region * r, region * rn[]) +static void starting_region(newfaction ** players, region * r, region * rn[]) { int n; - oceans_around(r, rn); freset(r, RF_MARK); for (n = 0; n != MAXDIRECTIONS; ++n) { @@ -915,11 +914,19 @@ static void starting_region(region * r, region * rn[]) } terraform_region(r, newterrain(T_PLAIN)); prepare_starting_region(r); - addplayer(r, addfaction("enno@eressea.de", itoa36(rng_int()), races, default_locale, 0)); + if (players && *players) { + newfaction *nf = *players; + const struct race *rc = nf->race ? nf->race : races; + const struct locale *lang = nf->lang ? nf->lang : default_locale; + const char * passwd = nf->password ? nf->password : itoa36(rng_int()); + addplayer(r, addfaction(nf->email, passwd, rc, lang, 0)); + *players = nf->next; + free_newfaction(nf); + } } /* E3A island generation */ -int build_island_e3(int x, int y, int numfactions, int minsize) +int build_island_e3(newfaction ** players, int x, int y, int numfactions, int minsize) { #define MIN_QUALITY 1000 int nfactions = 0; @@ -961,8 +968,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize) get_neighbours(r, rn); q = region_quality(r, rn); - if (q >= MIN_QUALITY && nfactions < numfactions) { - starting_region(r, rn); + if (q >= MIN_QUALITY && nfactions < numfactions && *players) { + starting_region(players, r, rn); minq = _min(minq, q); maxq = _max(maxq, q); ++nfactions; @@ -976,8 +983,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize) region *rn[MAXDIRECTIONS]; get_neighbours(r, rn); q = region_quality(r, rn); - if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions) { - starting_region(r, rn); + if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) { + starting_region(players, r, rn); minq = _min(minq, q); maxq = _max(maxq, q); ++nfactions; diff --git a/src/modules/autoseed.h b/src/modules/autoseed.h index 9844d017c..3cfe6225c 100644 --- a/src/modules/autoseed.h +++ b/src/modules/autoseed.h @@ -40,7 +40,7 @@ extern "C" { *terrains[], int distribution[], int size); extern int seed_adamantium(struct region *r, int base); - extern int build_island_e3(int x, int y, int numfactions, int minsize); + extern int build_island_e3(newfaction **players, int x, int y, int numfactions, int minsize); #ifdef __cplusplus }