~ubuntu-branches/ubuntu/vivid/empire/vivid-proposed

« back to all changes in this revision

Viewing changes to display.c

  • Committer: Package Import Robot
  • Author(s): Markus Koschany
  • Date: 2014-01-12 10:41:53 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20140112104153-iawyc84mk4v5qs6n
Tags: 1.11-1
* New maintainer Debian Games Team.
  - Add myself to Uploaders. (Closes: #733320)
* Imported Upstream version 1.11.
  - Fix several spelling errors in empire.6. Thanks to Bjarnig Ingi Gislason.
    (LP: #1070946)
  - Fix a typo in object.c that made a single city stop producing output.
    Thanks to the anonymous reporter. (Closes: #593434)
* Switch to source format 3.0 (quilt).
* Bump compat level to 9 and require debhelper >= 9. Add compat file.
* Drop lintian.override.
* Switch to dh-sequencer. Pass default build flags to upstream's Makefile.
* Add manpages file.
* debian/control:
  - Set priority from extra to optional.
  - Update package to Standards-Version 3.9.5.
  - Add VCS fields.
  - Add Homepage field.
  - Add ${misc:Depends} substvar.
  - Fix typo "they" in package description. (Closes: #668614)
  - Fix description-synopsis-starts-with-article.
* Use install file to install the binary, icons and desktop file.
* Drop dirs file. Not needed.
* Add watch file. Thanks to Bart Martens.
* Update debian/copyright to copyright format 1.0.
* Add icon entry to menu file.
* Install icons to /usr/share/pixmaps.
  - Convert to empire-logo.xpm with imagemagick at build time.
* Add empire.desktop file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: display.c,v 1.8 2002/04/19 09:17:01 esr Exp $  - (c) Copyright 1987, 1988 Chuck Simmons */
2
 
 
3
1
/*
4
2
 *    Copyright (C) 1987, 1988 Chuck Simmons
5
3
 * 
18
16
        point of view;
19
17
*/
20
18
 
21
 
#ifdef SYSV
22
19
#include <string.h>
23
 
#else
24
 
#include <strings.h>
25
 
#endif
26
 
 
27
20
#include <curses.h>
 
21
#include <stdarg.h>
28
22
#include "empire.h"
29
23
#include "extern.h"
30
24
 
33
27
static int ref_col;
34
28
static int save_sector; /* the currently displayed sector */
35
29
static int save_cursor; /* currently displayed cursor position */
36
 
static int change_ok = TRUE; /* true if new sector may be displayed */
 
30
static bool change_ok = true; /* true if new sector may be displayed */
37
31
 
38
 
static void show_loc(view_map_t vmap[],long loc);
 
32
static void show_loc(view_map_t vmap[],loc_t loc);
39
33
static void disp_square(view_map_t *vp);
40
 
int on_screen(long loc);
 
34
static bool on_screen(loc_t loc);
41
35
 
42
36
#ifdef A_COLOR
43
 
void init_colors()
 
37
void init_colors(void)
44
38
{
45
39
    start_color();
46
40
 
52
46
    init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
53
47
    init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
54
48
    init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
 
49
    attron(A_BOLD);     /* otherwise we get gray for white */
 
50
    keypad(stdscr, TRUE);
55
51
}
56
52
#endif /* A_COLOR */
57
53
 
58
54
/*
 
55
Used for win announcements 
 
56
 */
 
57
void announce (char *msg)
 
58
{
 
59
    (void) addstr (msg);
 
60
}
 
61
 
 
62
 
 
63
/*
 
64
 * Map input character to direction offset.
 
65
 * Attempts to enable arrow and keypad keys.
 
66
 */
 
67
int direction(chtype c)
 
68
{
 
69
    switch (c)
 
70
    {
 
71
    case 'w':
 
72
    case 'W':
 
73
    case KEY_UP:
 
74
        return 0;
 
75
 
 
76
    case 'e':
 
77
    case 'E':
 
78
    case KEY_A3:
 
79
    case KEY_PPAGE:
 
80
        return 1;
 
81
 
 
82
    case 'd':
 
83
    case 'D':
 
84
    case KEY_RIGHT:
 
85
        return 2;
 
86
 
 
87
    case 'c':
 
88
    case 'C':
 
89
    case KEY_C3:
 
90
    case KEY_NPAGE:
 
91
        return 3;
 
92
 
 
93
    case 'x':
 
94
    case 'X':
 
95
    case KEY_DOWN:
 
96
        return 4;
 
97
 
 
98
    case 'z':
 
99
    case 'Z':
 
100
    case KEY_C1:
 
101
    case KEY_END:
 
102
        return 5;
 
103
 
 
104
    case 'a':
 
105
    case 'A':
 
106
    case KEY_LEFT:
 
107
        return 6;
 
108
 
 
109
    case 'q':
 
110
    case 'Q':
 
111
    case KEY_A1:
 
112
    case KEY_HOME:
 
113
        return 7;
 
114
 
 
115
    default:
 
116
        return -1;
 
117
    }
 
118
}
 
119
 
 
120
/*
59
121
This routine is called when the current display has been
60
122
trashed and no sector is shown on the screen.
61
123
*/
62
124
 
63
 
void kill_display () {
64
 
        whose_map = UNOWNED;
 
125
void kill_display (void)
 
126
{
 
127
    whose_map = UNOWNED;
65
128
}
66
129
 
67
130
/*
69
132
screen even if the location to be displayed is already on the screen.
70
133
*/
71
134
 
72
 
void sector_change () {
73
 
        change_ok = TRUE;
 
135
void sector_change (void)
 
136
{
 
137
    change_ok = true;
74
138
}
75
139
 
76
140
/*
78
142
sector is not displayed, return -1.
79
143
*/
80
144
 
81
 
int cur_sector () {
82
 
        if (whose_map != USER) return (-1);
83
 
        return (save_sector);
 
145
int cur_sector (void)
 
146
{
 
147
    if (whose_map != USER)
 
148
        return (-1);
 
149
    return (save_sector);
84
150
}
85
151
 
86
152
/*
88
154
is not on the screen, we return -1.
89
155
*/
90
156
 
91
 
long cur_cursor () {
92
 
        if (whose_map != USER) return (-1);
93
 
        return (save_cursor);
 
157
loc_t cur_cursor (void)
 
158
{
 
159
    if (whose_map != USER)
 
160
        return (-1);
 
161
    return (save_cursor);
94
162
}
95
163
 
96
164
/*
103
171
*/
104
172
 
105
173
void
106
 
display_loc (whose, vmap, loc)
107
 
int whose; /* whose map to display */
108
 
view_map_t vmap[];
109
 
long loc; /* location to display */
 
174
display_loc (int whose, view_map_t vmap[], loc_t loc)
 
175
/* whose is whose map to display; loc is location to display */
110
176
{
111
 
        void print_sector();
112
 
        
113
 
        if (change_ok || whose != whose_map || !on_screen (loc))
114
 
                print_sector (whose, vmap, loc_sector (loc));
 
177
    if (change_ok || whose != whose_map || !on_screen (loc))
 
178
        print_sector (whose, vmap, loc_sector (loc));
115
179
                
 
180
    show_loc (vmap, loc);
 
181
}
 
182
 
 
183
/*
 
184
Display a location iff the location is on the screen.
 
185
*/
 
186
 
 
187
void
 
188
display_locx (int whose, view_map_t vmap[], loc_t loc)
 
189
/* whose is whose map to display; loc is location to display */
 
190
{
 
191
    if (whose == whose_map && on_screen (loc))
116
192
        show_loc (vmap, loc);
117
193
}
118
194
 
119
195
/*
120
 
Display a location iff the location is on the screen.
121
 
*/
122
 
 
123
 
void
124
 
display_locx (whose, vmap, loc)
125
 
int whose; /* whose map to display */
126
 
view_map_t vmap[];
127
 
long loc; /* location to display */
128
 
{
129
 
        if (whose == whose_map && on_screen (loc))
130
 
                show_loc (vmap, loc);
131
 
}
132
 
 
133
 
/*
134
196
Display a location which exists on the screen.
135
197
*/
136
198
 
137
199
void
138
 
show_loc (vmap, loc)
139
 
view_map_t vmap[];
140
 
long loc;
 
200
show_loc (view_map_t vmap[], loc_t loc)
141
201
{
142
 
        int r, c;
 
202
    int r, c;
143
203
        
144
 
        r = loc_row (loc);
145
 
        c = loc_col (loc);
146
 
        (void) move (r-ref_row+NUMTOPS, c-ref_col);
147
 
        disp_square(&vmap[loc]);
148
 
        save_cursor = loc; /* remember cursor location */
149
 
        (void) move (r-ref_row+NUMTOPS, c-ref_col);
 
204
    r = loc_row (loc);
 
205
    c = loc_col (loc);
 
206
    (void) move (r-ref_row+NUMTOPS, c-ref_col);
 
207
    disp_square(&vmap[loc]);
 
208
    save_cursor = loc; /* remember cursor location */
 
209
    (void) move (r-ref_row+NUMTOPS, c-ref_col);
150
210
}
151
211
 
152
212
/*
169
229
*/
170
230
 
171
231
void
172
 
print_sector (whose, vmap, sector)
173
 
char whose; /* USER or COMP */
174
 
view_map_t vmap[]; /* map to display */
175
 
int sector; /* sector to display */
 
232
print_sector(int whose, view_map_t vmap[], int sector)
 
233
/* whose is USER or COMP, vmap is map to display, sector is sector to display */
176
234
{
177
 
        void display_screen();
178
 
 
179
 
        int first_row, first_col, last_row, last_col;
180
 
        int display_rows, display_cols;
181
 
        int r, c;
182
 
 
183
 
        save_sector = sector; /* remember last sector displayed */
184
 
        change_ok = FALSE; /* we are displaying a new sector */
185
 
 
186
 
        display_rows = lines - NUMTOPS - 1; /* num lines to display */
187
 
        display_cols = cols - NUMSIDES;
188
 
 
189
 
        /* compute row and column edges of sector */
190
 
        first_row = sector_row (sector) * ROWS_PER_SECTOR;
191
 
        first_col = sector_col (sector) * COLS_PER_SECTOR;
192
 
        last_row = first_row + ROWS_PER_SECTOR - 1;
193
 
        last_col = first_col + COLS_PER_SECTOR - 1;
194
 
 
195
 
        if (!(whose == whose_map /* correct map is on screen? */
196
 
           && ref_row <= first_row /* top row on screen? */
197
 
           && ref_col <= first_col /* first col on screen? */
198
 
           && ref_row + display_rows - 1 >= last_row /* bot row on screen? */
199
 
           && ref_col + display_cols - 1 >= last_col)) /* last col on screen? */
 
235
    void display_screen();
 
236
 
 
237
    int first_row, first_col, last_row, last_col;
 
238
    int display_rows, display_cols;
 
239
    int r, c;
 
240
 
 
241
    save_sector = sector; /* remember last sector displayed */
 
242
    change_ok = false; /* we are displaying a new sector */
 
243
 
 
244
    display_rows = lines - NUMTOPS - 1; /* num lines to display */
 
245
    display_cols = cols - NUMSIDES;
 
246
 
 
247
    /* compute row and column edges of sector */
 
248
    first_row = sector_row (sector) * ROWS_PER_SECTOR;
 
249
    first_col = sector_col (sector) * COLS_PER_SECTOR;
 
250
    last_row = first_row + ROWS_PER_SECTOR - 1;
 
251
    last_col = first_col + COLS_PER_SECTOR - 1;
 
252
 
 
253
    if (!(whose == whose_map /* correct map is on screen? */
 
254
          && ref_row <= first_row /* top row on screen? */
 
255
          && ref_col <= first_col /* first col on screen? */
 
256
          && ref_row + display_rows - 1 >= last_row /* bot row on screen? */
 
257
          && ref_col + display_cols - 1 >= last_col)) /* last col on screen? */
200
258
        (void) clear (); /* erase current screen */
201
259
 
202
 
        /* figure out first row and col to print; subtract half
203
 
           the extra lines from the first line */
204
 
 
205
 
        ref_row = first_row - (display_rows - ROWS_PER_SECTOR) / 2;
206
 
        ref_col = first_col - (display_cols - COLS_PER_SECTOR) / 2;
207
 
 
208
 
        /* try not to go past bottom of map */
209
 
        if (ref_row + display_rows - 1 > MAP_HEIGHT - 1)
210
 
                ref_row = MAP_HEIGHT - 1 - (display_rows - 1);
211
 
 
212
 
        /* never go past top of map */
213
 
        if (ref_row < 0) ref_row = 0;
214
 
 
215
 
        /* same with columns */
216
 
        if (ref_col + display_cols - 1 > MAP_WIDTH - 1)
217
 
                ref_col = MAP_WIDTH - 1 - (display_cols - 1);
218
 
 
219
 
        if (ref_col < 0) ref_col = 0;
220
 
 
221
 
        whose_map = whose; /* remember whose map is displayed */
222
 
        display_screen (vmap);
223
 
 
224
 
        /* print x-coordinates along bottom of screen */
225
 
        for (c = ref_col; c < ref_col + display_cols && c < MAP_WIDTH; c++)
 
260
    /* figure out first row and col to print; subtract half
 
261
       the extra lines from the first line */
 
262
 
 
263
    ref_row = first_row - (display_rows - ROWS_PER_SECTOR) / 2;
 
264
    ref_col = first_col - (display_cols - COLS_PER_SECTOR) / 2;
 
265
 
 
266
    /* try not to go past bottom of map */
 
267
    if (ref_row + display_rows - 1 > MAP_HEIGHT - 1)
 
268
        ref_row = MAP_HEIGHT - 1 - (display_rows - 1);
 
269
 
 
270
    /* never go past top of map */
 
271
    if (ref_row < 0) ref_row = 0;
 
272
 
 
273
    /* same with columns */
 
274
    if (ref_col + display_cols - 1 > MAP_WIDTH - 1)
 
275
        ref_col = MAP_WIDTH - 1 - (display_cols - 1);
 
276
 
 
277
    if (ref_col < 0) ref_col = 0;
 
278
 
 
279
    whose_map = whose; /* remember whose map is displayed */
 
280
    display_screen (vmap);
 
281
 
 
282
    /* print x-coordinates along bottom of screen */
 
283
    for (c = ref_col; c < ref_col + display_cols && c < MAP_WIDTH; c++)
226
284
        if (c % 10 == 0) {
227
 
                pos_str (lines-1, c-ref_col, "%d", c,0,0,0,0,0,0,0);
228
 
        }
229
 
        /* print y-coordinates along right of screen */
230
 
        for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++) {
231
 
                if (r % 2 == 0)
232
 
                        pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, "%2d", r,0,0,0,0,0,0,0);
233
 
                else pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, "  ",0,0,0,0,0,0,0,0);
234
 
        }
235
 
        /* print round number */
236
 
        (void) sprintf (jnkbuf, "Sector %d Round %ld", sector, date);
237
 
        for (r = 0; jnkbuf[r] != '\0'; r++) {
238
 
                if (r+NUMTOPS >= MAP_HEIGHT) break;
239
 
                (void) move (r+NUMTOPS, cols-NUMSIDES+4);
240
 
                (void) addch ((chtype)jnkbuf[r]);
241
 
        }
 
285
            pos_str (lines-1, c-ref_col, "%d", c);
 
286
        }
 
287
    /* print y-coordinates along right of screen */
 
288
    for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++) {
 
289
        if (r % 2 == 0)
 
290
            pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, "%2d", r);
 
291
        else
 
292
            pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, "  ");
 
293
    }
 
294
    /* print round number */
 
295
    (void) sprintf (jnkbuf, "Sector %d Round %ld", sector, date);
 
296
    for (r = 0; jnkbuf[r] != '\0'; r++) {
 
297
        if (r+NUMTOPS >= MAP_HEIGHT) break;
 
298
        (void) move (r+NUMTOPS, cols-NUMSIDES+4);
 
299
        (void) addch ((chtype)jnkbuf[r]);
 
300
    }
242
301
}
243
302
 
244
303
/*
250
309
*/
251
310
 
252
311
 
253
 
static void disp_square(vp)
254
 
view_map_t *vp;
 
312
static void disp_square(view_map_t *vp)
255
313
{
256
314
#ifdef A_COLOR
257
 
        switch(vp->contents)
258
 
        {
259
 
        case '+':
260
 
                attron(COLOR_PAIR(COLOR_GREEN));
261
 
                break;
262
 
        case '.':
263
 
                attron(COLOR_PAIR(COLOR_CYAN));
264
 
                break;
265
 
        case 'a':
266
 
        case 'f':
267
 
        case 'p':
268
 
        case 'd':
269
 
        case 'b':
270
 
        case 't':
271
 
        case 'c':
272
 
        case 's':
273
 
        case 'z':
274
 
        case 'X':
275
 
                attron(COLOR_PAIR(COLOR_RED));
276
 
                break;
277
 
        default:
278
 
                attron(COLOR_PAIR(COLOR_WHITE));
279
 
                break;
280
 
        }
 
315
    chtype attr;
 
316
 
 
317
    switch(vp->contents)
 
318
    {
 
319
    case MAP_LAND:
 
320
        attr = COLOR_PAIR(COLOR_GREEN);
 
321
        break;
 
322
    case MAP_SEA:
 
323
        attr = COLOR_PAIR(COLOR_CYAN);
 
324
        break;
 
325
    case 'a':
 
326
    case 'f':
 
327
    case 'p':
 
328
    case 'd':
 
329
    case 'b':
 
330
    case 't':
 
331
    case 'c':
 
332
    case 's':
 
333
    case 'z':
 
334
    case 'X':
 
335
        attr = COLOR_PAIR(COLOR_RED);
 
336
        break;
 
337
    default:
 
338
        attr = COLOR_PAIR(COLOR_WHITE);
 
339
        break;
 
340
    }
 
341
    attron(attr);
281
342
#endif /* A_COLOR */
282
 
        (void) addch ((chtype)vp->contents);
 
343
    (void) addch ((chtype)vp->contents);
283
344
#ifdef A_COLOR
284
 
        attrset(0);
285
 
        attron(COLOR_PAIR(COLOR_WHITE));
 
345
    attroff(attr);
 
346
    attron(COLOR_PAIR(COLOR_WHITE));
286
347
#endif /* A_COLOR */
287
348
}
288
349
 
291
352
Display the portion of the map that appears on the screen.
292
353
*/
293
354
 
294
 
void display_screen (vmap)
295
 
view_map_t vmap[];
 
355
void display_screen(view_map_t vmap[])
296
356
{
297
 
        int display_rows, display_cols;
298
 
        int r, c;
299
 
        long t;
300
 
 
301
 
        display_rows = lines - NUMTOPS - 1; /* num lines to display */
302
 
        display_cols = cols - NUMSIDES;
303
 
 
304
 
        for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++)
 
357
    int display_rows, display_cols;
 
358
    int r, c;
 
359
    loc_t t;
 
360
 
 
361
    display_rows = lines - NUMTOPS - 1; /* num lines to display */
 
362
    display_cols = cols - NUMSIDES;
 
363
 
 
364
    for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++)
305
365
        for (c = ref_col; c < ref_col + display_cols && c < MAP_WIDTH; c++) {
306
 
                t = row_col_loc (r, c);
307
 
                (void) move (r-ref_row+NUMTOPS, c-ref_col);
308
 
                disp_square(&vmap[t]);
 
366
            t = row_col_loc (r, c);
 
367
            (void) move (r-ref_row+NUMTOPS, c-ref_col);
 
368
            disp_square(&vmap[t]);
309
369
        }
310
370
}
311
371
 
312
372
/*
313
 
Move the cursor in a specified direction.  We return TRUE if the
314
 
cursor remains in the currently displayed screen, otherwise FALSE.
 
373
Move the cursor in a specified direction.  We return true if the
 
374
cursor remains in the currently displayed screen, otherwise false.
315
375
We display the cursor on the screen, if possible.
316
376
*/
317
377
 
318
 
int
319
 
move_cursor (cursor, offset)
320
 
long *cursor; /* current cursor position */
321
 
int offset; /* offset to add to cursor */
 
378
bool
 
379
move_cursor(loc_t *cursor, int offset)
 
380
/* cursor is current cursor position, offset is offset to add to cursor */
322
381
{
323
 
        long t;
324
 
        int r, c;
 
382
    loc_t t;
 
383
    int r, c;
325
384
 
326
 
        t = *cursor + offset; /* proposed location */
327
 
        if (!map[t].on_board) return (FALSE); /* trying to move off map */
328
 
        if (!on_screen (t)) return (FALSE); /* loc is off screen */
 
385
    t = *cursor + offset; /* proposed location */
 
386
    if (!map[t].on_board) return (false); /* trying to move off map */
 
387
    if (!on_screen (t)) return (false); /* loc is off screen */
329
388
        
330
 
        *cursor = t; /* update cursor position */
331
 
        save_cursor = *cursor;
 
389
    *cursor = t; /* update cursor position */
 
390
    save_cursor = *cursor;
332
391
               
333
 
        r = loc_row (save_cursor);
334
 
        c = loc_col (save_cursor);
335
 
        (void) move (r-ref_row+NUMTOPS, c-ref_col);
 
392
    r = loc_row (save_cursor);
 
393
    c = loc_col (save_cursor);
 
394
    (void) move (r-ref_row+NUMTOPS, c-ref_col);
336
395
       
337
 
        return (TRUE);
 
396
    return (true);
338
397
}
339
398
 
340
399
/*
341
400
See if a location is displayed on the screen.
342
401
*/
343
402
 
344
 
int on_screen (loc)
345
 
long loc;
 
403
bool on_screen (loc_t loc)
346
404
{
347
 
        int new_r, new_c;
 
405
    int new_r, new_c;
348
406
        
349
 
        new_r = loc_row (loc);
350
 
        new_c = loc_col (loc);
351
 
 
352
 
        if (new_r < ref_row /* past top of screen */
353
 
         || new_r - ref_row > lines - NUMTOPS - 1 /* past bot of screen? */
354
 
         || new_c < ref_col /* past left edge of screen? */
355
 
         || new_c - ref_col > cols - NUMSIDES) /* past right edge of screen? */
356
 
        return (FALSE);
357
 
 
358
 
        return (TRUE);
 
407
    new_r = loc_row (loc);
 
408
    new_c = loc_col (loc);
 
409
 
 
410
    if (new_r < ref_row /* past top of screen */
 
411
        || new_r - ref_row > lines - NUMTOPS - 1 /* past bot of screen? */
 
412
        || new_c < ref_col /* past left edge of screen? */
 
413
        || new_c - ref_col > cols - NUMSIDES) /* past right edge of screen? */
 
414
        return (false);
 
415
 
 
416
    return (true);
359
417
}
360
418
 
361
419
/* Print a view map for debugging. */
362
420
 
363
421
void
364
 
print_xzoom (vmap)
365
 
view_map_t *vmap;
 
422
print_xzoom(view_map_t *vmap)
366
423
{
367
 
        print_zoom (vmap);
 
424
    print_zoom (vmap);
368
425
#if 0
369
 
        prompt ("Hit a key: ",0,0,0,0,0,0,0,0);
370
 
        (void) get_chx (); /* wait for user */
 
426
    prompt ("Hit a key: ",0,0,0,0,0,0,0,0);
 
427
    (void) get_chx (); /* wait for user */
371
428
#endif
372
429
}
373
430
 
378
435
char zoom_list[] = "XO*tcbsdpfaTCBSDPFAzZ+. ";
379
436
 
380
437
void
381
 
print_zoom (vmap)
382
 
view_map_t *vmap;
 
438
print_zoom(view_map_t *vmap)
383
439
{
384
 
        void print_zoom_cell();
385
 
 
386
 
        int row_inc, col_inc;
387
 
        int r, c;
388
 
 
389
 
        kill_display ();
390
 
 
391
 
        row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
392
 
        col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
393
 
 
394
 
        for (r = 0; r < MAP_HEIGHT; r += row_inc)
 
440
    void print_zoom_cell ();
 
441
 
 
442
    int row_inc, col_inc;
 
443
    int r, c;
 
444
 
 
445
    kill_display ();
 
446
 
 
447
    row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
 
448
    col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
 
449
 
 
450
    for (r = 0; r < MAP_HEIGHT; r += row_inc)
395
451
        for (c = 0; c < MAP_WIDTH; c += col_inc)
396
 
        print_zoom_cell (vmap, r, c, row_inc, col_inc);
 
452
            print_zoom_cell (vmap, r, c, row_inc, col_inc);
397
453
 
398
 
        pos_str (0, 0, "Round #%d", date,0,0,0,0,0,0,0);
 
454
    pos_str (0, 0, "Round #%d", date);
399
455
        
400
 
        (void) refresh ();
 
456
    (void) refresh ();
401
457
}
402
458
 
403
459
/*
405
461
*/
406
462
 
407
463
void
408
 
print_zoom_cell (vmap, row, col, row_inc, col_inc)
409
 
view_map_t *vmap;
410
 
int row, col;
411
 
int row_inc, col_inc;
 
464
print_zoom_cell(view_map_t *vmap, 
 
465
                 int row, int col, int row_inc, int col_inc)
412
466
{
413
 
        int r, c;
414
 
        char cell;
 
467
    int r, c;
 
468
    char cell;
415
469
 
416
 
        cell = ' ';
417
 
        for (r = row; r < row + row_inc; r++)
 
470
    cell = ' ';
 
471
    for (r = row; r < row + row_inc; r++)
418
472
        for (c = col; c < col + col_inc; c++)
419
 
        if (strchr (zoom_list, vmap[row_col_loc(r,c)].contents)
 
473
            if (strchr (zoom_list, vmap[row_col_loc(r,c)].contents)
420
474
                < strchr (zoom_list, cell))
421
 
        cell = vmap[row_col_loc(r,c)].contents;
 
475
                cell = vmap[row_col_loc(r,c)].contents;
422
476
        
423
 
        (void) move (row/row_inc + NUMTOPS, col/col_inc);
424
 
        (void) addch ((chtype)cell);
 
477
    (void) move (row/row_inc + NUMTOPS, col/col_inc);
 
478
    (void) addch ((chtype)cell);
425
479
}
426
480
 
427
481
/*
429
483
*/
430
484
 
431
485
void
432
 
print_pzoom (s, pmap, vmap)
433
 
char *s;
434
 
path_map_t *pmap;
435
 
view_map_t *vmap;
 
486
print_pzoom(char *s, path_map_t *pmap, view_map_t *vmap)
436
487
{
437
 
        void print_pzoom_cell();
438
 
 
439
 
        int row_inc, col_inc;
440
 
        int r, c;
441
 
 
442
 
        kill_display ();
443
 
 
444
 
        row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
445
 
        col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
446
 
 
447
 
        for (r = 0; r < MAP_HEIGHT; r += row_inc)
 
488
    void print_pzoom_cell();
 
489
 
 
490
    int row_inc, col_inc;
 
491
    int r, c;
 
492
 
 
493
    kill_display ();
 
494
 
 
495
    row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
 
496
    col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
 
497
 
 
498
    for (r = 0; r < MAP_HEIGHT; r += row_inc)
448
499
        for (c = 0; c < MAP_WIDTH; c += col_inc)
449
 
        print_pzoom_cell (pmap, vmap, r, c, row_inc, col_inc);
 
500
            print_pzoom_cell (pmap, vmap, r, c, row_inc, col_inc);
450
501
 
451
 
        prompt (s,0,0,0,0,0,0,0,0);
452
 
        (void) get_chx (); /* wait for user */
 
502
    prompt (s,0,0,0,0,0,0,0,0);
 
503
    (void) get_chx (); /* wait for user */
453
504
        
454
 
        (void) refresh ();
 
505
    (void) refresh ();
455
506
}
456
507
 
457
508
/*
464
515
*/
465
516
 
466
517
void
467
 
print_pzoom_cell (pmap, vmap, row, col, row_inc, col_inc)
468
 
path_map_t *pmap;
469
 
view_map_t *vmap;
470
 
int row, col;
471
 
int row_inc, col_inc;
 
518
print_pzoom_cell(path_map_t *pmap, view_map_t *vmap, 
 
519
                  int row, int col, int row_inc, int col_inc)
472
520
{
473
 
        int r, c;
474
 
        int sum, d;
475
 
        char cell;
 
521
    int r, c;
 
522
    int sum, d;
 
523
    char cell;
476
524
 
477
 
        sum = 0;
478
 
        d = 0; /* number of squares in cell */
 
525
    sum = 0;
 
526
    d = 0; /* number of squares in cell */
479
527
        
480
 
        for (r = row; r < row + row_inc; r++)
 
528
    for (r = row; r < row + row_inc; r++)
481
529
        for (c = col; c < col + col_inc; c++) {
482
 
                sum += pmap[row_col_loc(r,c)].cost;
483
 
                d += 1;
484
 
        }
485
 
        sum /= d;
486
 
        
487
 
        if (pmap[row_col_loc(row,col)].terrain == T_PATH) cell = '-';
488
 
        else if (sum < 0) cell = '!';
489
 
        else if (sum == INFINITY/2) cell = 'P';
490
 
        else if (sum == INFINITY) cell = ' ';
491
 
        else if (sum > INFINITY/2) cell = 'U';
492
 
        else {
493
 
                sum %= 36;
494
 
                if (sum < 10) cell = sum + '0';
495
 
                else cell = sum - 10 + 'a';
496
 
        }
497
 
        
498
 
        if (cell == ' ')
499
 
                print_zoom_cell (vmap, row, col, row_inc, col_inc);
500
 
        else {
501
 
                (void) move (row/row_inc + NUMTOPS, col/col_inc);
502
 
                (void) addch ((chtype)cell);
503
 
        }
 
530
            sum += pmap[row_col_loc(r,c)].cost;
 
531
            d += 1;
 
532
        }
 
533
    sum /= d;
 
534
        
 
535
    if (pmap[row_col_loc(row,col)].terrain == T_PATH) cell = '-';
 
536
    else if (sum < 0) cell = '!';
 
537
    else if (sum == INFINITY/2) cell = 'P';
 
538
    else if (sum == INFINITY) cell = ' ';
 
539
    else if (sum > INFINITY/2) cell = 'U';
 
540
    else {
 
541
        sum %= 36;
 
542
        if (sum < 10) cell = sum + '0';
 
543
        else cell = sum - 10 + 'a';
 
544
    }
 
545
        
 
546
    if (cell == ' ')
 
547
        print_zoom_cell (vmap, row, col, row_inc, col_inc);
 
548
    else {
 
549
        (void) move (row/row_inc + NUMTOPS, col/col_inc);
 
550
        (void) addch ((chtype)cell);
 
551
    }
504
552
}
505
553
 
506
554
/*
508
556
*/
509
557
 
510
558
void
511
 
display_score ()
512
 
{
513
 
        pos_str (1, cols-12, " User  Comp",0,0,0,0,0,0,0,0);
514
 
        pos_str (2, cols-12, "%5d %5d", user_score, comp_score,0,0,0,0,0,0);
515
 
}
 
559
display_score(void)
 
560
{
 
561
    pos_str (1, cols-12, " User  Comp");
 
562
    pos_str (2, cols-12, "%5d %5d", user_score, comp_score);
 
563
}
 
564
 
 
565
/*
 
566
Clear the end of a specified line starting at the specified column.
 
567
*/
 
568
 
 
569
void
 
570
clreol(int linep, int colp)
 
571
{
 
572
    (void) move (linep, colp);
 
573
    (void) clrtoeol();
 
574
}
 
575
 
 
576
/*
 
577
Initialize the terminal.
 
578
*/
 
579
 
 
580
void
 
581
ttinit(void)
 
582
{
 
583
    (void) initscr();
 
584
    (void) noecho();
 
585
    (void) crmode();
 
586
#ifdef A_COLOR
 
587
    init_colors();
 
588
#endif /* A_COLOR */
 
589
    lines = LINES;
 
590
    cols = COLS;
 
591
    if (lines > MAP_HEIGHT + NUMTOPS + 1)
 
592
        lines = MAP_HEIGHT + NUMTOPS + 1;
 
593
    if (cols > MAP_WIDTH + NUMSIDES)
 
594
        cols = MAP_WIDTH + NUMSIDES;
 
595
}
 
596
 
 
597
 
 
598
/*
 
599
Clear the screen.  We must also kill information maintained about the
 
600
display.
 
601
*/
 
602
 
 
603
void
 
604
clear_screen(void)
 
605
{
 
606
    (void) clear ();
 
607
    (void) refresh ();
 
608
    kill_display ();
 
609
}
 
610
 
 
611
/*
 
612
Audible complaint.
 
613
*/
 
614
 
 
615
void 
 
616
complain(void)
 
617
{
 
618
    (void) beep ();
 
619
}
 
620
 
 
621
/*
 
622
Redraw the screen.
 
623
*/
 
624
 
 
625
void 
 
626
redisplay(void)
 
627
{
 
628
    (void) refresh ();
 
629
}
 
630
 
 
631
void
 
632
redraw(void)
 
633
{
 
634
    (void) clearok (curscr, TRUE);
 
635
    (void) refresh ();
 
636
}
 
637
 
 
638
/*
 
639
Wait a little bit to give user a chance to see a message.  We refresh
 
640
the screen and pause for a few milliseconds.
 
641
*/
 
642
 
 
643
void
 
644
delay(void)
 
645
{
 
646
    int t = delay_time;
 
647
    int i = 500;
 
648
    (void) refresh ();
 
649
    if (t > i) {
 
650
        (void) move (LINES - 1, 0);
 
651
    }
 
652
    for (; t > 0; t -= i) {
 
653
        (void) napms ((t > i) ? i : t); /* pause a bit */
 
654
        if (t > i) {
 
655
            addstr ("*");
 
656
            refresh (); 
 
657
        }
 
658
    }
 
659
}
 
660
 
 
661
/*
 
662
Clean up the display.  This routine gets called as we leave the game.
 
663
*/
 
664
 
 
665
void
 
666
close_disp(void)
 
667
{
 
668
    (void) move (LINES - 1, 0);
 
669
    (void) clrtoeol ();
 
670
    (void) refresh ();
 
671
    (void) endwin ();
 
672
}
 
673
 
 
674
/*
 
675
Position the cursor and output a string.
 
676
*/
 
677
 
 
678
void
 
679
pos_str(int row, int col, char *str, ...)
 
680
{
 
681
    va_list ap;
 
682
    char junkbuf[STRSIZE];
 
683
 
 
684
    va_start(ap, str);
 
685
    (void) move (row, col);
 
686
    vsprintf(junkbuf, str, ap);
 
687
    (void) addstr (junkbuf);
 
688
    va_end(ap);
 
689
}
 
690
 
 
691
/*
 
692
Print a single cell in condensed format.
 
693
*/
 
694
 
 
695
extern char zoom_list[];
 
696
 
 
697
void
 
698
print_movie_cell(char *mbuf, int row, int col, int row_inc, int col_inc)
 
699
{
 
700
    int r, c;
 
701
    char cell;
 
702
 
 
703
    cell = ' ';
 
704
    for (r = row; r < row + row_inc; r++)
 
705
        for (c = col; c < col + col_inc; c++)
 
706
            if (strchr (zoom_list, mbuf[row_col_loc(r,c)])
 
707
                < strchr (zoom_list, cell))
 
708
                cell = mbuf[row_col_loc(r,c)];
 
709
        
 
710
    (void) move (row/row_inc + NUMTOPS, col/col_inc);
 
711
    (void) addch ((chtype)cell);
 
712
}
 
713
 
 
714
/* end */