Annotation of 43BSDTahoe/games/hunt/draw.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.