Fix the 'B' island generation to use the newfactions file, for use by new GMs.

configurable island size.
This commit is contained in:
Enno Rehling 2015-06-02 15:29:21 +02:00
parent c90496e60b
commit 0de5d698de
8 changed files with 50 additions and 26 deletions

View File

@ -93,6 +93,9 @@
<param name="GiveRestriction" value="3"/> <param name="GiveRestriction" value="3"/>
<param name="hunger.long" value="1"/> <param name="hunger.long" value="1"/>
<param name="init_spells" value="0"/> <param name="init_spells" value="0"/>
<param name="world.era" value="2"/>
<param name="seed.population.min" value="8"/>
<param name="seed.population.max" value="8"/>
<param name="rules.reserve.twophase" value="1"/> <param name="rules.reserve.twophase" value="1"/>
<param name="rules.owners.force_leave" value="1"/> <param name="rules.owners.force_leave" value="1"/>
<param name="rules.give.max_men" value="-1"/> <param name="rules.give.max_men" value="-1"/>

View File

@ -116,6 +116,8 @@
<param name="study.expensivemigrants" value="1"/> <param name="study.expensivemigrants" value="1"/>
<param name="study.speedup" value="2"/> <param name="study.speedup" value="2"/>
<param name="world.era" value="3"/> <param name="world.era" value="3"/>
<param name="seed.population.min" value="8"/>
<param name="seed.population.max" value="8"/>
<param name="rules.migrants" value="0"/> <param name="rules.migrants" value="0"/>
<param name="rules.reserve.twophase" value="1"/> <param name="rules.reserve.twophase" value="1"/>
<param name="rules.owners.force_leave" value="1"/> <param name="rules.owners.force_leave" value="1"/>

View File

@ -152,7 +152,7 @@ static int tolua_make_island(lua_State * L)
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); 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); tolua_pushnumber(L, n);
return 1; return 1;
} }

View File

@ -1500,7 +1500,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset)
FILE *F = fopen(filename, "wt"); FILE *F = fopen(filename, "wt");
if (era < 0) { if (era < 0) {
era = get_param_int(global.parameters, "world.era", 2); era = get_param_int(global.parameters, "world.era", 1);
} }
if (F == NULL) { if (F == NULL) {
perror(filename); perror(filename);

View File

@ -65,6 +65,7 @@
static int g_quit; static int g_quit;
int force_color = 0; int force_color = 0;
newfaction * new_players = 0;
state *current_state = NULL; state *current_state = NULL;
@ -793,7 +794,7 @@ static void handlekey(state * st, int c)
region *r; region *r;
char sbuffer[80]; char sbuffer[80];
static char kbuffer[80]; static char kbuffer[80];
int n, nx, ny; int n, nx, ny, minpop, maxpop;
switch (c) { switch (c) {
case FAST_RIGHT: case FAST_RIGHT:
@ -846,12 +847,20 @@ static void handlekey(state * st, int c)
loaddata(st); loaddata(st);
break; break;
case 'B': case 'B':
/* if (!new_players) {
make_block(st->cursor.x, st->cursor.y, 6, select_terrain(st, NULL)); sprintf(sbuffer, "%s/newfactions", basepath());
*/ new_players = read_newfactions(sbuffer);
}
cnormalize(&st->cursor, &nx, &ny); cnormalize(&st->cursor, &nx, &ny);
n = rng_int() % 8 + 8; minpop = get_param_int(global.parameters, "seed.population.min", 8);
build_island_e3(nx, ny, n, n * 3); 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->modified = 1;
st->wnd_info->update |= 1; st->wnd_info->update |= 1;
st->wnd_status->update |= 1; st->wnd_status->update |= 1;
@ -1052,8 +1061,11 @@ static void handlekey(state * st, int c)
tag_region(st->selected, nx, ny); tag_region(st->selected, nx, ny);
break; break;
case 'A': case 'A':
if (!new_players) {
sprintf(sbuffer, "%s/newfactions", basepath()); sprintf(sbuffer, "%s/newfactions", basepath());
seed_players(sbuffer, false); new_players = read_newfactions(sbuffer);
}
seed_players(&new_players, false);
st->wnd_map->update |= 1; st->wnd_map->update |= 1;
break; break;
case '/': case '/':
@ -1332,15 +1344,14 @@ const char *prompt)
return buffer[0] != 0; 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) {
if (players != NULL) { while (*players) {
while (players) { int n = listlen(*players);
int n = listlen(players);
int k = (n + ISLANDSIZE - 1) / ISLANDSIZE; int k = (n + ISLANDSIZE - 1) / ISLANDSIZE;
k = n / k; 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) { if (n == 0) {
break; break;
} }

View File

@ -20,6 +20,7 @@ extern "C" {
struct state; struct state;
struct region; struct region;
struct terrain_type; struct terrain_type;
struct newfaction;
int gmmain(int argc, char *argv[]); int gmmain(int argc, char *argv[]);
int curses_readline(struct lua_State *L, char *buffer, size_t size, int curses_readline(struct lua_State *L, char *buffer, size_t size,
@ -35,7 +36,7 @@ extern "C" {
void state_close(struct state *); void state_close(struct state *);
void make_block(int x, int y, int radius, const struct terrain_type *terrain); 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 #ifdef __cplusplus
} }

View File

@ -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; int n;
oceans_around(r, rn); oceans_around(r, rn);
freset(r, RF_MARK); freset(r, RF_MARK);
for (n = 0; n != MAXDIRECTIONS; ++n) { for (n = 0; n != MAXDIRECTIONS; ++n) {
@ -915,11 +914,19 @@ static void starting_region(region * r, region * rn[])
} }
terraform_region(r, newterrain(T_PLAIN)); terraform_region(r, newterrain(T_PLAIN));
prepare_starting_region(r); 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 */ /* 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 #define MIN_QUALITY 1000
int nfactions = 0; int nfactions = 0;
@ -961,8 +968,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize)
get_neighbours(r, rn); get_neighbours(r, rn);
q = region_quality(r, rn); q = region_quality(r, rn);
if (q >= MIN_QUALITY && nfactions < numfactions) { if (q >= MIN_QUALITY && nfactions < numfactions && *players) {
starting_region(r, rn); starting_region(players, r, rn);
minq = _min(minq, q); minq = _min(minq, q);
maxq = _max(maxq, q); maxq = _max(maxq, q);
++nfactions; ++nfactions;
@ -976,8 +983,8 @@ int build_island_e3(int x, int y, int numfactions, int minsize)
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) { if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) {
starting_region(r, rn); starting_region(players, r, rn);
minq = _min(minq, q); minq = _min(minq, q);
maxq = _max(maxq, q); maxq = _max(maxq, q);
++nfactions; ++nfactions;

View File

@ -40,7 +40,7 @@ extern "C" {
*terrains[], int distribution[], int size); *terrains[], int distribution[], int size);
extern int seed_adamantium(struct region *r, int base); 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 #ifdef __cplusplus
} }