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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)pl_7.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/sail/pl_7.c,v 1.7 1999/11/30 03:49:37 billf Exp $
35 * $DragonFly: src/games/sail/pl_7.c,v 1.2 2003/06/17 04:25:25 dillon Exp $
38 #include <sys/ttydefaults.h>
47 static char sc_hasprompt
;
48 static char *sc_prompt
;
54 /* initscr() already done in SCREENTEST() */
55 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
56 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
57 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
58 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
59 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
61 (void) leaveok(view_w
, 1);
62 (void) leaveok(slot_w
, 1);
63 (void) leaveok(stat_w
, 1);
64 (void) leaveok(turn_w
, 1);
71 /* alarm already turned off */
73 (void) wmove(scroll_w
, SCROLL_Y
- 1, 0);
74 (void) wclrtoeol(scroll_w
);
83 repaired
= loaded
= fired
= changed
= 0;
87 if (mf
->readyL
& R_LOADING
) {
88 if (mf
->readyL
& R_DOUBLE
)
89 mf
->readyL
= R_LOADING
;
91 mf
->readyL
= R_LOADED
;
93 if (mf
->readyR
& R_LOADING
) {
94 if (mf
->readyR
& R_DOUBLE
)
95 mf
->readyR
= R_LOADING
;
97 mf
->readyR
= R_LOADED
;
100 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0, 0);
103 (void) wmove(scroll_w
, sc_line
, 0);
104 (void) wclrtoeol(scroll_w
);
111 (void) wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
114 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0, 0);
115 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
116 Write(W_FS
, ms
, 0, 0, 0, 0, 0);
118 Write(W_FS
, ms
, 0, 2, 0, 0, 0);
122 if (mf
->captured
!= 0)
123 leave(LEAVE_CAPTURED
);
125 leave(LEAVE_HURRICAN
);
130 (void) signal(SIGALRM
, newturn
);
135 Signal(fmt
, ship
, a
, b
, c
, d
)
145 (void) wprintw(scroll_w
, fmt
, a
, b
, c
, d
);
147 (void) wprintw(scroll_w
, fmt
, ship
->shipname
,
148 colours(ship
), sterncolour(ship
), a
, b
, c
, d
);
154 if (++sc_line
>= SCROLL_Y
)
156 (void) wmove(scroll_w
, sc_line
, 0);
157 (void) wclrtoeol(scroll_w
);
167 (void)sprintf(buf
, p
, ship
->shipname
, colours(ship
),
174 (void) waddstr(scroll_w
, p
);
185 sgetch(p
, ship
, flag
)
194 (void) wrefresh(scroll_w
);
196 while ((c
= wgetch(scroll_w
)) == EOF
)
198 if (flag
&& c
>= ' ' && c
< 0x7f)
199 (void) waddch(scroll_w
, c
);
212 prompt(pr
, (struct ship
*)0);
217 (void) wrefresh(scroll_w
);
219 while ((c
= wgetch(scroll_w
)) == EOF
)
228 (void) waddstr(scroll_w
, "\b \b");
233 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
235 (void) waddch(scroll_w
, c
);
237 (void) putchar(CTRL('g'));
248 (void) wrefresh(scroll_w
); /* move the cursor */
255 (void) werase(view_w
);
258 && sp
->file
->row
> viewrow
259 && sp
->file
->row
< viewrow
+ VIEW_Y
260 && sp
->file
->col
> viewcol
261 && sp
->file
->col
< viewcol
+ VIEW_X
) {
262 (void) wmove(view_w
, sp
->file
->row
- viewrow
,
263 sp
->file
->col
- viewcol
);
264 (void) waddch(view_w
, colours(sp
));
266 sternrow(sp
) - viewrow
,
267 sterncol(sp
) - viewcol
);
268 (void) waddch(view_w
, sterncolour(sp
));
271 (void) wrefresh(view_w
);
276 (void) wmove(turn_w
, 0, 0);
277 (void) wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
278 (void) wrefresh(turn_w
);
283 (void) wmove(stat_w
, STAT_1
, 0);
284 (void) wprintw(stat_w
, "Points %3d\n", mf
->points
);
285 (void) wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
286 (void) wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
288 (void) wmove(stat_w
, STAT_2
, 0);
289 (void) wprintw(stat_w
, " 0 %c(%c)\n",
290 maxmove(ms
, winddir
+ 3, -1) + '0',
291 maxmove(ms
, winddir
+ 3, 1) + '0');
292 (void) waddstr(stat_w
, " \\|/\n");
293 (void) wprintw(stat_w
, " -^-%c(%c)\n",
294 maxmove(ms
, winddir
+ 2, -1) + '0',
295 maxmove(ms
, winddir
+ 2, 1) + '0');
296 (void) waddstr(stat_w
, " /|\\\n");
297 (void) wprintw(stat_w
, " | %c(%c)\n",
298 maxmove(ms
, winddir
+ 1, -1) + '0',
299 maxmove(ms
, winddir
+ 1, 1) + '0');
300 (void) wprintw(stat_w
, " %c(%c)\n",
301 maxmove(ms
, winddir
, -1) + '0',
302 maxmove(ms
, winddir
, 1) + '0');
304 (void) wmove(stat_w
, STAT_3
, 0);
305 (void) wprintw(stat_w
, "Load %c%c %c%c\n",
306 loadname
[mf
->loadL
], readyname(mf
->readyL
),
307 loadname
[mf
->loadR
], readyname(mf
->readyR
));
308 (void) wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
309 (void) wprintw(stat_w
, "Crew %2d %2d %2d\n",
310 mc
->crew1
, mc
->crew2
, mc
->crew3
);
311 (void) wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
312 (void) wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
313 (void) wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
315 (void) waddch(stat_w
, '-');
317 (void) wprintw(stat_w
, "%d", mc
->rig4
);
318 (void) wrefresh(stat_w
);
323 if (!boarding(ms
, 0)) {
324 (void) mvwaddstr(slot_w
, 0, 0, " ");
325 (void) mvwaddstr(slot_w
, 1, 0, " ");
327 (void) mvwaddstr(slot_w
, 1, 0, "OBP");
328 if (!boarding(ms
, 1)) {
329 (void) mvwaddstr(slot_w
, 2, 0, " ");
330 (void) mvwaddstr(slot_w
, 3, 0, " ");
332 (void) mvwaddstr(slot_w
, 3, 0, "DBP");
334 (void) wmove(slot_w
, SLOT_Y
-4, 0);
336 (void) wprintw(slot_w
, "%dRH", mf
->RH
);
338 (void) waddstr(slot_w
, " ");
339 (void) wmove(slot_w
, SLOT_Y
-3, 0);
341 (void) wprintw(slot_w
, "%dRG", mf
->RG
);
343 (void) waddstr(slot_w
, " ");
344 (void) wmove(slot_w
, SLOT_Y
-2, 0);
346 (void) wprintw(slot_w
, "%dRR", mf
->RR
);
348 (void) waddstr(slot_w
, " ");
351 (void) wmove(slot_w
, 7, 1);
352 (void) wprintw(slot_w
,"%d", windspeed
);
353 (void) mvwaddch(slot_w
, Y
, 0, ' ');
354 (void) mvwaddch(slot_w
, Y
, 2, ' ');
355 (void) mvwaddch(slot_w
, Y
-1, 0, ' ');
356 (void) mvwaddch(slot_w
, Y
-1, 1, ' ');
357 (void) mvwaddch(slot_w
, Y
-1, 2, ' ');
358 (void) mvwaddch(slot_w
, Y
+1, 0, ' ');
359 (void) mvwaddch(slot_w
, Y
+1, 1, ' ');
360 (void) mvwaddch(slot_w
, Y
+1, 2, ' ');
361 (void) wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
365 (void) waddch(slot_w
, '|');
369 (void) waddch(slot_w
, '/');
373 (void) waddch(slot_w
, '-');
377 (void) waddch(slot_w
, '\\');
380 (void) mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
381 (void) wrefresh(slot_w
);
389 (void) werase(view_w
);
390 (void) werase(slot_w
);
391 (void) werase(scroll_w
);
392 (void) werase(stat_w
);
393 (void) werase(turn_w
);
397 (void) move(BOX_T
, BOX_L
);
398 for (n
= 0; n
< BOX_X
; n
++)
400 (void) move(BOX_B
, BOX_L
);
401 for (n
= 0; n
< BOX_X
; n
++)
403 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
404 (void) mvaddch(n
, BOX_L
, '|');
405 (void) mvaddch(n
, BOX_R
, '|');
407 (void) mvaddch(BOX_T
, BOX_L
, '+');
408 (void) mvaddch(BOX_T
, BOX_R
, '+');
409 (void) mvaddch(BOX_B
, BOX_L
, '+');
410 (void) mvaddch(BOX_B
, BOX_R
, '+');
413 #define WSaIM "Wooden Ships & Iron Men"
414 (void) wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
415 (void) waddstr(view_w
, WSaIM
);
416 (void) wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
417 (void) waddstr(view_w
, cc
->name
);
418 (void) wrefresh(view_w
);
420 (void) move(LINE_T
, LINE_L
);
421 (void) printw("Class %d %s (%d guns) '%s' (%c%c)",
423 classname
[mc
->class],
433 viewrow
= mf
->row
- VIEW_Y
/ 2;
434 viewcol
= mf
->col
- VIEW_X
/ 2;
439 viewrow
-= VIEW_Y
/ 3;
444 viewrow
+= VIEW_Y
/ 3;
449 viewcol
-= VIEW_X
/ 5;
454 viewcol
+= VIEW_X
/ 5;
461 if (mf
->row
< viewrow
+ VIEW_Y
/4)
462 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
463 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
464 viewrow
= mf
->row
- VIEW_Y
/4;
465 if (mf
->col
< viewcol
+ VIEW_X
/8)
466 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
467 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
468 viewcol
= mf
->col
- VIEW_X
/8;