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