-/* $NetBSD: pl_7.c,v 1.32 2009/03/14 22:52:53 dholland Exp $ */
+/* $NetBSD: pl_7.c,v 1.34 2009/03/15 00:50:47 dholland Exp $ */
/*
* Copyright (c) 1983, 1993
#if 0
static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: pl_7.c,v 1.32 2009/03/14 22:52:53 dholland Exp $");
+__RCSID("$NetBSD: pl_7.c,v 1.34 2009/03/15 00:50:47 dholland Exp $");
#endif
#endif /* not lint */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <string.h>
#include "extern.h"
#include "player.h"
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()) {
+ if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) {
+ err(1, "signal(SIGTSTP)");
+ }
+
+ if (initscr() == NULL) {
errx(1, "Can't sail on this terminal.");
}
- /* initscr() already done in SCREENTEST() */
+ 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();
cbreak();
+
+ done_curses++;
}
void
}
}
-/*ARGSUSED*/
-void
-newturn(int n __unused)
-{
- repaired = loaded = fired = changed = 0;
- movebuf[0] = '\0';
-
- alarm(0);
- if (mf->readyL & R_LOADING) {
- if (mf->readyL & R_DOUBLE)
- mf->readyL = R_LOADING;
- else
- mf->readyL = R_LOADED;
- }
- if (mf->readyR & R_LOADING) {
- if (mf->readyR & R_DOUBLE)
- mf->readyR = R_LOADING;
- else
- mf->readyR = R_LOADED;
- }
- if (!hasdriver)
- send_ddead();
-
- if (sc_hasprompt) {
- wmove(scroll_w, sc_line, 0);
- wclrtoeol(scroll_w);
- }
- if (Sync() < 0)
- leave(LEAVE_SYNC);
- if (!hasdriver)
- leave(LEAVE_DRIVER);
- if (sc_hasprompt)
- wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
-
- if (turn % 50 == 0)
- send_alive();
- if (mf->FS && (!mc->rig1 || windspeed == 6))
- send_fs(ms, 0);
- if (mf->FS == 1)
- send_fs(ms, 2);
-
- if (mf->struck)
- leave(LEAVE_QUIT);
- if (mf->captured != 0)
- leave(LEAVE_CAPTURED);
- if (windspeed == 7)
- leave(LEAVE_HURRICAN);
-
- adjustview();
- draw_screen();
-
- signal(SIGALRM, newturn);
- alarm(7);
-}
-
/*VARARGS2*/
void
Signal(const char *fmt, struct ship *ship, ...)
Scroll();
}
+/*
+ * Next two functions called from newturn() to poke display. Shouldn't
+ * exist... XXX
+ */
+
+void
+display_hide_prompt(void)
+{
+ if (sc_hasprompt) {
+ wmove(scroll_w, sc_line, 0);
+ wclrtoeol(scroll_w);
+ }
+}
+
+void
+display_reshow_prompt(void)
+{
+ if (sc_hasprompt)
+ wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
+}
+
+
int
sgetch(const char *p, struct ship *ship, int flag)
{
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)
{
viewcol += VIEW_X / 5;
}
-static void
-adjustview(void)
+/* Called from newturn()... rename? */
+void
+display_adjust_view(void)
{
if (dont_adjust)
return;