1: /* 2: * Hunt 3: * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold 4: * San Francisco, California 5: * 6: * Copyright (c) 1985 Regents of the University of California. 7: * All rights reserved. The Berkeley software License Agreement 8: * specifies the terms and conditions for redistribution. 9: */ 10: 11: # include "hunt.h" 12: 13: drawmaze(pp) 14: register PLAYER *pp; 15: { 16: register int x; 17: register char *sp; 18: register int y; 19: register char *endp; 20: 21: clrscr(pp); 22: outstr(pp, pp->p_maze[0], WIDTH); 23: for (y = 1; y < HEIGHT - 1; y++) { 24: endp = &pp->p_maze[y][WIDTH]; 25: for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++) 26: if (*sp != SPACE) { 27: cgoto(pp, y, x); 28: if (pp->p_x == x && pp->p_y == y) 29: outch(pp, translate(*sp)); 30: else 31: outch(pp, *sp); 32: } 33: } 34: cgoto(pp, HEIGHT - 1, 0); 35: outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH); 36: drawstatus(pp); 37: } 38: 39: /* 40: * drawstatus - put up the status lines (this assumes the screen 41: * size is 80x24 with the maze being 64x24) 42: */ 43: drawstatus(pp) 44: register PLAYER *pp; 45: { 46: register int i; 47: register PLAYER *np; 48: 49: (void) sprintf(Buf, "%-13.13s", pp->p_ident->i_name); 50: cgoto(pp, STAT_NAME_ROW, STAT_LABEL_COL); 51: outstr(pp, Buf, 13); 52: 53: cgoto(pp, STAT_AMMO_ROW, STAT_LABEL_COL); 54: outstr(pp, "Ammo:", 5); 55: (void) sprintf(Buf, "%3d", pp->p_ammo); 56: cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL); 57: outstr(pp, Buf, 3); 58: 59: cgoto(pp, STAT_CLOAK_ROW, STAT_LABEL_COL); 60: outstr(pp, "Cloak:", 6); 61: cgoto(pp, STAT_CLOAK_ROW, STAT_VALUE_COL); 62: outstr(pp, (pp->p_cloak < 0) ? " " : " on", 3); 63: 64: cgoto(pp, STAT_SCAN_ROW, STAT_LABEL_COL); 65: outstr(pp, "Scan:", 5); 66: cgoto(pp, STAT_SCAN_ROW, STAT_VALUE_COL); 67: outstr(pp, (pp->p_scan < 0) ? " " : " on", 3); 68: 69: cgoto(pp, STAT_GUN_ROW, STAT_LABEL_COL); 70: outstr(pp, "Gun:", 4); 71: cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL); 72: outstr(pp, (pp->p_ncshot < MAXNCSHOT) ? " ok" : " ", 3); 73: 74: cgoto(pp, STAT_DAM_ROW, STAT_LABEL_COL); 75: outstr(pp, "Damage:", 7); 76: (void) sprintf(Buf, "%2d/%2d", pp->p_damage, pp->p_damcap); 77: cgoto(pp, STAT_DAM_ROW, STAT_VALUE_COL); 78: outstr(pp, Buf, 5); 79: 80: cgoto(pp, STAT_KILL_ROW, STAT_LABEL_COL); 81: outstr(pp, "Kills:", 6); 82: (void) sprintf(Buf, "%3d", (pp->p_damcap - MAXDAM) / 2); 83: cgoto(pp, STAT_KILL_ROW, STAT_VALUE_COL); 84: outstr(pp, Buf, 3); 85: 86: cgoto(pp, STAT_PLAY_ROW, STAT_LABEL_COL); 87: outstr(pp, "Player:", 7); 88: for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++) { 89: (void) sprintf(Buf, "%5.2f%c%-10.10s", np->p_ident->i_score, 90: stat_char(np), np->p_ident->i_name); 91: cgoto(pp, i++, STAT_NAME_COL); 92: outstr(pp, Buf, STAT_NAME_LEN); 93: } 94: 95: # ifdef MONITOR 96: cgoto(pp, STAT_MON_ROW, STAT_LABEL_COL); 97: outstr(pp, "Monitor:", 8); 98: for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++) { 99: (void) sprintf(Buf, "%5.5s %-10.10s", " ", np->p_ident->i_name); 100: cgoto(pp, i++, STAT_NAME_COL); 101: outstr(pp, Buf, STAT_NAME_LEN); 102: } 103: # endif MONITOR 104: } 105: 106: # ifndef CPUHOG 107: look(pp) 108: register PLAYER *pp; 109: { 110: register int x, y; 111: 112: x = pp->p_x; 113: y = pp->p_y; 114: 115: check(pp, y - 1, x - 1); 116: check(pp, y - 1, x ); 117: check(pp, y - 1, x + 1); 118: check(pp, y , x - 1); 119: check(pp, y , x ); 120: check(pp, y , x + 1); 121: check(pp, y + 1, x - 1); 122: check(pp, y + 1, x ); 123: check(pp, y + 1, x + 1); 124: 125: switch (pp->p_face) { 126: case LEFTS: 127: see(pp, LEFTS); 128: see(pp, ABOVE); 129: see(pp, BELOW); 130: break; 131: case RIGHT: 132: see(pp, RIGHT); 133: see(pp, ABOVE); 134: see(pp, BELOW); 135: break; 136: case ABOVE: 137: see(pp, ABOVE); 138: see(pp, LEFTS); 139: see(pp, RIGHT); 140: break; 141: case BELOW: 142: see(pp, BELOW); 143: see(pp, LEFTS); 144: see(pp, RIGHT); 145: break; 146: # ifdef FLY 147: case FLYER: 148: break; 149: # endif FLY 150: } 151: cgoto(pp, y, x); 152: } 153: 154: see(pp, face) 155: register PLAYER *pp; 156: int face; 157: { 158: register char *sp; 159: register int y, x, i, cnt; 160: 161: x = pp->p_x; 162: y = pp->p_y; 163: 164: switch (face) { 165: case LEFTS: 166: sp = &Maze[y][x]; 167: for (i = 0; See_over[*--sp]; i++) 168: continue; 169: 170: if (i == 0) 171: break; 172: 173: cnt = i; 174: x = pp->p_x - 1; 175: --y; 176: while (i--) 177: check(pp, y, --x); 178: i = cnt; 179: x = pp->p_x - 1; 180: ++y; 181: while (i--) 182: check(pp, y, --x); 183: i = cnt; 184: x = pp->p_x - 1; 185: ++y; 186: while (i--) 187: check(pp, y, --x); 188: break; 189: case RIGHT: 190: sp = &Maze[y][++x]; 191: for (i = 0; See_over[*sp++]; i++) 192: continue; 193: 194: if (i == 0) 195: break; 196: 197: cnt = i; 198: x = pp->p_x + 1; 199: --y; 200: while (i--) 201: check(pp, y, ++x); 202: i = cnt; 203: x = pp->p_x + 1; 204: ++y; 205: while (i--) 206: check(pp, y, ++x); 207: i = cnt; 208: x = pp->p_x + 1; 209: ++y; 210: while (i--) 211: check(pp, y, ++x); 212: break; 213: case ABOVE: 214: sp = &Maze[--y][x]; 215: if (!See_over[*sp]) 216: break; 217: do { 218: --y; 219: sp -= sizeof Maze[0]; 220: check(pp, y, x - 1); 221: check(pp, y, x ); 222: check(pp, y, x + 1); 223: } while (See_over[*sp]); 224: break; 225: case BELOW: 226: sp = &Maze[++y][x]; 227: if (!See_over[*sp]) 228: break; 229: do { 230: y++; 231: sp += sizeof Maze[0]; 232: check(pp, y, x - 1); 233: check(pp, y, x ); 234: check(pp, y, x + 1); 235: } while (See_over[*sp]); 236: break; 237: } 238: } 239: 240: # else CPUHOG 241: 242: look(pp) 243: register PLAYER *pp; 244: { 245: switch (pp->p_face) { 246: case LEFTS: 247: lookquad2(pp, pp->p_y, pp->p_x); 248: lookquad3(pp, pp->p_y, pp->p_x); 249: break; 250: case RIGHT: 251: lookquad1(pp, pp->p_y, pp->p_x); 252: lookquad4(pp, pp->p_y, pp->p_x); 253: break; 254: case ABOVE: 255: lookquad3(pp, pp->p_y, pp->p_x); 256: lookquad4(pp, pp->p_y, pp->p_x); 257: break; 258: case BELOW: 259: lookquad1(pp, pp->p_y, pp->p_x); 260: lookquad2(pp, pp->p_y, pp->p_x); 261: break; 262: } 263: cgoto(pp, pp->p_y, pp->p_x); 264: } 265: # endif CPUHOG 266: 267: check(pp, y, x) 268: PLAYER *pp; 269: int y, x; 270: { 271: register int index; 272: register int ch; 273: register PLAYER *rpp; 274: 275: index = y * sizeof Maze[0] + x; 276: ch = ((char *) Maze)[index]; 277: if (ch != ((char *) pp->p_maze)[index]) { 278: rpp = pp; 279: cgoto(rpp, y, x); 280: if (x == rpp->p_x && y == rpp->p_y) 281: outch(rpp, translate(ch)); 282: else 283: outch(rpp, ch); 284: ((char *) rpp->p_maze)[index] = ch; 285: } 286: } 287: 288: /* 289: * showstat 290: * Update the status of players 291: */ 292: showstat(pp) 293: register PLAYER *pp; 294: { 295: register PLAYER *np; 296: register int y; 297: register char c; 298: 299: y = STAT_PLAY_ROW + 1 + (pp - Player); 300: c = stat_char(pp); 301: # ifdef MONITOR 302: for (np = Monitor; np < End_monitor; np++) { 303: cgoto(np, y, STAT_SCAN_COL); 304: outch(np, c); 305: } 306: # endif MONITOR 307: for (np = Player; np < End_player; np++) { 308: cgoto(np, y, STAT_SCAN_COL); 309: outch(np, c); 310: } 311: } 312: 313: /* 314: * drawplayer: 315: * Draw the player on the screen and show him to everyone who's scanning 316: * unless he is cloaked. 317: */ 318: drawplayer(pp, draw) 319: PLAYER *pp; 320: FLAG draw; 321: { 322: register PLAYER *newp; 323: register int x, y; 324: 325: x = pp->p_x; 326: y = pp->p_y; 327: Maze[y][x] = draw ? pp->p_face : pp->p_over; 328: 329: # ifdef MONITOR 330: for (newp = Monitor; newp < End_monitor; newp++) 331: check(newp, y, x); 332: # endif MONITOR 333: 334: for (newp = Player; newp < End_player; newp++) { 335: if (!draw || newp == pp) { 336: check(newp, y, x); 337: continue; 338: } 339: if (newp->p_scan == 0) { 340: cgoto(newp, STAT_SCAN_ROW, STAT_VALUE_COL); 341: outstr(newp, " ", 3); 342: newp->p_scan--; 343: showstat(newp); 344: } 345: else if (newp->p_scan > 0) { 346: if (pp->p_cloak < 0) 347: check(newp, y, x); 348: newp->p_scan--; 349: } 350: } 351: if (!draw || pp->p_cloak < 0) 352: return; 353: if (pp->p_cloak-- == 0) { 354: cgoto(pp, STAT_CLOAK_ROW, STAT_VALUE_COL); 355: outstr(pp, " ", 3); 356: showstat(pp); 357: } 358: } 359: 360: message(pp, s) 361: register PLAYER *pp; 362: char *s; 363: { 364: cgoto(pp, HEIGHT, 0); 365: outstr(pp, s, strlen(s)); 366: ce(pp); 367: } 368: 369: /* 370: * translate: 371: * Turn a charcter into the right direction character if we are 372: * looking at the current player. 373: */ 374: translate(ch) 375: char ch; 376: { 377: switch (ch) { 378: case LEFTS: 379: return '<'; 380: case RIGHT: 381: return '>'; 382: case ABOVE: 383: return '^'; 384: case BELOW: 385: return 'v'; 386: } 387: return ch; 388: }