2009-03-16 01:19:23 +03:00
|
|
|
/* $NetBSD: pl_7.c,v 1.37 2009/03/15 22:19:23 dholland Exp $ */
|
1995-04-22 14:36:43 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-04-22 14:36:43 +04:00
|
|
|
* Copyright (c) 1983, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 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.
|
2003-08-07 13:36:50 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-04-22 14:36:43 +04:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
2009-03-16 01:19:23 +03:00
|
|
|
__RCSID("$NetBSD: pl_7.c,v 1.37 2009/03/15 22:19:23 dholland Exp $");
|
1995-04-22 14:36:43 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2001-01-04 07:41:41 +03:00
|
|
|
#include <curses.h>
|
2009-03-02 10:17:24 +03:00
|
|
|
#include <err.h>
|
2009-03-15 06:33:56 +03:00
|
|
|
#include <errno.h>
|
2001-01-04 06:51:23 +03:00
|
|
|
#include <signal.h>
|
1997-10-13 23:42:53 +04:00
|
|
|
#include <stdarg.h>
|
2001-01-04 06:21:16 +03:00
|
|
|
#include <stdio.h>
|
2001-01-16 05:44:43 +03:00
|
|
|
#include <stdlib.h>
|
2001-01-04 09:33:18 +03:00
|
|
|
#include <string.h>
|
2009-03-15 06:33:56 +03:00
|
|
|
#include "array.h"
|
2001-01-04 07:41:41 +03:00
|
|
|
#include "extern.h"
|
2001-01-04 06:21:16 +03:00
|
|
|
#include "player.h"
|
2001-01-04 07:41:41 +03:00
|
|
|
#include "display.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
/*
|
|
|
|
* Use values above KEY_MAX for custom keycodes. (blymn@ says this is ok)
|
|
|
|
*/
|
|
|
|
#define KEY_ESC(ch) (KEY_MAX+10+ch)
|
|
|
|
|
1995-04-22 14:36:43 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* Display interface
|
|
|
|
*/
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
static void draw_view(void);
|
|
|
|
static void draw_turn(void);
|
|
|
|
static void draw_stat(void);
|
|
|
|
static void draw_slot(void);
|
|
|
|
static void draw_board(void);
|
|
|
|
|
|
|
|
static struct stringarray *sc_lines;
|
|
|
|
static unsigned sc_scrollup;
|
|
|
|
static bool sc_hasprompt;
|
|
|
|
static bool sc_hideprompt;
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
static const char *sc_prompt;
|
|
|
|
static const char *sc_buf;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-03-15 03:35:42 +03:00
|
|
|
static WINDOW *view_w;
|
2009-03-15 06:33:56 +03:00
|
|
|
static WINDOW *turn_w;
|
|
|
|
static WINDOW *stat_w;
|
2009-03-15 03:35:42 +03:00
|
|
|
static WINDOW *slot_w;
|
|
|
|
static WINDOW *scroll_w;
|
2009-03-15 06:33:56 +03:00
|
|
|
|
|
|
|
static bool obp[3];
|
|
|
|
static bool dbp[3];
|
1999-12-28 21:05:24 +03:00
|
|
|
|
2001-01-04 08:34:56 +03:00
|
|
|
int done_curses;
|
|
|
|
int loaded, fired, changed, repaired;
|
|
|
|
int dont_adjust;
|
1999-12-28 21:05:24 +03:00
|
|
|
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 */
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// overall initialization
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
define_esc_key(int ch)
|
|
|
|
{
|
|
|
|
char seq[3] = { '\x1b', ch, 0 };
|
|
|
|
|
|
|
|
define_key(seq, KEY_ESC(ch));
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
initscreen(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
int ch;
|
|
|
|
|
|
|
|
sc_lines = stringarray_create();
|
|
|
|
if (sc_lines == NULL) {
|
|
|
|
err(1, "malloc");
|
|
|
|
}
|
|
|
|
|
2009-03-15 03:35:42 +03:00
|
|
|
if (signal(SIGTSTP, SIG_DFL) == SIG_ERR) {
|
|
|
|
err(1, "signal(SIGTSTP)");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initscr() == NULL) {
|
2009-03-02 10:17:24 +03:00
|
|
|
errx(1, "Can't sail on this terminal.");
|
2000-01-31 14:08:53 +03:00
|
|
|
}
|
2009-03-15 03:35:42 +03:00
|
|
|
if (STAT_R >= COLS || SCROLL_Y <= 0) {
|
|
|
|
errx(1, "Window/terminal not large enough.");
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
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);
|
2009-03-15 03:35:42 +03:00
|
|
|
|
|
|
|
if (view_w == NULL ||
|
|
|
|
slot_w == NULL ||
|
|
|
|
scroll_w == NULL ||
|
|
|
|
stat_w == NULL ||
|
|
|
|
turn_w == NULL) {
|
|
|
|
endwin();
|
|
|
|
errx(1, "Curses initialization failed.");
|
|
|
|
}
|
|
|
|
|
2001-01-02 00:57:37 +03:00
|
|
|
leaveok(view_w, 1);
|
|
|
|
leaveok(slot_w, 1);
|
|
|
|
leaveok(stat_w, 1);
|
|
|
|
leaveok(turn_w, 1);
|
1993-03-21 12:45:37 +03:00
|
|
|
noecho();
|
2001-12-06 15:21:00 +03:00
|
|
|
cbreak();
|
2009-03-15 03:35:42 +03:00
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
/*
|
|
|
|
* Define esc-x keys
|
|
|
|
*/
|
|
|
|
for (ch = 0; ch < 127; ch++) {
|
|
|
|
define_esc_key(ch);
|
|
|
|
}
|
|
|
|
|
2009-03-15 03:35:42 +03:00
|
|
|
done_curses++;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
cleanupscreen(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
/* alarm already turned off */
|
|
|
|
if (done_curses) {
|
2001-01-02 00:57:37 +03:00
|
|
|
wmove(scroll_w, SCROLL_Y - 1, 0);
|
|
|
|
wclrtoeol(scroll_w);
|
2009-03-15 06:33:56 +03:00
|
|
|
display_redraw();
|
1993-03-21 12:45:37 +03:00
|
|
|
endwin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// scrolling message area
|
|
|
|
|
|
|
|
static void
|
|
|
|
scrollarea_add(const char *text)
|
|
|
|
{
|
|
|
|
char *copy;
|
|
|
|
int errsave;
|
|
|
|
|
|
|
|
copy = strdup(text);
|
|
|
|
if (copy == NULL) {
|
|
|
|
goto nomem;
|
|
|
|
}
|
|
|
|
if (stringarray_add(sc_lines, copy, NULL)) {
|
|
|
|
goto nomem;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
nomem:
|
|
|
|
/*
|
|
|
|
* XXX this should use leave(), but that won't
|
|
|
|
* currently work right.
|
|
|
|
*/
|
|
|
|
errsave = errno;
|
|
|
|
#if 0
|
|
|
|
leave(LEAVE_MALLOC);
|
|
|
|
#else
|
|
|
|
cleanupscreen();
|
|
|
|
sync_close(!hasdriver);
|
|
|
|
errno = errsave;
|
|
|
|
err(1, "malloc");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
draw_scroll(void)
|
|
|
|
{
|
|
|
|
unsigned total_lines;
|
|
|
|
unsigned visible_lines;
|
|
|
|
unsigned index_of_top;
|
|
|
|
unsigned index_of_y;
|
|
|
|
unsigned y;
|
|
|
|
unsigned cursorx;
|
|
|
|
|
|
|
|
werase(scroll_w);
|
|
|
|
|
2009-03-16 01:19:23 +03:00
|
|
|
/* XXX: SCROLL_Y and whatnot should be unsigned too */
|
2009-03-15 06:33:56 +03:00
|
|
|
visible_lines = SCROLL_Y - 1;
|
|
|
|
|
|
|
|
total_lines = stringarray_num(sc_lines);
|
|
|
|
if (total_lines > visible_lines) {
|
|
|
|
index_of_top = total_lines - visible_lines;
|
|
|
|
} else {
|
|
|
|
index_of_top = 0;
|
|
|
|
}
|
|
|
|
if (index_of_top < sc_scrollup) {
|
|
|
|
index_of_top = 0;
|
|
|
|
} else {
|
|
|
|
index_of_top -= sc_scrollup;
|
|
|
|
}
|
|
|
|
|
2009-03-16 01:19:23 +03:00
|
|
|
for (y = 0; y < visible_lines; y++) {
|
2009-03-15 06:33:56 +03:00
|
|
|
index_of_y = index_of_top + y;
|
|
|
|
if (index_of_y >= total_lines) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
wmove(scroll_w, y, 0);
|
|
|
|
waddstr(scroll_w, stringarray_get(sc_lines, index_of_y));
|
|
|
|
}
|
|
|
|
if (sc_hasprompt && !sc_hideprompt) {
|
|
|
|
wmove(scroll_w, SCROLL_Y-1, 0);
|
|
|
|
waddstr(scroll_w, sc_prompt);
|
|
|
|
waddstr(scroll_w, sc_buf);
|
|
|
|
cursorx = strlen(sc_prompt) + strlen(sc_buf);
|
|
|
|
wmove(scroll_w, SCROLL_Y-1, cursorx);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wmove(scroll_w, SCROLL_Y-1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*VARARGS2*/
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
|
|
|
Signal(const char *fmt, struct ship *ship, ...)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-13 23:42:53 +04:00
|
|
|
va_list ap;
|
|
|
|
char format[BUFSIZ];
|
2009-03-15 06:33:56 +03:00
|
|
|
char buf[BUFSIZ];
|
1997-10-13 23:42:53 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!done_curses)
|
|
|
|
return;
|
2001-09-24 17:22:25 +04:00
|
|
|
va_start(ap, ship);
|
2009-03-15 06:33:56 +03:00
|
|
|
if (*fmt == '\a') {
|
|
|
|
beep();
|
|
|
|
fmt++;
|
|
|
|
}
|
1997-10-13 23:42:53 +04:00
|
|
|
fmtship(format, sizeof(format), fmt, ship);
|
2009-03-15 06:33:56 +03:00
|
|
|
vsnprintf(buf, sizeof(buf), format, ap);
|
1997-10-13 23:42:53 +04:00
|
|
|
va_end(ap);
|
2009-03-15 06:33:56 +03:00
|
|
|
scrollarea_add(buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
/*VARARGS2*/
|
|
|
|
void
|
|
|
|
Msg(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
2009-03-15 06:33:56 +03:00
|
|
|
char buf[BUFSIZ];
|
1997-10-13 23:42:53 +04:00
|
|
|
|
|
|
|
if (!done_curses)
|
|
|
|
return;
|
2001-09-24 17:22:25 +04:00
|
|
|
va_start(ap, fmt);
|
2009-03-15 06:33:56 +03:00
|
|
|
if (*fmt == '\a') {
|
|
|
|
beep();
|
|
|
|
fmt++;
|
|
|
|
}
|
|
|
|
vsnprintf(buf, sizeof(buf), fmt, ap);
|
1997-10-13 23:42:53 +04:00
|
|
|
va_end(ap);
|
2009-03-15 06:33:56 +03:00
|
|
|
scrollarea_add(buf);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-04 05:43:32 +03:00
|
|
|
prompt(const char *p, struct ship *ship)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-14 01:02:57 +04:00
|
|
|
static char buf[BUFSIZ];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-14 01:02:57 +04:00
|
|
|
fmtship(buf, sizeof(buf), p, ship);
|
|
|
|
sc_prompt = buf;
|
1993-03-21 12:45:37 +03:00
|
|
|
sc_buf = "";
|
2009-03-15 06:33:56 +03:00
|
|
|
sc_hasprompt = true;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2001-01-04 05:43:32 +03:00
|
|
|
static void
|
2009-03-15 06:33:56 +03:00
|
|
|
endprompt(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
sc_prompt = NULL;
|
|
|
|
sc_buf = NULL;
|
|
|
|
sc_hasprompt = false;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 03:50:47 +03:00
|
|
|
/*
|
|
|
|
* Next two functions called from newturn() to poke display. Shouldn't
|
|
|
|
* exist... XXX
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
display_hide_prompt(void)
|
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
sc_hideprompt = true;
|
|
|
|
draw_scroll();
|
|
|
|
wrefresh(scroll_w);
|
2009-03-15 03:50:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
display_reshow_prompt(void)
|
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
sc_hideprompt = false;
|
|
|
|
draw_scroll();
|
|
|
|
wrefresh(scroll_w);
|
2009-03-15 03:50:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
int
|
2001-01-02 00:57:37 +03:00
|
|
|
sgetch(const char *p, struct ship *ship, int flag)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-13 23:42:53 +04:00
|
|
|
int c;
|
2009-03-15 06:33:56 +03:00
|
|
|
char input[2];
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
prompt(p, ship);
|
2009-03-15 06:33:56 +03:00
|
|
|
input[0] = '\0';
|
|
|
|
input[1] = '\0';
|
|
|
|
sc_buf = input;
|
1993-03-21 12:45:37 +03:00
|
|
|
blockalarm();
|
2009-03-15 06:33:56 +03:00
|
|
|
draw_scroll();
|
2001-01-02 00:57:37 +03:00
|
|
|
wrefresh(scroll_w);
|
2009-03-15 06:33:56 +03:00
|
|
|
fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
unblockalarm();
|
|
|
|
while ((c = wgetch(scroll_w)) == EOF)
|
|
|
|
;
|
2009-03-15 06:33:56 +03:00
|
|
|
if (flag && c >= ' ' && c < 0x7f) {
|
|
|
|
blockalarm();
|
|
|
|
input[0] = c;
|
|
|
|
draw_scroll();
|
|
|
|
wrefresh(scroll_w);
|
|
|
|
fflush(stdout);
|
|
|
|
unblockalarm();
|
|
|
|
}
|
|
|
|
endprompt();
|
1993-03-21 12:45:37 +03:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
sgetstr(const char *pr, char *buf, int n)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-13 23:42:53 +04:00
|
|
|
int c;
|
|
|
|
char *p = buf;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
prompt(pr, (struct ship *)0);
|
|
|
|
sc_buf = buf;
|
|
|
|
for (;;) {
|
|
|
|
*p = 0;
|
|
|
|
blockalarm();
|
2009-03-15 06:33:56 +03:00
|
|
|
draw_scroll();
|
2001-01-02 00:57:37 +03:00
|
|
|
wrefresh(scroll_w);
|
2009-03-15 06:33:56 +03:00
|
|
|
fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
unblockalarm();
|
|
|
|
while ((c = wgetch(scroll_w)) == EOF)
|
|
|
|
;
|
|
|
|
switch (c) {
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
2009-03-15 06:33:56 +03:00
|
|
|
endprompt();
|
1993-03-21 12:45:37 +03:00
|
|
|
return;
|
|
|
|
case '\b':
|
|
|
|
if (p > buf) {
|
2009-03-15 06:33:56 +03:00
|
|
|
/*waddstr(scroll_w, "\b \b");*/
|
1993-03-21 12:45:37 +03:00
|
|
|
p--;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (c >= ' ' && c < 0x7f && p < buf + n - 1) {
|
|
|
|
*p++ = c;
|
2009-03-15 06:33:56 +03:00
|
|
|
/*waddch(scroll_w, c);*/
|
1993-03-21 12:45:37 +03:00
|
|
|
} else
|
2009-03-15 06:33:56 +03:00
|
|
|
beep();
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// drawing of other panes
|
|
|
|
|
|
|
|
void
|
|
|
|
display_force_full_redraw(void)
|
|
|
|
{
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2009-03-15 06:33:56 +03:00
|
|
|
display_redraw(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
draw_board();
|
1993-03-21 12:45:37 +03:00
|
|
|
draw_view();
|
|
|
|
draw_turn();
|
|
|
|
draw_stat();
|
|
|
|
draw_slot();
|
2009-03-15 06:33:56 +03:00
|
|
|
draw_scroll();
|
|
|
|
/* move the cursor */
|
|
|
|
wrefresh(scroll_w);
|
|
|
|
/* paranoia */
|
|
|
|
fflush(stdout);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
static void
|
2001-01-02 00:57:37 +03:00
|
|
|
draw_view(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-13 23:42:53 +04:00
|
|
|
struct ship *sp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-01-02 00:57:37 +03:00
|
|
|
werase(view_w);
|
1993-03-21 12:45:37 +03:00
|
|
|
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) {
|
2001-01-02 00:57:37 +03:00
|
|
|
wmove(view_w, sp->file->row - viewrow,
|
1993-03-21 12:45:37 +03:00
|
|
|
sp->file->col - viewcol);
|
2001-01-02 00:57:37 +03:00
|
|
|
waddch(view_w, colours(sp));
|
|
|
|
wmove(view_w,
|
1993-03-21 12:45:37 +03:00
|
|
|
sternrow(sp) - viewrow,
|
|
|
|
sterncol(sp) - viewcol);
|
2001-01-02 00:57:37 +03:00
|
|
|
waddch(view_w, sterncolour(sp));
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
2001-01-02 00:57:37 +03:00
|
|
|
wrefresh(view_w);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
static void
|
2001-01-02 00:57:37 +03:00
|
|
|
draw_turn(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-01-02 00:57:37 +03:00
|
|
|
wmove(turn_w, 0, 0);
|
|
|
|
wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn);
|
|
|
|
wrefresh(turn_w);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
static void
|
2001-01-02 00:57:37 +03:00
|
|
|
draw_stat(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2001-01-02 00:57:37 +03:00
|
|
|
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));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-01-02 00:57:37 +03:00
|
|
|
wmove(stat_w, STAT_2, 0);
|
|
|
|
wprintw(stat_w, " 0 %c(%c)\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
maxmove(ms, winddir + 3, -1) + '0',
|
|
|
|
maxmove(ms, winddir + 3, 1) + '0');
|
2001-01-02 00:57:37 +03:00
|
|
|
waddstr(stat_w, " \\|/\n");
|
|
|
|
wprintw(stat_w, " -^-%c(%c)\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
maxmove(ms, winddir + 2, -1) + '0',
|
|
|
|
maxmove(ms, winddir + 2, 1) + '0');
|
2001-01-02 00:57:37 +03:00
|
|
|
waddstr(stat_w, " /|\\\n");
|
|
|
|
wprintw(stat_w, " | %c(%c)\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
maxmove(ms, winddir + 1, -1) + '0',
|
|
|
|
maxmove(ms, winddir + 1, 1) + '0');
|
2001-01-02 00:57:37 +03:00
|
|
|
wprintw(stat_w, " %c(%c)\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
maxmove(ms, winddir, -1) + '0',
|
|
|
|
maxmove(ms, winddir, 1) + '0');
|
|
|
|
|
2001-01-02 00:57:37 +03:00
|
|
|
wmove(stat_w, STAT_3, 0);
|
|
|
|
wprintw(stat_w, "Load %c%c %c%c\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
loadname[mf->loadL], readyname(mf->readyL),
|
|
|
|
loadname[mf->loadR], readyname(mf->readyR));
|
2001-01-02 00:57:37 +03:00
|
|
|
wprintw(stat_w, "Hull %2d\n", mc->hull);
|
|
|
|
wprintw(stat_w, "Crew %2d %2d %2d\n",
|
1993-03-21 12:45:37 +03:00
|
|
|
mc->crew1, mc->crew2, mc->crew3);
|
2001-01-02 00:57:37 +03:00
|
|
|
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);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (mc->rig4 < 0)
|
2001-01-02 00:57:37 +03:00
|
|
|
waddch(stat_w, '-');
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2001-01-02 00:57:37 +03:00
|
|
|
wprintw(stat_w, "%d", mc->rig4);
|
|
|
|
wrefresh(stat_w);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
draw_slot(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
int i;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!boarding(ms, 0)) {
|
2001-01-02 00:57:37 +03:00
|
|
|
mvwaddstr(slot_w, 0, 0, " ");
|
|
|
|
mvwaddstr(slot_w, 1, 0, " ");
|
2009-03-15 06:33:56 +03:00
|
|
|
} else {
|
|
|
|
wmove(slot_w, 0, 0);
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
waddch(slot_w, obp[i] ? '1'+i : ' ');
|
|
|
|
}
|
2001-01-02 00:57:37 +03:00
|
|
|
mvwaddstr(slot_w, 1, 0, "OBP");
|
2009-03-15 06:33:56 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
if (!boarding(ms, 1)) {
|
2001-01-02 00:57:37 +03:00
|
|
|
mvwaddstr(slot_w, 2, 0, " ");
|
|
|
|
mvwaddstr(slot_w, 3, 0, " ");
|
2009-03-15 06:33:56 +03:00
|
|
|
} else {
|
|
|
|
wmove(slot_w, 2, 0);
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
waddch(slot_w, dbp[i] ? '1'+i : ' ');
|
|
|
|
}
|
2001-01-02 00:57:37 +03:00
|
|
|
mvwaddstr(slot_w, 3, 0, "DBP");
|
2009-03-15 06:33:56 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-01-02 00:57:37 +03:00
|
|
|
wmove(slot_w, SLOT_Y-4, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (mf->RH)
|
2001-01-02 00:57:37 +03:00
|
|
|
wprintw(slot_w, "%dRH", mf->RH);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2001-01-02 00:57:37 +03:00
|
|
|
waddstr(slot_w, " ");
|
|
|
|
wmove(slot_w, SLOT_Y-3, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (mf->RG)
|
2001-01-02 00:57:37 +03:00
|
|
|
wprintw(slot_w, "%dRG", mf->RG);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2001-01-02 00:57:37 +03:00
|
|
|
waddstr(slot_w, " ");
|
|
|
|
wmove(slot_w, SLOT_Y-2, 0);
|
1993-03-21 12:45:37 +03:00
|
|
|
if (mf->RR)
|
2001-01-02 00:57:37 +03:00
|
|
|
wprintw(slot_w, "%dRR", mf->RR);
|
1993-03-21 12:45:37 +03:00
|
|
|
else
|
2001-01-02 00:57:37 +03:00
|
|
|
waddstr(slot_w, " ");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
#define Y (SLOT_Y/2)
|
2001-01-02 00:57:37 +03:00
|
|
|
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]);
|
1993-03-21 12:45:37 +03:00
|
|
|
switch (winddir) {
|
|
|
|
case 1:
|
|
|
|
case 5:
|
2001-01-02 00:57:37 +03:00
|
|
|
waddch(slot_w, '|');
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 6:
|
2001-01-02 00:57:37 +03:00
|
|
|
waddch(slot_w, '/');
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 7:
|
2001-01-02 00:57:37 +03:00
|
|
|
waddch(slot_w, '-');
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
case 8:
|
2001-01-02 00:57:37 +03:00
|
|
|
waddch(slot_w, '\\');
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
2001-01-02 00:57:37 +03:00
|
|
|
mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+');
|
|
|
|
wrefresh(slot_w);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
draw_board(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-13 23:42:53 +04:00
|
|
|
int n;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
erase();
|
2001-01-02 00:57:37 +03:00
|
|
|
werase(view_w);
|
|
|
|
werase(slot_w);
|
|
|
|
werase(scroll_w);
|
|
|
|
werase(stat_w);
|
|
|
|
werase(turn_w);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2001-01-02 00:57:37 +03:00
|
|
|
move(BOX_T, BOX_L);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (n = 0; n < BOX_X; n++)
|
2001-01-02 00:57:37 +03:00
|
|
|
addch('-');
|
|
|
|
move(BOX_B, BOX_L);
|
1993-03-21 12:45:37 +03:00
|
|
|
for (n = 0; n < BOX_X; n++)
|
2001-01-02 00:57:37 +03:00
|
|
|
addch('-');
|
1993-03-21 12:45:37 +03:00
|
|
|
for (n = BOX_T+1; n < BOX_B; n++) {
|
2001-01-02 00:57:37 +03:00
|
|
|
mvaddch(n, BOX_L, '|');
|
|
|
|
mvaddch(n, BOX_R, '|');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
2001-01-02 00:57:37 +03:00
|
|
|
mvaddch(BOX_T, BOX_L, '+');
|
|
|
|
mvaddch(BOX_T, BOX_R, '+');
|
|
|
|
mvaddch(BOX_B, BOX_L, '+');
|
|
|
|
mvaddch(BOX_B, BOX_R, '+');
|
|
|
|
refresh();
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
#if 0
|
1993-03-21 12:45:37 +03:00
|
|
|
#define WSaIM "Wooden Ships & Iron Men"
|
2001-01-02 00:57:37 +03:00
|
|
|
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);
|
2009-03-15 06:33:56 +03:00
|
|
|
#endif
|
2001-01-02 00:57:37 +03:00
|
|
|
|
|
|
|
move(LINE_T, LINE_L);
|
|
|
|
printw("Class %d %s (%d guns) '%s' (%c%c)",
|
1993-03-21 12:45:37 +03:00
|
|
|
mc->class,
|
|
|
|
classname[mc->class],
|
|
|
|
mc->guns,
|
|
|
|
ms->shipname,
|
|
|
|
colours(ms),
|
|
|
|
sterncolour(ms));
|
2001-01-02 00:57:37 +03:00
|
|
|
refresh();
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 03:35:42 +03:00
|
|
|
void
|
2009-03-15 06:33:56 +03:00
|
|
|
display_set_obp(int which, bool show)
|
2009-03-15 03:35:42 +03:00
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
obp[which] = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
display_set_dbp(int which, bool show)
|
|
|
|
{
|
|
|
|
dbp[which] = show;
|
2009-03-15 03:35:42 +03:00
|
|
|
}
|
|
|
|
|
2009-03-15 06:33:56 +03:00
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// external actions on the display
|
|
|
|
|
2009-03-15 03:35:42 +03:00
|
|
|
void
|
2009-03-15 06:33:56 +03:00
|
|
|
display_scroll_pageup(void)
|
2009-03-15 03:35:42 +03:00
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
unsigned total_lines, visible_lines, limit;
|
|
|
|
unsigned pagesize = SCROLL_Y - 2;
|
|
|
|
|
|
|
|
total_lines = stringarray_num(sc_lines);
|
|
|
|
visible_lines = SCROLL_Y - 1;
|
|
|
|
limit = total_lines - visible_lines;
|
|
|
|
|
|
|
|
sc_scrollup += pagesize;
|
|
|
|
if (sc_scrollup > limit) {
|
|
|
|
sc_scrollup = limit;
|
|
|
|
}
|
2009-03-15 03:35:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-15 06:33:56 +03:00
|
|
|
display_scroll_pagedown(void)
|
2009-03-15 03:35:42 +03:00
|
|
|
{
|
2009-03-15 06:33:56 +03:00
|
|
|
unsigned pagesize = SCROLL_Y - 2;
|
|
|
|
|
|
|
|
if (sc_scrollup < pagesize) {
|
|
|
|
sc_scrollup = 0;
|
|
|
|
} else {
|
|
|
|
sc_scrollup -= pagesize;
|
|
|
|
}
|
2009-03-15 03:35:42 +03:00
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
centerview(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
viewrow = mf->row - VIEW_Y / 2;
|
|
|
|
viewcol = mf->col - VIEW_X / 2;
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
upview(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
viewrow -= VIEW_Y / 3;
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
downview(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
viewrow += VIEW_Y / 3;
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
leftview(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
viewcol -= VIEW_X / 5;
|
|
|
|
}
|
|
|
|
|
1997-10-13 23:42:53 +04:00
|
|
|
void
|
2001-01-02 00:57:37 +03:00
|
|
|
rightview(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
viewcol += VIEW_X / 5;
|
|
|
|
}
|
|
|
|
|
2009-03-15 03:50:47 +03:00
|
|
|
/* Called from newturn()... rename? */
|
|
|
|
void
|
|
|
|
display_adjust_view(void)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
if (dont_adjust)
|
|
|
|
return;
|
|
|
|
if (mf->row < viewrow + VIEW_Y/4)
|
|
|
|
viewrow = mf->row - (VIEW_Y - VIEW_Y/4);
|
|
|
|
else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4))
|
|
|
|
viewrow = mf->row - VIEW_Y/4;
|
|
|
|
if (mf->col < viewcol + VIEW_X/8)
|
|
|
|
viewcol = mf->col - (VIEW_X - VIEW_X/8);
|
|
|
|
else if (mf->col > viewcol + (VIEW_X - VIEW_X/8))
|
|
|
|
viewcol = mf->col - VIEW_X/8;
|
|
|
|
}
|