made the save function work, and not print so much (quiet now understands

'real quiet' as anything >=2 in some places).
Made the listbox code handle PNEXT and PPREV, very helpful for the faction
list.
This commit is contained in:
Enno Rehling 2006-03-26 21:14:35 +00:00
parent dda37aaee6
commit a14d57f32d
6 changed files with 112 additions and 49 deletions

View File

@ -466,7 +466,7 @@ unitorders(FILE * F, struct faction * f)
if (u && u->faction == f) { if (u && u->faction == f) {
order ** ordp; order ** ordp;
if (!quiet) { if (quiet==0) {
printf(",_%4s_", itoa36(u->no)); printf(",_%4s_", itoa36(u->no));
fflush(stdout); fflush(stdout);
} }
@ -545,7 +545,7 @@ factionorders(void)
* muß in "Gänsefüßchen" stehen!! */ * muß in "Gänsefüßchen" stehen!! */
/* War vorher in main.c:getgarbage() */ /* War vorher in main.c:getgarbage() */
if (!quiet) { if (quiet==0) {
printf(" %4s;", factionid(f)); printf(" %4s;", factionid(f));
fflush(stdout); fflush(stdout);
} }
@ -1495,7 +1495,7 @@ readfaction(FILE * F)
if (strlen(f->banner)>=DISPLAYSIZE) f->banner[DISPLAYSIZE] = 0; if (strlen(f->banner)>=DISPLAYSIZE) f->banner[DISPLAYSIZE] = 0;
#endif #endif
if (!quiet) printf(" - Lese Partei %s (%s)\n", f->name, factionid(f)); if (quiet==0) printf(" - Lese Partei %s (%s)\n", f->name, factionid(f));
rds(F, &email); rds(F, &email);
if (set_email(&f->email, email)!=0) { if (set_email(&f->email, email)!=0) {
@ -1758,7 +1758,7 @@ readgame(const char * filename, int backup)
read_alliances(F); read_alliances(F);
} }
n = ri(F); n = ri(F);
printf(" - Einzulesende Parteien: %d\n", n); if (quiet<2) printf(" - Einzulesende Parteien: %d\n", n);
fp = &factions; fp = &factions;
while (*fp) fp=&(*fp)->next; while (*fp) fp=&(*fp)->next;
@ -1784,7 +1784,7 @@ readgame(const char * filename, int backup)
n = ri(F); n = ri(F);
if (rmax<0) rmax = n; if (rmax<0) rmax = n;
printf(" - Einzulesende Regionen: %d/%d\r", rmax, n); if (quiet<2) printf(" - Einzulesende Regionen: %d/%d\r", rmax, n);
if (loadplane || dirtyload || firstx || firsty || maxregions>=0) { if (loadplane || dirtyload || firstx || firsty || maxregions>=0) {
incomplete_data = true; incomplete_data = true;
} }
@ -1809,7 +1809,7 @@ readgame(const char * filename, int backup)
if (dirtyload) break; if (dirtyload) break;
skip = true; skip = true;
} }
if ((n & 0x3FF) == 0) { /* das spart extrem Zeit */ if (quiet<2 && (n & 0x3FF) == 0) { /* das spart extrem Zeit */
printf(" - Einzulesende Regionen: %d/%d ", rmax, n); printf(" - Einzulesende Regionen: %d/%d ", rmax, n);
printf("* %d,%d \r", x, y); printf("* %d,%d \r", x, y);
} }
@ -1910,7 +1910,7 @@ readgame(const char * filename, int backup)
} }
} }
} }
printf("\n"); if (quiet<2) printf("\n");
if (!dirtyload) { if (!dirtyload) {
read_borders(F); read_borders(F);
} }
@ -1918,10 +1918,10 @@ readgame(const char * filename, int backup)
fclose(F); fclose(F);
/* Unaufgeloeste Zeiger initialisieren */ /* Unaufgeloeste Zeiger initialisieren */
printf("\n - Referenzen initialisieren...\n"); if (quiet<2) printf("\n - Referenzen initialisieren...\n");
resolve(); resolve();
printf("\n - Leere Gruppen löschen...\n"); if (quiet<2) printf("\n - Leere Gruppen löschen...\n");
for (f=factions; f; f=f->next) { for (f=factions; f; f=f->next) {
group ** gp = &f->groups; group ** gp = &f->groups;
while (*gp) { while (*gp) {
@ -1938,7 +1938,7 @@ readgame(const char * filename, int backup)
building * b; building * b;
for (b=r->buildings;b;b=b->next) update_lighthouse(b); for (b=r->buildings;b;b=b->next) update_lighthouse(b);
} }
printf(" - Regionen initialisieren & verbinden...\n"); if (quiet < 2) printf(" - Regionen initialisieren & verbinden...\n");
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
for (u = f->units; u; u = u->nextF) { for (u = f->units; u; u = u->nextF) {
if (u->number>0) { if (u->number>0) {
@ -2047,7 +2047,7 @@ writegame(const char *filename, int quiet)
wi(F, n); wi(F, n);
wnl(F); wnl(F);
printf(" - Schreibe %d Parteien...\n",n); if (quiet < 2) printf(" - Schreibe %d Parteien...\n",n);
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
writefaction(F, f); writefaction(F, f);
} }
@ -2060,11 +2060,11 @@ writegame(const char *filename, int quiet)
n=listlen(regions); n=listlen(regions);
wi(F, n); wi(F, n);
wnl(F); wnl(F);
printf(" - Schreibe Regionen: %d \r", n); if (quiet<2) printf(" - Schreibe Regionen: %d \r", n);
for (r = regions; r; r = r->next, --n) { for (r = regions; r; r = r->next, --n) {
/* plus leerzeile */ /* plus leerzeile */
if ((n%1024)==0) { /* das spart extrem Zeit */ if (quiet<2 && (n%1024)==0) { /* das spart extrem Zeit */
printf(" - Schreibe Regionen: %d \r", n); printf(" - Schreibe Regionen: %d \r", n);
fflush(stdout); fflush(stdout);
} }
@ -2112,7 +2112,7 @@ writegame(const char *filename, int quiet)
write_borders(F); write_borders(F);
wnl(F); wnl(F);
fclose(F); fclose(F);
printf("\nOk.\n"); if (quiet<2) printf("\nOk.\n");
return 0; return 0;
} }

View File

@ -44,7 +44,7 @@
void void
init_triggers(void) init_triggers(void)
{ {
fprintf(stdout, "- registering triggers\n"); if (quiet<2) printf("- registering triggers\n");
tt_register(&tt_changefaction); tt_register(&tt_changefaction);
tt_register(&tt_changerace); tt_register(&tt_changerace);
tt_register(&tt_createcurse); tt_register(&tt_createcurse);

View File

@ -88,11 +88,11 @@ do_selection(list_selection * sel, const char * title, void (*perform)(list_sele
for (;;) { for (;;) {
int input; int input;
if (update) { if (update) {
/* wclear(wn); */
for (s=top;s!=NULL && top->index+height!=s->index;s=s->next) { for (s=top;s!=NULL && top->index+height!=s->index;s=s->next) {
i = s->index-top->index; i = s->index-top->index;
wmove(wn, i + 1, 4); wmove(wn, i + 1, 4);
waddnstr(wn, s->str, -1); waddnstr(wn, s->str, -1);
wclrtoeol(wn);
} }
wborder(wn, 0, 0, 0, 0, 0, 0, 0, 0); wborder(wn, 0, 0, 0, 0, 0, 0, 0, 0);
mvwprintw(wn, 0, 2, "[ %s ]", title); mvwprintw(wn, 0, 2, "[ %s ]", title);
@ -103,7 +103,7 @@ do_selection(list_selection * sel, const char * title, void (*perform)(list_sele
wmove(wn, i + 1, 2); wmove(wn, i + 1, 2);
waddstr(wn, "->"); waddstr(wn, "->");
wmove(wn, i + 1, 4); wmove(wn, i + 1, 4);
waddnstr(wn, current->str, width); waddnstr(wn, current->str, -1);
wattroff(wn, A_BOLD | COLOR_PAIR(COLOR_YELLOW)); wattroff(wn, A_BOLD | COLOR_PAIR(COLOR_YELLOW));
wrefresh(wn); wrefresh(wn);
@ -116,6 +116,29 @@ do_selection(list_selection * sel, const char * title, void (*perform)(list_sele
waddnstr(wn, current->str, width); waddnstr(wn, current->str, width);
switch (input) { switch (input) {
case KEY_NPAGE:
for (i=0;i!=height/2;++i) {
if (current->next) {
current = current->next;
if (current->index-height>=top->index) {
top=current;
update = true;
}
}
}
break;
case KEY_PPAGE:
for (i=0;i!=height/2;++i) {
if (current->prev) {
if (current==top) {
top = sel;
while (top->index+height<current->index) top=top->next;
update = true;
}
current = current->prev;
}
}
break;
case KEY_DOWN: case KEY_DOWN:
if (current->next) { if (current->next) {
current = current->next; current = current->next;
@ -159,6 +182,10 @@ do_selection(list_selection * sel, const char * title, void (*perform)(list_sele
if (s==NULL) s = top; if (s==NULL) s = top;
} }
} }
if (current->index-height>=top->index) {
top=current;
update = true;
}
} }
} }
} }

View File

@ -13,6 +13,28 @@
#include "editing.h" #include "editing.h"
#include <kernel/region.h> #include <kernel/region.h>
#include <modules/autoseed.h>
#include <util/rng.h>
#define ISLANDSIZE 20
#define TURNS_PER_ISLAND 4
void
seed_players(const char * filename, boolean new_island)
{
newfaction * players = read_newfactions(filename);
if (players!=NULL) {
rng_init(players->subscription);
while (players) {
int n = listlen(players);
int k = (n+ISLANDSIZE-1)/ISLANDSIZE;
k = n / k;
n = autoseed(&players, k, new_island || (turn % TURNS_PER_ISLAND)==0);
if (n==0) {
break;
}
}
}
}
void void
make_block(short x, short y, short radius, const struct terrain_type * terrain) make_block(short x, short y, short radius, const struct terrain_type * terrain)

View File

@ -13,5 +13,6 @@
extern void make_block(short x, short y, short radius, const struct terrain_type * terrain); extern void make_block(short x, short y, short radius, const struct terrain_type * terrain);
extern void make_island(short x, short y, int size); extern void make_island(short x, short y, int size);
extern void seed_players(const char * filename, boolean new_island);
#endif /* GM_EDITING */ #endif /* GM_EDITING */

View File

@ -17,7 +17,6 @@
#include "editing.h" #include "editing.h"
#include "curses/listbox.h" #include "curses/listbox.h"
#include <modules/autoseed.h>
#include <modules/xmas.h> #include <modules/xmas.h>
#include <modules/gmcmd.h> #include <modules/gmcmd.h>
#ifdef MUSEUM_MODULE #ifdef MUSEUM_MODULE
@ -99,7 +98,7 @@ read_args(int argc, char **argv)
{ {
int i; int i;
quiet = 1; quiet = 0xFF; /* no printing whatsoever */
turn = first_turn; turn = first_turn;
for (i=1;i!=argc;++i) { for (i=1;i!=argc;++i) {
@ -227,9 +226,12 @@ init_curses(void)
if (has_colors() || force_color) { if (has_colors() || force_color) {
short bcol = COLOR_BLACK; short bcol = COLOR_BLACK;
start_color(); start_color();
#ifdef WIN32
/* looks crap on putty with TERM=linux */
if (can_change_color()) { if (can_change_color()) {
init_color(COLOR_YELLOW, 1000, 1000, 0); init_color(COLOR_YELLOW, 1000, 1000, 0);
} }
#endif
init_pair(COLOR_BLACK, COLOR_BLACK, bcol); init_pair(COLOR_BLACK, COLOR_BLACK, bcol);
init_pair(COLOR_GREEN, COLOR_GREEN, bcol); init_pair(COLOR_GREEN, COLOR_GREEN, bcol);
init_pair(COLOR_GREEN, COLOR_GREEN, bcol); init_pair(COLOR_GREEN, COLOR_GREEN, bcol);
@ -248,12 +250,12 @@ init_curses(void)
} }
keypad(stdscr, TRUE); /* enable keyboard mapping */ keypad(stdscr, TRUE); /* enable keyboard mapping */
meta(stdscr, TRUE);
nonl(); /* tell curses not to do NL->CR/NL on output */ nonl(); /* tell curses not to do NL->CR/NL on output */
cbreak(); /* take input chars one at a time, no wait for \n */ cbreak(); /* take input chars one at a time, no wait for \n */
noecho(); /* don't echo input */ noecho(); /* don't echo input */
scrollok(stdscr, FALSE); scrollok(stdscr, FALSE);
refresh(); refresh();
/* wclear(stdscr); */
} }
static map_region * static map_region *
@ -680,6 +682,7 @@ handlekey(state * st, int c)
region *r; region *r;
boolean invert = false; boolean invert = false;
char sbuffer[80]; char sbuffer[80];
static char kbuffer[80];
switch(c) { switch(c) {
case FAST_RIGHT: case FAST_RIGHT:
@ -951,6 +954,11 @@ handlekey(state * st, int c)
if (tagged_region(st->selected, cursor)) untag_region(st->selected, cursor); if (tagged_region(st->selected, cursor)) untag_region(st->selected, cursor);
else tag_region(st->selected, cursor); else tag_region(st->selected, cursor);
break; break;
case 'A':
sprintf(sbuffer, "%s/newfactions", basepath());
seed_players(sbuffer, false);
st->wnd_map->update |= 1;
break;
case '/': case '/':
statusline(st->wnd_status->handle, "find-"); statusline(st->wnd_status->handle, "find-");
doupdate(); doupdate();
@ -1033,8 +1041,13 @@ handlekey(state * st, int c)
} }
} }
if (wnd==NULL) { if (wnd==NULL) {
sprintf(sbuffer, "getch: 0x%x", c); if (kbuffer[0]==0) {
statusline(st->wnd_status->handle, sbuffer); strcpy(kbuffer, "getch:");
}
sprintf(sbuffer, " 0x%x", c);
strncat(kbuffer, sbuffer, sizeof(kbuffer));
statusline(st->wnd_status->handle, kbuffer);
if (strlen(kbuffer)>70) kbuffer[0]=0;
} }
break; break;
} }