106
display_loc (whose, vmap, loc)
107
int whose; /* whose map to display */
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 */
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));
180
show_loc (vmap, loc);
184
Display a location iff the location is on the screen.
188
display_locx (int whose, view_map_t vmap[], loc_t loc)
189
/* whose is whose map to display; loc is location to display */
191
if (whose == whose_map && on_screen (loc))
116
192
show_loc (vmap, loc);
120
Display a location iff the location is on the screen.
124
display_locx (whose, vmap, loc)
125
int whose; /* whose map to display */
127
long loc; /* location to display */
129
if (whose == whose_map && on_screen (loc))
130
show_loc (vmap, loc);
134
196
Display a location which exists on the screen.
200
show_loc (view_map_t vmap[], loc_t 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);
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);
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 */
177
void display_screen();
179
int first_row, first_col, last_row, last_col;
180
int display_rows, display_cols;
183
save_sector = sector; /* remember last sector displayed */
184
change_ok = FALSE; /* we are displaying a new sector */
186
display_rows = lines - NUMTOPS - 1; /* num lines to display */
187
display_cols = cols - NUMSIDES;
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;
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();
237
int first_row, first_col, last_row, last_col;
238
int display_rows, display_cols;
241
save_sector = sector; /* remember last sector displayed */
242
change_ok = false; /* we are displaying a new sector */
244
display_rows = lines - NUMTOPS - 1; /* num lines to display */
245
display_cols = cols - NUMSIDES;
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;
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 */
202
/* figure out first row and col to print; subtract half
203
the extra lines from the first line */
205
ref_row = first_row - (display_rows - ROWS_PER_SECTOR) / 2;
206
ref_col = first_col - (display_cols - COLS_PER_SECTOR) / 2;
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);
212
/* never go past top of map */
213
if (ref_row < 0) ref_row = 0;
215
/* same with columns */
216
if (ref_col + display_cols - 1 > MAP_WIDTH - 1)
217
ref_col = MAP_WIDTH - 1 - (display_cols - 1);
219
if (ref_col < 0) ref_col = 0;
221
whose_map = whose; /* remember whose map is displayed */
222
display_screen (vmap);
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 */
263
ref_row = first_row - (display_rows - ROWS_PER_SECTOR) / 2;
264
ref_col = first_col - (display_cols - COLS_PER_SECTOR) / 2;
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);
270
/* never go past top of map */
271
if (ref_row < 0) ref_row = 0;
273
/* same with columns */
274
if (ref_col + display_cols - 1 > MAP_WIDTH - 1)
275
ref_col = MAP_WIDTH - 1 - (display_cols - 1);
277
if (ref_col < 0) ref_col = 0;
279
whose_map = whose; /* remember whose map is displayed */
280
display_screen (vmap);
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);
229
/* print y-coordinates along right of screen */
230
for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++) {
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);
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]);
285
pos_str (lines-1, c-ref_col, "%d", c);
287
/* print y-coordinates along right of screen */
288
for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++) {
290
pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, "%2d", r);
292
pos_str (r-ref_row+NUMTOPS, cols-NUMSIDES+1, " ");
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]);
291
352
Display the portion of the map that appears on the screen.
294
void display_screen (vmap)
355
void display_screen(view_map_t vmap[])
297
int display_rows, display_cols;
301
display_rows = lines - NUMTOPS - 1; /* num lines to display */
302
display_cols = cols - NUMSIDES;
304
for (r = ref_row; r < ref_row + display_rows && r < MAP_HEIGHT; r++)
357
int display_rows, display_cols;
361
display_rows = lines - NUMTOPS - 1; /* num lines to display */
362
display_cols = cols - NUMSIDES;
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]);
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.
319
move_cursor (cursor, offset)
320
long *cursor; /* current cursor position */
321
int offset; /* offset to add to cursor */
379
move_cursor(loc_t *cursor, int offset)
380
/* cursor is current cursor position, offset is offset to add to cursor */
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 */
330
*cursor = t; /* update cursor position */
331
save_cursor = *cursor;
389
*cursor = t; /* update cursor position */
390
save_cursor = *cursor;
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);
341
400
See if a location is displayed on the screen.
403
bool on_screen (loc_t loc)
349
new_r = loc_row (loc);
350
new_c = loc_col (loc);
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? */
407
new_r = loc_row (loc);
408
new_c = loc_col (loc);
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? */
361
419
/* Print a view map for debugging. */
422
print_xzoom(view_map_t *vmap)
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 */
378
435
char zoom_list[] = "XO*tcbsdpfaTCBSDPFAzZ+. ";
438
print_zoom(view_map_t *vmap)
384
void print_zoom_cell();
386
int row_inc, col_inc;
391
row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
392
col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
394
for (r = 0; r < MAP_HEIGHT; r += row_inc)
440
void print_zoom_cell ();
442
int row_inc, col_inc;
447
row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
448
col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
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);
398
pos_str (0, 0, "Round #%d", date,0,0,0,0,0,0,0);
454
pos_str (0, 0, "Round #%d", date);
408
print_zoom_cell (vmap, row, col, row_inc, col_inc)
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)
417
for (r = row; r < row + row_inc; r++)
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;
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);
432
print_pzoom (s, pmap, vmap)
486
print_pzoom(char *s, path_map_t *pmap, view_map_t *vmap)
437
void print_pzoom_cell();
439
int row_inc, col_inc;
444
row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
445
col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
447
for (r = 0; r < MAP_HEIGHT; r += row_inc)
488
void print_pzoom_cell();
490
int row_inc, col_inc;
495
row_inc = (MAP_HEIGHT + lines - NUMTOPS - 1) / (lines - NUMTOPS);
496
col_inc = (MAP_WIDTH + cols - 1) / (cols - 1);
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);
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 */
467
print_pzoom_cell (pmap, vmap, row, col, row_inc, col_inc)
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)
478
d = 0; /* number of squares in cell */
526
d = 0; /* number of squares in cell */
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;
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';
494
if (sum < 10) cell = sum + '0';
495
else cell = sum - 10 + 'a';
499
print_zoom_cell (vmap, row, col, row_inc, col_inc);
501
(void) move (row/row_inc + NUMTOPS, col/col_inc);
502
(void) addch ((chtype)cell);
530
sum += pmap[row_col_loc(r,c)].cost;
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';
542
if (sum < 10) cell = sum + '0';
543
else cell = sum - 10 + 'a';
547
print_zoom_cell (vmap, row, col, row_inc, col_inc);
549
(void) move (row/row_inc + NUMTOPS, col/col_inc);
550
(void) addch ((chtype)cell);
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);
561
pos_str (1, cols-12, " User Comp");
562
pos_str (2, cols-12, "%5d %5d", user_score, comp_score);
566
Clear the end of a specified line starting at the specified column.
570
clreol(int linep, int colp)
572
(void) move (linep, colp);
577
Initialize the terminal.
591
if (lines > MAP_HEIGHT + NUMTOPS + 1)
592
lines = MAP_HEIGHT + NUMTOPS + 1;
593
if (cols > MAP_WIDTH + NUMSIDES)
594
cols = MAP_WIDTH + NUMSIDES;
599
Clear the screen. We must also kill information maintained about the
634
(void) clearok (curscr, TRUE);
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.
650
(void) move (LINES - 1, 0);
652
for (; t > 0; t -= i) {
653
(void) napms ((t > i) ? i : t); /* pause a bit */
662
Clean up the display. This routine gets called as we leave the game.
668
(void) move (LINES - 1, 0);
675
Position the cursor and output a string.
679
pos_str(int row, int col, char *str, ...)
682
char junkbuf[STRSIZE];
685
(void) move (row, col);
686
vsprintf(junkbuf, str, ap);
687
(void) addstr (junkbuf);
692
Print a single cell in condensed format.
695
extern char zoom_list[];
698
print_movie_cell(char *mbuf, int row, int col, int row_inc, int col_inc)
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)];
710
(void) move (row/row_inc + NUMTOPS, col/col_inc);
711
(void) addch ((chtype)cell);