]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
1 /* $NetBSD: pl_7.c,v 1.23 2001/01/16 02:44:43 cgd 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.23 2001/01/16 02:44:43 cgd Exp $");
56 void initscreen(void);
57 void cleanupscreen(void);
59 void Signal(const char *, struct ship
*, ...)
60 __attribute__((__format__(__printf__
,1,3)));
61 void Msg(const char *, ...)
62 __attribute__((__format__(__printf__
,1,2)));
63 static void Scroll(void);
64 void prompt(const char *, struct ship
*);
65 static void endprompt(int);
66 int sgetch(const char *, struct ship
*, int);
67 void sgetstr(const char *, char *, int);
68 void draw_screen(void);
73 void draw_board(void);
74 void centerview(void);
79 static void adjustview(void);
85 static char sc_hasprompt
;
86 static const char *sc_prompt
;
87 static const char *sc_buf
;
97 int loaded
, fired
, changed
, repaired
;
100 char movebuf
[sizeof SHIP(0)->file
->movebuf
];
102 struct ship
*ms
; /* memorial structure, &cc->ship[player] */
103 struct File
*mf
; /* ms->file */
104 struct shipspecs
*mc
; /* ms->specs */
110 printf("Can't sail on this terminal.\n");
113 /* initscr() already done in SCREENTEST() */
114 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
115 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
116 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
117 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
118 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
131 /* alarm already turned off */
133 wmove(scroll_w
, SCROLL_Y
- 1, 0);
142 newturn(int n
__attribute__((__unused__
)))
144 repaired
= loaded
= fired
= changed
= 0;
148 if (mf
->readyL
& R_LOADING
) {
149 if (mf
->readyL
& R_DOUBLE
)
150 mf
->readyL
= R_LOADING
;
152 mf
->readyL
= R_LOADED
;
154 if (mf
->readyR
& R_LOADING
) {
155 if (mf
->readyR
& R_DOUBLE
)
156 mf
->readyR
= R_LOADING
;
158 mf
->readyR
= R_LOADED
;
161 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
164 wmove(scroll_w
, sc_line
, 0);
172 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
175 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
176 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
177 Write(W_FS
, ms
, 0, 0, 0, 0);
179 Write(W_FS
, ms
, 2, 0, 0, 0);
183 if (mf
->captured
!= 0)
184 leave(LEAVE_CAPTURED
);
186 leave(LEAVE_HURRICAN
);
191 signal(SIGALRM
, newturn
);
197 Signal(const char *fmt
, struct ship
*ship
, ...)
207 fmtship(format
, sizeof(format
), fmt
, ship
);
208 vwprintw(scroll_w
, format
, ap
);
215 Msg(const char *fmt
, ...)
224 vwprintw(scroll_w
, fmt
, ap
);
232 if (++sc_line
>= SCROLL_Y
)
234 wmove(scroll_w
, sc_line
, 0);
239 prompt(const char *p
, struct ship
*ship
)
241 static char buf
[BUFSIZ
];
243 fmtship(buf
, sizeof(buf
), p
, ship
);
247 waddstr(scroll_w
, buf
);
259 sgetch(const char *p
, struct ship
*ship
, int flag
)
266 while ((c
= wgetch(scroll_w
)) == EOF
)
268 if (flag
&& c
>= ' ' && c
< 0x7f)
275 sgetstr(const char *pr
, char *buf
, int n
)
280 prompt(pr
, (struct ship
*)0);
287 while ((c
= wgetch(scroll_w
)) == EOF
)
296 waddstr(scroll_w
, "\b \b");
301 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
317 wrefresh(scroll_w
); /* move the cursor */
328 && sp
->file
->row
> viewrow
329 && sp
->file
->row
< viewrow
+ VIEW_Y
330 && sp
->file
->col
> viewcol
331 && sp
->file
->col
< viewcol
+ VIEW_X
) {
332 wmove(view_w
, sp
->file
->row
- viewrow
,
333 sp
->file
->col
- viewcol
);
334 waddch(view_w
, colours(sp
));
336 sternrow(sp
) - viewrow
,
337 sterncol(sp
) - viewcol
);
338 waddch(view_w
, sterncolour(sp
));
348 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
355 wmove(stat_w
, STAT_1
, 0);
356 wprintw(stat_w
, "Points %3d\n", mf
->points
);
357 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
358 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
360 wmove(stat_w
, STAT_2
, 0);
361 wprintw(stat_w
, " 0 %c(%c)\n",
362 maxmove(ms
, winddir
+ 3, -1) + '0',
363 maxmove(ms
, winddir
+ 3, 1) + '0');
364 waddstr(stat_w
, " \\|/\n");
365 wprintw(stat_w
, " -^-%c(%c)\n",
366 maxmove(ms
, winddir
+ 2, -1) + '0',
367 maxmove(ms
, winddir
+ 2, 1) + '0');
368 waddstr(stat_w
, " /|\\\n");
369 wprintw(stat_w
, " | %c(%c)\n",
370 maxmove(ms
, winddir
+ 1, -1) + '0',
371 maxmove(ms
, winddir
+ 1, 1) + '0');
372 wprintw(stat_w
, " %c(%c)\n",
373 maxmove(ms
, winddir
, -1) + '0',
374 maxmove(ms
, winddir
, 1) + '0');
376 wmove(stat_w
, STAT_3
, 0);
377 wprintw(stat_w
, "Load %c%c %c%c\n",
378 loadname
[mf
->loadL
], readyname(mf
->readyL
),
379 loadname
[mf
->loadR
], readyname(mf
->readyR
));
380 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
381 wprintw(stat_w
, "Crew %2d %2d %2d\n",
382 mc
->crew1
, mc
->crew2
, mc
->crew3
);
383 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
384 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
385 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
389 wprintw(stat_w
, "%d", mc
->rig4
);
396 if (!boarding(ms
, 0)) {
397 mvwaddstr(slot_w
, 0, 0, " ");
398 mvwaddstr(slot_w
, 1, 0, " ");
400 mvwaddstr(slot_w
, 1, 0, "OBP");
401 if (!boarding(ms
, 1)) {
402 mvwaddstr(slot_w
, 2, 0, " ");
403 mvwaddstr(slot_w
, 3, 0, " ");
405 mvwaddstr(slot_w
, 3, 0, "DBP");
407 wmove(slot_w
, SLOT_Y
-4, 0);
409 wprintw(slot_w
, "%dRH", mf
->RH
);
411 waddstr(slot_w
, " ");
412 wmove(slot_w
, SLOT_Y
-3, 0);
414 wprintw(slot_w
, "%dRG", mf
->RG
);
416 waddstr(slot_w
, " ");
417 wmove(slot_w
, SLOT_Y
-2, 0);
419 wprintw(slot_w
, "%dRR", mf
->RR
);
421 waddstr(slot_w
, " ");
425 wprintw(slot_w
,"%d", windspeed
);
426 mvwaddch(slot_w
, Y
, 0, ' ');
427 mvwaddch(slot_w
, Y
, 2, ' ');
428 mvwaddch(slot_w
, Y
-1, 0, ' ');
429 mvwaddch(slot_w
, Y
-1, 1, ' ');
430 mvwaddch(slot_w
, Y
-1, 2, ' ');
431 mvwaddch(slot_w
, Y
+1, 0, ' ');
432 mvwaddch(slot_w
, Y
+1, 1, ' ');
433 mvwaddch(slot_w
, Y
+1, 2, ' ');
434 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
450 waddch(slot_w
, '\\');
453 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
472 for (n
= 0; n
< BOX_X
; n
++)
475 for (n
= 0; n
< BOX_X
; n
++)
477 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
478 mvaddch(n
, BOX_L
, '|');
479 mvaddch(n
, BOX_R
, '|');
481 mvaddch(BOX_T
, BOX_L
, '+');
482 mvaddch(BOX_T
, BOX_R
, '+');
483 mvaddch(BOX_B
, BOX_L
, '+');
484 mvaddch(BOX_B
, BOX_R
, '+');
487 #define WSaIM "Wooden Ships & Iron Men"
488 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
489 waddstr(view_w
, WSaIM
);
490 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
491 waddstr(view_w
, cc
->name
);
494 move(LINE_T
, LINE_L
);
495 printw("Class %d %s (%d guns) '%s' (%c%c)",
497 classname
[mc
->class],
508 viewrow
= mf
->row
- VIEW_Y
/ 2;
509 viewcol
= mf
->col
- VIEW_X
/ 2;
515 viewrow
-= VIEW_Y
/ 3;
521 viewrow
+= VIEW_Y
/ 3;
527 viewcol
-= VIEW_X
/ 5;
533 viewcol
+= VIEW_X
/ 5;
541 if (mf
->row
< viewrow
+ VIEW_Y
/4)
542 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
543 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
544 viewrow
= mf
->row
- VIEW_Y
/4;
545 if (mf
->col
< viewcol
+ VIEW_X
/8)
546 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
547 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
548 viewcol
= mf
->col
- VIEW_X
/8;