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

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

unix.superglobalmegacorp.com

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