Home | History | Annotate | Line # | Download | only in sail
pl_7.c revision 1.39
      1  1.39  dholland /*	$NetBSD: pl_7.c,v 1.39 2010/08/06 03:10:26 dholland Exp $	*/
      2   1.6       cgd 
      3   1.1       cgd /*
      4   1.6       cgd  * Copyright (c) 1983, 1993
      5   1.6       cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15  1.27       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1       cgd  *    may be used to endorse or promote products derived from this software
     17   1.1       cgd  *    without specific prior written permission.
     18   1.1       cgd  *
     19   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1       cgd  * SUCH DAMAGE.
     30   1.1       cgd  */
     31   1.1       cgd 
     32   1.7  christos #include <sys/cdefs.h>
     33   1.1       cgd #ifndef lint
     34   1.6       cgd #if 0
     35   1.6       cgd static char sccsid[] = "@(#)pl_7.c	8.1 (Berkeley) 5/31/93";
     36   1.6       cgd #else
     37  1.39  dholland __RCSID("$NetBSD: pl_7.c,v 1.39 2010/08/06 03:10:26 dholland Exp $");
     38   1.6       cgd #endif
     39   1.1       cgd #endif /* not lint */
     40   1.1       cgd 
     41  1.20     jwise #include <curses.h>
     42  1.29  dholland #include <err.h>
     43  1.35  dholland #include <errno.h>
     44  1.19     jwise #include <signal.h>
     45   1.7  christos #include <stdarg.h>
     46  1.18     jwise #include <stdio.h>
     47  1.23       cgd #include <stdlib.h>
     48  1.22    itojun #include <string.h>
     49  1.35  dholland #include "array.h"
     50  1.20     jwise #include "extern.h"
     51  1.18     jwise #include "player.h"
     52  1.20     jwise #include "display.h"
     53   1.6       cgd 
     54  1.35  dholland /*
     55  1.35  dholland  * Use values above KEY_MAX for custom keycodes. (blymn@ says this is ok)
     56  1.35  dholland  */
     57  1.35  dholland #define KEY_ESC(ch) (KEY_MAX+10+ch)
     58  1.35  dholland 
     59   1.1       cgd 
     60   1.1       cgd /*
     61   1.1       cgd  * Display interface
     62   1.1       cgd  */
     63   1.1       cgd 
     64  1.35  dholland static void draw_view(void);
     65  1.35  dholland static void draw_turn(void);
     66  1.35  dholland static void draw_stat(void);
     67  1.35  dholland static void draw_slot(void);
     68  1.35  dholland static void draw_board(void);
     69  1.35  dholland 
     70  1.35  dholland static struct stringarray *sc_lines;
     71  1.35  dholland static unsigned sc_scrollup;
     72  1.35  dholland static bool sc_hasprompt;
     73  1.35  dholland static bool sc_hideprompt;
     74  1.11       jsm static const char *sc_prompt;
     75  1.11       jsm static const char *sc_buf;
     76  1.13       jsm 
     77  1.33  dholland static WINDOW *view_w;
     78  1.35  dholland static WINDOW *turn_w;
     79  1.35  dholland static WINDOW *stat_w;
     80  1.33  dholland static WINDOW *slot_w;
     81  1.33  dholland static WINDOW *scroll_w;
     82  1.35  dholland 
     83  1.35  dholland static bool obp[3];
     84  1.35  dholland static bool dbp[3];
     85  1.13       jsm 
     86  1.21     jwise int done_curses;
     87  1.21     jwise int loaded, fired, changed, repaired;
     88  1.21     jwise int dont_adjust;
     89  1.38  dholland static int viewrow, viewcol;
     90  1.13       jsm char movebuf[sizeof SHIP(0)->file->movebuf];
     91  1.13       jsm int player;
     92  1.13       jsm struct ship *ms;		/* memorial structure, &cc->ship[player] */
     93  1.13       jsm struct File *mf;		/* ms->file */
     94  1.13       jsm struct shipspecs *mc;		/* ms->specs */
     95   1.1       cgd 
     96  1.35  dholland ////////////////////////////////////////////////////////////
     97  1.35  dholland // overall initialization
     98  1.35  dholland 
     99  1.35  dholland static
    100  1.35  dholland void
    101  1.35  dholland define_esc_key(int ch)
    102  1.35  dholland {
    103  1.35  dholland 	char seq[3] = { '\x1b', ch, 0 };
    104  1.35  dholland 
    105  1.35  dholland 	define_key(seq, KEY_ESC(ch));
    106  1.35  dholland }
    107  1.35  dholland 
    108   1.7  christos void
    109  1.16     jwise initscreen(void)
    110   1.1       cgd {
    111  1.35  dholland 	int ch;
    112  1.35  dholland 
    113  1.35  dholland 	sc_lines = stringarray_create();
    114  1.35  dholland 	if (sc_lines == NULL) {
    115  1.35  dholland 		err(1, "malloc");
    116  1.35  dholland 	}
    117  1.35  dholland 
    118  1.33  dholland 	if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) {
    119  1.33  dholland 		err(1, "signal(SIGTSTP)");
    120  1.33  dholland 	}
    121  1.33  dholland 
    122  1.33  dholland 	if (initscr() == NULL) {
    123  1.29  dholland 		errx(1, "Can't sail on this terminal.");
    124  1.14       jsm 	}
    125  1.33  dholland 	if (STAT_R >= COLS || SCROLL_Y <= 0) {
    126  1.33  dholland 		errx(1, "Window/terminal not large enough.");
    127  1.33  dholland 	}
    128  1.33  dholland 
    129   1.1       cgd 	view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L);
    130   1.1       cgd 	slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L);
    131   1.1       cgd 	scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L);
    132   1.1       cgd 	stat_w = newwin(STAT_Y, STAT_X, STAT_T, STAT_L);
    133   1.1       cgd 	turn_w = newwin(TURN_Y, TURN_X, TURN_T, TURN_L);
    134  1.33  dholland 
    135  1.33  dholland 	if (view_w == NULL ||
    136  1.33  dholland 	    slot_w == NULL ||
    137  1.33  dholland 	    scroll_w == NULL ||
    138  1.33  dholland 	    stat_w == NULL ||
    139  1.33  dholland 	    turn_w == NULL) {
    140  1.33  dholland 		endwin();
    141  1.33  dholland 		errx(1, "Curses initialization failed.");
    142  1.33  dholland 	}
    143  1.33  dholland 
    144  1.16     jwise 	leaveok(view_w, 1);
    145  1.16     jwise 	leaveok(slot_w, 1);
    146  1.16     jwise 	leaveok(stat_w, 1);
    147  1.16     jwise 	leaveok(turn_w, 1);
    148   1.1       cgd 	noecho();
    149  1.26     blymn 	cbreak();
    150  1.33  dholland 
    151  1.35  dholland 	/*
    152  1.35  dholland 	 * Define esc-x keys
    153  1.35  dholland 	 */
    154  1.35  dholland 	for (ch = 0; ch < 127; ch++) {
    155  1.39  dholland 		if (ch != '[') {
    156  1.39  dholland 			define_esc_key(ch);
    157  1.39  dholland 		}
    158  1.35  dholland 	}
    159  1.35  dholland 
    160  1.33  dholland 	done_curses++;
    161   1.1       cgd }
    162   1.1       cgd 
    163   1.7  christos void
    164  1.16     jwise cleanupscreen(void)
    165   1.1       cgd {
    166   1.1       cgd 	/* alarm already turned off */
    167   1.1       cgd 	if (done_curses) {
    168  1.16     jwise 		wmove(scroll_w, SCROLL_Y - 1, 0);
    169  1.16     jwise 		wclrtoeol(scroll_w);
    170  1.35  dholland 		display_redraw();
    171   1.1       cgd 		endwin();
    172   1.1       cgd 	}
    173   1.1       cgd }
    174   1.1       cgd 
    175  1.35  dholland ////////////////////////////////////////////////////////////
    176  1.35  dholland // scrolling message area
    177  1.35  dholland 
    178  1.35  dholland static void
    179  1.35  dholland scrollarea_add(const char *text)
    180  1.35  dholland {
    181  1.35  dholland 	char *copy;
    182  1.35  dholland 	int errsave;
    183  1.35  dholland 
    184  1.35  dholland 	copy = strdup(text);
    185  1.35  dholland 	if (copy == NULL) {
    186  1.35  dholland 		goto nomem;
    187  1.35  dholland 	}
    188  1.35  dholland 	if (stringarray_add(sc_lines, copy, NULL)) {
    189  1.35  dholland 		goto nomem;
    190  1.35  dholland 	}
    191  1.35  dholland 	return;
    192  1.35  dholland 
    193  1.35  dholland nomem:
    194  1.35  dholland 	/*
    195  1.35  dholland 	 * XXX this should use leave(), but that won't
    196  1.35  dholland 	 * currently work right.
    197  1.35  dholland 	 */
    198  1.35  dholland 	errsave = errno;
    199  1.35  dholland #if 0
    200  1.35  dholland 	leave(LEAVE_MALLOC);
    201  1.35  dholland #else
    202  1.35  dholland 	cleanupscreen();
    203  1.35  dholland 	sync_close(!hasdriver);
    204  1.35  dholland 	errno = errsave;
    205  1.35  dholland 	err(1, "malloc");
    206  1.35  dholland #endif
    207  1.35  dholland }
    208  1.35  dholland 
    209  1.35  dholland static void
    210  1.35  dholland draw_scroll(void)
    211  1.35  dholland {
    212  1.35  dholland 	unsigned total_lines;
    213  1.35  dholland 	unsigned visible_lines;
    214  1.35  dholland 	unsigned index_of_top;
    215  1.35  dholland 	unsigned index_of_y;
    216  1.35  dholland 	unsigned y;
    217  1.35  dholland 	unsigned cursorx;
    218  1.35  dholland 
    219  1.35  dholland 	werase(scroll_w);
    220  1.35  dholland 
    221  1.37  dholland 	/* XXX: SCROLL_Y and whatnot should be unsigned too */
    222  1.35  dholland 	visible_lines = SCROLL_Y - 1;
    223  1.35  dholland 
    224  1.35  dholland 	total_lines = stringarray_num(sc_lines);
    225  1.35  dholland 	if (total_lines > visible_lines) {
    226  1.35  dholland 		index_of_top = total_lines - visible_lines;
    227  1.35  dholland 	} else {
    228  1.35  dholland 		index_of_top = 0;
    229  1.35  dholland 	}
    230  1.35  dholland 	if (index_of_top < sc_scrollup) {
    231  1.35  dholland 		index_of_top = 0;
    232  1.35  dholland 	} else {
    233  1.35  dholland 		index_of_top -= sc_scrollup;
    234  1.35  dholland 	}
    235  1.35  dholland 
    236  1.37  dholland 	for (y = 0; y < visible_lines; y++) {
    237  1.35  dholland 		index_of_y = index_of_top + y;
    238  1.35  dholland 		if (index_of_y >= total_lines) {
    239  1.35  dholland 			break;
    240  1.35  dholland 		}
    241  1.35  dholland 		wmove(scroll_w, y, 0);
    242  1.35  dholland 		waddstr(scroll_w, stringarray_get(sc_lines, index_of_y));
    243  1.35  dholland 	}
    244  1.35  dholland 	if (sc_hasprompt && !sc_hideprompt) {
    245  1.35  dholland 		wmove(scroll_w, SCROLL_Y-1, 0);
    246  1.35  dholland 		waddstr(scroll_w, sc_prompt);
    247  1.35  dholland 		waddstr(scroll_w, sc_buf);
    248  1.35  dholland 		cursorx = strlen(sc_prompt) + strlen(sc_buf);
    249  1.35  dholland 		wmove(scroll_w, SCROLL_Y-1, cursorx);
    250  1.35  dholland 	}
    251  1.35  dholland 	else {
    252  1.35  dholland 		wmove(scroll_w, SCROLL_Y-1, 0);
    253  1.35  dholland 	}
    254  1.35  dholland }
    255  1.35  dholland 
    256   1.1       cgd /*VARARGS2*/
    257   1.7  christos void
    258   1.7  christos Signal(const char *fmt, struct ship *ship, ...)
    259   1.1       cgd {
    260   1.7  christos 	va_list ap;
    261   1.7  christos 	char format[BUFSIZ];
    262  1.35  dholland 	char buf[BUFSIZ];
    263   1.7  christos 
    264   1.1       cgd 	if (!done_curses)
    265   1.1       cgd 		return;
    266  1.25       wiz 	va_start(ap, ship);
    267  1.35  dholland 	if (*fmt == '\a') {
    268  1.35  dholland 		beep();
    269  1.35  dholland 		fmt++;
    270  1.35  dholland 	}
    271   1.7  christos 	fmtship(format, sizeof(format), fmt, ship);
    272  1.35  dholland 	vsnprintf(buf, sizeof(buf), format, ap);
    273   1.7  christos 	va_end(ap);
    274  1.35  dholland 	scrollarea_add(buf);
    275   1.7  christos }
    276   1.7  christos 
    277   1.7  christos /*VARARGS2*/
    278   1.7  christos void
    279   1.7  christos Msg(const char *fmt, ...)
    280   1.7  christos {
    281   1.7  christos 	va_list ap;
    282  1.35  dholland 	char buf[BUFSIZ];
    283   1.7  christos 
    284   1.7  christos 	if (!done_curses)
    285   1.7  christos 		return;
    286  1.25       wiz 	va_start(ap, fmt);
    287  1.35  dholland 	if (*fmt == '\a') {
    288  1.35  dholland 		beep();
    289  1.35  dholland 		fmt++;
    290  1.35  dholland 	}
    291  1.35  dholland 	vsnprintf(buf, sizeof(buf), fmt, ap);
    292   1.7  christos 	va_end(ap);
    293  1.35  dholland 	scrollarea_add(buf);
    294   1.1       cgd }
    295   1.1       cgd 
    296  1.38  dholland static void
    297  1.17     jwise prompt(const char *p, struct ship *ship)
    298   1.1       cgd {
    299   1.8  christos 	static char buf[BUFSIZ];
    300   1.1       cgd 
    301   1.8  christos 	fmtship(buf, sizeof(buf), p, ship);
    302   1.8  christos 	sc_prompt = buf;
    303   1.1       cgd 	sc_buf = "";
    304  1.35  dholland 	sc_hasprompt = true;
    305   1.1       cgd }
    306   1.1       cgd 
    307  1.17     jwise static void
    308  1.35  dholland endprompt(void)
    309   1.1       cgd {
    310  1.35  dholland 	sc_prompt = NULL;
    311  1.35  dholland 	sc_buf = NULL;
    312  1.35  dholland 	sc_hasprompt = false;
    313   1.1       cgd }
    314   1.1       cgd 
    315  1.34  dholland /*
    316  1.34  dholland  * Next two functions called from newturn() to poke display. Shouldn't
    317  1.34  dholland  * exist... XXX
    318  1.34  dholland  */
    319  1.34  dholland 
    320  1.34  dholland void
    321  1.34  dholland display_hide_prompt(void)
    322  1.34  dholland {
    323  1.35  dholland 	sc_hideprompt = true;
    324  1.35  dholland 	draw_scroll();
    325  1.35  dholland 	wrefresh(scroll_w);
    326  1.34  dholland }
    327  1.34  dholland 
    328  1.34  dholland void
    329  1.34  dholland display_reshow_prompt(void)
    330  1.34  dholland {
    331  1.35  dholland 	sc_hideprompt = false;
    332  1.35  dholland 	draw_scroll();
    333  1.35  dholland 	wrefresh(scroll_w);
    334  1.34  dholland }
    335  1.34  dholland 
    336  1.34  dholland 
    337   1.7  christos int
    338  1.16     jwise sgetch(const char *p, struct ship *ship, int flag)
    339   1.1       cgd {
    340   1.7  christos 	int c;
    341  1.35  dholland 	char input[2];
    342  1.35  dholland 
    343   1.1       cgd 	prompt(p, ship);
    344  1.35  dholland 	input[0] = '\0';
    345  1.35  dholland 	input[1] = '\0';
    346  1.35  dholland 	sc_buf = input;
    347   1.1       cgd 	blockalarm();
    348  1.35  dholland 	draw_scroll();
    349  1.16     jwise 	wrefresh(scroll_w);
    350  1.35  dholland 	fflush(stdout);
    351   1.1       cgd 	unblockalarm();
    352   1.1       cgd 	while ((c = wgetch(scroll_w)) == EOF)
    353   1.1       cgd 		;
    354  1.35  dholland 	if (flag && c >= ' ' && c < 0x7f) {
    355  1.35  dholland 		blockalarm();
    356  1.35  dholland 		input[0] = c;
    357  1.35  dholland 		draw_scroll();
    358  1.35  dholland 		wrefresh(scroll_w);
    359  1.35  dholland 		fflush(stdout);
    360  1.35  dholland 		unblockalarm();
    361  1.35  dholland 	}
    362  1.35  dholland 	endprompt();
    363   1.1       cgd 	return c;
    364   1.1       cgd }
    365   1.1       cgd 
    366   1.7  christos void
    367  1.16     jwise sgetstr(const char *pr, char *buf, int n)
    368   1.1       cgd {
    369   1.7  christos 	int c;
    370   1.7  christos 	char *p = buf;
    371   1.1       cgd 
    372   1.1       cgd 	prompt(pr, (struct ship *)0);
    373   1.1       cgd 	sc_buf = buf;
    374   1.1       cgd 	for (;;) {
    375   1.1       cgd 		*p = 0;
    376   1.1       cgd 		blockalarm();
    377  1.35  dholland 		draw_scroll();
    378  1.16     jwise 		wrefresh(scroll_w);
    379  1.35  dholland 		fflush(stdout);
    380   1.1       cgd 		unblockalarm();
    381   1.1       cgd 		while ((c = wgetch(scroll_w)) == EOF)
    382   1.1       cgd 			;
    383   1.1       cgd 		switch (c) {
    384   1.1       cgd 		case '\n':
    385   1.1       cgd 		case '\r':
    386  1.35  dholland 			endprompt();
    387   1.1       cgd 			return;
    388   1.1       cgd 		case '\b':
    389   1.1       cgd 			if (p > buf) {
    390  1.35  dholland 				/*waddstr(scroll_w, "\b \b");*/
    391   1.1       cgd 				p--;
    392   1.1       cgd 			}
    393   1.1       cgd 			break;
    394   1.1       cgd 		default:
    395   1.1       cgd 			if (c >= ' ' && c < 0x7f && p < buf + n - 1) {
    396   1.1       cgd 				*p++ = c;
    397  1.35  dholland 				/*waddch(scroll_w, c);*/
    398   1.1       cgd 			} else
    399  1.35  dholland 				beep();
    400   1.1       cgd 		}
    401   1.1       cgd 	}
    402   1.1       cgd }
    403   1.1       cgd 
    404  1.35  dholland ////////////////////////////////////////////////////////////
    405  1.35  dholland // drawing of other panes
    406  1.35  dholland 
    407  1.35  dholland void
    408  1.35  dholland display_force_full_redraw(void)
    409  1.35  dholland {
    410  1.35  dholland 	clear();
    411  1.35  dholland }
    412  1.35  dholland 
    413   1.7  christos void
    414  1.35  dholland display_redraw(void)
    415   1.1       cgd {
    416  1.35  dholland 	draw_board();
    417   1.1       cgd 	draw_view();
    418   1.1       cgd 	draw_turn();
    419   1.1       cgd 	draw_stat();
    420   1.1       cgd 	draw_slot();
    421  1.35  dholland 	draw_scroll();
    422  1.35  dholland 	/* move the cursor */
    423  1.35  dholland 	wrefresh(scroll_w);
    424  1.35  dholland 	/* paranoia */
    425  1.35  dholland 	fflush(stdout);
    426   1.1       cgd }
    427   1.1       cgd 
    428  1.35  dholland static void
    429  1.16     jwise draw_view(void)
    430   1.1       cgd {
    431   1.7  christos 	struct ship *sp;
    432   1.1       cgd 
    433  1.16     jwise 	werase(view_w);
    434   1.1       cgd 	foreachship(sp) {
    435   1.1       cgd 		if (sp->file->dir
    436   1.1       cgd 		    && sp->file->row > viewrow
    437   1.1       cgd 		    && sp->file->row < viewrow + VIEW_Y
    438   1.1       cgd 		    && sp->file->col > viewcol
    439   1.1       cgd 		    && sp->file->col < viewcol + VIEW_X) {
    440  1.16     jwise 			wmove(view_w, sp->file->row - viewrow,
    441   1.1       cgd 				sp->file->col - viewcol);
    442  1.16     jwise 			waddch(view_w, colours(sp));
    443  1.16     jwise 			wmove(view_w,
    444   1.1       cgd 				sternrow(sp) - viewrow,
    445   1.1       cgd 				sterncol(sp) - viewcol);
    446  1.16     jwise 			waddch(view_w, sterncolour(sp));
    447   1.1       cgd 		}
    448   1.1       cgd 	}
    449  1.16     jwise 	wrefresh(view_w);
    450   1.1       cgd }
    451   1.1       cgd 
    452  1.35  dholland static void
    453  1.16     jwise draw_turn(void)
    454   1.1       cgd {
    455  1.16     jwise 	wmove(turn_w, 0, 0);
    456  1.16     jwise 	wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn);
    457  1.16     jwise 	wrefresh(turn_w);
    458   1.1       cgd }
    459   1.1       cgd 
    460  1.35  dholland static void
    461  1.16     jwise draw_stat(void)
    462   1.1       cgd {
    463  1.16     jwise 	wmove(stat_w, STAT_1, 0);
    464  1.16     jwise 	wprintw(stat_w, "Points  %3d\n", mf->points);
    465  1.16     jwise 	wprintw(stat_w, "Fouls    %2d\n", fouled(ms));
    466  1.16     jwise 	wprintw(stat_w, "Grapples %2d\n", grappled(ms));
    467   1.1       cgd 
    468  1.16     jwise 	wmove(stat_w, STAT_2, 0);
    469  1.16     jwise 	wprintw(stat_w, "    0 %c(%c)\n",
    470   1.1       cgd 		maxmove(ms, winddir + 3, -1) + '0',
    471   1.1       cgd 		maxmove(ms, winddir + 3, 1) + '0');
    472  1.16     jwise 	waddstr(stat_w, "   \\|/\n");
    473  1.16     jwise 	wprintw(stat_w, "   -^-%c(%c)\n",
    474   1.1       cgd 		maxmove(ms, winddir + 2, -1) + '0',
    475   1.1       cgd 		maxmove(ms, winddir + 2, 1) + '0');
    476  1.16     jwise 	waddstr(stat_w, "   /|\\\n");
    477  1.16     jwise 	wprintw(stat_w, "    | %c(%c)\n",
    478   1.1       cgd 		maxmove(ms, winddir + 1, -1) + '0',
    479   1.1       cgd 		maxmove(ms, winddir + 1, 1) + '0');
    480  1.16     jwise 	wprintw(stat_w, "   %c(%c)\n",
    481   1.1       cgd 		maxmove(ms, winddir, -1) + '0',
    482   1.1       cgd 		maxmove(ms, winddir, 1) + '0');
    483   1.1       cgd 
    484  1.16     jwise 	wmove(stat_w, STAT_3, 0);
    485  1.16     jwise 	wprintw(stat_w, "Load  %c%c %c%c\n",
    486   1.1       cgd 		loadname[mf->loadL], readyname(mf->readyL),
    487   1.1       cgd 		loadname[mf->loadR], readyname(mf->readyR));
    488  1.16     jwise 	wprintw(stat_w, "Hull %2d\n", mc->hull);
    489  1.16     jwise 	wprintw(stat_w, "Crew %2d %2d %2d\n",
    490   1.1       cgd 		mc->crew1, mc->crew2, mc->crew3);
    491  1.16     jwise 	wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR);
    492  1.16     jwise 	wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR);
    493  1.16     jwise 	wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3);
    494   1.1       cgd 	if (mc->rig4 < 0)
    495  1.16     jwise 		waddch(stat_w, '-');
    496   1.1       cgd 	else
    497  1.16     jwise 		wprintw(stat_w, "%d", mc->rig4);
    498  1.16     jwise 	wrefresh(stat_w);
    499   1.1       cgd }
    500   1.1       cgd 
    501   1.7  christos void
    502  1.16     jwise draw_slot(void)
    503   1.1       cgd {
    504  1.35  dholland 	int i;
    505  1.35  dholland 
    506   1.1       cgd 	if (!boarding(ms, 0)) {
    507  1.16     jwise 		mvwaddstr(slot_w, 0, 0, "   ");
    508  1.16     jwise 		mvwaddstr(slot_w, 1, 0, "   ");
    509  1.35  dholland 	} else {
    510  1.35  dholland 		wmove(slot_w, 0, 0);
    511  1.35  dholland 		for (i = 0; i < 3; i++) {
    512  1.35  dholland 			waddch(slot_w, obp[i] ? '1'+i : ' ');
    513  1.35  dholland 		}
    514  1.16     jwise 		mvwaddstr(slot_w, 1, 0, "OBP");
    515  1.35  dholland 	}
    516   1.1       cgd 	if (!boarding(ms, 1)) {
    517  1.16     jwise 		mvwaddstr(slot_w, 2, 0, "   ");
    518  1.16     jwise 		mvwaddstr(slot_w, 3, 0, "   ");
    519  1.35  dholland 	} else {
    520  1.35  dholland 		wmove(slot_w, 2, 0);
    521  1.35  dholland 		for (i = 0; i < 3; i++) {
    522  1.35  dholland 			waddch(slot_w, dbp[i] ? '1'+i : ' ');
    523  1.35  dholland 		}
    524  1.16     jwise 		mvwaddstr(slot_w, 3, 0, "DBP");
    525  1.35  dholland 	}
    526   1.1       cgd 
    527  1.16     jwise 	wmove(slot_w, SLOT_Y-4, 0);
    528   1.1       cgd 	if (mf->RH)
    529  1.16     jwise 		wprintw(slot_w, "%dRH", mf->RH);
    530   1.1       cgd 	else
    531  1.16     jwise 		waddstr(slot_w, "   ");
    532  1.16     jwise 	wmove(slot_w, SLOT_Y-3, 0);
    533   1.1       cgd 	if (mf->RG)
    534  1.16     jwise 		wprintw(slot_w, "%dRG", mf->RG);
    535   1.1       cgd 	else
    536  1.16     jwise 		waddstr(slot_w, "   ");
    537  1.16     jwise 	wmove(slot_w, SLOT_Y-2, 0);
    538   1.1       cgd 	if (mf->RR)
    539  1.16     jwise 		wprintw(slot_w, "%dRR", mf->RR);
    540   1.1       cgd 	else
    541  1.16     jwise 		waddstr(slot_w, "   ");
    542   1.1       cgd 
    543   1.1       cgd #define Y	(SLOT_Y/2)
    544  1.16     jwise 	wmove(slot_w, 7, 1);
    545  1.16     jwise 	wprintw(slot_w,"%d", windspeed);
    546  1.16     jwise 	mvwaddch(slot_w, Y, 0, ' ');
    547  1.16     jwise 	mvwaddch(slot_w, Y, 2, ' ');
    548  1.16     jwise 	mvwaddch(slot_w, Y-1, 0, ' ');
    549  1.16     jwise 	mvwaddch(slot_w, Y-1, 1, ' ');
    550  1.16     jwise 	mvwaddch(slot_w, Y-1, 2, ' ');
    551  1.16     jwise 	mvwaddch(slot_w, Y+1, 0, ' ');
    552  1.16     jwise 	mvwaddch(slot_w, Y+1, 1, ' ');
    553  1.16     jwise 	mvwaddch(slot_w, Y+1, 2, ' ');
    554  1.16     jwise 	wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]);
    555   1.1       cgd 	switch (winddir) {
    556   1.1       cgd 	case 1:
    557   1.1       cgd 	case 5:
    558  1.16     jwise 		waddch(slot_w, '|');
    559   1.1       cgd 		break;
    560   1.1       cgd 	case 2:
    561   1.1       cgd 	case 6:
    562  1.16     jwise 		waddch(slot_w, '/');
    563   1.1       cgd 		break;
    564   1.1       cgd 	case 3:
    565   1.1       cgd 	case 7:
    566  1.16     jwise 		waddch(slot_w, '-');
    567   1.1       cgd 		break;
    568   1.1       cgd 	case 4:
    569   1.1       cgd 	case 8:
    570  1.16     jwise 		waddch(slot_w, '\\');
    571   1.1       cgd 		break;
    572   1.1       cgd 	}
    573  1.16     jwise 	mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+');
    574  1.16     jwise 	wrefresh(slot_w);
    575   1.1       cgd }
    576   1.1       cgd 
    577   1.7  christos void
    578  1.16     jwise draw_board(void)
    579   1.1       cgd {
    580   1.7  christos 	int n;
    581   1.1       cgd 
    582  1.35  dholland 	erase();
    583  1.16     jwise 	werase(view_w);
    584  1.16     jwise 	werase(slot_w);
    585  1.16     jwise 	werase(scroll_w);
    586  1.16     jwise 	werase(stat_w);
    587  1.16     jwise 	werase(turn_w);
    588   1.1       cgd 
    589  1.16     jwise 	move(BOX_T, BOX_L);
    590   1.1       cgd 	for (n = 0; n < BOX_X; n++)
    591  1.16     jwise 		addch('-');
    592  1.16     jwise 	move(BOX_B, BOX_L);
    593   1.1       cgd 	for (n = 0; n < BOX_X; n++)
    594  1.16     jwise 		addch('-');
    595   1.1       cgd 	for (n = BOX_T+1; n < BOX_B; n++) {
    596  1.16     jwise 		mvaddch(n, BOX_L, '|');
    597  1.16     jwise 		mvaddch(n, BOX_R, '|');
    598   1.1       cgd 	}
    599  1.16     jwise 	mvaddch(BOX_T, BOX_L, '+');
    600  1.16     jwise 	mvaddch(BOX_T, BOX_R, '+');
    601  1.16     jwise 	mvaddch(BOX_B, BOX_L, '+');
    602  1.16     jwise 	mvaddch(BOX_B, BOX_R, '+');
    603  1.16     jwise 	refresh();
    604   1.1       cgd 
    605  1.35  dholland #if 0
    606   1.1       cgd #define WSaIM "Wooden Ships & Iron Men"
    607  1.16     jwise 	wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2);
    608  1.16     jwise 	waddstr(view_w, WSaIM);
    609  1.16     jwise 	wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2);
    610  1.16     jwise 	waddstr(view_w, cc->name);
    611  1.16     jwise 	wrefresh(view_w);
    612  1.35  dholland #endif
    613   1.1       cgd 
    614  1.16     jwise 	move(LINE_T, LINE_L);
    615  1.16     jwise 	printw("Class %d %s (%d guns) '%s' (%c%c)",
    616   1.1       cgd 		mc->class,
    617   1.1       cgd 		classname[mc->class],
    618   1.1       cgd 		mc->guns,
    619   1.1       cgd 		ms->shipname,
    620   1.1       cgd 		colours(ms),
    621   1.1       cgd 		sterncolour(ms));
    622  1.16     jwise 	refresh();
    623   1.1       cgd }
    624   1.1       cgd 
    625  1.33  dholland void
    626  1.35  dholland display_set_obp(int which, bool show)
    627  1.35  dholland {
    628  1.35  dholland 	obp[which] = show;
    629  1.35  dholland }
    630  1.35  dholland 
    631  1.35  dholland void
    632  1.35  dholland display_set_dbp(int which, bool show)
    633  1.33  dholland {
    634  1.35  dholland 	dbp[which] = show;
    635  1.33  dholland }
    636  1.33  dholland 
    637  1.35  dholland ////////////////////////////////////////////////////////////
    638  1.35  dholland // external actions on the display
    639  1.35  dholland 
    640  1.33  dholland void
    641  1.35  dholland display_scroll_pageup(void)
    642  1.33  dholland {
    643  1.35  dholland 	unsigned total_lines, visible_lines, limit;
    644  1.35  dholland 	unsigned pagesize = SCROLL_Y - 2;
    645  1.35  dholland 
    646  1.35  dholland 	total_lines = stringarray_num(sc_lines);
    647  1.35  dholland 	visible_lines = SCROLL_Y - 1;
    648  1.35  dholland 	limit = total_lines - visible_lines;
    649  1.35  dholland 
    650  1.35  dholland 	sc_scrollup += pagesize;
    651  1.35  dholland 	if (sc_scrollup > limit) {
    652  1.35  dholland 		sc_scrollup = limit;
    653  1.35  dholland 	}
    654  1.33  dholland }
    655  1.33  dholland 
    656  1.33  dholland void
    657  1.35  dholland display_scroll_pagedown(void)
    658  1.33  dholland {
    659  1.35  dholland 	unsigned pagesize = SCROLL_Y - 2;
    660  1.35  dholland 
    661  1.35  dholland 	if (sc_scrollup < pagesize) {
    662  1.35  dholland 		sc_scrollup = 0;
    663  1.35  dholland 	} else {
    664  1.35  dholland 		sc_scrollup -= pagesize;
    665  1.35  dholland 	}
    666  1.33  dholland }
    667  1.33  dholland 
    668   1.7  christos void
    669  1.16     jwise centerview(void)
    670   1.1       cgd {
    671   1.1       cgd 	viewrow = mf->row - VIEW_Y / 2;
    672   1.1       cgd 	viewcol = mf->col - VIEW_X / 2;
    673   1.1       cgd }
    674   1.1       cgd 
    675   1.7  christos void
    676  1.16     jwise upview(void)
    677   1.1       cgd {
    678   1.1       cgd 	viewrow -= VIEW_Y / 3;
    679   1.1       cgd }
    680   1.1       cgd 
    681   1.7  christos void
    682  1.16     jwise downview(void)
    683   1.1       cgd {
    684   1.1       cgd 	viewrow += VIEW_Y / 3;
    685   1.1       cgd }
    686   1.1       cgd 
    687   1.7  christos void
    688  1.16     jwise leftview(void)
    689   1.1       cgd {
    690   1.1       cgd 	viewcol -= VIEW_X / 5;
    691   1.1       cgd }
    692   1.1       cgd 
    693   1.7  christos void
    694  1.16     jwise rightview(void)
    695   1.1       cgd {
    696   1.1       cgd 	viewcol += VIEW_X / 5;
    697   1.1       cgd }
    698   1.1       cgd 
    699  1.34  dholland /* Called from newturn()... rename? */
    700  1.34  dholland void
    701  1.34  dholland display_adjust_view(void)
    702   1.1       cgd {
    703   1.1       cgd 	if (dont_adjust)
    704   1.1       cgd 		return;
    705   1.1       cgd 	if (mf->row < viewrow + VIEW_Y/4)
    706   1.1       cgd 		viewrow = mf->row - (VIEW_Y - VIEW_Y/4);
    707   1.1       cgd 	else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4))
    708   1.1       cgd 		viewrow = mf->row - VIEW_Y/4;
    709   1.1       cgd 	if (mf->col < viewcol + VIEW_X/8)
    710   1.1       cgd 		viewcol = mf->col - (VIEW_X - VIEW_X/8);
    711   1.1       cgd 	else if (mf->col > viewcol + (VIEW_X - VIEW_X/8))
    712   1.1       cgd 		viewcol = mf->col - VIEW_X/8;
    713   1.1       cgd }
    714