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