]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.29 2009/03/02 07:17:24 dholland 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: pl_7.c,v 1.29 2009/03/02 07:17:24 dholland Exp $");
53 static void Scroll(void);
54 static void endprompt(int);
55 static void adjustview(void);
61 static char sc_hasprompt
;
62 static const char *sc_prompt
;
63 static const char *sc_buf
;
73 int loaded
, fired
, changed
, repaired
;
76 char movebuf
[sizeof SHIP(0)->file
->movebuf
];
78 struct ship
*ms
; /* memorial structure, &cc->ship[player] */
79 struct File
*mf
; /* ms->file */
80 struct shipspecs
*mc
; /* ms->specs */
86 errx(1, "Can't sail on this terminal.");
88 /* initscr() already done in SCREENTEST() */
89 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
90 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
91 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
92 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
93 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
106 /* alarm already turned off */
108 wmove(scroll_w
, SCROLL_Y
- 1, 0);
117 newturn(int n __unused
)
119 repaired
= loaded
= fired
= changed
= 0;
123 if (mf
->readyL
& R_LOADING
) {
124 if (mf
->readyL
& R_DOUBLE
)
125 mf
->readyL
= R_LOADING
;
127 mf
->readyL
= R_LOADED
;
129 if (mf
->readyR
& R_LOADING
) {
130 if (mf
->readyR
& R_DOUBLE
)
131 mf
->readyR
= R_LOADING
;
133 mf
->readyR
= R_LOADED
;
136 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
139 wmove(scroll_w
, sc_line
, 0);
147 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
150 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
151 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
152 Write(W_FS
, ms
, 0, 0, 0, 0);
154 Write(W_FS
, ms
, 2, 0, 0, 0);
158 if (mf
->captured
!= 0)
159 leave(LEAVE_CAPTURED
);
161 leave(LEAVE_HURRICAN
);
166 signal(SIGALRM
, newturn
);
172 Signal(const char *fmt
, struct ship
*ship
, ...)
182 fmtship(format
, sizeof(format
), fmt
, ship
);
183 vwprintw(scroll_w
, format
, ap
);
190 Msg(const char *fmt
, ...)
199 vwprintw(scroll_w
, fmt
, ap
);
207 if (++sc_line
>= SCROLL_Y
)
209 wmove(scroll_w
, sc_line
, 0);
214 prompt(const char *p
, struct ship
*ship
)
216 static char buf
[BUFSIZ
];
218 fmtship(buf
, sizeof(buf
), p
, ship
);
222 waddstr(scroll_w
, buf
);
234 sgetch(const char *p
, struct ship
*ship
, int flag
)
241 while ((c
= wgetch(scroll_w
)) == EOF
)
243 if (flag
&& c
>= ' ' && c
< 0x7f)
250 sgetstr(const char *pr
, char *buf
, int n
)
255 prompt(pr
, (struct ship
*)0);
262 while ((c
= wgetch(scroll_w
)) == EOF
)
271 waddstr(scroll_w
, "\b \b");
276 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
292 wrefresh(scroll_w
); /* move the cursor */
303 && sp
->file
->row
> viewrow
304 && sp
->file
->row
< viewrow
+ VIEW_Y
305 && sp
->file
->col
> viewcol
306 && sp
->file
->col
< viewcol
+ VIEW_X
) {
307 wmove(view_w
, sp
->file
->row
- viewrow
,
308 sp
->file
->col
- viewcol
);
309 waddch(view_w
, colours(sp
));
311 sternrow(sp
) - viewrow
,
312 sterncol(sp
) - viewcol
);
313 waddch(view_w
, sterncolour(sp
));
323 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
330 wmove(stat_w
, STAT_1
, 0);
331 wprintw(stat_w
, "Points %3d\n", mf
->points
);
332 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
333 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
335 wmove(stat_w
, STAT_2
, 0);
336 wprintw(stat_w
, " 0 %c(%c)\n",
337 maxmove(ms
, winddir
+ 3, -1) + '0',
338 maxmove(ms
, winddir
+ 3, 1) + '0');
339 waddstr(stat_w
, " \\|/\n");
340 wprintw(stat_w
, " -^-%c(%c)\n",
341 maxmove(ms
, winddir
+ 2, -1) + '0',
342 maxmove(ms
, winddir
+ 2, 1) + '0');
343 waddstr(stat_w
, " /|\\\n");
344 wprintw(stat_w
, " | %c(%c)\n",
345 maxmove(ms
, winddir
+ 1, -1) + '0',
346 maxmove(ms
, winddir
+ 1, 1) + '0');
347 wprintw(stat_w
, " %c(%c)\n",
348 maxmove(ms
, winddir
, -1) + '0',
349 maxmove(ms
, winddir
, 1) + '0');
351 wmove(stat_w
, STAT_3
, 0);
352 wprintw(stat_w
, "Load %c%c %c%c\n",
353 loadname
[mf
->loadL
], readyname(mf
->readyL
),
354 loadname
[mf
->loadR
], readyname(mf
->readyR
));
355 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
356 wprintw(stat_w
, "Crew %2d %2d %2d\n",
357 mc
->crew1
, mc
->crew2
, mc
->crew3
);
358 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
359 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
360 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
364 wprintw(stat_w
, "%d", mc
->rig4
);
371 if (!boarding(ms
, 0)) {
372 mvwaddstr(slot_w
, 0, 0, " ");
373 mvwaddstr(slot_w
, 1, 0, " ");
375 mvwaddstr(slot_w
, 1, 0, "OBP");
376 if (!boarding(ms
, 1)) {
377 mvwaddstr(slot_w
, 2, 0, " ");
378 mvwaddstr(slot_w
, 3, 0, " ");
380 mvwaddstr(slot_w
, 3, 0, "DBP");
382 wmove(slot_w
, SLOT_Y
-4, 0);
384 wprintw(slot_w
, "%dRH", mf
->RH
);
386 waddstr(slot_w
, " ");
387 wmove(slot_w
, SLOT_Y
-3, 0);
389 wprintw(slot_w
, "%dRG", mf
->RG
);
391 waddstr(slot_w
, " ");
392 wmove(slot_w
, SLOT_Y
-2, 0);
394 wprintw(slot_w
, "%dRR", mf
->RR
);
396 waddstr(slot_w
, " ");
400 wprintw(slot_w
,"%d", windspeed
);
401 mvwaddch(slot_w
, Y
, 0, ' ');
402 mvwaddch(slot_w
, Y
, 2, ' ');
403 mvwaddch(slot_w
, Y
-1, 0, ' ');
404 mvwaddch(slot_w
, Y
-1, 1, ' ');
405 mvwaddch(slot_w
, Y
-1, 2, ' ');
406 mvwaddch(slot_w
, Y
+1, 0, ' ');
407 mvwaddch(slot_w
, Y
+1, 1, ' ');
408 mvwaddch(slot_w
, Y
+1, 2, ' ');
409 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
425 waddch(slot_w
, '\\');
428 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
447 for (n
= 0; n
< BOX_X
; n
++)
450 for (n
= 0; n
< BOX_X
; n
++)
452 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
453 mvaddch(n
, BOX_L
, '|');
454 mvaddch(n
, BOX_R
, '|');
456 mvaddch(BOX_T
, BOX_L
, '+');
457 mvaddch(BOX_T
, BOX_R
, '+');
458 mvaddch(BOX_B
, BOX_L
, '+');
459 mvaddch(BOX_B
, BOX_R
, '+');
462 #define WSaIM "Wooden Ships & Iron Men"
463 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
464 waddstr(view_w
, WSaIM
);
465 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
466 waddstr(view_w
, cc
->name
);
469 move(LINE_T
, LINE_L
);
470 printw("Class %d %s (%d guns) '%s' (%c%c)",
472 classname
[mc
->class],
483 viewrow
= mf
->row
- VIEW_Y
/ 2;
484 viewcol
= mf
->col
- VIEW_X
/ 2;
490 viewrow
-= VIEW_Y
/ 3;
496 viewrow
+= VIEW_Y
/ 3;
502 viewcol
-= VIEW_X
/ 5;
508 viewcol
+= VIEW_X
/ 5;
516 if (mf
->row
< viewrow
+ VIEW_Y
/4)
517 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
518 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
519 viewrow
= mf
->row
- VIEW_Y
/4;
520 if (mf
->col
< viewcol
+ VIEW_X
/8)
521 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
522 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
523 viewcol
= mf
->col
- VIEW_X
/8;