2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)pl_7.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/sail/pl_7.c,v 1.7 1999/11/30 03:49:37 billf Exp $
33 #include <sys/ttydefaults.h>
42 static char sc_hasprompt
;
43 static const char *sc_prompt
;
44 static const char *sc_buf
;
47 static void Scroll(void);
48 static void prompt(const char *, struct ship
*);
49 static void endprompt(char);
50 static void adjustview(void);
55 /* initscr() already done in SCREENTEST() */
56 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
57 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
58 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
59 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
60 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
73 /* alarm already turned off */
75 wmove(scroll_w
, SCROLL_Y
- 1, 0);
83 newturn(__unused
int sig
)
85 repaired
= loaded
= fired
= changed
= 0;
89 if (mf
->readyL
& R_LOADING
) {
90 if (mf
->readyL
& R_DOUBLE
)
91 mf
->readyL
= R_LOADING
;
93 mf
->readyL
= R_LOADED
;
95 if (mf
->readyR
& R_LOADING
) {
96 if (mf
->readyR
& R_DOUBLE
)
97 mf
->readyR
= R_LOADING
;
99 mf
->readyR
= R_LOADED
;
102 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
105 wmove(scroll_w
, sc_line
, 0);
113 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
116 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
117 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
118 Write(W_FS
, ms
, 0, 0, 0, 0);
120 Write(W_FS
, ms
, 2, 0, 0, 0);
124 if (mf
->captured
!= 0)
125 leave(LEAVE_CAPTURED
);
127 leave(LEAVE_HURRICAN
);
132 signal(SIGALRM
, newturn
);
138 Signal(const char *fmt
, struct ship
*ship
, ...)
149 vw_printw(scroll_w
, fmt
, ap
);
151 fmtship(format
, sizeof(format
), fmt
, ship
);
152 vw_printw(scroll_w
, format
, ap
);
161 if (++sc_line
>= SCROLL_Y
)
163 wmove(scroll_w
, sc_line
, 0);
168 prompt(const char *p
, struct ship
*ship
)
173 printf(buf
, p
, ship
->shipname
, colours(ship
),
180 waddstr(scroll_w
, p
);
192 sgetch(const char *p
, struct ship
*ship
, char flag
)
200 while ((c
= wgetch(scroll_w
)) == EOF
)
202 if (flag
&& c
>= ' ' && c
< 0x7f)
209 sgetstr(const char *pr
, char *buf
, int n
)
221 while ((c
= wgetch(scroll_w
)) == EOF
)
230 waddstr(scroll_w
, "\b \b");
235 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
251 wrefresh(scroll_w
); /* move the cursor */
262 && sp
->file
->row
> viewrow
263 && sp
->file
->row
< viewrow
+ VIEW_Y
264 && sp
->file
->col
> viewcol
265 && sp
->file
->col
< viewcol
+ VIEW_X
) {
266 wmove(view_w
, sp
->file
->row
- viewrow
,
267 sp
->file
->col
- viewcol
);
268 waddch(view_w
, colours(sp
));
270 sternrow(sp
) - viewrow
,
271 sterncol(sp
) - viewcol
);
272 waddch(view_w
, sterncolour(sp
));
282 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
289 wmove(stat_w
, STAT_1
, 0);
290 wprintw(stat_w
, "Points %3d\n", mf
->points
);
291 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
292 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
294 wmove(stat_w
, STAT_2
, 0);
295 wprintw(stat_w
, " 0 %c(%c)\n",
296 maxmove(ms
, winddir
+ 3, -1) + '0',
297 maxmove(ms
, winddir
+ 3, 1) + '0');
298 waddstr(stat_w
, " \\|/\n");
299 wprintw(stat_w
, " -^-%c(%c)\n",
300 maxmove(ms
, winddir
+ 2, -1) + '0',
301 maxmove(ms
, winddir
+ 2, 1) + '0');
302 waddstr(stat_w
, " /|\\\n");
303 wprintw(stat_w
, " | %c(%c)\n",
304 maxmove(ms
, winddir
+ 1, -1) + '0',
305 maxmove(ms
, winddir
+ 1, 1) + '0');
306 wprintw(stat_w
, " %c(%c)\n",
307 maxmove(ms
, winddir
, -1) + '0',
308 maxmove(ms
, winddir
, 1) + '0');
310 wmove(stat_w
, STAT_3
, 0);
311 wprintw(stat_w
, "Load %c%c %c%c\n",
312 loadname
[mf
->loadL
], readyname(mf
->readyL
),
313 loadname
[mf
->loadR
], readyname(mf
->readyR
));
314 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
315 wprintw(stat_w
, "Crew %2d %2d %2d\n",
316 mc
->crew1
, mc
->crew2
, mc
->crew3
);
317 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
318 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
319 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
323 wprintw(stat_w
, "%d", mc
->rig4
);
330 if (!boarding(ms
, 0)) {
331 mvwaddstr(slot_w
, 0, 0, " ");
332 mvwaddstr(slot_w
, 1, 0, " ");
334 mvwaddstr(slot_w
, 1, 0, "OBP");
335 if (!boarding(ms
, 1)) {
336 mvwaddstr(slot_w
, 2, 0, " ");
337 mvwaddstr(slot_w
, 3, 0, " ");
339 mvwaddstr(slot_w
, 3, 0, "DBP");
341 wmove(slot_w
, SLOT_Y
-4, 0);
343 wprintw(slot_w
, "%dRH", mf
->RH
);
345 waddstr(slot_w
, " ");
346 wmove(slot_w
, SLOT_Y
-3, 0);
348 wprintw(slot_w
, "%dRG", mf
->RG
);
350 waddstr(slot_w
, " ");
351 wmove(slot_w
, SLOT_Y
-2, 0);
353 wprintw(slot_w
, "%dRR", mf
->RR
);
355 waddstr(slot_w
, " ");
359 wprintw(slot_w
,"%d", windspeed
);
360 mvwaddch(slot_w
, Y
, 0, ' ');
361 mvwaddch(slot_w
, Y
, 2, ' ');
362 mvwaddch(slot_w
, Y
-1, 0, ' ');
363 mvwaddch(slot_w
, Y
-1, 1, ' ');
364 mvwaddch(slot_w
, Y
-1, 2, ' ');
365 mvwaddch(slot_w
, Y
+1, 0, ' ');
366 mvwaddch(slot_w
, Y
+1, 1, ' ');
367 mvwaddch(slot_w
, Y
+1, 2, ' ');
368 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
384 waddch(slot_w
, '\\');
387 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
406 for (n
= 0; n
< BOX_X
; n
++)
409 for (n
= 0; n
< BOX_X
; n
++)
411 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
412 mvaddch(n
, BOX_L
, '|');
413 mvaddch(n
, BOX_R
, '|');
415 mvaddch(BOX_T
, BOX_L
, '+');
416 mvaddch(BOX_T
, BOX_R
, '+');
417 mvaddch(BOX_B
, BOX_L
, '+');
418 mvaddch(BOX_B
, BOX_R
, '+');
421 #define WSaIM "Wooden Ships & Iron Men"
422 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
423 waddstr(view_w
, WSaIM
);
424 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
425 waddstr(view_w
, cc
->name
);
428 move(LINE_T
, LINE_L
);
429 printw("Class %d %s (%d guns) '%s' (%c%c)",
431 classname
[mc
->class],
442 viewrow
= mf
->row
- VIEW_Y
/ 2;
443 viewcol
= mf
->col
- VIEW_X
/ 2;
449 viewrow
-= VIEW_Y
/ 3;
455 viewrow
+= VIEW_Y
/ 3;
461 viewcol
-= VIEW_X
/ 5;
467 viewcol
+= VIEW_X
/ 5;
475 if (mf
->row
< viewrow
+ VIEW_Y
/4)
476 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
477 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
478 viewrow
= mf
->row
- VIEW_Y
/4;
479 if (mf
->col
< viewcol
+ VIEW_X
/8)
480 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
481 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
482 viewcol
= mf
->col
- VIEW_X
/8;