From a0600509f7ca6befd3fbbf30b0f65ad66f545550 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 29 Mar 1990 23:22:44 +0000 Subject: [PATCH] Color & save-interval implementation. --- display.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- empire.c | 4 +++- extern.h | 4 ++++ main.c | 12 +++++++++-- util.c | 3 +++ 5 files changed, 82 insertions(+), 5 deletions(-) diff --git a/display.c b/display.c index d1327ac..8a7e4e4 100644 --- a/display.c +++ b/display.c @@ -35,6 +35,22 @@ static int save_sector; /* the currently displayed sector */ static int save_cursor; /* currently displayed cursor position */ static int change_ok = TRUE; /* true if new sector may be displayed */ +#ifdef A_COLOR +void init_colors() +{ + start_color(); + + init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); + init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); + init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); + init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); + init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); + init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); + init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); + init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); +} +#endif /* A_COLOR */ + /* This routine is called when the current display has been trashed and no sector is shown on the screen. @@ -124,7 +140,7 @@ long loc; r = loc_row (loc); c = loc_col (loc); (void) move (r-ref_row+NUMTOPS, c-ref_col); - (void) addch ((chtype)vmap[loc].contents);; + disp_square(&vmap[loc]); save_cursor = loc; /* remember cursor location */ (void) move (r-ref_row+NUMTOPS, c-ref_col); } @@ -221,6 +237,50 @@ int sector; /* sector to display */ } } +/* +Display the contents of a single map square. + +Fancy color hacks are done here. At the moment this is kind of bogus, +because the color doesn't convey any extra information, it just looks +pretty. +*/ + + +static disp_square(vp) +view_map_t *vp; +{ +#ifdef A_COLOR + switch(vp->contents) + { + case '+': + attron(COLOR_PAIR(COLOR_GREEN)); + break; + case '.': + attron(COLOR_PAIR(COLOR_BLUE)); + break; + case 'a': + case 'f': + case 'p': + case 'd': + case 'b': + case 't': + case 'c': + case 'z': + case 'X': + attron(COLOR_PAIR(COLOR_RED)); + break; + default: + attron(COLOR_PAIR(COLOR_WHITE)); + break; + } +#endif /* A_COLOR */ + (void) addch ((chtype)vp->contents); +#ifdef A_COLOR + attrset(0); +#endif /* A_COLOR */ +} + + /* Display the portion of the map that appears on the screen. */ @@ -239,7 +299,7 @@ view_map_t vmap[]; for (c = ref_col; c < ref_col + display_cols && c < MAP_WIDTH; c++) { t = row_col_loc (r, c); (void) move (r-ref_row+NUMTOPS, c-ref_col); - (void) addch ((chtype)vmap[t].contents);; + disp_square(&vmap[t]); } } diff --git a/empire.c b/empire.c index 6175136..6f1d8cd 100644 --- a/empire.c +++ b/empire.c @@ -23,6 +23,7 @@ empire () { void print_zoom(); char order; + int turn = 0; ttinit (); /* init tty */ rndini (); /* init random number generator */ @@ -42,7 +43,8 @@ empire () { if (automove) { /* don't ask for cmd in auto mode */ user_move (); comp_move (1); - save_game (); + if (++turn % save_interval == 0) + save_game (); } else { prompt (0); /* blank top line */ diff --git a/extern.h b/extern.h index c8cd46c..fe0a4df 100644 --- a/extern.h +++ b/extern.h @@ -16,6 +16,7 @@ int SMOOTH; /* number of times to smooth map */ int WATER_RATIO; /* percentage of map that is water */ int MIN_CITY_DIST; /* cities must be at least this far apart */ int delay_time; +int save_interval; /* turns between autosaves */ real_map_t map[MAP_SIZE]; /* the way the world really looks */ view_map_t comp_map[MAP_SIZE]; /* computer's view of the world */ @@ -149,6 +150,9 @@ void print_zoom(); void print_pzoom(); void print_xzoom(); void display_score(); +#ifdef A_COLOR +void init_colors(); +#endif /* A_COLOR */ void init_game(); /* game routines */ void save_game(); diff --git a/main.c b/main.c index a4f5010..3d3fcec 100644 --- a/main.c +++ b/main.c @@ -20,13 +20,16 @@ options: -d delay: number of milliseconds to delay between output. default is 2000 (2 seconds). + + -S saveinterval: sets turn interval between saves. + default is 10 */ #include #include "empire.h" #include "extern.h" -#define OPTFLAGS "w:s:d:" +#define OPTFLAGS "w:s:d:S:" main (argc, argv) int argc; @@ -37,12 +40,13 @@ char *argv[]; extern int optind; extern int opterr; /* set to 1 to suppress error msg */ int errflg = 0; - int wflg, sflg, dflg; + int wflg, sflg, dflg, Sflg; int land; wflg = 70; /* set defaults */ sflg = 5; dflg = 2000; + Sflg = 10; /* * extract command line options @@ -59,6 +63,9 @@ char *argv[]; case 'd': dflg = atoi (optarg); break; + case 'S': + Sflg = atoi (optarg); + break; case '?': /* illegal option? */ errflg++; break; @@ -86,6 +93,7 @@ char *argv[]; SMOOTH = sflg; WATER_RATIO = wflg; delay_time = dflg; + save_interval = Sflg; /* compute min distance between cities */ land = MAP_SIZE * (100 - WATER_RATIO) / 100; /* available land */ diff --git a/util.c b/util.c index 60d32d7..5e959d2 100644 --- a/util.c +++ b/util.c @@ -69,6 +69,9 @@ ttinit() (void) initscr(); (void) noecho(); (void) crmode(); +#ifdef A_COLOR + init_colors(); +#endif /* A_COLOR */ lines = LINES; cols = COLS; if (lines > MAP_HEIGHT + NUMTOPS + 1) -- 2.43.0