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