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