pl_7.c revision 1.35 1 1.35 dholland /* $NetBSD: pl_7.c,v 1.35 2009/03/15 03:33:56 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.35 dholland __RCSID("$NetBSD: pl_7.c,v 1.35 2009/03/15 03:33:56 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.13 jsm 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.35 dholland define_esc_key(ch);
156 1.35 dholland }
157 1.35 dholland
158 1.33 dholland done_curses++;
159 1.1 cgd }
160 1.1 cgd
161 1.7 christos void
162 1.16 jwise cleanupscreen(void)
163 1.1 cgd {
164 1.1 cgd /* alarm already turned off */
165 1.1 cgd if (done_curses) {
166 1.16 jwise wmove(scroll_w, SCROLL_Y - 1, 0);
167 1.16 jwise wclrtoeol(scroll_w);
168 1.35 dholland display_redraw();
169 1.1 cgd endwin();
170 1.1 cgd }
171 1.1 cgd }
172 1.1 cgd
173 1.35 dholland ////////////////////////////////////////////////////////////
174 1.35 dholland // scrolling message area
175 1.35 dholland
176 1.35 dholland static void
177 1.35 dholland scrollarea_add(const char *text)
178 1.35 dholland {
179 1.35 dholland char *copy;
180 1.35 dholland int errsave;
181 1.35 dholland
182 1.35 dholland copy = strdup(text);
183 1.35 dholland if (copy == NULL) {
184 1.35 dholland goto nomem;
185 1.35 dholland }
186 1.35 dholland if (stringarray_add(sc_lines, copy, NULL)) {
187 1.35 dholland goto nomem;
188 1.35 dholland }
189 1.35 dholland return;
190 1.35 dholland
191 1.35 dholland nomem:
192 1.35 dholland /*
193 1.35 dholland * XXX this should use leave(), but that won't
194 1.35 dholland * currently work right.
195 1.35 dholland */
196 1.35 dholland errsave = errno;
197 1.35 dholland #if 0
198 1.35 dholland leave(LEAVE_MALLOC);
199 1.35 dholland #else
200 1.35 dholland cleanupscreen();
201 1.35 dholland sync_close(!hasdriver);
202 1.35 dholland errno = errsave;
203 1.35 dholland err(1, "malloc");
204 1.35 dholland #endif
205 1.35 dholland }
206 1.35 dholland
207 1.35 dholland static void
208 1.35 dholland draw_scroll(void)
209 1.35 dholland {
210 1.35 dholland unsigned total_lines;
211 1.35 dholland unsigned visible_lines;
212 1.35 dholland unsigned index_of_top;
213 1.35 dholland unsigned index_of_y;
214 1.35 dholland unsigned y;
215 1.35 dholland unsigned cursorx;
216 1.35 dholland
217 1.35 dholland werase(scroll_w);
218 1.35 dholland
219 1.35 dholland visible_lines = SCROLL_Y - 1;
220 1.35 dholland
221 1.35 dholland total_lines = stringarray_num(sc_lines);
222 1.35 dholland if (total_lines > visible_lines) {
223 1.35 dholland index_of_top = total_lines - visible_lines;
224 1.35 dholland } else {
225 1.35 dholland index_of_top = 0;
226 1.35 dholland }
227 1.35 dholland if (index_of_top < sc_scrollup) {
228 1.35 dholland index_of_top = 0;
229 1.35 dholland } else {
230 1.35 dholland index_of_top -= sc_scrollup;
231 1.35 dholland }
232 1.35 dholland
233 1.35 dholland for (y = 0; y < SCROLL_Y - 1; y++) {
234 1.35 dholland index_of_y = index_of_top + y;
235 1.35 dholland if (index_of_y >= total_lines) {
236 1.35 dholland break;
237 1.35 dholland }
238 1.35 dholland wmove(scroll_w, y, 0);
239 1.35 dholland waddstr(scroll_w, stringarray_get(sc_lines, index_of_y));
240 1.35 dholland }
241 1.35 dholland if (sc_hasprompt && !sc_hideprompt) {
242 1.35 dholland wmove(scroll_w, SCROLL_Y-1, 0);
243 1.35 dholland waddstr(scroll_w, sc_prompt);
244 1.35 dholland waddstr(scroll_w, sc_buf);
245 1.35 dholland cursorx = strlen(sc_prompt) + strlen(sc_buf);
246 1.35 dholland wmove(scroll_w, SCROLL_Y-1, cursorx);
247 1.35 dholland }
248 1.35 dholland else {
249 1.35 dholland wmove(scroll_w, SCROLL_Y-1, 0);
250 1.35 dholland }
251 1.35 dholland }
252 1.35 dholland
253 1.1 cgd /*VARARGS2*/
254 1.7 christos void
255 1.7 christos Signal(const char *fmt, struct ship *ship, ...)
256 1.1 cgd {
257 1.7 christos va_list ap;
258 1.7 christos char format[BUFSIZ];
259 1.35 dholland char buf[BUFSIZ];
260 1.7 christos
261 1.1 cgd if (!done_curses)
262 1.1 cgd return;
263 1.25 wiz va_start(ap, ship);
264 1.35 dholland if (*fmt == '\a') {
265 1.35 dholland beep();
266 1.35 dholland fmt++;
267 1.35 dholland }
268 1.7 christos fmtship(format, sizeof(format), fmt, ship);
269 1.35 dholland vsnprintf(buf, sizeof(buf), format, ap);
270 1.7 christos va_end(ap);
271 1.35 dholland scrollarea_add(buf);
272 1.7 christos }
273 1.7 christos
274 1.7 christos /*VARARGS2*/
275 1.7 christos void
276 1.7 christos Msg(const char *fmt, ...)
277 1.7 christos {
278 1.7 christos va_list ap;
279 1.35 dholland char buf[BUFSIZ];
280 1.7 christos
281 1.7 christos if (!done_curses)
282 1.7 christos return;
283 1.25 wiz va_start(ap, fmt);
284 1.35 dholland if (*fmt == '\a') {
285 1.35 dholland beep();
286 1.35 dholland fmt++;
287 1.35 dholland }
288 1.35 dholland vsnprintf(buf, sizeof(buf), fmt, ap);
289 1.7 christos va_end(ap);
290 1.35 dholland scrollarea_add(buf);
291 1.1 cgd }
292 1.1 cgd
293 1.7 christos void
294 1.17 jwise prompt(const char *p, struct ship *ship)
295 1.1 cgd {
296 1.8 christos static char buf[BUFSIZ];
297 1.1 cgd
298 1.8 christos fmtship(buf, sizeof(buf), p, ship);
299 1.8 christos sc_prompt = buf;
300 1.1 cgd sc_buf = "";
301 1.35 dholland sc_hasprompt = true;
302 1.1 cgd }
303 1.1 cgd
304 1.17 jwise static void
305 1.35 dholland endprompt(void)
306 1.1 cgd {
307 1.35 dholland sc_prompt = NULL;
308 1.35 dholland sc_buf = NULL;
309 1.35 dholland sc_hasprompt = false;
310 1.1 cgd }
311 1.1 cgd
312 1.34 dholland /*
313 1.34 dholland * Next two functions called from newturn() to poke display. Shouldn't
314 1.34 dholland * exist... XXX
315 1.34 dholland */
316 1.34 dholland
317 1.34 dholland void
318 1.34 dholland display_hide_prompt(void)
319 1.34 dholland {
320 1.35 dholland sc_hideprompt = true;
321 1.35 dholland draw_scroll();
322 1.35 dholland wrefresh(scroll_w);
323 1.34 dholland }
324 1.34 dholland
325 1.34 dholland void
326 1.34 dholland display_reshow_prompt(void)
327 1.34 dholland {
328 1.35 dholland sc_hideprompt = false;
329 1.35 dholland draw_scroll();
330 1.35 dholland wrefresh(scroll_w);
331 1.34 dholland }
332 1.34 dholland
333 1.34 dholland
334 1.7 christos int
335 1.16 jwise sgetch(const char *p, struct ship *ship, int flag)
336 1.1 cgd {
337 1.7 christos int c;
338 1.35 dholland char input[2];
339 1.35 dholland
340 1.1 cgd prompt(p, ship);
341 1.35 dholland input[0] = '\0';
342 1.35 dholland input[1] = '\0';
343 1.35 dholland sc_buf = input;
344 1.1 cgd blockalarm();
345 1.35 dholland draw_scroll();
346 1.16 jwise wrefresh(scroll_w);
347 1.35 dholland fflush(stdout);
348 1.1 cgd unblockalarm();
349 1.1 cgd while ((c = wgetch(scroll_w)) == EOF)
350 1.1 cgd ;
351 1.35 dholland if (flag && c >= ' ' && c < 0x7f) {
352 1.35 dholland blockalarm();
353 1.35 dholland input[0] = c;
354 1.35 dholland draw_scroll();
355 1.35 dholland wrefresh(scroll_w);
356 1.35 dholland fflush(stdout);
357 1.35 dholland unblockalarm();
358 1.35 dholland }
359 1.35 dholland endprompt();
360 1.1 cgd return c;
361 1.1 cgd }
362 1.1 cgd
363 1.7 christos void
364 1.16 jwise sgetstr(const char *pr, char *buf, int n)
365 1.1 cgd {
366 1.7 christos int c;
367 1.7 christos char *p = buf;
368 1.1 cgd
369 1.1 cgd prompt(pr, (struct ship *)0);
370 1.1 cgd sc_buf = buf;
371 1.1 cgd for (;;) {
372 1.1 cgd *p = 0;
373 1.1 cgd blockalarm();
374 1.35 dholland draw_scroll();
375 1.16 jwise wrefresh(scroll_w);
376 1.35 dholland fflush(stdout);
377 1.1 cgd unblockalarm();
378 1.1 cgd while ((c = wgetch(scroll_w)) == EOF)
379 1.1 cgd ;
380 1.1 cgd switch (c) {
381 1.1 cgd case '\n':
382 1.1 cgd case '\r':
383 1.35 dholland endprompt();
384 1.1 cgd return;
385 1.1 cgd case '\b':
386 1.1 cgd if (p > buf) {
387 1.35 dholland /*waddstr(scroll_w, "\b \b");*/
388 1.1 cgd p--;
389 1.1 cgd }
390 1.1 cgd break;
391 1.1 cgd default:
392 1.1 cgd if (c >= ' ' && c < 0x7f && p < buf + n - 1) {
393 1.1 cgd *p++ = c;
394 1.35 dholland /*waddch(scroll_w, c);*/
395 1.1 cgd } else
396 1.35 dholland beep();
397 1.1 cgd }
398 1.1 cgd }
399 1.1 cgd }
400 1.1 cgd
401 1.35 dholland ////////////////////////////////////////////////////////////
402 1.35 dholland // drawing of other panes
403 1.35 dholland
404 1.35 dholland void
405 1.35 dholland display_force_full_redraw(void)
406 1.35 dholland {
407 1.35 dholland clear();
408 1.35 dholland }
409 1.35 dholland
410 1.7 christos void
411 1.35 dholland display_redraw(void)
412 1.1 cgd {
413 1.35 dholland draw_board();
414 1.1 cgd draw_view();
415 1.1 cgd draw_turn();
416 1.1 cgd draw_stat();
417 1.1 cgd draw_slot();
418 1.35 dholland draw_scroll();
419 1.35 dholland /* move the cursor */
420 1.35 dholland wrefresh(scroll_w);
421 1.35 dholland /* paranoia */
422 1.35 dholland fflush(stdout);
423 1.1 cgd }
424 1.1 cgd
425 1.35 dholland static void
426 1.16 jwise draw_view(void)
427 1.1 cgd {
428 1.7 christos struct ship *sp;
429 1.1 cgd
430 1.16 jwise werase(view_w);
431 1.1 cgd foreachship(sp) {
432 1.1 cgd if (sp->file->dir
433 1.1 cgd && sp->file->row > viewrow
434 1.1 cgd && sp->file->row < viewrow + VIEW_Y
435 1.1 cgd && sp->file->col > viewcol
436 1.1 cgd && sp->file->col < viewcol + VIEW_X) {
437 1.16 jwise wmove(view_w, sp->file->row - viewrow,
438 1.1 cgd sp->file->col - viewcol);
439 1.16 jwise waddch(view_w, colours(sp));
440 1.16 jwise wmove(view_w,
441 1.1 cgd sternrow(sp) - viewrow,
442 1.1 cgd sterncol(sp) - viewcol);
443 1.16 jwise waddch(view_w, sterncolour(sp));
444 1.1 cgd }
445 1.1 cgd }
446 1.16 jwise wrefresh(view_w);
447 1.1 cgd }
448 1.1 cgd
449 1.35 dholland static void
450 1.16 jwise draw_turn(void)
451 1.1 cgd {
452 1.16 jwise wmove(turn_w, 0, 0);
453 1.16 jwise wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn);
454 1.16 jwise wrefresh(turn_w);
455 1.1 cgd }
456 1.1 cgd
457 1.35 dholland static void
458 1.16 jwise draw_stat(void)
459 1.1 cgd {
460 1.16 jwise wmove(stat_w, STAT_1, 0);
461 1.16 jwise wprintw(stat_w, "Points %3d\n", mf->points);
462 1.16 jwise wprintw(stat_w, "Fouls %2d\n", fouled(ms));
463 1.16 jwise wprintw(stat_w, "Grapples %2d\n", grappled(ms));
464 1.1 cgd
465 1.16 jwise wmove(stat_w, STAT_2, 0);
466 1.16 jwise wprintw(stat_w, " 0 %c(%c)\n",
467 1.1 cgd maxmove(ms, winddir + 3, -1) + '0',
468 1.1 cgd maxmove(ms, winddir + 3, 1) + '0');
469 1.16 jwise waddstr(stat_w, " \\|/\n");
470 1.16 jwise wprintw(stat_w, " -^-%c(%c)\n",
471 1.1 cgd maxmove(ms, winddir + 2, -1) + '0',
472 1.1 cgd maxmove(ms, winddir + 2, 1) + '0');
473 1.16 jwise waddstr(stat_w, " /|\\\n");
474 1.16 jwise wprintw(stat_w, " | %c(%c)\n",
475 1.1 cgd maxmove(ms, winddir + 1, -1) + '0',
476 1.1 cgd maxmove(ms, winddir + 1, 1) + '0');
477 1.16 jwise wprintw(stat_w, " %c(%c)\n",
478 1.1 cgd maxmove(ms, winddir, -1) + '0',
479 1.1 cgd maxmove(ms, winddir, 1) + '0');
480 1.1 cgd
481 1.16 jwise wmove(stat_w, STAT_3, 0);
482 1.16 jwise wprintw(stat_w, "Load %c%c %c%c\n",
483 1.1 cgd loadname[mf->loadL], readyname(mf->readyL),
484 1.1 cgd loadname[mf->loadR], readyname(mf->readyR));
485 1.16 jwise wprintw(stat_w, "Hull %2d\n", mc->hull);
486 1.16 jwise wprintw(stat_w, "Crew %2d %2d %2d\n",
487 1.1 cgd mc->crew1, mc->crew2, mc->crew3);
488 1.16 jwise wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR);
489 1.16 jwise wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR);
490 1.16 jwise wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3);
491 1.1 cgd if (mc->rig4 < 0)
492 1.16 jwise waddch(stat_w, '-');
493 1.1 cgd else
494 1.16 jwise wprintw(stat_w, "%d", mc->rig4);
495 1.16 jwise wrefresh(stat_w);
496 1.1 cgd }
497 1.1 cgd
498 1.7 christos void
499 1.16 jwise draw_slot(void)
500 1.1 cgd {
501 1.35 dholland int i;
502 1.35 dholland
503 1.1 cgd if (!boarding(ms, 0)) {
504 1.16 jwise mvwaddstr(slot_w, 0, 0, " ");
505 1.16 jwise mvwaddstr(slot_w, 1, 0, " ");
506 1.35 dholland } else {
507 1.35 dholland wmove(slot_w, 0, 0);
508 1.35 dholland for (i = 0; i < 3; i++) {
509 1.35 dholland waddch(slot_w, obp[i] ? '1'+i : ' ');
510 1.35 dholland }
511 1.16 jwise mvwaddstr(slot_w, 1, 0, "OBP");
512 1.35 dholland }
513 1.1 cgd if (!boarding(ms, 1)) {
514 1.16 jwise mvwaddstr(slot_w, 2, 0, " ");
515 1.16 jwise mvwaddstr(slot_w, 3, 0, " ");
516 1.35 dholland } else {
517 1.35 dholland wmove(slot_w, 2, 0);
518 1.35 dholland for (i = 0; i < 3; i++) {
519 1.35 dholland waddch(slot_w, dbp[i] ? '1'+i : ' ');
520 1.35 dholland }
521 1.16 jwise mvwaddstr(slot_w, 3, 0, "DBP");
522 1.35 dholland }
523 1.1 cgd
524 1.16 jwise wmove(slot_w, SLOT_Y-4, 0);
525 1.1 cgd if (mf->RH)
526 1.16 jwise wprintw(slot_w, "%dRH", mf->RH);
527 1.1 cgd else
528 1.16 jwise waddstr(slot_w, " ");
529 1.16 jwise wmove(slot_w, SLOT_Y-3, 0);
530 1.1 cgd if (mf->RG)
531 1.16 jwise wprintw(slot_w, "%dRG", mf->RG);
532 1.1 cgd else
533 1.16 jwise waddstr(slot_w, " ");
534 1.16 jwise wmove(slot_w, SLOT_Y-2, 0);
535 1.1 cgd if (mf->RR)
536 1.16 jwise wprintw(slot_w, "%dRR", mf->RR);
537 1.1 cgd else
538 1.16 jwise waddstr(slot_w, " ");
539 1.1 cgd
540 1.1 cgd #define Y (SLOT_Y/2)
541 1.16 jwise wmove(slot_w, 7, 1);
542 1.16 jwise wprintw(slot_w,"%d", windspeed);
543 1.16 jwise mvwaddch(slot_w, Y, 0, ' ');
544 1.16 jwise mvwaddch(slot_w, Y, 2, ' ');
545 1.16 jwise mvwaddch(slot_w, Y-1, 0, ' ');
546 1.16 jwise mvwaddch(slot_w, Y-1, 1, ' ');
547 1.16 jwise mvwaddch(slot_w, Y-1, 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 wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]);
552 1.1 cgd switch (winddir) {
553 1.1 cgd case 1:
554 1.1 cgd case 5:
555 1.16 jwise waddch(slot_w, '|');
556 1.1 cgd break;
557 1.1 cgd case 2:
558 1.1 cgd case 6:
559 1.16 jwise waddch(slot_w, '/');
560 1.1 cgd break;
561 1.1 cgd case 3:
562 1.1 cgd case 7:
563 1.16 jwise waddch(slot_w, '-');
564 1.1 cgd break;
565 1.1 cgd case 4:
566 1.1 cgd case 8:
567 1.16 jwise waddch(slot_w, '\\');
568 1.1 cgd break;
569 1.1 cgd }
570 1.16 jwise mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+');
571 1.16 jwise wrefresh(slot_w);
572 1.1 cgd }
573 1.1 cgd
574 1.7 christos void
575 1.16 jwise draw_board(void)
576 1.1 cgd {
577 1.7 christos int n;
578 1.1 cgd
579 1.35 dholland erase();
580 1.16 jwise werase(view_w);
581 1.16 jwise werase(slot_w);
582 1.16 jwise werase(scroll_w);
583 1.16 jwise werase(stat_w);
584 1.16 jwise werase(turn_w);
585 1.1 cgd
586 1.16 jwise move(BOX_T, BOX_L);
587 1.1 cgd for (n = 0; n < BOX_X; n++)
588 1.16 jwise addch('-');
589 1.16 jwise move(BOX_B, BOX_L);
590 1.1 cgd for (n = 0; n < BOX_X; n++)
591 1.16 jwise addch('-');
592 1.1 cgd for (n = BOX_T+1; n < BOX_B; n++) {
593 1.16 jwise mvaddch(n, BOX_L, '|');
594 1.16 jwise mvaddch(n, BOX_R, '|');
595 1.1 cgd }
596 1.16 jwise mvaddch(BOX_T, BOX_L, '+');
597 1.16 jwise mvaddch(BOX_T, BOX_R, '+');
598 1.16 jwise mvaddch(BOX_B, BOX_L, '+');
599 1.16 jwise mvaddch(BOX_B, BOX_R, '+');
600 1.16 jwise refresh();
601 1.1 cgd
602 1.35 dholland #if 0
603 1.1 cgd #define WSaIM "Wooden Ships & Iron Men"
604 1.16 jwise wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2);
605 1.16 jwise waddstr(view_w, WSaIM);
606 1.16 jwise wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2);
607 1.16 jwise waddstr(view_w, cc->name);
608 1.16 jwise wrefresh(view_w);
609 1.35 dholland #endif
610 1.1 cgd
611 1.16 jwise move(LINE_T, LINE_L);
612 1.16 jwise printw("Class %d %s (%d guns) '%s' (%c%c)",
613 1.1 cgd mc->class,
614 1.1 cgd classname[mc->class],
615 1.1 cgd mc->guns,
616 1.1 cgd ms->shipname,
617 1.1 cgd colours(ms),
618 1.1 cgd sterncolour(ms));
619 1.16 jwise refresh();
620 1.1 cgd }
621 1.1 cgd
622 1.33 dholland void
623 1.35 dholland display_set_obp(int which, bool show)
624 1.35 dholland {
625 1.35 dholland obp[which] = show;
626 1.35 dholland }
627 1.35 dholland
628 1.35 dholland void
629 1.35 dholland display_set_dbp(int which, bool show)
630 1.33 dholland {
631 1.35 dholland dbp[which] = show;
632 1.33 dholland }
633 1.33 dholland
634 1.35 dholland ////////////////////////////////////////////////////////////
635 1.35 dholland // external actions on the display
636 1.35 dholland
637 1.33 dholland void
638 1.35 dholland display_scroll_pageup(void)
639 1.33 dholland {
640 1.35 dholland unsigned total_lines, visible_lines, limit;
641 1.35 dholland unsigned pagesize = SCROLL_Y - 2;
642 1.35 dholland
643 1.35 dholland total_lines = stringarray_num(sc_lines);
644 1.35 dholland visible_lines = SCROLL_Y - 1;
645 1.35 dholland limit = total_lines - visible_lines;
646 1.35 dholland
647 1.35 dholland sc_scrollup += pagesize;
648 1.35 dholland if (sc_scrollup > limit) {
649 1.35 dholland sc_scrollup = limit;
650 1.35 dholland }
651 1.33 dholland }
652 1.33 dholland
653 1.33 dholland void
654 1.35 dholland display_scroll_pagedown(void)
655 1.33 dholland {
656 1.35 dholland unsigned pagesize = SCROLL_Y - 2;
657 1.35 dholland
658 1.35 dholland if (sc_scrollup < pagesize) {
659 1.35 dholland sc_scrollup = 0;
660 1.35 dholland } else {
661 1.35 dholland sc_scrollup -= pagesize;
662 1.35 dholland }
663 1.33 dholland }
664 1.33 dholland
665 1.7 christos void
666 1.16 jwise centerview(void)
667 1.1 cgd {
668 1.1 cgd viewrow = mf->row - VIEW_Y / 2;
669 1.1 cgd viewcol = mf->col - VIEW_X / 2;
670 1.1 cgd }
671 1.1 cgd
672 1.7 christos void
673 1.16 jwise upview(void)
674 1.1 cgd {
675 1.1 cgd viewrow -= VIEW_Y / 3;
676 1.1 cgd }
677 1.1 cgd
678 1.7 christos void
679 1.16 jwise downview(void)
680 1.1 cgd {
681 1.1 cgd viewrow += VIEW_Y / 3;
682 1.1 cgd }
683 1.1 cgd
684 1.7 christos void
685 1.16 jwise leftview(void)
686 1.1 cgd {
687 1.1 cgd viewcol -= VIEW_X / 5;
688 1.1 cgd }
689 1.1 cgd
690 1.7 christos void
691 1.16 jwise rightview(void)
692 1.1 cgd {
693 1.1 cgd viewcol += VIEW_X / 5;
694 1.1 cgd }
695 1.1 cgd
696 1.34 dholland /* Called from newturn()... rename? */
697 1.34 dholland void
698 1.34 dholland display_adjust_view(void)
699 1.1 cgd {
700 1.1 cgd if (dont_adjust)
701 1.1 cgd return;
702 1.1 cgd if (mf->row < viewrow + VIEW_Y/4)
703 1.1 cgd viewrow = mf->row - (VIEW_Y - VIEW_Y/4);
704 1.1 cgd else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4))
705 1.1 cgd viewrow = mf->row - VIEW_Y/4;
706 1.1 cgd if (mf->col < viewcol + VIEW_X/8)
707 1.1 cgd viewcol = mf->col - (VIEW_X - VIEW_X/8);
708 1.1 cgd else if (mf->col > viewcol + (VIEW_X - VIEW_X/8))
709 1.1 cgd viewcol = mf->col - VIEW_X/8;
710 1.1 cgd }
711