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