]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.19 2001/01/04 03:51:24 jwise 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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: pl_7.c,v 1.19 2001/01/04 03:51:24 jwise Exp $");
51 void initscreen(void);
52 void cleanupscreen(void);
54 void Signal(const char *, struct ship
*, ...);
55 void Msg(const char *, ...);
56 static void Scroll(void);
57 void prompt(const char *, struct ship
*);
58 static void endprompt(int);
59 int sgetch(const char *, struct ship
*, int);
60 void sgetstr(const char *, char *, int);
61 void draw_screen(void);
66 void draw_board(void);
67 void centerview(void);
72 static void adjustview(void);
78 static char sc_hasprompt
;
79 static const char *sc_prompt
;
80 static const char *sc_buf
;
90 char loaded
, fired
, changed
, repaired
;
93 char movebuf
[sizeof SHIP(0)->file
->movebuf
];
95 struct ship
*ms
; /* memorial structure, &cc->ship[player] */
96 struct File
*mf
; /* ms->file */
97 struct shipspecs
*mc
; /* ms->specs */
103 printf("Can't sail on this terminal.\n");
106 /* initscr() already done in SCREENTEST() */
107 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
108 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
109 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
110 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
111 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
124 /* alarm already turned off */
126 wmove(scroll_w
, SCROLL_Y
- 1, 0);
135 newturn(int n
__attribute__((__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
;
154 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
157 wmove(scroll_w
, sc_line
, 0);
165 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
168 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
169 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
170 Write(W_FS
, ms
, 0, 0, 0, 0);
172 Write(W_FS
, ms
, 2, 0, 0, 0);
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],
501 viewrow
= mf
->row
- VIEW_Y
/ 2;
502 viewcol
= mf
->col
- VIEW_X
/ 2;
508 viewrow
-= VIEW_Y
/ 3;
514 viewrow
+= VIEW_Y
/ 3;
520 viewcol
-= VIEW_X
/ 5;
526 viewcol
+= VIEW_X
/ 5;
534 if (mf
->row
< viewrow
+ VIEW_Y
/4)
535 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
536 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
537 viewrow
= mf
->row
- VIEW_Y
/4;
538 if (mf
->col
< viewcol
+ VIEW_X
/8)
539 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
540 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
541 viewcol
= mf
->col
- VIEW_X
/8;