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