X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/462fca95471224f85b85be911e72faee16cd1597..89a2669a8a8be664d488ac22db57f6c9f9f2b8ec:/sail/pl_7.c diff --git a/sail/pl_7.c b/sail/pl_7.c index f7156ba8..23172567 100644 --- a/sail/pl_7.c +++ b/sail/pl_7.c @@ -1,6 +1,8 @@ +/* $NetBSD: pl_7.c,v 1.34 2009/03/15 00:50:47 dholland Exp $ */ + /* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -10,11 +12,7 @@ * 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. * @@ -31,192 +29,218 @@ * SUCH DAMAGE. */ +#include #ifndef lint -/*static char sccsid[] = "from: @(#)pl_7.c 5.7 (Berkeley) 2/28/91";*/ -static char rcsid[] = "$Id: pl_7.c,v 1.2 1993/08/01 18:51:35 mycroft Exp $"; +#if 0 +static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93"; +#else +__RCSID("$NetBSD: pl_7.c,v 1.34 2009/03/15 00:50:47 dholland Exp $"); +#endif #endif /* not lint */ +#include +#include +#include +#include +#include +#include +#include +#include "extern.h" #include "player.h" +#include "display.h" + +static void Scroll(void); +static void endprompt(int); /* * Display interface */ static char sc_hasprompt; -static char *sc_prompt; -static char *sc_buf; +static const char *sc_prompt; +static const char *sc_buf; static int sc_line; -initscreen() +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; +int dont_adjust; +int viewrow, viewcol; +char movebuf[sizeof SHIP(0)->file->movebuf]; +int player; +struct ship *ms; /* memorial structure, &cc->ship[player] */ +struct File *mf; /* ms->file */ +struct shipspecs *mc; /* ms->specs */ + +void +initscreen(void) { - /* initscr() already done in SCREENTEST() */ + if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) { + err(1, "signal(SIGTSTP)"); + } + + 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++; - (void) leaveok(view_w, 1); - (void) leaveok(slot_w, 1); - (void) leaveok(stat_w, 1); - (void) leaveok(turn_w, 1); -#ifdef SIGTSTP - { - void susp(); - (void) signal(SIGTSTP, susp); + + if (view_w == NULL || + slot_w == NULL || + scroll_w == NULL || + stat_w == NULL || + turn_w == NULL) { + endwin(); + errx(1, "Curses initialization failed."); } -#endif + + leaveok(view_w, 1); + leaveok(slot_w, 1); + leaveok(stat_w, 1); + leaveok(turn_w, 1); noecho(); - crmode(); + cbreak(); + + done_curses++; } -cleanupscreen() +void +cleanupscreen(void) { /* alarm already turned off */ if (done_curses) { - (void) wmove(scroll_w, SCROLL_Y - 1, 0); - (void) wclrtoeol(scroll_w); + wmove(scroll_w, SCROLL_Y - 1, 0); + wclrtoeol(scroll_w); draw_screen(); endwin(); } } +/*VARARGS2*/ void -newturn() +Signal(const char *fmt, struct ship *ship, ...) { - repaired = loaded = fired = changed = 0; - movebuf[0] = '\0'; - - (void) 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) - Write(W_DDEAD, SHIP(0), 0, 0, 0, 0, 0); + va_list ap; + char format[BUFSIZ]; - if (sc_hasprompt) { - (void) wmove(scroll_w, sc_line, 0); - (void) wclrtoeol(scroll_w); - } - if (Sync() < 0) - leave(LEAVE_SYNC); - if (!hasdriver) - leave(LEAVE_DRIVER); - if (sc_hasprompt) - (void) wprintw(scroll_w, "%s%s", sc_prompt, sc_buf); - - if (turn % 50 == 0) - Write(W_ALIVE, SHIP(0), 0, 0, 0, 0, 0); - if (mf->FS && (!mc->rig1 || windspeed == 6)) - Write(W_FS, ms, 0, 0, 0, 0, 0); - if (mf->FS == 1) - Write(W_FS, ms, 0, 2, 0, 0, 0); - - if (mf->struck) - leave(LEAVE_QUIT); - if (mf->captured != 0) - leave(LEAVE_CAPTURED); - if (windspeed == 7) - leave(LEAVE_HURRICAN); - - adjustview(); - draw_screen(); - - (void) signal(SIGALRM, newturn); - (void) alarm(7); + if (!done_curses) + return; + va_start(ap, ship); + if (*fmt == '\a') + putchar(*fmt++); + fmtship(format, sizeof(format), fmt, ship); + vwprintw(scroll_w, format, ap); + va_end(ap); + Scroll(); } /*VARARGS2*/ -Signal(fmt, ship, a, b, c, d) -char *fmt; -register struct ship *ship; -int a, b, c, d; +void +Msg(const char *fmt, ...) { + va_list ap; + if (!done_curses) return; - if (*fmt == '\7') + va_start(ap, fmt); + if (*fmt == '\a') putchar(*fmt++); - if (ship == 0) - (void) wprintw(scroll_w, fmt, a, b, c, d); - else - (void) wprintw(scroll_w, fmt, ship->shipname, - colours(ship), sterncolour(ship), a, b, c, d); + vwprintw(scroll_w, fmt, ap); + va_end(ap); Scroll(); } -Scroll() +static void +Scroll(void) { if (++sc_line >= SCROLL_Y) sc_line = 0; - (void) wmove(scroll_w, sc_line, 0); - (void) wclrtoeol(scroll_w); + wmove(scroll_w, sc_line, 0); + wclrtoeol(scroll_w); } -prompt(p, ship) -register char *p; -struct ship *ship; +void +prompt(const char *p, struct ship *ship) { - static char buf[60]; + static char buf[BUFSIZ]; - if (ship != 0) { - (void)sprintf(buf, p, ship->shipname, colours(ship), - sterncolour(ship)); - p = buf; - } - sc_prompt = p; + fmtship(buf, sizeof(buf), p, ship); + sc_prompt = buf; sc_buf = ""; sc_hasprompt = 1; - (void) waddstr(scroll_w, p); + waddstr(scroll_w, buf); } -endprompt(flag) -char flag; +static void +endprompt(int flag) { sc_hasprompt = 0; if (flag) Scroll(); } -sgetch(p, ship, flag) -char *p; -struct ship *ship; -char flag; +/* + * Next two functions called from newturn() to poke display. Shouldn't + * exist... XXX + */ + +void +display_hide_prompt(void) { - register c; + 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) +{ + int c; prompt(p, ship); blockalarm(); - (void) wrefresh(scroll_w); + wrefresh(scroll_w); unblockalarm(); while ((c = wgetch(scroll_w)) == EOF) ; if (flag && c >= ' ' && c < 0x7f) - (void) waddch(scroll_w, c); + waddch(scroll_w, c); endprompt(flag); return c; } -sgetstr(pr, buf, n) -char *pr; -register char *buf; -register n; +void +sgetstr(const char *pr, char *buf, int n) { - register c; - register char *p = buf; + int c; + char *p = buf; prompt(pr, (struct ship *)0); sc_buf = buf; for (;;) { *p = 0; blockalarm(); - (void) wrefresh(scroll_w); + wrefresh(scroll_w); unblockalarm(); while ((c = wgetch(scroll_w)) == EOF) ; @@ -227,236 +251,274 @@ register n; return; case '\b': if (p > buf) { - (void) waddstr(scroll_w, "\b \b"); + waddstr(scroll_w, "\b \b"); p--; } break; default: if (c >= ' ' && c < 0x7f && p < buf + n - 1) { *p++ = c; - (void) waddch(scroll_w, c); + waddch(scroll_w, c); } else - (void) putchar(CTRL('g')); + putchar('\a'); } } } -draw_screen() +void +draw_screen(void) { draw_view(); draw_turn(); draw_stat(); draw_slot(); - (void) wrefresh(scroll_w); /* move the cursor */ + wrefresh(scroll_w); /* move the cursor */ } -draw_view() +void +draw_view(void) { - register struct ship *sp; + struct ship *sp; - (void) werase(view_w); + werase(view_w); foreachship(sp) { if (sp->file->dir && sp->file->row > viewrow && sp->file->row < viewrow + VIEW_Y && sp->file->col > viewcol && sp->file->col < viewcol + VIEW_X) { - (void) wmove(view_w, sp->file->row - viewrow, + wmove(view_w, sp->file->row - viewrow, sp->file->col - viewcol); - (void) waddch(view_w, colours(sp)); - (void) wmove(view_w, + waddch(view_w, colours(sp)); + wmove(view_w, sternrow(sp) - viewrow, sterncol(sp) - viewcol); - (void) waddch(view_w, sterncolour(sp)); + waddch(view_w, sterncolour(sp)); } } - (void) wrefresh(view_w); + wrefresh(view_w); } -draw_turn() +void +draw_turn(void) { - (void) wmove(turn_w, 0, 0); - (void) wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn); - (void) wrefresh(turn_w); + wmove(turn_w, 0, 0); + wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn); + wrefresh(turn_w); } -draw_stat() +void +draw_stat(void) { - (void) wmove(stat_w, STAT_1, 0); - (void) wprintw(stat_w, "Points %3d\n", mf->points); - (void) wprintw(stat_w, "Fouls %2d\n", fouled(ms)); - (void) wprintw(stat_w, "Grapples %2d\n", grappled(ms)); + wmove(stat_w, STAT_1, 0); + wprintw(stat_w, "Points %3d\n", mf->points); + wprintw(stat_w, "Fouls %2d\n", fouled(ms)); + wprintw(stat_w, "Grapples %2d\n", grappled(ms)); - (void) wmove(stat_w, STAT_2, 0); - (void) wprintw(stat_w, " 0 %c(%c)\n", + wmove(stat_w, STAT_2, 0); + wprintw(stat_w, " 0 %c(%c)\n", maxmove(ms, winddir + 3, -1) + '0', maxmove(ms, winddir + 3, 1) + '0'); - (void) waddstr(stat_w, " \\|/\n"); - (void) wprintw(stat_w, " -^-%c(%c)\n", + waddstr(stat_w, " \\|/\n"); + wprintw(stat_w, " -^-%c(%c)\n", maxmove(ms, winddir + 2, -1) + '0', maxmove(ms, winddir + 2, 1) + '0'); - (void) waddstr(stat_w, " /|\\\n"); - (void) wprintw(stat_w, " | %c(%c)\n", + waddstr(stat_w, " /|\\\n"); + wprintw(stat_w, " | %c(%c)\n", maxmove(ms, winddir + 1, -1) + '0', maxmove(ms, winddir + 1, 1) + '0'); - (void) wprintw(stat_w, " %c(%c)\n", + wprintw(stat_w, " %c(%c)\n", maxmove(ms, winddir, -1) + '0', maxmove(ms, winddir, 1) + '0'); - (void) wmove(stat_w, STAT_3, 0); - (void) wprintw(stat_w, "Load %c%c %c%c\n", + wmove(stat_w, STAT_3, 0); + wprintw(stat_w, "Load %c%c %c%c\n", loadname[mf->loadL], readyname(mf->readyL), loadname[mf->loadR], readyname(mf->readyR)); - (void) wprintw(stat_w, "Hull %2d\n", mc->hull); - (void) wprintw(stat_w, "Crew %2d %2d %2d\n", + wprintw(stat_w, "Hull %2d\n", mc->hull); + wprintw(stat_w, "Crew %2d %2d %2d\n", mc->crew1, mc->crew2, mc->crew3); - (void) wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR); - (void) wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR); - (void) wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3); + wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR); + wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR); + wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3); if (mc->rig4 < 0) - (void) waddch(stat_w, '-'); + waddch(stat_w, '-'); else - (void) wprintw(stat_w, "%d", mc->rig4); - (void) wrefresh(stat_w); + wprintw(stat_w, "%d", mc->rig4); + wrefresh(stat_w); } -draw_slot() +void +draw_slot(void) { if (!boarding(ms, 0)) { - (void) mvwaddstr(slot_w, 0, 0, " "); - (void) mvwaddstr(slot_w, 1, 0, " "); + mvwaddstr(slot_w, 0, 0, " "); + mvwaddstr(slot_w, 1, 0, " "); } else - (void) mvwaddstr(slot_w, 1, 0, "OBP"); + mvwaddstr(slot_w, 1, 0, "OBP"); if (!boarding(ms, 1)) { - (void) mvwaddstr(slot_w, 2, 0, " "); - (void) mvwaddstr(slot_w, 3, 0, " "); + mvwaddstr(slot_w, 2, 0, " "); + mvwaddstr(slot_w, 3, 0, " "); } else - (void) mvwaddstr(slot_w, 3, 0, "DBP"); + mvwaddstr(slot_w, 3, 0, "DBP"); - (void) wmove(slot_w, SLOT_Y-4, 0); + wmove(slot_w, SLOT_Y-4, 0); if (mf->RH) - (void) wprintw(slot_w, "%dRH", mf->RH); + wprintw(slot_w, "%dRH", mf->RH); else - (void) waddstr(slot_w, " "); - (void) wmove(slot_w, SLOT_Y-3, 0); + waddstr(slot_w, " "); + wmove(slot_w, SLOT_Y-3, 0); if (mf->RG) - (void) wprintw(slot_w, "%dRG", mf->RG); + wprintw(slot_w, "%dRG", mf->RG); else - (void) waddstr(slot_w, " "); - (void) wmove(slot_w, SLOT_Y-2, 0); + waddstr(slot_w, " "); + wmove(slot_w, SLOT_Y-2, 0); if (mf->RR) - (void) wprintw(slot_w, "%dRR", mf->RR); + wprintw(slot_w, "%dRR", mf->RR); else - (void) waddstr(slot_w, " "); + waddstr(slot_w, " "); #define Y (SLOT_Y/2) - (void) wmove(slot_w, 7, 1); - (void) wprintw(slot_w,"%d", windspeed); - (void) mvwaddch(slot_w, Y, 0, ' '); - (void) mvwaddch(slot_w, Y, 2, ' '); - (void) mvwaddch(slot_w, Y-1, 0, ' '); - (void) mvwaddch(slot_w, Y-1, 1, ' '); - (void) mvwaddch(slot_w, Y-1, 2, ' '); - (void) mvwaddch(slot_w, Y+1, 0, ' '); - (void) mvwaddch(slot_w, Y+1, 1, ' '); - (void) mvwaddch(slot_w, Y+1, 2, ' '); - (void) wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]); + wmove(slot_w, 7, 1); + wprintw(slot_w,"%d", windspeed); + mvwaddch(slot_w, Y, 0, ' '); + mvwaddch(slot_w, Y, 2, ' '); + mvwaddch(slot_w, Y-1, 0, ' '); + mvwaddch(slot_w, Y-1, 1, ' '); + mvwaddch(slot_w, Y-1, 2, ' '); + mvwaddch(slot_w, Y+1, 0, ' '); + mvwaddch(slot_w, Y+1, 1, ' '); + mvwaddch(slot_w, Y+1, 2, ' '); + wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]); switch (winddir) { case 1: case 5: - (void) waddch(slot_w, '|'); + waddch(slot_w, '|'); break; case 2: case 6: - (void) waddch(slot_w, '/'); + waddch(slot_w, '/'); break; case 3: case 7: - (void) waddch(slot_w, '-'); + waddch(slot_w, '-'); break; case 4: case 8: - (void) waddch(slot_w, '\\'); + waddch(slot_w, '\\'); break; } - (void) mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+'); - (void) wrefresh(slot_w); + mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+'); + wrefresh(slot_w); } -draw_board() +void +draw_board(void) { - register int n; + int n; - (void) clear(); - (void) werase(view_w); - (void) werase(slot_w); - (void) werase(scroll_w); - (void) werase(stat_w); - (void) werase(turn_w); + clear(); + werase(view_w); + werase(slot_w); + werase(scroll_w); + werase(stat_w); + werase(turn_w); sc_line = 0; - (void) move(BOX_T, BOX_L); + move(BOX_T, BOX_L); for (n = 0; n < BOX_X; n++) - (void) addch('-'); - (void) move(BOX_B, BOX_L); + addch('-'); + move(BOX_B, BOX_L); for (n = 0; n < BOX_X; n++) - (void) addch('-'); + addch('-'); for (n = BOX_T+1; n < BOX_B; n++) { - (void) mvaddch(n, BOX_L, '|'); - (void) mvaddch(n, BOX_R, '|'); + mvaddch(n, BOX_L, '|'); + mvaddch(n, BOX_R, '|'); } - (void) mvaddch(BOX_T, BOX_L, '+'); - (void) mvaddch(BOX_T, BOX_R, '+'); - (void) mvaddch(BOX_B, BOX_L, '+'); - (void) mvaddch(BOX_B, BOX_R, '+'); - (void) refresh(); + mvaddch(BOX_T, BOX_L, '+'); + mvaddch(BOX_T, BOX_R, '+'); + mvaddch(BOX_B, BOX_L, '+'); + mvaddch(BOX_B, BOX_R, '+'); + refresh(); #define WSaIM "Wooden Ships & Iron Men" - (void) wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2); - (void) waddstr(view_w, WSaIM); - (void) wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2); - (void) waddstr(view_w, cc->name); - (void) wrefresh(view_w); - - (void) move(LINE_T, LINE_L); - (void) printw("Class %d %s (%d guns) '%s' (%c%c)", + wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2); + waddstr(view_w, WSaIM); + wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2); + waddstr(view_w, cc->name); + wrefresh(view_w); + + move(LINE_T, LINE_L); + printw("Class %d %s (%d guns) '%s' (%c%c)", mc->class, classname[mc->class], mc->guns, ms->shipname, colours(ms), sterncolour(ms)); - (void) refresh(); + refresh(); +} + +/* Called after show_[od]bp. Shouldn't really exist... XXX */ +void +display_refresh_slot_w(void) +{ + blockalarm(); + wrefresh(slot_w); + unblockalarm(); } -centerview() +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) { viewrow = mf->row - VIEW_Y / 2; viewcol = mf->col - VIEW_X / 2; } -upview() +void +upview(void) { viewrow -= VIEW_Y / 3; } -downview() +void +downview(void) { viewrow += VIEW_Y / 3; } -leftview() +void +leftview(void) { viewcol -= VIEW_X / 5; } -rightview() +void +rightview(void) { viewcol += VIEW_X / 5; } -adjustview() +/* Called from newturn()... rename? */ +void +display_adjust_view(void) { if (dont_adjust) return; @@ -469,14 +531,3 @@ adjustview() else if (mf->col > viewcol + (VIEW_X - VIEW_X/8)) viewcol = mf->col - VIEW_X/8; } - -#ifdef SIGTSTP -void -susp() -{ - blockalarm(); - tstp(); - (void) signal(SIGTSTP, susp); - unblockalarm(); -} -#endif