-/* $NetBSD: pl_7.c,v 1.21 2001/01/04 05:34:56 jwise Exp $ */
+/* $NetBSD: pl_7.c,v 1.33 2009/03/15 00:35:42 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#if 0
static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: pl_7.c,v 1.21 2001/01/04 05:34:56 jwise Exp $");
+__RCSID("$NetBSD: pl_7.c,v 1.33 2009/03/15 00:35:42 dholland Exp $");
#endif
#endif /* not lint */
#include <curses.h>
+#include <err.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
+#include <string.h>
#include "extern.h"
#include "player.h"
#include "display.h"
-void initscreen(void);
-void cleanupscreen(void);
-void newturn(int);
-void Signal(const char *, struct ship *, ...)
- __attribute__((__format__(__printf__,1,3)));
-void Msg(const char *, ...)
- __attribute__((__format__(__printf__,1,2)));
-static void Scroll(void);
-void prompt(const char *, struct ship *);
-static void endprompt(int);
-int sgetch(const char *, struct ship *, int);
-void sgetstr(const char *, char *, int);
-void draw_screen(void);
-void draw_view(void);
-void draw_turn(void);
-void draw_stat(void);
-void draw_slot(void);
-void draw_board(void);
-void centerview(void);
-void upview(void);
-void downview(void);
-void leftview(void);
-void rightview(void);
-static void adjustview(void);
+static void Scroll(void);
+static void endprompt(int);
+static void adjustview(void);
/*
* Display interface
static const char *sc_buf;
static int sc_line;
-WINDOW *view_w;
-WINDOW *slot_w;
-WINDOW *scroll_w;
-WINDOW *stat_w;
-WINDOW *turn_w;
+static WINDOW *view_w;
+static WINDOW *slot_w;
+static WINDOW *scroll_w;
+static WINDOW *stat_w;
+static WINDOW *turn_w;
int done_curses;
int loaded, fired, changed, repaired;
void
initscreen(void)
{
- if (!SCREENTEST()) {
- printf("Can't sail on this terminal.\n");
- exit(1);
+ if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) {
+ err(1, "signal(SIGTSTP)");
}
- /* initscr() already done in SCREENTEST() */
+
+ if (initscr() == NULL) {
+ errx(1, "Can't sail on this terminal.");
+ }
+ if (STAT_R >= COLS || SCROLL_Y <= 0) {
+ errx(1, "Window/terminal not large enough.");
+ }
+
view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L);
slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L);
scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L);
stat_w = newwin(STAT_Y, STAT_X, STAT_T, STAT_L);
turn_w = newwin(TURN_Y, TURN_X, TURN_T, TURN_L);
- done_curses++;
+
+ if (view_w == NULL ||
+ slot_w == NULL ||
+ scroll_w == NULL ||
+ stat_w == NULL ||
+ turn_w == NULL) {
+ endwin();
+ errx(1, "Curses initialization failed.");
+ }
+
leaveok(view_w, 1);
leaveok(slot_w, 1);
leaveok(stat_w, 1);
leaveok(turn_w, 1);
noecho();
- crmode();
+ cbreak();
+
+ done_curses++;
}
void
/*ARGSUSED*/
void
-newturn(int n __attribute__((__unused__)))
+newturn(int n __unused)
{
repaired = loaded = fired = changed = 0;
movebuf[0] = '\0';
mf->readyR = R_LOADED;
}
if (!hasdriver)
- Write(W_DDEAD, SHIP(0), 0, 0, 0, 0);
+ send_ddead();
if (sc_hasprompt) {
wmove(scroll_w, sc_line, 0);
wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
if (turn % 50 == 0)
- Write(W_ALIVE, SHIP(0), 0, 0, 0, 0);
+ send_alive();
if (mf->FS && (!mc->rig1 || windspeed == 6))
- Write(W_FS, ms, 0, 0, 0, 0);
+ send_fs(ms, 0);
if (mf->FS == 1)
- Write(W_FS, ms, 2, 0, 0, 0);
+ send_fs(ms, 2);
if (mf->struck)
leave(LEAVE_QUIT);
va_list ap;
char format[BUFSIZ];
- va_start(ap, ship);
if (!done_curses)
return;
- if (*fmt == '\7')
+ va_start(ap, ship);
+ if (*fmt == '\a')
putchar(*fmt++);
fmtship(format, sizeof(format), fmt, ship);
vwprintw(scroll_w, format, ap);
{
va_list ap;
- va_start(ap, fmt);
if (!done_curses)
return;
- if (*fmt == '\7')
+ va_start(ap, fmt);
+ if (*fmt == '\a')
putchar(*fmt++);
vwprintw(scroll_w, fmt, ap);
va_end(ap);
refresh();
}
+/* Called after show_[od]bp. Shouldn't really exist... XXX */
+void
+display_refresh_slot_w(void)
+{
+ blockalarm();
+ wrefresh(slot_w);
+ unblockalarm();
+}
+
+void
+display_show_obp(int which, bool show)
+{
+ wmove(slot_w, 0, which);
+ waddch(slot_w, show ? '1' + which : ' ');
+ mvwaddstr(slot_w, 1, 0, "OBP");
+}
+
+void
+display_show_dbp(int which, bool show)
+{
+ wmove(slot_w, 2, which);
+ waddch(slot_w, show ? '1' + which : ' ');
+ mvwaddstr(slot_w, 3, 0, "DBP");
+}
+
void
centerview(void)
{