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