|
|
1.1 ! root 1: /* ! 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. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)pl_7.c 5.1 (Berkeley) 5/29/85"; ! 9: #endif not lint ! 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: { ! 24: /* initscr() already done in SCREENTEST() */ ! 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); ! 35: #ifdef SIGTSTP ! 36: { ! 37: int susp(); ! 38: (void) signal(SIGTSTP, susp); ! 39: } ! 40: #endif ! 41: noecho(); ! 42: crmode(); ! 43: } ! 44: ! 45: cleanupscreen() ! 46: { ! 47: /* alarm already turned off */ ! 48: if (done_curses) { ! 49: (void) wmove(scroll_w, SCROLL_Y - 1, 0); ! 50: (void) wclrtoeol(scroll_w); ! 51: draw_screen(); ! 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; ! 72: if (!hasdriver) ! 73: Write(W_DDEAD, SHIP(0), 0, 0, 0, 0, 0); ! 74: ! 75: if (sc_hasprompt) { ! 76: (void) wmove(scroll_w, sc_line, 0); ! 77: (void) wclrtoeol(scroll_w); ! 78: } ! 79: if (Sync() < 0) ! 80: leave(LEAVE_SYNC); ! 81: if (!hasdriver) ! 82: leave(LEAVE_DRIVER); ! 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: ! 139: if (ship != 0) ! 140: p = sprintf(buf, p, ship->shipname, colours(ship), ! 141: sterncolour(ship)); ! 142: sc_prompt = p; ! 143: sc_buf = ""; ! 144: sc_hasprompt = 1; ! 145: (void) waddstr(scroll_w, p); ! 146: } ! 147: ! 148: endprompt(flag) ! 149: char flag; ! 150: { ! 151: sc_hasprompt = 0; ! 152: if (flag) ! 153: Scroll(); ! 154: } ! 155: ! 156: sgetch(p, ship, flag) ! 157: char *p; ! 158: struct ship *ship; ! 159: char flag; ! 160: { ! 161: register c; ! 162: ! 163: prompt(p, ship); ! 164: blockalarm(); ! 165: (void) wrefresh(scroll_w); ! 166: unblockalarm(); ! 167: while ((c = wgetch(scroll_w)) == EOF) ! 168: ; ! 169: if (flag && c >= ' ' && c < 0x7f) ! 170: (void) waddch(scroll_w, c); ! 171: endprompt(flag); ! 172: return c; ! 173: } ! 174: ! 175: sgetstr(pr, buf, n) ! 176: char *pr; ! 177: register char *buf; ! 178: register n; ! 179: { ! 180: register c; ! 181: register char *p = buf; ! 182: ! 183: prompt(pr, (struct ship *)0); ! 184: sc_buf = buf; ! 185: for (;;) { ! 186: *p = 0; ! 187: blockalarm(); ! 188: (void) wrefresh(scroll_w); ! 189: unblockalarm(); ! 190: while ((c = wgetch(scroll_w)) == EOF) ! 191: ; ! 192: switch (c) { ! 193: case '\n': ! 194: case '\r': ! 195: endprompt(1); ! 196: return; ! 197: case '\b': ! 198: if (p > buf) { ! 199: (void) waddstr(scroll_w, "\b \b"); ! 200: p--; ! 201: } ! 202: break; ! 203: default: ! 204: if (c >= ' ' && c < 0x7f && p < buf + n - 1) { ! 205: *p++ = c; ! 206: (void) waddch(scroll_w, c); ! 207: } else ! 208: (void) putchar(CTRL(g)); ! 209: } ! 210: } ! 211: } ! 212: ! 213: draw_screen() ! 214: { ! 215: draw_view(); ! 216: draw_turn(); ! 217: draw_stat(); ! 218: draw_slot(); ! 219: (void) wrefresh(scroll_w); /* move the cursor */ ! 220: } ! 221: ! 222: draw_view() ! 223: { ! 224: register struct ship *sp; ! 225: ! 226: (void) werase(view_w); ! 227: foreachship(sp) { ! 228: if (sp->file->dir ! 229: && sp->file->row > viewrow ! 230: && sp->file->row < viewrow + VIEW_Y ! 231: && sp->file->col > viewcol ! 232: && sp->file->col < viewcol + VIEW_X) { ! 233: (void) wmove(view_w, sp->file->row - viewrow, ! 234: sp->file->col - viewcol); ! 235: (void) waddch(view_w, colours(sp)); ! 236: (void) wmove(view_w, ! 237: sternrow(sp) - viewrow, ! 238: sterncol(sp) - viewcol); ! 239: (void) waddch(view_w, sterncolour(sp)); ! 240: } ! 241: } ! 242: (void) wrefresh(view_w); ! 243: } ! 244: ! 245: draw_turn() ! 246: { ! 247: (void) wmove(turn_w, 0, 0); ! 248: (void) wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn); ! 249: (void) wrefresh(turn_w); ! 250: } ! 251: ! 252: draw_stat() ! 253: { ! 254: (void) wmove(stat_w, STAT_1, 0); ! 255: (void) wprintw(stat_w, "Points %3d\n", mf->points); ! 256: (void) wprintw(stat_w, "Fouls %2d\n", fouled(ms)); ! 257: (void) wprintw(stat_w, "Grapples %2d\n", grappled(ms)); ! 258: ! 259: (void) wmove(stat_w, STAT_2, 0); ! 260: (void) wprintw(stat_w, " 0 %c(%c)\n", ! 261: maxmove(ms, winddir + 3, -1) + '0', ! 262: maxmove(ms, winddir + 3, 1) + '0'); ! 263: (void) waddstr(stat_w, " \\|/\n"); ! 264: (void) wprintw(stat_w, " -^-%c(%c)\n", ! 265: maxmove(ms, winddir + 2, -1) + '0', ! 266: maxmove(ms, winddir + 2, 1) + '0'); ! 267: (void) waddstr(stat_w, " /|\\\n"); ! 268: (void) wprintw(stat_w, " | %c(%c)\n", ! 269: maxmove(ms, winddir + 1, -1) + '0', ! 270: maxmove(ms, winddir + 1, 1) + '0'); ! 271: (void) wprintw(stat_w, " %c(%c)\n", ! 272: maxmove(ms, winddir, -1) + '0', ! 273: maxmove(ms, winddir, 1) + '0'); ! 274: ! 275: (void) wmove(stat_w, STAT_3, 0); ! 276: (void) wprintw(stat_w, "Load %c%c %c%c\n", ! 277: loadname[mf->loadL], readyname(mf->readyL), ! 278: loadname[mf->loadR], readyname(mf->readyR)); ! 279: (void) wprintw(stat_w, "Hull %2d\n", mc->hull); ! 280: (void) wprintw(stat_w, "Crew %2d %2d %2d\n", ! 281: mc->crew1, mc->crew2, mc->crew3); ! 282: (void) wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR); ! 283: (void) wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR); ! 284: (void) wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3); ! 285: if (mc->rig4 < 0) ! 286: (void) waddch(stat_w, '-'); ! 287: else ! 288: (void) wprintw(stat_w, "%d", mc->rig4); ! 289: (void) wrefresh(stat_w); ! 290: } ! 291: ! 292: draw_slot() ! 293: { ! 294: if (!boarding(ms, 0)) { ! 295: (void) mvwaddstr(slot_w, 0, 0, " "); ! 296: (void) mvwaddstr(slot_w, 1, 0, " "); ! 297: } else ! 298: (void) mvwaddstr(slot_w, 1, 0, "OBP"); ! 299: if (!boarding(ms, 1)) { ! 300: (void) mvwaddstr(slot_w, 2, 0, " "); ! 301: (void) mvwaddstr(slot_w, 3, 0, " "); ! 302: } else ! 303: (void) mvwaddstr(slot_w, 3, 0, "DBP"); ! 304: ! 305: (void) wmove(slot_w, SLOT_Y-4, 0); ! 306: if (mf->RH) ! 307: (void) wprintw(slot_w, "%dRH", mf->RH); ! 308: else ! 309: (void) waddstr(slot_w, " "); ! 310: (void) wmove(slot_w, SLOT_Y-3, 0); ! 311: if (mf->RG) ! 312: (void) wprintw(slot_w, "%dRG", mf->RG); ! 313: else ! 314: (void) waddstr(slot_w, " "); ! 315: (void) wmove(slot_w, SLOT_Y-2, 0); ! 316: if (mf->RR) ! 317: (void) wprintw(slot_w, "%dRR", mf->RR); ! 318: else ! 319: (void) waddstr(slot_w, " "); ! 320: ! 321: #define Y (SLOT_Y/2) ! 322: (void) wmove(slot_w, 7, 1); ! 323: (void) wprintw(slot_w,"%d", windspeed); ! 324: (void) mvwaddch(slot_w, Y, 0, ' '); ! 325: (void) mvwaddch(slot_w, Y, 2, ' '); ! 326: (void) mvwaddch(slot_w, Y-1, 0, ' '); ! 327: (void) mvwaddch(slot_w, Y-1, 1, ' '); ! 328: (void) mvwaddch(slot_w, Y-1, 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) wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]); ! 333: switch (winddir) { ! 334: case 1: ! 335: case 5: ! 336: (void) waddch(slot_w, '|'); ! 337: break; ! 338: case 2: ! 339: case 6: ! 340: (void) waddch(slot_w, '/'); ! 341: break; ! 342: case 3: ! 343: case 7: ! 344: (void) waddch(slot_w, '-'); ! 345: break; ! 346: case 4: ! 347: case 8: ! 348: (void) waddch(slot_w, '\\'); ! 349: break; ! 350: } ! 351: (void) mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+'); ! 352: (void) wrefresh(slot_w); ! 353: } ! 354: ! 355: draw_board() ! 356: { ! 357: register int n; ! 358: ! 359: (void) clear(); ! 360: (void) werase(view_w); ! 361: (void) werase(slot_w); ! 362: (void) werase(scroll_w); ! 363: (void) werase(stat_w); ! 364: (void) werase(turn_w); ! 365: ! 366: sc_line = 0; ! 367: ! 368: (void) move(BOX_T, BOX_L); ! 369: for (n = 0; n < BOX_X; n++) ! 370: (void) addch('-'); ! 371: (void) move(BOX_B, BOX_L); ! 372: for (n = 0; n < BOX_X; n++) ! 373: (void) addch('-'); ! 374: for (n = BOX_T+1; n < BOX_B; n++) { ! 375: (void) mvaddch(n, BOX_L, '|'); ! 376: (void) mvaddch(n, BOX_R, '|'); ! 377: } ! 378: (void) mvaddch(BOX_T, BOX_L, '+'); ! 379: (void) mvaddch(BOX_T, BOX_R, '+'); ! 380: (void) mvaddch(BOX_B, BOX_L, '+'); ! 381: (void) mvaddch(BOX_B, BOX_R, '+'); ! 382: (void) refresh(); ! 383: ! 384: #define WSaIM "Wooden Ships & Iron Men" ! 385: (void) wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2); ! 386: (void) waddstr(view_w, WSaIM); ! 387: (void) wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2); ! 388: (void) waddstr(view_w, cc->name); ! 389: (void) wrefresh(view_w); ! 390: ! 391: (void) move(LINE_T, LINE_L); ! 392: (void) printw("Class %d %s (%d guns) '%s' (%c%c)", ! 393: mc->class, ! 394: classname[mc->class], ! 395: mc->guns, ! 396: ms->shipname, ! 397: colours(ms), ! 398: sterncolour(ms)); ! 399: (void) refresh(); ! 400: } ! 401: ! 402: centerview() ! 403: { ! 404: viewrow = mf->row - VIEW_Y / 2; ! 405: viewcol = mf->col - VIEW_X / 2; ! 406: } ! 407: ! 408: upview() ! 409: { ! 410: viewrow -= VIEW_Y / 3; ! 411: } ! 412: ! 413: downview() ! 414: { ! 415: viewrow += VIEW_Y / 3; ! 416: } ! 417: ! 418: leftview() ! 419: { ! 420: viewcol -= VIEW_X / 5; ! 421: } ! 422: ! 423: rightview() ! 424: { ! 425: viewcol += VIEW_X / 5; ! 426: } ! 427: ! 428: adjustview() ! 429: { ! 430: if (dont_adjust) ! 431: return; ! 432: if (mf->row < viewrow + VIEW_Y/4) ! 433: viewrow = mf->row - (VIEW_Y - VIEW_Y/4); ! 434: else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4)) ! 435: viewrow = mf->row - VIEW_Y/4; ! 436: if (mf->col < viewcol + VIEW_X/8) ! 437: viewcol = mf->col - (VIEW_X - VIEW_X/8); ! 438: else if (mf->col > viewcol + (VIEW_X - VIEW_X/8)) ! 439: viewcol = mf->col - VIEW_X/8; ! 440: } ! 441: ! 442: #ifdef SIGTSTP ! 443: susp() ! 444: { ! 445: blockalarm(); ! 446: tstp(); ! 447: (void) signal(SIGTSTP, susp); ! 448: unblockalarm(); ! 449: } ! 450: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.