]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.26 2001/12/06 12:21:00 blymn 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.26 2001/12/06 12:21:00 blymn Exp $");
56 static void Scroll(void);
57 static void endprompt(int);
58 static void adjustview(void);
64 static char sc_hasprompt
;
65 static const char *sc_prompt
;
66 static const char *sc_buf
;
76 int loaded
, fired
, changed
, repaired
;
79 char movebuf
[sizeof SHIP(0)->file
->movebuf
];
81 struct ship
*ms
; /* memorial structure, &cc->ship[player] */
82 struct File
*mf
; /* ms->file */
83 struct shipspecs
*mc
; /* ms->specs */
89 printf("Can't sail on this terminal.\n");
92 /* initscr() already done in SCREENTEST() */
93 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
94 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
95 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
96 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
97 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
110 /* alarm already turned off */
112 wmove(scroll_w
, SCROLL_Y
- 1, 0);
121 newturn(int n
__attribute__((__unused__
)))
123 repaired
= loaded
= fired
= changed
= 0;
127 if (mf
->readyL
& R_LOADING
) {
128 if (mf
->readyL
& R_DOUBLE
)
129 mf
->readyL
= R_LOADING
;
131 mf
->readyL
= R_LOADED
;
133 if (mf
->readyR
& R_LOADING
) {
134 if (mf
->readyR
& R_DOUBLE
)
135 mf
->readyR
= R_LOADING
;
137 mf
->readyR
= R_LOADED
;
140 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
143 wmove(scroll_w
, sc_line
, 0);
151 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
154 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
155 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
156 Write(W_FS
, ms
, 0, 0, 0, 0);
158 Write(W_FS
, ms
, 2, 0, 0, 0);
162 if (mf
->captured
!= 0)
163 leave(LEAVE_CAPTURED
);
165 leave(LEAVE_HURRICAN
);
170 signal(SIGALRM
, newturn
);
176 Signal(const char *fmt
, struct ship
*ship
, ...)
186 fmtship(format
, sizeof(format
), fmt
, ship
);
187 vwprintw(scroll_w
, format
, ap
);
194 Msg(const char *fmt
, ...)
203 vwprintw(scroll_w
, fmt
, ap
);
211 if (++sc_line
>= SCROLL_Y
)
213 wmove(scroll_w
, sc_line
, 0);
218 prompt(const char *p
, struct ship
*ship
)
220 static char buf
[BUFSIZ
];
222 fmtship(buf
, sizeof(buf
), p
, ship
);
226 waddstr(scroll_w
, buf
);
238 sgetch(const char *p
, struct ship
*ship
, int flag
)
245 while ((c
= wgetch(scroll_w
)) == EOF
)
247 if (flag
&& c
>= ' ' && c
< 0x7f)
254 sgetstr(const char *pr
, char *buf
, int n
)
259 prompt(pr
, (struct ship
*)0);
266 while ((c
= wgetch(scroll_w
)) == EOF
)
275 waddstr(scroll_w
, "\b \b");
280 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
296 wrefresh(scroll_w
); /* move the cursor */
307 && sp
->file
->row
> viewrow
308 && sp
->file
->row
< viewrow
+ VIEW_Y
309 && sp
->file
->col
> viewcol
310 && sp
->file
->col
< viewcol
+ VIEW_X
) {
311 wmove(view_w
, sp
->file
->row
- viewrow
,
312 sp
->file
->col
- viewcol
);
313 waddch(view_w
, colours(sp
));
315 sternrow(sp
) - viewrow
,
316 sterncol(sp
) - viewcol
);
317 waddch(view_w
, sterncolour(sp
));
327 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
334 wmove(stat_w
, STAT_1
, 0);
335 wprintw(stat_w
, "Points %3d\n", mf
->points
);
336 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
337 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
339 wmove(stat_w
, STAT_2
, 0);
340 wprintw(stat_w
, " 0 %c(%c)\n",
341 maxmove(ms
, winddir
+ 3, -1) + '0',
342 maxmove(ms
, winddir
+ 3, 1) + '0');
343 waddstr(stat_w
, " \\|/\n");
344 wprintw(stat_w
, " -^-%c(%c)\n",
345 maxmove(ms
, winddir
+ 2, -1) + '0',
346 maxmove(ms
, winddir
+ 2, 1) + '0');
347 waddstr(stat_w
, " /|\\\n");
348 wprintw(stat_w
, " | %c(%c)\n",
349 maxmove(ms
, winddir
+ 1, -1) + '0',
350 maxmove(ms
, winddir
+ 1, 1) + '0');
351 wprintw(stat_w
, " %c(%c)\n",
352 maxmove(ms
, winddir
, -1) + '0',
353 maxmove(ms
, winddir
, 1) + '0');
355 wmove(stat_w
, STAT_3
, 0);
356 wprintw(stat_w
, "Load %c%c %c%c\n",
357 loadname
[mf
->loadL
], readyname(mf
->readyL
),
358 loadname
[mf
->loadR
], readyname(mf
->readyR
));
359 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
360 wprintw(stat_w
, "Crew %2d %2d %2d\n",
361 mc
->crew1
, mc
->crew2
, mc
->crew3
);
362 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
363 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
364 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
368 wprintw(stat_w
, "%d", mc
->rig4
);
375 if (!boarding(ms
, 0)) {
376 mvwaddstr(slot_w
, 0, 0, " ");
377 mvwaddstr(slot_w
, 1, 0, " ");
379 mvwaddstr(slot_w
, 1, 0, "OBP");
380 if (!boarding(ms
, 1)) {
381 mvwaddstr(slot_w
, 2, 0, " ");
382 mvwaddstr(slot_w
, 3, 0, " ");
384 mvwaddstr(slot_w
, 3, 0, "DBP");
386 wmove(slot_w
, SLOT_Y
-4, 0);
388 wprintw(slot_w
, "%dRH", mf
->RH
);
390 waddstr(slot_w
, " ");
391 wmove(slot_w
, SLOT_Y
-3, 0);
393 wprintw(slot_w
, "%dRG", mf
->RG
);
395 waddstr(slot_w
, " ");
396 wmove(slot_w
, SLOT_Y
-2, 0);
398 wprintw(slot_w
, "%dRR", mf
->RR
);
400 waddstr(slot_w
, " ");
404 wprintw(slot_w
,"%d", windspeed
);
405 mvwaddch(slot_w
, Y
, 0, ' ');
406 mvwaddch(slot_w
, Y
, 2, ' ');
407 mvwaddch(slot_w
, Y
-1, 0, ' ');
408 mvwaddch(slot_w
, Y
-1, 1, ' ');
409 mvwaddch(slot_w
, Y
-1, 2, ' ');
410 mvwaddch(slot_w
, Y
+1, 0, ' ');
411 mvwaddch(slot_w
, Y
+1, 1, ' ');
412 mvwaddch(slot_w
, Y
+1, 2, ' ');
413 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
429 waddch(slot_w
, '\\');
432 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
451 for (n
= 0; n
< BOX_X
; n
++)
454 for (n
= 0; n
< BOX_X
; n
++)
456 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
457 mvaddch(n
, BOX_L
, '|');
458 mvaddch(n
, BOX_R
, '|');
460 mvaddch(BOX_T
, BOX_L
, '+');
461 mvaddch(BOX_T
, BOX_R
, '+');
462 mvaddch(BOX_B
, BOX_L
, '+');
463 mvaddch(BOX_B
, BOX_R
, '+');
466 #define WSaIM "Wooden Ships & Iron Men"
467 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
468 waddstr(view_w
, WSaIM
);
469 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
470 waddstr(view_w
, cc
->name
);
473 move(LINE_T
, LINE_L
);
474 printw("Class %d %s (%d guns) '%s' (%c%c)",
476 classname
[mc
->class],
487 viewrow
= mf
->row
- VIEW_Y
/ 2;
488 viewcol
= mf
->col
- VIEW_X
/ 2;
494 viewrow
-= VIEW_Y
/ 3;
500 viewrow
+= VIEW_Y
/ 3;
506 viewcol
-= VIEW_X
/ 5;
512 viewcol
+= VIEW_X
/ 5;
520 if (mf
->row
< viewrow
+ VIEW_Y
/4)
521 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
522 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
523 viewrow
= mf
->row
- VIEW_Y
/4;
524 if (mf
->col
< viewcol
+ VIEW_X
/8)
525 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
526 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
527 viewcol
= mf
->col
- VIEW_X
/8;