]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.33 2009/03/15 00:35:42 dholland Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: pl_7.c,v 1.33 2009/03/15 00:35:42 dholland Exp $");
53 static void Scroll(void);
54 static void endprompt(int);
55 static void adjustview(void);
61 static char sc_hasprompt
;
62 static const char *sc_prompt
;
63 static const char *sc_buf
;
66 static WINDOW
*view_w
;
67 static WINDOW
*slot_w
;
68 static WINDOW
*scroll_w
;
69 static WINDOW
*stat_w
;
70 static WINDOW
*turn_w
;
73 int loaded
, fired
, changed
, repaired
;
76 char movebuf
[sizeof SHIP(0)->file
->movebuf
];
78 struct ship
*ms
; /* memorial structure, &cc->ship[player] */
79 struct File
*mf
; /* ms->file */
80 struct shipspecs
*mc
; /* ms->specs */
85 if (signal(SIGTSTP
, SIG_DFL
) == SIG_ERR
) {
86 err(1, "signal(SIGTSTP)");
89 if (initscr() == NULL
) {
90 errx(1, "Can't sail on this terminal.");
92 if (STAT_R
>= COLS
|| SCROLL_Y
<= 0) {
93 errx(1, "Window/terminal not large enough.");
96 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
97 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
98 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
99 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
100 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
102 if (view_w
== NULL
||
108 errx(1, "Curses initialization failed.");
124 /* alarm already turned off */
126 wmove(scroll_w
, SCROLL_Y
- 1, 0);
135 newturn(int n __unused
)
137 repaired
= loaded
= fired
= changed
= 0;
141 if (mf
->readyL
& R_LOADING
) {
142 if (mf
->readyL
& R_DOUBLE
)
143 mf
->readyL
= R_LOADING
;
145 mf
->readyL
= R_LOADED
;
147 if (mf
->readyR
& R_LOADING
) {
148 if (mf
->readyR
& R_DOUBLE
)
149 mf
->readyR
= R_LOADING
;
151 mf
->readyR
= R_LOADED
;
157 wmove(scroll_w
, sc_line
, 0);
165 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
169 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
176 if (mf
->captured
!= 0)
177 leave(LEAVE_CAPTURED
);
179 leave(LEAVE_HURRICAN
);
184 signal(SIGALRM
, newturn
);
190 Signal(const char *fmt
, struct ship
*ship
, ...)
200 fmtship(format
, sizeof(format
), fmt
, ship
);
201 vwprintw(scroll_w
, format
, ap
);
208 Msg(const char *fmt
, ...)
217 vwprintw(scroll_w
, fmt
, ap
);
225 if (++sc_line
>= SCROLL_Y
)
227 wmove(scroll_w
, sc_line
, 0);
232 prompt(const char *p
, struct ship
*ship
)
234 static char buf
[BUFSIZ
];
236 fmtship(buf
, sizeof(buf
), p
, ship
);
240 waddstr(scroll_w
, buf
);
252 sgetch(const char *p
, struct ship
*ship
, int flag
)
259 while ((c
= wgetch(scroll_w
)) == EOF
)
261 if (flag
&& c
>= ' ' && c
< 0x7f)
268 sgetstr(const char *pr
, char *buf
, int n
)
273 prompt(pr
, (struct ship
*)0);
280 while ((c
= wgetch(scroll_w
)) == EOF
)
289 waddstr(scroll_w
, "\b \b");
294 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
310 wrefresh(scroll_w
); /* move the cursor */
321 && sp
->file
->row
> viewrow
322 && sp
->file
->row
< viewrow
+ VIEW_Y
323 && sp
->file
->col
> viewcol
324 && sp
->file
->col
< viewcol
+ VIEW_X
) {
325 wmove(view_w
, sp
->file
->row
- viewrow
,
326 sp
->file
->col
- viewcol
);
327 waddch(view_w
, colours(sp
));
329 sternrow(sp
) - viewrow
,
330 sterncol(sp
) - viewcol
);
331 waddch(view_w
, sterncolour(sp
));
341 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
348 wmove(stat_w
, STAT_1
, 0);
349 wprintw(stat_w
, "Points %3d\n", mf
->points
);
350 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
351 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
353 wmove(stat_w
, STAT_2
, 0);
354 wprintw(stat_w
, " 0 %c(%c)\n",
355 maxmove(ms
, winddir
+ 3, -1) + '0',
356 maxmove(ms
, winddir
+ 3, 1) + '0');
357 waddstr(stat_w
, " \\|/\n");
358 wprintw(stat_w
, " -^-%c(%c)\n",
359 maxmove(ms
, winddir
+ 2, -1) + '0',
360 maxmove(ms
, winddir
+ 2, 1) + '0');
361 waddstr(stat_w
, " /|\\\n");
362 wprintw(stat_w
, " | %c(%c)\n",
363 maxmove(ms
, winddir
+ 1, -1) + '0',
364 maxmove(ms
, winddir
+ 1, 1) + '0');
365 wprintw(stat_w
, " %c(%c)\n",
366 maxmove(ms
, winddir
, -1) + '0',
367 maxmove(ms
, winddir
, 1) + '0');
369 wmove(stat_w
, STAT_3
, 0);
370 wprintw(stat_w
, "Load %c%c %c%c\n",
371 loadname
[mf
->loadL
], readyname(mf
->readyL
),
372 loadname
[mf
->loadR
], readyname(mf
->readyR
));
373 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
374 wprintw(stat_w
, "Crew %2d %2d %2d\n",
375 mc
->crew1
, mc
->crew2
, mc
->crew3
);
376 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
377 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
378 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
382 wprintw(stat_w
, "%d", mc
->rig4
);
389 if (!boarding(ms
, 0)) {
390 mvwaddstr(slot_w
, 0, 0, " ");
391 mvwaddstr(slot_w
, 1, 0, " ");
393 mvwaddstr(slot_w
, 1, 0, "OBP");
394 if (!boarding(ms
, 1)) {
395 mvwaddstr(slot_w
, 2, 0, " ");
396 mvwaddstr(slot_w
, 3, 0, " ");
398 mvwaddstr(slot_w
, 3, 0, "DBP");
400 wmove(slot_w
, SLOT_Y
-4, 0);
402 wprintw(slot_w
, "%dRH", mf
->RH
);
404 waddstr(slot_w
, " ");
405 wmove(slot_w
, SLOT_Y
-3, 0);
407 wprintw(slot_w
, "%dRG", mf
->RG
);
409 waddstr(slot_w
, " ");
410 wmove(slot_w
, SLOT_Y
-2, 0);
412 wprintw(slot_w
, "%dRR", mf
->RR
);
414 waddstr(slot_w
, " ");
418 wprintw(slot_w
,"%d", windspeed
);
419 mvwaddch(slot_w
, Y
, 0, ' ');
420 mvwaddch(slot_w
, Y
, 2, ' ');
421 mvwaddch(slot_w
, Y
-1, 0, ' ');
422 mvwaddch(slot_w
, Y
-1, 1, ' ');
423 mvwaddch(slot_w
, Y
-1, 2, ' ');
424 mvwaddch(slot_w
, Y
+1, 0, ' ');
425 mvwaddch(slot_w
, Y
+1, 1, ' ');
426 mvwaddch(slot_w
, Y
+1, 2, ' ');
427 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
443 waddch(slot_w
, '\\');
446 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
465 for (n
= 0; n
< BOX_X
; n
++)
468 for (n
= 0; n
< BOX_X
; n
++)
470 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
471 mvaddch(n
, BOX_L
, '|');
472 mvaddch(n
, BOX_R
, '|');
474 mvaddch(BOX_T
, BOX_L
, '+');
475 mvaddch(BOX_T
, BOX_R
, '+');
476 mvaddch(BOX_B
, BOX_L
, '+');
477 mvaddch(BOX_B
, BOX_R
, '+');
480 #define WSaIM "Wooden Ships & Iron Men"
481 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
482 waddstr(view_w
, WSaIM
);
483 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
484 waddstr(view_w
, cc
->name
);
487 move(LINE_T
, LINE_L
);
488 printw("Class %d %s (%d guns) '%s' (%c%c)",
490 classname
[mc
->class],
498 /* Called after show_[od]bp. Shouldn't really exist... XXX */
500 display_refresh_slot_w(void)
508 display_show_obp(int which
, bool show
)
510 wmove(slot_w
, 0, which
);
511 waddch(slot_w
, show
? '1' + which
: ' ');
512 mvwaddstr(slot_w
, 1, 0, "OBP");
516 display_show_dbp(int which
, bool show
)
518 wmove(slot_w
, 2, which
);
519 waddch(slot_w
, show
? '1' + which
: ' ');
520 mvwaddstr(slot_w
, 3, 0, "DBP");
526 viewrow
= mf
->row
- VIEW_Y
/ 2;
527 viewcol
= mf
->col
- VIEW_X
/ 2;
533 viewrow
-= VIEW_Y
/ 3;
539 viewrow
+= VIEW_Y
/ 3;
545 viewcol
-= VIEW_X
/ 5;
551 viewcol
+= VIEW_X
/ 5;
559 if (mf
->row
< viewrow
+ VIEW_Y
/4)
560 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
561 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
562 viewrow
= mf
->row
- VIEW_Y
/4;
563 if (mf
->col
< viewcol
+ VIEW_X
/8)
564 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
565 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
566 viewcol
= mf
->col
- VIEW_X
/8;