seed a single faction from newplayers file.

This commit is contained in:
Enno Rehling 2017-07-23 09:15:23 +02:00
parent bdb30f1b82
commit 475c9f8cd8
2 changed files with 39 additions and 26 deletions

View File

@ -814,7 +814,7 @@ static void select_regions(state * st, int selectmode)
st->wnd_map->update |= 3; st->wnd_map->update |= 3;
} }
void loaddata(state *st) { static void loaddata(state *st) {
char datafile[MAX_PATH]; char datafile[MAX_PATH];
askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile));
@ -824,7 +824,7 @@ void loaddata(state *st) {
} }
} }
void savedata(state *st) { static void savedata(state *st) {
char datafile[MAX_PATH]; char datafile[MAX_PATH];
askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile)); askstring(st->wnd_status->handle, "save as:", datafile, sizeof(datafile));
@ -835,6 +835,20 @@ void savedata(state *st) {
} }
} }
static void seed_player(state *st, const newfaction *player) {
if (player) {
region *r;
int nx = st->cursor.x;
int ny = st->cursor.y;
pnormalize(&nx, &ny, st->cursor.pl);
r = findregion(nx, ny);
if (r) {
addplayer(r, addfaction(player->email, player->password, player->race,
player->lang, player->subscription));
}
}
}
static void handlekey(state * st, int c) static void handlekey(state * st, int c)
{ {
window *wnd; window *wnd;
@ -897,10 +911,6 @@ static void handlekey(state * st, int c)
loaddata(st); loaddata(st);
break; break;
case 'B': case 'B':
if (!new_players) {
join_path(basepath(), "newfactions", sbuffer, sizeof(sbuffer));
new_players = read_newfactions(sbuffer);
}
cnormalize(&st->cursor, &nx, &ny); cnormalize(&st->cursor, &nx, &ny);
minpop = config_get_int("editor.population.min", 8); minpop = config_get_int("editor.population.min", 8);
maxpop = config_get_int("editor.population.max", minpop); maxpop = config_get_int("editor.population.max", minpop);
@ -1111,13 +1121,15 @@ static void handlekey(state * st, int c)
else else
tag_region(st->selected, nx, ny); tag_region(st->selected, nx, ny);
break; break;
case 'A': case 's': /* seed */
if (!new_players) { if (new_players) {
join_path(basepath(), "newfactions", sbuffer, sizeof(sbuffer)); newfaction * next = new_players->next;
new_players = read_newfactions(sbuffer); seed_player(st, new_players);
free(new_players->email);
free(new_players->password);
free(new_players);
new_players = next;
} }
seed_players(&new_players, false);
st->wnd_map->update |= 1;
break; break;
case '/': case '/':
statusline(st->wnd_status->handle, "find-"); statusline(st->wnd_status->handle, "find-");
@ -1289,13 +1301,15 @@ void run_mapper(void)
int split = 20; int split = 20;
state *st; state *st;
point tl; point tl;
/* FIXME: dsiable logging char sbuffer[512];
int old_flags = log_flags;
log_flags &= ~(LOG_CPERROR | LOG_CPWARNING); if (!new_players) {
*/ join_path(basepath(), "newfactions", sbuffer, sizeof(sbuffer));
new_players = read_newfactions(sbuffer);
}
init_curses(); init_curses();
curs_set(1); curs_set(1);
set_readline(curses_readline); set_readline(curses_readline);
assert(stdscr); assert(stdscr);
getbegyx(stdscr, x, y); getbegyx(stdscr, x, y);

View File

@ -22,7 +22,6 @@ extern "C" {
struct terrain_type; struct terrain_type;
struct newfaction; struct newfaction;
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,
const char *prompt); const char *prompt);