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