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. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)pl_7.c 8.1 (Berkeley) 5/31/93
30 * $FreeBSD: src/games/sail/pl_7.c,v 1.7 1999/11/30 03:49:37 billf Exp $
31 * $DragonFly: src/games/sail/pl_7.c,v 1.3 2006/09/03 17:33:13 pavalos Exp $
34 #include <sys/ttydefaults.h>
43 static char sc_hasprompt
;
44 static const char *sc_prompt
;
45 static const char *sc_buf
;
48 static void Scroll(void);
49 static void prompt(const char *, struct ship
*);
50 static void endprompt(char);
51 static void adjustview(void);
56 /* initscr() already done in SCREENTEST() */
57 view_w
= newwin(VIEW_Y
, VIEW_X
, VIEW_T
, VIEW_L
);
58 slot_w
= newwin(SLOT_Y
, SLOT_X
, SLOT_T
, SLOT_L
);
59 scroll_w
= newwin(SCROLL_Y
, SCROLL_X
, SCROLL_T
, SCROLL_L
);
60 stat_w
= newwin(STAT_Y
, STAT_X
, STAT_T
, STAT_L
);
61 turn_w
= newwin(TURN_Y
, TURN_X
, TURN_T
, TURN_L
);
74 /* alarm already turned off */
76 wmove(scroll_w
, SCROLL_Y
- 1, 0);
86 repaired
= loaded
= fired
= changed
= 0;
90 if (mf
->readyL
& R_LOADING
) {
91 if (mf
->readyL
& R_DOUBLE
)
92 mf
->readyL
= R_LOADING
;
94 mf
->readyL
= R_LOADED
;
96 if (mf
->readyR
& R_LOADING
) {
97 if (mf
->readyR
& R_DOUBLE
)
98 mf
->readyR
= R_LOADING
;
100 mf
->readyR
= R_LOADED
;
103 Write(W_DDEAD
, SHIP(0), 0, 0, 0, 0);
106 wmove(scroll_w
, sc_line
, 0);
114 wprintw(scroll_w
, "%s%s", sc_prompt
, sc_buf
);
117 Write(W_ALIVE
, SHIP(0), 0, 0, 0, 0);
118 if (mf
->FS
&& (!mc
->rig1
|| windspeed
== 6))
119 Write(W_FS
, ms
, 0, 0, 0, 0);
121 Write(W_FS
, ms
, 2, 0, 0, 0);
125 if (mf
->captured
!= 0)
126 leave(LEAVE_CAPTURED
);
128 leave(LEAVE_HURRICAN
);
133 signal(SIGALRM
, (sig_t
)newturn
);
139 Signal(const char *fmt
, struct ship
*ship
, ...)
150 vw_printw(scroll_w
, fmt
, ap
);
152 fmtship(format
, sizeof(format
), fmt
, ship
);
153 vw_printw(scroll_w
, format
, ap
);
162 if (++sc_line
>= SCROLL_Y
)
164 wmove(scroll_w
, sc_line
, 0);
169 prompt(const char *p
, struct ship
*ship
)
174 printf(buf
, p
, ship
->shipname
, colours(ship
),
181 waddstr(scroll_w
, p
);
193 sgetch(const char *p
, struct ship
*ship
, char flag
)
201 while ((c
= wgetch(scroll_w
)) == EOF
)
203 if (flag
&& c
>= ' ' && c
< 0x7f)
210 sgetstr(const char *pr
, char *buf
, int n
)
222 while ((c
= wgetch(scroll_w
)) == EOF
)
231 waddstr(scroll_w
, "\b \b");
236 if (c
>= ' ' && c
< 0x7f && p
< buf
+ n
- 1) {
252 wrefresh(scroll_w
); /* move the cursor */
263 && sp
->file
->row
> viewrow
264 && sp
->file
->row
< viewrow
+ VIEW_Y
265 && sp
->file
->col
> viewcol
266 && sp
->file
->col
< viewcol
+ VIEW_X
) {
267 wmove(view_w
, sp
->file
->row
- viewrow
,
268 sp
->file
->col
- viewcol
);
269 waddch(view_w
, colours(sp
));
271 sternrow(sp
) - viewrow
,
272 sterncol(sp
) - viewcol
);
273 waddch(view_w
, sterncolour(sp
));
283 wprintw(turn_w
, "%cTurn %d", dont_adjust
?'*':'-', turn
);
290 wmove(stat_w
, STAT_1
, 0);
291 wprintw(stat_w
, "Points %3d\n", mf
->points
);
292 wprintw(stat_w
, "Fouls %2d\n", fouled(ms
));
293 wprintw(stat_w
, "Grapples %2d\n", grappled(ms
));
295 wmove(stat_w
, STAT_2
, 0);
296 wprintw(stat_w
, " 0 %c(%c)\n",
297 maxmove(ms
, winddir
+ 3, -1) + '0',
298 maxmove(ms
, winddir
+ 3, 1) + '0');
299 waddstr(stat_w
, " \\|/\n");
300 wprintw(stat_w
, " -^-%c(%c)\n",
301 maxmove(ms
, winddir
+ 2, -1) + '0',
302 maxmove(ms
, winddir
+ 2, 1) + '0');
303 waddstr(stat_w
, " /|\\\n");
304 wprintw(stat_w
, " | %c(%c)\n",
305 maxmove(ms
, winddir
+ 1, -1) + '0',
306 maxmove(ms
, winddir
+ 1, 1) + '0');
307 wprintw(stat_w
, " %c(%c)\n",
308 maxmove(ms
, winddir
, -1) + '0',
309 maxmove(ms
, winddir
, 1) + '0');
311 wmove(stat_w
, STAT_3
, 0);
312 wprintw(stat_w
, "Load %c%c %c%c\n",
313 loadname
[mf
->loadL
], readyname(mf
->readyL
),
314 loadname
[mf
->loadR
], readyname(mf
->readyR
));
315 wprintw(stat_w
, "Hull %2d\n", mc
->hull
);
316 wprintw(stat_w
, "Crew %2d %2d %2d\n",
317 mc
->crew1
, mc
->crew2
, mc
->crew3
);
318 wprintw(stat_w
, "Guns %2d %2d\n", mc
->gunL
, mc
->gunR
);
319 wprintw(stat_w
, "Carr %2d %2d\n", mc
->carL
, mc
->carR
);
320 wprintw(stat_w
, "Rigg %d %d %d ", mc
->rig1
, mc
->rig2
, mc
->rig3
);
324 wprintw(stat_w
, "%d", mc
->rig4
);
331 if (!boarding(ms
, 0)) {
332 mvwaddstr(slot_w
, 0, 0, " ");
333 mvwaddstr(slot_w
, 1, 0, " ");
335 mvwaddstr(slot_w
, 1, 0, "OBP");
336 if (!boarding(ms
, 1)) {
337 mvwaddstr(slot_w
, 2, 0, " ");
338 mvwaddstr(slot_w
, 3, 0, " ");
340 mvwaddstr(slot_w
, 3, 0, "DBP");
342 wmove(slot_w
, SLOT_Y
-4, 0);
344 wprintw(slot_w
, "%dRH", mf
->RH
);
346 waddstr(slot_w
, " ");
347 wmove(slot_w
, SLOT_Y
-3, 0);
349 wprintw(slot_w
, "%dRG", mf
->RG
);
351 waddstr(slot_w
, " ");
352 wmove(slot_w
, SLOT_Y
-2, 0);
354 wprintw(slot_w
, "%dRR", mf
->RR
);
356 waddstr(slot_w
, " ");
360 wprintw(slot_w
,"%d", windspeed
);
361 mvwaddch(slot_w
, Y
, 0, ' ');
362 mvwaddch(slot_w
, Y
, 2, ' ');
363 mvwaddch(slot_w
, Y
-1, 0, ' ');
364 mvwaddch(slot_w
, Y
-1, 1, ' ');
365 mvwaddch(slot_w
, Y
-1, 2, ' ');
366 mvwaddch(slot_w
, Y
+1, 0, ' ');
367 mvwaddch(slot_w
, Y
+1, 1, ' ');
368 mvwaddch(slot_w
, Y
+1, 2, ' ');
369 wmove(slot_w
, Y
- dr
[winddir
], 1 - dc
[winddir
]);
385 waddch(slot_w
, '\\');
388 mvwaddch(slot_w
, Y
+ dr
[winddir
], 1 + dc
[winddir
], '+');
407 for (n
= 0; n
< BOX_X
; n
++)
410 for (n
= 0; n
< BOX_X
; n
++)
412 for (n
= BOX_T
+1; n
< BOX_B
; n
++) {
413 mvaddch(n
, BOX_L
, '|');
414 mvaddch(n
, BOX_R
, '|');
416 mvaddch(BOX_T
, BOX_L
, '+');
417 mvaddch(BOX_T
, BOX_R
, '+');
418 mvaddch(BOX_B
, BOX_L
, '+');
419 mvaddch(BOX_B
, BOX_R
, '+');
422 #define WSaIM "Wooden Ships & Iron Men"
423 wmove(view_w
, 2, (VIEW_X
- sizeof WSaIM
- 1) / 2);
424 waddstr(view_w
, WSaIM
);
425 wmove(view_w
, 4, (VIEW_X
- strlen(cc
->name
)) / 2);
426 waddstr(view_w
, cc
->name
);
429 move(LINE_T
, LINE_L
);
430 printw("Class %d %s (%d guns) '%s' (%c%c)",
432 classname
[mc
->class],
443 viewrow
= mf
->row
- VIEW_Y
/ 2;
444 viewcol
= mf
->col
- VIEW_X
/ 2;
450 viewrow
-= VIEW_Y
/ 3;
456 viewrow
+= VIEW_Y
/ 3;
462 viewcol
-= VIEW_X
/ 5;
468 viewcol
+= VIEW_X
/ 5;
476 if (mf
->row
< viewrow
+ VIEW_Y
/4)
477 viewrow
= mf
->row
- (VIEW_Y
- VIEW_Y
/4);
478 else if (mf
->row
> viewrow
+ (VIEW_Y
- VIEW_Y
/4))
479 viewrow
= mf
->row
- VIEW_Y
/4;
480 if (mf
->col
< viewcol
+ VIEW_X
/8)
481 viewcol
= mf
->col
- (VIEW_X
- VIEW_X
/8);
482 else if (mf
->col
> viewcol
+ (VIEW_X
- VIEW_X
/8))
483 viewcol
= mf
->col
- VIEW_X
/8;