]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.10 1999/02/10 00:45:46 hubertf 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.10 1999/02/10 00:45:46 hubertf Exp $");
45 #include <sys/ttydefaults.h>
59 static char sc_hasprompt
;
60 static char *sc_prompt
;
67 /* initscr() already done in SCREENTEST() */
68 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
69 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
70 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
71 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
72 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
74 (void) leaveok(view_w
, 1);
75 (void) leaveok(slot_w
, 1);
76 (void) leaveok(stat_w
, 1);
77 (void) leaveok(turn_w
, 1);
85 /* alarm already turned off */
87 (void) wmove(scroll_w
, SCROLL_Y
- 1, 0);
88 (void) wclrtoeol(scroll_w
);
99 repaired
= loaded
= fired
= changed
= 0;
103 if (mf
->readyL
& R_LOADING
) {
104 if (mf
->readyL
& R_DOUBLE
)
105 mf
->readyL
= R_LOADING
;
107 mf
->readyL
= R_LOADED
;
109 if (mf
->readyR
& R_LOADING
) {
110 if (mf
->readyR
& R_DOUBLE
)
111 mf
->readyR
= R_LOADING
;
113 mf
->readyR
= R_LOADED
;
116 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
119 (void) wmove(scroll_w
, sc_line
, 0);
120 (void) wclrtoeol(scroll_w
);
127 (void) wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
130 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
131 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
132 Write(W_FS
, ms
, 0, 0, 0, 0);
134 Write(W_FS
, ms
, 2, 0, 0, 0);
138 if (mf
->captured
!= 0)
139 leave(LEAVE_CAPTURED
);
141 leave(LEAVE_HURRICAN
);
146 (void) signal(SIGALRM
, newturn
);
153 Signal(const char *fmt
, struct ship
*ship
, ...)
166 fmt
= va_arg(ap
, const char *);
167 ship
= va_arg(ap
, struct ship
*);
175 fmtship(format
, sizeof(format
), fmt
, ship
);
176 (void) vwprintw(scroll_w
, format
, ap
);
184 Msg(const char *fmt
, ...)
195 fmt
= va_arg(ap
, const char *);
204 (void) vwprintw(scroll_w
, fmt
, ap
);
212 if (++sc_line
>= SCROLL_Y
)
214 (void) wmove(scroll_w
, sc_line
, 0);
215 (void) wclrtoeol(scroll_w
);
223 static char buf
[BUFSIZ
];
225 fmtship(buf
, sizeof(buf
), p
, ship
);
229 (void) waddstr(scroll_w
, buf
);
242 sgetch(p
, ship
, flag
)
250 (void) wrefresh(scroll_w
);
252 while ((c
= wgetch(scroll_w
)) == EOF
)
254 if (flag
&& c
>= ' ' && c
< 0x7f)
255 (void) waddch(scroll_w
, c
);
269 prompt(pr
, (struct ship
*)0);
274 (void) wrefresh(scroll_w
);
276 while ((c
= wgetch(scroll_w
)) == EOF
)
285 (void) waddstr(scroll_w
, "\b \b");
290 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
292 (void) waddch(scroll_w
, c
);
294 (void) putchar('\a');
306 (void) wrefresh(scroll_w
); /* move the cursor */
314 (void) werase(view_w
);
317 && sp
->file
->row
> viewrow
318 && sp
->file
->row
< viewrow
+ VIEW_Y
319 && sp
->file
->col
> viewcol
320 && sp
->file
->col
< viewcol
+ VIEW_X
) {
321 (void) wmove(view_w
, sp
->file
->row
- viewrow
,
322 sp
->file
->col
- viewcol
);
323 (void) waddch(view_w
, colours(sp
));
325 sternrow(sp
) - viewrow
,
326 sterncol(sp
) - viewcol
);
327 (void) waddch(view_w
, sterncolour(sp
));
330 (void) wrefresh(view_w
);
336 (void) wmove(turn_w
, 0, 0);
337 (void) wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
338 (void) wrefresh(turn_w
);
344 (void) wmove(stat_w
, STAT_1
, 0);
345 (void) wprintw(stat_w
, "Points %3d\n", mf
->points
);
346 (void) wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
347 (void) wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
349 (void) wmove(stat_w
, STAT_2
, 0);
350 (void) wprintw(stat_w
, " 0 %c(%c)\n",
351 maxmove(ms
, winddir
+ 3, -1) + '0',
352 maxmove(ms
, winddir
+ 3, 1) + '0');
353 (void) waddstr(stat_w
, " \\|/\n");
354 (void) wprintw(stat_w
, " -^-%c(%c)\n",
355 maxmove(ms
, winddir
+ 2, -1) + '0',
356 maxmove(ms
, winddir
+ 2, 1) + '0');
357 (void) waddstr(stat_w
, " /|\\\n");
358 (void) wprintw(stat_w
, " | %c(%c)\n",
359 maxmove(ms
, winddir
+ 1, -1) + '0',
360 maxmove(ms
, winddir
+ 1, 1) + '0');
361 (void) wprintw(stat_w
, " %c(%c)\n",
362 maxmove(ms
, winddir
, -1) + '0',
363 maxmove(ms
, winddir
, 1) + '0');
365 (void) wmove(stat_w
, STAT_3
, 0);
366 (void) wprintw(stat_w
, "Load %c%c %c%c\n",
367 loadname
[mf
->loadL
], readyname(mf
->readyL
),
368 loadname
[mf
->loadR
], readyname(mf
->readyR
));
369 (void) wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
370 (void) wprintw(stat_w
, "Crew %2d %2d %2d\n",
371 mc
->crew1
, mc
->crew2
, mc
->crew3
);
372 (void) wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
373 (void) wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
374 (void) wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
376 (void) waddch(stat_w
, '-');
378 (void) wprintw(stat_w
, "%d", mc
->rig4
);
379 (void) wrefresh(stat_w
);
385 if (!boarding(ms
, 0)) {
386 (void) mvwaddstr(slot_w
, 0, 0, " ");
387 (void) mvwaddstr(slot_w
, 1, 0, " ");
389 (void) mvwaddstr(slot_w
, 1, 0, "OBP");
390 if (!boarding(ms
, 1)) {
391 (void) mvwaddstr(slot_w
, 2, 0, " ");
392 (void) mvwaddstr(slot_w
, 3, 0, " ");
394 (void) mvwaddstr(slot_w
, 3, 0, "DBP");
396 (void) wmove(slot_w
, SLOT_Y
-4, 0);
398 (void) wprintw(slot_w
, "%dRH", mf
->RH
);
400 (void) waddstr(slot_w
, " ");
401 (void) wmove(slot_w
, SLOT_Y
-3, 0);
403 (void) wprintw(slot_w
, "%dRG", mf
->RG
);
405 (void) waddstr(slot_w
, " ");
406 (void) wmove(slot_w
, SLOT_Y
-2, 0);
408 (void) wprintw(slot_w
, "%dRR", mf
->RR
);
410 (void) waddstr(slot_w
, " ");
413 (void) wmove(slot_w
, 7, 1);
414 (void) wprintw(slot_w
,"%d", windspeed
);
415 (void) mvwaddch(slot_w
, Y
, 0, ' ');
416 (void) mvwaddch(slot_w
, Y
, 2, ' ');
417 (void) mvwaddch(slot_w
, Y
-1, 0, ' ');
418 (void) mvwaddch(slot_w
, Y
-1, 1, ' ');
419 (void) mvwaddch(slot_w
, Y
-1, 2, ' ');
420 (void) mvwaddch(slot_w
, Y
+1, 0, ' ');
421 (void) mvwaddch(slot_w
, Y
+1, 1, ' ');
422 (void) mvwaddch(slot_w
, Y
+1, 2, ' ');
423 (void) wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
427 (void) waddch(slot_w
, '|');
431 (void) waddch(slot_w
, '/');
435 (void) waddch(slot_w
, '-');
439 (void) waddch(slot_w
, '\\');
442 (void) mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
443 (void) wrefresh(slot_w
);
452 (void) werase(view_w
);
453 (void) werase(slot_w
);
454 (void) werase(scroll_w
);
455 (void) werase(stat_w
);
456 (void) werase(turn_w
);
460 (void) move(BOX_T
, BOX_L
);
461 for (n
= 0; n
< BOX_X
; n
++)
463 (void) move(BOX_B
, BOX_L
);
464 for (n
= 0; n
< BOX_X
; n
++)
466 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
467 (void) mvaddch(n
, BOX_L
, '|');
468 (void) mvaddch(n
, BOX_R
, '|');
470 (void) mvaddch(BOX_T
, BOX_L
, '+');
471 (void) mvaddch(BOX_T
, BOX_R
, '+');
472 (void) mvaddch(BOX_B
, BOX_L
, '+');
473 (void) mvaddch(BOX_B
, BOX_R
, '+');
476 #define WSaIM "Wooden Ships & Iron Men"
477 (void) wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
478 (void) waddstr(view_w
, WSaIM
);
479 (void) wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
480 (void) waddstr(view_w
, cc
->name
);
481 (void) wrefresh(view_w
);
483 (void) move(LINE_T
, LINE_L
);
484 (void) printw("Class %d %s (%d guns) '%s' (%c%c)",
486 classname
[mc
->class],
497 viewrow
= mf
->row
- VIEW_Y
/ 2;
498 viewcol
= mf
->col
- VIEW_X
/ 2;
504 viewrow
-= VIEW_Y
/ 3;
510 viewrow
+= VIEW_Y
/ 3;
516 viewcol
-= VIEW_X
/ 5;
522 viewcol
+= VIEW_X
/ 5;
530 if (mf
->row
< viewrow
+ VIEW_Y
/4)
531 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
532 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
533 viewrow
= mf
->row
- VIEW_Y
/4;
534 if (mf
->col
< viewcol
+ VIEW_X
/8)
535 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
536 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
537 viewcol
= mf
->col
- VIEW_X
/8;