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