]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.8 1997/10/13 21:04:32 christos 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.8 1997/10/13 21:04:32 christos 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
;
108 if (mf
->readyR
& R_LOADING
)
109 if (mf
->readyR
& R_DOUBLE
)
110 mf
->readyR
= R_LOADING
;
112 mf
->readyR
= R_LOADED
;
114 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0, 0);
117 (void) wmove(scroll_w
, sc_line
, 0);
118 (void) wclrtoeol(scroll_w
);
125 (void) wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
128 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0, 0);
129 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
130 Write(W_FS
, ms
, 0, 0, 0, 0, 0);
132 Write(W_FS
, ms
, 0, 2, 0, 0, 0);
136 if (mf
->captured
!= 0)
137 leave(LEAVE_CAPTURED
);
139 leave(LEAVE_HURRICAN
);
144 (void) signal(SIGALRM
, newturn
);
151 Signal(const char *fmt
, struct ship
*ship
, ...)
164 fmt
= va_arg(ap
, const char *);
165 ship
= va_arg(ap
, struct ship
*);
173 fmtship(format
, sizeof(format
), fmt
, ship
);
174 (void) vwprintw(scroll_w
, format
, ap
);
182 Msg(const char *fmt
, ...)
193 fmt
= va_arg(ap
, const char *);
202 (void) vwprintw(scroll_w
, fmt
, ap
);
210 if (++sc_line
>= SCROLL_Y
)
212 (void) wmove(scroll_w
, sc_line
, 0);
213 (void) wclrtoeol(scroll_w
);
221 static char buf
[BUFSIZ
];
223 fmtship(buf
, sizeof(buf
), p
, ship
);
227 (void) waddstr(scroll_w
, buf
);
240 sgetch(p
, ship
, flag
)
248 (void) wrefresh(scroll_w
);
250 while ((c
= wgetch(scroll_w
)) == EOF
)
252 if (flag
&& c
>= ' ' && c
< 0x7f)
253 (void) waddch(scroll_w
, c
);
267 prompt(pr
, (struct ship
*)0);
272 (void) wrefresh(scroll_w
);
274 while ((c
= wgetch(scroll_w
)) == EOF
)
283 (void) waddstr(scroll_w
, "\b \b");
288 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
290 (void) waddch(scroll_w
, c
);
292 (void) putchar('\a');
304 (void) wrefresh(scroll_w
); /* move the cursor */
312 (void) werase(view_w
);
315 && sp
->file
->row
> viewrow
316 && sp
->file
->row
< viewrow
+ VIEW_Y
317 && sp
->file
->col
> viewcol
318 && sp
->file
->col
< viewcol
+ VIEW_X
) {
319 (void) wmove(view_w
, sp
->file
->row
- viewrow
,
320 sp
->file
->col
- viewcol
);
321 (void) waddch(view_w
, colours(sp
));
323 sternrow(sp
) - viewrow
,
324 sterncol(sp
) - viewcol
);
325 (void) waddch(view_w
, sterncolour(sp
));
328 (void) wrefresh(view_w
);
334 (void) wmove(turn_w
, 0, 0);
335 (void) wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
336 (void) wrefresh(turn_w
);
342 (void) wmove(stat_w
, STAT_1
, 0);
343 (void) wprintw(stat_w
, "Points %3d\n", mf
->points
);
344 (void) wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
345 (void) wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
347 (void) wmove(stat_w
, STAT_2
, 0);
348 (void) wprintw(stat_w
, " 0 %c(%c)\n",
349 maxmove(ms
, winddir
+ 3, -1) + '0',
350 maxmove(ms
, winddir
+ 3, 1) + '0');
351 (void) waddstr(stat_w
, " \\|/\n");
352 (void) wprintw(stat_w
, " -^-%c(%c)\n",
353 maxmove(ms
, winddir
+ 2, -1) + '0',
354 maxmove(ms
, winddir
+ 2, 1) + '0');
355 (void) waddstr(stat_w
, " /|\\\n");
356 (void) wprintw(stat_w
, " | %c(%c)\n",
357 maxmove(ms
, winddir
+ 1, -1) + '0',
358 maxmove(ms
, winddir
+ 1, 1) + '0');
359 (void) wprintw(stat_w
, " %c(%c)\n",
360 maxmove(ms
, winddir
, -1) + '0',
361 maxmove(ms
, winddir
, 1) + '0');
363 (void) wmove(stat_w
, STAT_3
, 0);
364 (void) wprintw(stat_w
, "Load %c%c %c%c\n",
365 loadname
[mf
->loadL
], readyname(mf
->readyL
),
366 loadname
[mf
->loadR
], readyname(mf
->readyR
));
367 (void) wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
368 (void) wprintw(stat_w
, "Crew %2d %2d %2d\n",
369 mc
->crew1
, mc
->crew2
, mc
->crew3
);
370 (void) wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
371 (void) wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
372 (void) wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
374 (void) waddch(stat_w
, '-');
376 (void) wprintw(stat_w
, "%d", mc
->rig4
);
377 (void) wrefresh(stat_w
);
383 if (!boarding(ms
, 0)) {
384 (void) mvwaddstr(slot_w
, 0, 0, " ");
385 (void) mvwaddstr(slot_w
, 1, 0, " ");
387 (void) mvwaddstr(slot_w
, 1, 0, "OBP");
388 if (!boarding(ms
, 1)) {
389 (void) mvwaddstr(slot_w
, 2, 0, " ");
390 (void) mvwaddstr(slot_w
, 3, 0, " ");
392 (void) mvwaddstr(slot_w
, 3, 0, "DBP");
394 (void) wmove(slot_w
, SLOT_Y
-4, 0);
396 (void) wprintw(slot_w
, "%dRH", mf
->RH
);
398 (void) waddstr(slot_w
, " ");
399 (void) wmove(slot_w
, SLOT_Y
-3, 0);
401 (void) wprintw(slot_w
, "%dRG", mf
->RG
);
403 (void) waddstr(slot_w
, " ");
404 (void) wmove(slot_w
, SLOT_Y
-2, 0);
406 (void) wprintw(slot_w
, "%dRR", mf
->RR
);
408 (void) waddstr(slot_w
, " ");
411 (void) wmove(slot_w
, 7, 1);
412 (void) wprintw(slot_w
,"%d", windspeed
);
413 (void) mvwaddch(slot_w
, Y
, 0, ' ');
414 (void) mvwaddch(slot_w
, Y
, 2, ' ');
415 (void) mvwaddch(slot_w
, Y
-1, 0, ' ');
416 (void) mvwaddch(slot_w
, Y
-1, 1, ' ');
417 (void) mvwaddch(slot_w
, Y
-1, 2, ' ');
418 (void) mvwaddch(slot_w
, Y
+1, 0, ' ');
419 (void) mvwaddch(slot_w
, Y
+1, 1, ' ');
420 (void) mvwaddch(slot_w
, Y
+1, 2, ' ');
421 (void) wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
425 (void) waddch(slot_w
, '|');
429 (void) waddch(slot_w
, '/');
433 (void) waddch(slot_w
, '-');
437 (void) waddch(slot_w
, '\\');
440 (void) mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
441 (void) wrefresh(slot_w
);
450 (void) werase(view_w
);
451 (void) werase(slot_w
);
452 (void) werase(scroll_w
);
453 (void) werase(stat_w
);
454 (void) werase(turn_w
);
458 (void) move(BOX_T
, BOX_L
);
459 for (n
= 0; n
< BOX_X
; n
++)
461 (void) move(BOX_B
, BOX_L
);
462 for (n
= 0; n
< BOX_X
; n
++)
464 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
465 (void) mvaddch(n
, BOX_L
, '|');
466 (void) mvaddch(n
, BOX_R
, '|');
468 (void) mvaddch(BOX_T
, BOX_L
, '+');
469 (void) mvaddch(BOX_T
, BOX_R
, '+');
470 (void) mvaddch(BOX_B
, BOX_L
, '+');
471 (void) mvaddch(BOX_B
, BOX_R
, '+');
474 #define WSaIM "Wooden Ships & Iron Men"
475 (void) wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
476 (void) waddstr(view_w
, WSaIM
);
477 (void) wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
478 (void) waddstr(view_w
, cc
->name
);
479 (void) wrefresh(view_w
);
481 (void) move(LINE_T
, LINE_L
);
482 (void) printw("Class %d %s (%d guns) '%s' (%c%c)",
484 classname
[mc
->class],
495 viewrow
= mf
->row
- VIEW_Y
/ 2;
496 viewcol
= mf
->col
- VIEW_X
/ 2;
502 viewrow
-= VIEW_Y
/ 3;
508 viewrow
+= VIEW_Y
/ 3;
514 viewcol
-= VIEW_X
/ 5;
520 viewcol
+= VIEW_X
/ 5;
528 if (mf
->row
< viewrow
+ VIEW_Y
/4)
529 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
530 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
531 viewrow
= mf
->row
- VIEW_Y
/4;
532 if (mf
->col
< viewcol
+ VIEW_X
/8)
533 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
534 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
535 viewcol
= mf
->col
- VIEW_X
/8;