2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#)pl_7.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/sail/pl_7.c,v 1.7 1999/11/30 03:49:37 billf Exp $
35 * $DragonFly: src/games/sail/pl_7.c,v 1.3 2006/09/03 17:33:13 pavalos Exp $
38 #include <sys/ttydefaults.h>
47 static char sc_hasprompt
;
48 static const char *sc_prompt
;
49 static const char *sc_buf
;
52 static void Scroll(void);
53 static void prompt(const char *, struct ship
*);
54 static void endprompt(char);
55 static void adjustview(void);
60 /* initscr() already done in SCREENTEST() */
61 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
62 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
63 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
64 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
65 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
78 /* alarm already turned off */
80 wmove(scroll_w
, SCROLL_Y
- 1, 0);
90 repaired
= loaded
= fired
= changed
= 0;
94 if (mf
->readyL
& R_LOADING
) {
95 if (mf
->readyL
& R_DOUBLE
)
96 mf
->readyL
= R_LOADING
;
98 mf
->readyL
= R_LOADED
;
100 if (mf
->readyR
& R_LOADING
) {
101 if (mf
->readyR
& R_DOUBLE
)
102 mf
->readyR
= R_LOADING
;
104 mf
->readyR
= R_LOADED
;
107 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
110 wmove(scroll_w
, sc_line
, 0);
118 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
121 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
122 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
123 Write(W_FS
, ms
, 0, 0, 0, 0);
125 Write(W_FS
, ms
, 2, 0, 0, 0);
129 if (mf
->captured
!= 0)
130 leave(LEAVE_CAPTURED
);
132 leave(LEAVE_HURRICAN
);
137 signal(SIGALRM
, (sig_t
)newturn
);
143 Signal(const char *fmt
, struct ship
*ship
, ...)
154 vw_printw(scroll_w
, fmt
, ap
);
156 fmtship(format
, sizeof(format
), fmt
, ship
);
157 vw_printw(scroll_w
, format
, ap
);
166 if (++sc_line
>= SCROLL_Y
)
168 wmove(scroll_w
, sc_line
, 0);
173 prompt(const char *p
, struct ship
*ship
)
178 printf(buf
, p
, ship
->shipname
, colours(ship
),
185 waddstr(scroll_w
, p
);
197 sgetch(const char *p
, struct ship
*ship
, char flag
)
205 while ((c
= wgetch(scroll_w
)) == EOF
)
207 if (flag
&& c
>= ' ' && c
< 0x7f)
214 sgetstr(const char *pr
, char *buf
, int n
)
226 while ((c
= wgetch(scroll_w
)) == EOF
)
235 waddstr(scroll_w
, "\b \b");
240 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
256 wrefresh(scroll_w
); /* move the cursor */
267 && sp
->file
->row
> viewrow
268 && sp
->file
->row
< viewrow
+ VIEW_Y
269 && sp
->file
->col
> viewcol
270 && sp
->file
->col
< viewcol
+ VIEW_X
) {
271 wmove(view_w
, sp
->file
->row
- viewrow
,
272 sp
->file
->col
- viewcol
);
273 waddch(view_w
, colours(sp
));
275 sternrow(sp
) - viewrow
,
276 sterncol(sp
) - viewcol
);
277 waddch(view_w
, sterncolour(sp
));
287 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
294 wmove(stat_w
, STAT_1
, 0);
295 wprintw(stat_w
, "Points %3d\n", mf
->points
);
296 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
297 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
299 wmove(stat_w
, STAT_2
, 0);
300 wprintw(stat_w
, " 0 %c(%c)\n",
301 maxmove(ms
, winddir
+ 3, -1) + '0',
302 maxmove(ms
, winddir
+ 3, 1) + '0');
303 waddstr(stat_w
, " \\|/\n");
304 wprintw(stat_w
, " -^-%c(%c)\n",
305 maxmove(ms
, winddir
+ 2, -1) + '0',
306 maxmove(ms
, winddir
+ 2, 1) + '0');
307 waddstr(stat_w
, " /|\\\n");
308 wprintw(stat_w
, " | %c(%c)\n",
309 maxmove(ms
, winddir
+ 1, -1) + '0',
310 maxmove(ms
, winddir
+ 1, 1) + '0');
311 wprintw(stat_w
, " %c(%c)\n",
312 maxmove(ms
, winddir
, -1) + '0',
313 maxmove(ms
, winddir
, 1) + '0');
315 wmove(stat_w
, STAT_3
, 0);
316 wprintw(stat_w
, "Load %c%c %c%c\n",
317 loadname
[mf
->loadL
], readyname(mf
->readyL
),
318 loadname
[mf
->loadR
], readyname(mf
->readyR
));
319 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
320 wprintw(stat_w
, "Crew %2d %2d %2d\n",
321 mc
->crew1
, mc
->crew2
, mc
->crew3
);
322 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
323 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
324 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
328 wprintw(stat_w
, "%d", mc
->rig4
);
335 if (!boarding(ms
, 0)) {
336 mvwaddstr(slot_w
, 0, 0, " ");
337 mvwaddstr(slot_w
, 1, 0, " ");
339 mvwaddstr(slot_w
, 1, 0, "OBP");
340 if (!boarding(ms
, 1)) {
341 mvwaddstr(slot_w
, 2, 0, " ");
342 mvwaddstr(slot_w
, 3, 0, " ");
344 mvwaddstr(slot_w
, 3, 0, "DBP");
346 wmove(slot_w
, SLOT_Y
-4, 0);
348 wprintw(slot_w
, "%dRH", mf
->RH
);
350 waddstr(slot_w
, " ");
351 wmove(slot_w
, SLOT_Y
-3, 0);
353 wprintw(slot_w
, "%dRG", mf
->RG
);
355 waddstr(slot_w
, " ");
356 wmove(slot_w
, SLOT_Y
-2, 0);
358 wprintw(slot_w
, "%dRR", mf
->RR
);
360 waddstr(slot_w
, " ");
364 wprintw(slot_w
,"%d", windspeed
);
365 mvwaddch(slot_w
, Y
, 0, ' ');
366 mvwaddch(slot_w
, Y
, 2, ' ');
367 mvwaddch(slot_w
, Y
-1, 0, ' ');
368 mvwaddch(slot_w
, Y
-1, 1, ' ');
369 mvwaddch(slot_w
, Y
-1, 2, ' ');
370 mvwaddch(slot_w
, Y
+1, 0, ' ');
371 mvwaddch(slot_w
, Y
+1, 1, ' ');
372 mvwaddch(slot_w
, Y
+1, 2, ' ');
373 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
389 waddch(slot_w
, '\\');
392 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
411 for (n
= 0; n
< BOX_X
; n
++)
414 for (n
= 0; n
< BOX_X
; n
++)
416 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
417 mvaddch(n
, BOX_L
, '|');
418 mvaddch(n
, BOX_R
, '|');
420 mvaddch(BOX_T
, BOX_L
, '+');
421 mvaddch(BOX_T
, BOX_R
, '+');
422 mvaddch(BOX_B
, BOX_L
, '+');
423 mvaddch(BOX_B
, BOX_R
, '+');
426 #define WSaIM "Wooden Ships & Iron Men"
427 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
428 waddstr(view_w
, WSaIM
);
429 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
430 waddstr(view_w
, cc
->name
);
433 move(LINE_T
, LINE_L
);
434 printw("Class %d %s (%d guns) '%s' (%c%c)",
436 classname
[mc
->class],
447 viewrow
= mf
->row
- VIEW_Y
/ 2;
448 viewcol
= mf
->col
- VIEW_X
/ 2;
454 viewrow
-= VIEW_Y
/ 3;
460 viewrow
+= VIEW_Y
/ 3;
466 viewcol
-= VIEW_X
/ 5;
472 viewcol
+= VIEW_X
/ 5;
480 if (mf
->row
< viewrow
+ VIEW_Y
/4)
481 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
482 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
483 viewrow
= mf
->row
- VIEW_Y
/4;
484 if (mf
->col
< viewcol
+ VIEW_X
/8)
485 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
486 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
487 viewcol
= mf
->col
- VIEW_X
/8;