]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - sail/pl_7.c
use CPPFLAGS instead of CFLAGS
[bsdgames-darwin.git] / sail / pl_7.c
1 /* $NetBSD: pl_7.c,v 1.8 1997/10/13 21:04:32 christos Exp $ */
2
3 /*
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
22 *
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
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)pl_7.c 8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: pl_7.c,v 1.8 1997/10/13 21:04:32 christos Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include <sys/ttydefaults.h>
46 #include "player.h"
47 #ifdef __STDC__
48 #include <stdarg.h>
49 #else
50 #include <varargs.h>
51 #endif
52 #include <unistd.h>
53
54
55 /*
56 * Display interface
57 */
58
59 static char sc_hasprompt;
60 static char *sc_prompt;
61 static char *sc_buf;
62 static int sc_line;
63
64 void
65 initscreen()
66 {
67 /* initscr() already done in SCREENTEST() */
68 view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L);
69 slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L);
70 scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L);
71 stat_w = newwin(STAT_Y, STAT_X, STAT_T, STAT_L);
72 turn_w = newwin(TURN_Y, TURN_X, TURN_T, TURN_L);
73 done_curses++;
74 (void) leaveok(view_w, 1);
75 (void) leaveok(slot_w, 1);
76 (void) leaveok(stat_w, 1);
77 (void) leaveok(turn_w, 1);
78 noecho();
79 crmode();
80 }
81
82 void
83 cleanupscreen()
84 {
85 /* alarm already turned off */
86 if (done_curses) {
87 (void) wmove(scroll_w, SCROLL_Y - 1, 0);
88 (void) wclrtoeol(scroll_w);
89 draw_screen();
90 endwin();
91 }
92 }
93
94 /*ARGSUSED*/
95 void
96 newturn(n)
97 int n;
98 {
99 repaired = loaded = fired = changed = 0;
100 movebuf[0] = '\0';
101
102 (void) alarm(0);
103 if (mf->readyL & R_LOADING)
104 if (mf->readyL & R_DOUBLE)
105 mf->readyL = R_LOADING;
106 else
107 mf->readyL = R_LOADED;
108 if (mf->readyR & R_LOADING)
109 if (mf->readyR & R_DOUBLE)
110 mf->readyR = R_LOADING;
111 else
112 mf->readyR = R_LOADED;
113 if (!hasdriver)
114 Write(W_DDEAD, SHIP(0), 0, 0, 0, 0, 0);
115
116 if (sc_hasprompt) {
117 (void) wmove(scroll_w, sc_line, 0);
118 (void) wclrtoeol(scroll_w);
119 }
120 if (Sync() < 0)
121 leave(LEAVE_SYNC);
122 if (!hasdriver)
123 leave(LEAVE_DRIVER);
124 if (sc_hasprompt)
125 (void) wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
126
127 if (turn % 50 == 0)
128 Write(W_ALIVE, SHIP(0), 0, 0, 0, 0, 0);
129 if (mf->FS && (!mc->rig1 || windspeed == 6))
130 Write(W_FS, ms, 0, 0, 0, 0, 0);
131 if (mf->FS == 1)
132 Write(W_FS, ms, 0, 2, 0, 0, 0);
133
134 if (mf->struck)
135 leave(LEAVE_QUIT);
136 if (mf->captured != 0)
137 leave(LEAVE_CAPTURED);
138 if (windspeed == 7)
139 leave(LEAVE_HURRICAN);
140
141 adjustview();
142 draw_screen();
143
144 (void) signal(SIGALRM, newturn);
145 (void) alarm(7);
146 }
147
148 /*VARARGS2*/
149 void
150 #ifdef __STDC__
151 Signal(const char *fmt, struct ship *ship, ...)
152 #else
153 Signal(va_alist)
154 va_dcl
155 #endif
156 {
157 va_list ap;
158 char format[BUFSIZ];
159 #ifndef __STDC__
160 const char *fmt;
161 struct ship *ship;
162
163 va_start(ap);
164 fmt = va_arg(ap, const char *);
165 ship = va_arg(ap, struct ship *);
166 #else
167 va_start(ap, ship);
168 #endif
169 if (!done_curses)
170 return;
171 if (*fmt == '\7')
172 putchar(*fmt++);
173 fmtship(format, sizeof(format), fmt, ship);
174 (void) vwprintw(scroll_w, format, ap);
175 va_end(ap);
176 Scroll();
177 }
178
179 /*VARARGS2*/
180 void
181 #ifdef __STDC__
182 Msg(const char *fmt, ...)
183 #else
184 Msg(va_alist)
185 va_dcl
186 #endif
187 {
188 va_list ap;
189 #ifndef __STDC__
190 const char *fmt;
191
192 va_start(ap);
193 fmt = va_arg(ap, const char *);
194 #else
195 va_start(ap, fmt);
196 #endif
197
198 if (!done_curses)
199 return;
200 if (*fmt == '\7')
201 putchar(*fmt++);
202 (void) vwprintw(scroll_w, fmt, ap);
203 va_end(ap);
204 Scroll();
205 }
206
207 void
208 Scroll()
209 {
210 if (++sc_line >= SCROLL_Y)
211 sc_line = 0;
212 (void) wmove(scroll_w, sc_line, 0);
213 (void) wclrtoeol(scroll_w);
214 }
215
216 void
217 prompt(p, ship)
218 char *p;
219 struct ship *ship;
220 {
221 static char buf[BUFSIZ];
222
223 fmtship(buf, sizeof(buf), p, ship);
224 sc_prompt = buf;
225 sc_buf = "";
226 sc_hasprompt = 1;
227 (void) waddstr(scroll_w, buf);
228 }
229
230 void
231 endprompt(flag)
232 char flag;
233 {
234 sc_hasprompt = 0;
235 if (flag)
236 Scroll();
237 }
238
239 int
240 sgetch(p, ship, flag)
241 char *p;
242 struct ship *ship;
243 char flag;
244 {
245 int c;
246 prompt(p, ship);
247 blockalarm();
248 (void) wrefresh(scroll_w);
249 unblockalarm();
250 while ((c = wgetch(scroll_w)) == EOF)
251 ;
252 if (flag && c >= ' ' && c < 0x7f)
253 (void) waddch(scroll_w, c);
254 endprompt(flag);
255 return c;
256 }
257
258 void
259 sgetstr(pr, buf, n)
260 char *pr;
261 char *buf;
262 int n;
263 {
264 int c;
265 char *p = buf;
266
267 prompt(pr, (struct ship *)0);
268 sc_buf = buf;
269 for (;;) {
270 *p = 0;
271 blockalarm();
272 (void) wrefresh(scroll_w);
273 unblockalarm();
274 while ((c = wgetch(scroll_w)) == EOF)
275 ;
276 switch (c) {
277 case '\n':
278 case '\r':
279 endprompt(1);
280 return;
281 case '\b':
282 if (p > buf) {
283 (void) waddstr(scroll_w, "\b \b");
284 p--;
285 }
286 break;
287 default:
288 if (c >= ' ' && c < 0x7f && p < buf + n - 1) {
289 *p++ = c;
290 (void) waddch(scroll_w, c);
291 } else
292 (void) putchar('\a');
293 }
294 }
295 }
296
297 void
298 draw_screen()
299 {
300 draw_view();
301 draw_turn();
302 draw_stat();
303 draw_slot();
304 (void) wrefresh(scroll_w); /* move the cursor */
305 }
306
307 void
308 draw_view()
309 {
310 struct ship *sp;
311
312 (void) werase(view_w);
313 foreachship(sp) {
314 if (sp->file->dir
315 && sp->file->row > viewrow
316 && sp->file->row < viewrow + VIEW_Y
317 && sp->file->col > viewcol
318 && sp->file->col < viewcol + VIEW_X) {
319 (void) wmove(view_w, sp->file->row - viewrow,
320 sp->file->col - viewcol);
321 (void) waddch(view_w, colours(sp));
322 (void) wmove(view_w,
323 sternrow(sp) - viewrow,
324 sterncol(sp) - viewcol);
325 (void) waddch(view_w, sterncolour(sp));
326 }
327 }
328 (void) wrefresh(view_w);
329 }
330
331 void
332 draw_turn()
333 {
334 (void) wmove(turn_w, 0, 0);
335 (void) wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn);
336 (void) wrefresh(turn_w);
337 }
338
339 void
340 draw_stat()
341 {
342 (void) wmove(stat_w, STAT_1, 0);
343 (void) wprintw(stat_w, "Points %3d\n", mf->points);
344 (void) wprintw(stat_w, "Fouls %2d\n", fouled(ms));
345 (void) wprintw(stat_w, "Grapples %2d\n", grappled(ms));
346
347 (void) wmove(stat_w, STAT_2, 0);
348 (void) wprintw(stat_w, " 0 %c(%c)\n",
349 maxmove(ms, winddir + 3, -1) + '0',
350 maxmove(ms, winddir + 3, 1) + '0');
351 (void) waddstr(stat_w, " \\|/\n");
352 (void) wprintw(stat_w, " -^-%c(%c)\n",
353 maxmove(ms, winddir + 2, -1) + '0',
354 maxmove(ms, winddir + 2, 1) + '0');
355 (void) waddstr(stat_w, " /|\\\n");
356 (void) wprintw(stat_w, " | %c(%c)\n",
357 maxmove(ms, winddir + 1, -1) + '0',
358 maxmove(ms, winddir + 1, 1) + '0');
359 (void) wprintw(stat_w, " %c(%c)\n",
360 maxmove(ms, winddir, -1) + '0',
361 maxmove(ms, winddir, 1) + '0');
362
363 (void) wmove(stat_w, STAT_3, 0);
364 (void) wprintw(stat_w, "Load %c%c %c%c\n",
365 loadname[mf->loadL], readyname(mf->readyL),
366 loadname[mf->loadR], readyname(mf->readyR));
367 (void) wprintw(stat_w, "Hull %2d\n", mc->hull);
368 (void) wprintw(stat_w, "Crew %2d %2d %2d\n",
369 mc->crew1, mc->crew2, mc->crew3);
370 (void) wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR);
371 (void) wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR);
372 (void) wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3);
373 if (mc->rig4 < 0)
374 (void) waddch(stat_w, '-');
375 else
376 (void) wprintw(stat_w, "%d", mc->rig4);
377 (void) wrefresh(stat_w);
378 }
379
380 void
381 draw_slot()
382 {
383 if (!boarding(ms, 0)) {
384 (void) mvwaddstr(slot_w, 0, 0, " ");
385 (void) mvwaddstr(slot_w, 1, 0, " ");
386 } else
387 (void) mvwaddstr(slot_w, 1, 0, "OBP");
388 if (!boarding(ms, 1)) {
389 (void) mvwaddstr(slot_w, 2, 0, " ");
390 (void) mvwaddstr(slot_w, 3, 0, " ");
391 } else
392 (void) mvwaddstr(slot_w, 3, 0, "DBP");
393
394 (void) wmove(slot_w, SLOT_Y-4, 0);
395 if (mf->RH)
396 (void) wprintw(slot_w, "%dRH", mf->RH);
397 else
398 (void) waddstr(slot_w, " ");
399 (void) wmove(slot_w, SLOT_Y-3, 0);
400 if (mf->RG)
401 (void) wprintw(slot_w, "%dRG", mf->RG);
402 else
403 (void) waddstr(slot_w, " ");
404 (void) wmove(slot_w, SLOT_Y-2, 0);
405 if (mf->RR)
406 (void) wprintw(slot_w, "%dRR", mf->RR);
407 else
408 (void) waddstr(slot_w, " ");
409
410 #define Y (SLOT_Y/2)
411 (void) wmove(slot_w, 7, 1);
412 (void) wprintw(slot_w,"%d", windspeed);
413 (void) mvwaddch(slot_w, Y, 0, ' ');
414 (void) mvwaddch(slot_w, Y, 2, ' ');
415 (void) mvwaddch(slot_w, Y-1, 0, ' ');
416 (void) mvwaddch(slot_w, Y-1, 1, ' ');
417 (void) mvwaddch(slot_w, Y-1, 2, ' ');
418 (void) mvwaddch(slot_w, Y+1, 0, ' ');
419 (void) mvwaddch(slot_w, Y+1, 1, ' ');
420 (void) mvwaddch(slot_w, Y+1, 2, ' ');
421 (void) wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]);
422 switch (winddir) {
423 case 1:
424 case 5:
425 (void) waddch(slot_w, '|');
426 break;
427 case 2:
428 case 6:
429 (void) waddch(slot_w, '/');
430 break;
431 case 3:
432 case 7:
433 (void) waddch(slot_w, '-');
434 break;
435 case 4:
436 case 8:
437 (void) waddch(slot_w, '\\');
438 break;
439 }
440 (void) mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+');
441 (void) wrefresh(slot_w);
442 }
443
444 void
445 draw_board()
446 {
447 int n;
448
449 (void) clear();
450 (void) werase(view_w);
451 (void) werase(slot_w);
452 (void) werase(scroll_w);
453 (void) werase(stat_w);
454 (void) werase(turn_w);
455
456 sc_line = 0;
457
458 (void) move(BOX_T, BOX_L);
459 for (n = 0; n < BOX_X; n++)
460 (void) addch('-');
461 (void) move(BOX_B, BOX_L);
462 for (n = 0; n < BOX_X; n++)
463 (void) addch('-');
464 for (n = BOX_T+1; n < BOX_B; n++) {
465 (void) mvaddch(n, BOX_L, '|');
466 (void) mvaddch(n, BOX_R, '|');
467 }
468 (void) mvaddch(BOX_T, BOX_L, '+');
469 (void) mvaddch(BOX_T, BOX_R, '+');
470 (void) mvaddch(BOX_B, BOX_L, '+');
471 (void) mvaddch(BOX_B, BOX_R, '+');
472 (void) refresh();
473
474 #define WSaIM "Wooden Ships & Iron Men"
475 (void) wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2);
476 (void) waddstr(view_w, WSaIM);
477 (void) wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2);
478 (void) waddstr(view_w, cc->name);
479 (void) wrefresh(view_w);
480
481 (void) move(LINE_T, LINE_L);
482 (void) printw("Class %d %s (%d guns) '%s' (%c%c)",
483 mc->class,
484 classname[mc->class],
485 mc->guns,
486 ms->shipname,
487 colours(ms),
488 sterncolour(ms));
489 (void) refresh();
490 }
491
492 void
493 centerview()
494 {
495 viewrow = mf->row - VIEW_Y / 2;
496 viewcol = mf->col - VIEW_X / 2;
497 }
498
499 void
500 upview()
501 {
502 viewrow -= VIEW_Y / 3;
503 }
504
505 void
506 downview()
507 {
508 viewrow += VIEW_Y / 3;
509 }
510
511 void
512 leftview()
513 {
514 viewcol -= VIEW_X / 5;
515 }
516
517 void
518 rightview()
519 {
520 viewcol += VIEW_X / 5;
521 }
522
523 void
524 adjustview()
525 {
526 if (dont_adjust)
527 return;
528 if (mf->row < viewrow + VIEW_Y/4)
529 viewrow = mf->row - (VIEW_Y - VIEW_Y/4);
530 else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4))
531 viewrow = mf->row - VIEW_Y/4;
532 if (mf->col < viewcol + VIEW_X/8)
533 viewcol = mf->col - (VIEW_X - VIEW_X/8);
534 else if (mf->col > viewcol + (VIEW_X - VIEW_X/8))
535 viewcol = mf->col - VIEW_X/8;
536 }