Annotation of 43BSDTahoe/games/hunt/execute.c, revision 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[] = "@(#)execute.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: # undef CTRL
        !            31: # define       CTRL(x) ('x' & 037)
        !            32: 
        !            33: # ifdef MONITOR
        !            34: /*
        !            35:  * mon_execute:
        !            36:  *     Execute a single monitor command
        !            37:  */
        !            38: mon_execute(pp)
        !            39: register PLAYER        *pp;
        !            40: {
        !            41:        register char   ch;
        !            42: 
        !            43:        ch = pp->p_cbuf[pp->p_ncount++];
        !            44:        switch (ch) {
        !            45:          case CTRL(L):
        !            46:                sendcom(pp, REDRAW);
        !            47:                break;
        !            48:          case 'q':
        !            49:                (void) strcpy(pp->p_death, "| Quit |");
        !            50:                break;
        !            51:        }
        !            52: }
        !            53: # endif MONITOR
        !            54: 
        !            55: /*
        !            56:  * execute:
        !            57:  *     Execute a single command
        !            58:  */
        !            59: execute(pp)
        !            60: register PLAYER        *pp;
        !            61: {
        !            62:        register char   ch;
        !            63: 
        !            64:        ch = pp->p_cbuf[pp->p_ncount++];
        !            65: 
        !            66: # ifdef        FLY
        !            67:        if (pp->p_flying >= 0) {
        !            68:                switch (ch) {
        !            69:                  case CTRL(L):
        !            70:                        sendcom(pp, REDRAW);
        !            71:                        break;
        !            72:                  case 'q':
        !            73:                        (void) strcpy(pp->p_death, "| Quit |");
        !            74:                        break;
        !            75:                }
        !            76:                return;
        !            77:        }
        !            78: # endif        FLY
        !            79: 
        !            80:        switch (ch) {
        !            81:          case CTRL(L):
        !            82:                sendcom(pp, REDRAW);
        !            83:                break;
        !            84:          case 'h':
        !            85:                move(pp, LEFTS);
        !            86:                break;
        !            87:          case 'H':
        !            88:                face(pp, LEFTS);
        !            89:                break;
        !            90:          case 'j':
        !            91:                move(pp, BELOW);
        !            92:                break;
        !            93:          case 'J':
        !            94:                face(pp, BELOW);
        !            95:                break;
        !            96:          case 'k':
        !            97:                move(pp, ABOVE);
        !            98:                break;
        !            99:          case 'K':
        !           100:                face(pp, ABOVE);
        !           101:                break;
        !           102:          case 'l':
        !           103:                move(pp, RIGHT);
        !           104:                break;
        !           105:          case 'L':
        !           106:                face(pp, RIGHT);
        !           107:                break;
        !           108:          case 'f':
        !           109:                fire(pp, SHOT);
        !           110:                break;
        !           111:          case 'g':
        !           112:                fire(pp, GRENADE);
        !           113:                break;
        !           114:          case 'F':
        !           115:                fire(pp, SATCHEL);
        !           116:                break;
        !           117:          case 'G':
        !           118:                fire(pp, BOMB);
        !           119:                break;
        !           120: # ifdef        OOZE
        !           121:          case 'o':
        !           122:                fire_slime(pp, SLIMEREQ);
        !           123:                break;
        !           124:          case 'O':
        !           125:                fire_slime(pp, SSLIMEREQ);
        !           126:                break;
        !           127: # endif        OOZE
        !           128:          case 's':
        !           129:                scan(pp);
        !           130:                break;
        !           131:          case 'c':
        !           132:                cloak(pp);
        !           133:                break;
        !           134:          case 'q':
        !           135:                (void) strcpy(pp->p_death, "| Quit |");
        !           136:                break;
        !           137:        }
        !           138: }
        !           139: 
        !           140: /*
        !           141:  * move:
        !           142:  *     Execute a move in the given direction
        !           143:  */
        !           144: move(pp, dir)
        !           145: register PLAYER        *pp;
        !           146: int            dir;
        !           147: {
        !           148:        register PLAYER *newp;
        !           149:        register int    x, y;
        !           150:        register FLAG   moved;
        !           151:        register BULLET *bp;
        !           152: 
        !           153:        y = pp->p_y;
        !           154:        x = pp->p_x;
        !           155: 
        !           156:        switch (dir) {
        !           157:          case LEFTS:
        !           158:                x--;
        !           159:                break;
        !           160:          case RIGHT:
        !           161:                x++;
        !           162:                break;
        !           163:          case ABOVE:
        !           164:                y--;
        !           165:                break;
        !           166:          case BELOW:
        !           167:                y++;
        !           168:                break;
        !           169:        }
        !           170: 
        !           171:        moved = FALSE;
        !           172:        switch (Maze[y][x]) {
        !           173:          case SPACE:
        !           174: # ifdef RANDOM
        !           175:          case DOOR:
        !           176: # endif RANDOM
        !           177:                moved = TRUE;
        !           178:                break;
        !           179:          case WALL1:
        !           180:          case WALL2:
        !           181:          case WALL3:
        !           182: # ifdef REFLECT
        !           183:          case WALL4:
        !           184:          case WALL5:
        !           185: # endif REFLECT
        !           186:                break;
        !           187:          case MINE:
        !           188:          case GMINE:
        !           189:                if (dir == pp->p_face)
        !           190:                        pickup(pp, y, x, 5, Maze[y][x]);
        !           191:                else if (opposite(dir, pp->p_face))
        !           192:                        pickup(pp, y, x, 95, Maze[y][x]);
        !           193:                else
        !           194:                        pickup(pp, y, x, 50, Maze[y][x]);
        !           195:                Maze[y][x] = SPACE;
        !           196:                moved = TRUE;
        !           197:                break;
        !           198:          case SHOT:
        !           199:          case GRENADE:
        !           200:          case SATCHEL:
        !           201:          case BOMB:
        !           202:                bp = is_bullet(y, x);
        !           203:                if (bp != NULL)
        !           204:                        bp->b_expl = TRUE;
        !           205:                Maze[y][x] = SPACE;
        !           206:                moved = TRUE;
        !           207:                break;
        !           208:          case LEFTS:
        !           209:          case RIGHT:
        !           210:          case ABOVE:
        !           211:          case BELOW:
        !           212: # ifdef FLY
        !           213:          case FLYER:
        !           214: # endif FLY
        !           215:                if (dir != pp->p_face)
        !           216:                        sendcom(pp, BELL);
        !           217:                else {
        !           218:                        newp = play_at(y, x);
        !           219:                        checkdam(newp, pp, pp->p_ident, STABDAM, KNIFE);
        !           220:                }
        !           221:                break;
        !           222:        }
        !           223:        if (moved) {
        !           224:                if (pp->p_ncshot > 0)
        !           225:                        if (--pp->p_ncshot == MAXNCSHOT) {
        !           226:                                cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
        !           227:                                outstr(pp, " ok", 3);
        !           228:                        }
        !           229:                if (pp->p_undershot) {
        !           230:                        fixshots(pp->p_y, pp->p_x, pp->p_over);
        !           231:                        pp->p_undershot = FALSE;
        !           232:                }
        !           233:                drawplayer(pp, FALSE);
        !           234:                pp->p_over = Maze[y][x];
        !           235:                pp->p_y = y;
        !           236:                pp->p_x = x;
        !           237:                drawplayer(pp, TRUE);
        !           238:        }
        !           239: }
        !           240: 
        !           241: /*
        !           242:  * face:
        !           243:  *     Change the direction the player is facing
        !           244:  */
        !           245: face(pp, dir)
        !           246: register PLAYER        *pp;
        !           247: register int   dir;
        !           248: {
        !           249:        if (pp->p_face != dir) {
        !           250:                pp->p_face = dir;
        !           251:                drawplayer(pp, TRUE);
        !           252:        }
        !           253: }
        !           254: 
        !           255: /*
        !           256:  * fire:
        !           257:  *     Fire a shot of the given type in the given direction
        !           258:  */
        !           259: fire(pp, type)
        !           260: register PLAYER        *pp;
        !           261: register char  type;
        !           262: {
        !           263:        register int    req_index;
        !           264:        static int      req[4] = { BULREQ, GRENREQ, SATREQ, BOMBREQ };
        !           265:        static int      shot_type[4] = { SHOT, GRENADE, SATCHEL, BOMB };
        !           266: 
        !           267:        if (pp == NULL)
        !           268:                return;
        !           269:        if (pp->p_ammo == 0) {
        !           270:                message(pp, "No more charges.");
        !           271:                return;
        !           272:        }
        !           273:        if (pp->p_ncshot > MAXNCSHOT)
        !           274:                return;
        !           275:        if (pp->p_ncshot++ == MAXNCSHOT) {
        !           276:                cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
        !           277:                outstr(pp, "   ", 3);
        !           278:        }
        !           279:        switch (type) {
        !           280:          case SHOT:
        !           281:                req_index = 0;
        !           282:                break;
        !           283:          case GRENADE:
        !           284:                req_index = 1;
        !           285:                break;
        !           286:          case SATCHEL:
        !           287:                req_index = 2;
        !           288:                break;
        !           289:          case BOMB:
        !           290:                req_index = 3;
        !           291:                break;
        !           292: # ifdef DEBUG
        !           293:          default:
        !           294:                message(pp, "What you do!!!");
        !           295:                return;
        !           296: # endif DEBUG
        !           297:        }
        !           298:        while (pp->p_ammo < req[req_index])
        !           299:                req_index--;
        !           300:        pp->p_ammo -= req[req_index];
        !           301:        (void) sprintf(Buf, "%3d", pp->p_ammo);
        !           302:        cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
        !           303:        outstr(pp, Buf, 3);
        !           304: 
        !           305:        add_shot(shot_type[req_index], pp->p_y, pp->p_x, pp->p_face,
        !           306:                req[req_index], pp, FALSE, pp->p_face);
        !           307:        pp->p_undershot = TRUE;
        !           308: 
        !           309:        /*
        !           310:         * Show the object to everyone
        !           311:         */
        !           312:        showexpl(pp->p_y, pp->p_x, shot_type[req_index]);
        !           313:        for (pp = Player; pp < End_player; pp++)
        !           314:                sendcom(pp, REFRESH);
        !           315: # ifdef MONITOR
        !           316:        for (pp = Monitor; pp < End_monitor; pp++)
        !           317:                sendcom(pp, REFRESH);
        !           318: # endif MONITOR
        !           319: }
        !           320: 
        !           321: # ifdef        OOZE
        !           322: /*
        !           323:  * fire_slime:
        !           324:  *     Fire a slime shot in the given direction
        !           325:  */
        !           326: fire_slime(pp, req)
        !           327: register PLAYER        *pp;
        !           328: register int   req;
        !           329: {
        !           330:        if (pp == NULL)
        !           331:                return;
        !           332:        if (pp->p_ammo < req) {
        !           333:                message(pp, "Not enough charges.");
        !           334:                return;
        !           335:        }
        !           336:        if (pp->p_ncshot > MAXNCSHOT)
        !           337:                return;
        !           338:        if (pp->p_ncshot++ == MAXNCSHOT) {
        !           339:                cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
        !           340:                outstr(pp, "   ", 3);
        !           341:        }
        !           342:        pp->p_ammo -= req;
        !           343:        (void) sprintf(Buf, "%3d", pp->p_ammo);
        !           344:        cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
        !           345:        outstr(pp, Buf, 3);
        !           346: 
        !           347:        add_shot(SLIME, pp->p_y, pp->p_x, pp->p_face, req, pp, FALSE,
        !           348:                pp->p_face);
        !           349: 
        !           350:        /*
        !           351:         * Show the object to everyone
        !           352:         */
        !           353:        showexpl(pp->p_y, pp->p_x, SLIME);
        !           354:        for (pp = Player; pp < End_player; pp++)
        !           355:                sendcom(pp, REFRESH);
        !           356: # ifdef MONITOR
        !           357:        for (pp = Monitor; pp < End_monitor; pp++)
        !           358:                sendcom(pp, REFRESH);
        !           359: # endif MONITOR
        !           360: }
        !           361: # endif        OOZE
        !           362: 
        !           363: /*
        !           364:  * create_shot:
        !           365:  *     Create a shot with the given properties
        !           366:  */
        !           367: add_shot(type, y, x, face, charge, owner, expl, over)
        !           368: int    type;
        !           369: int    y, x;
        !           370: char   face;
        !           371: int    charge;
        !           372: PLAYER *owner;
        !           373: int    expl;
        !           374: char   over;
        !           375: {
        !           376:        register BULLET *bp;
        !           377: 
        !           378: # ifdef CONSTANT_MOVE
        !           379:        /*
        !           380:         * if there are no bullets in flight, set up the alarm
        !           381:         */
        !           382: 
        !           383:        if (Bullets == NULL)
        !           384:                bul_alarm(1);
        !           385: # endif CONSTANT_MOVE
        !           386: 
        !           387:        bp = create_shot(type, y, x, face, charge, owner,
        !           388:                (owner == NULL) ? NULL : owner->p_ident, expl, over);
        !           389:        bp->b_next = Bullets;
        !           390:        Bullets = bp;
        !           391: }
        !           392: 
        !           393: BULLET *
        !           394: create_shot(type, y, x, face, charge, owner, score, expl, over)
        !           395: int    type;
        !           396: int    y, x;
        !           397: char   face;
        !           398: int    charge;
        !           399: PLAYER *owner;
        !           400: IDENT  *score;
        !           401: int    expl;
        !           402: char   over;
        !           403: {
        !           404:        register BULLET *bp;
        !           405: 
        !           406:        bp = (BULLET *) malloc(sizeof (BULLET));        /* NOSTRICT */
        !           407:        if (bp == NULL) {
        !           408:                if (owner != NULL)
        !           409:                        message(owner, "Out of memory");
        !           410:                return NULL;
        !           411:        }
        !           412: 
        !           413:        bp->b_face = face;
        !           414:        bp->b_x = x;
        !           415:        bp->b_y = y;
        !           416:        bp->b_charge = charge;
        !           417:        bp->b_owner = owner;
        !           418:        bp->b_score = score;
        !           419:        bp->b_type = type;
        !           420:        bp->b_expl = expl;
        !           421:        bp->b_over = over;
        !           422:        bp->b_next = NULL;
        !           423: 
        !           424:        return bp;
        !           425: }
        !           426: 
        !           427: /*
        !           428:  * cloak:
        !           429:  *     Turn on or increase length of a cloak
        !           430:  */
        !           431: cloak(pp)
        !           432: register PLAYER        *pp;
        !           433: {
        !           434:        if (pp->p_ammo <= 0) {
        !           435:                message(pp, "No more charges");
        !           436:                return;
        !           437:        }
        !           438:        (void) sprintf(Buf, "%3d", --pp->p_ammo);
        !           439:        cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
        !           440:        outstr(pp, Buf, 3);
        !           441: 
        !           442:        pp->p_cloak += CLOAKLEN;
        !           443:        cgoto(pp, STAT_CLOAK_ROW, STAT_VALUE_COL);
        !           444:        outstr(pp, " on", 3);
        !           445: 
        !           446:        if (pp->p_scan >= 0) {
        !           447:                pp->p_scan = -1;
        !           448:                cgoto(pp, STAT_SCAN_ROW, STAT_VALUE_COL);
        !           449:                outstr(pp, "   ", 3);
        !           450:        }
        !           451: 
        !           452:        showstat(pp);
        !           453: }
        !           454: 
        !           455: /*
        !           456:  * scan:
        !           457:  *     Turn on or increase length of a scan
        !           458:  */
        !           459: scan(pp)
        !           460: register PLAYER        *pp;
        !           461: {
        !           462:        if (pp->p_ammo <= 0) {
        !           463:                message(pp, "No more charges");
        !           464:                return;
        !           465:        }
        !           466:        (void) sprintf(Buf, "%3d", --pp->p_ammo);
        !           467:        cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
        !           468:        outstr(pp, Buf, 3);
        !           469: 
        !           470:        pp->p_scan += SCANLEN;
        !           471:        cgoto(pp, STAT_SCAN_ROW, STAT_VALUE_COL);
        !           472:        outstr(pp, " on", 3);
        !           473: 
        !           474:        if (pp->p_cloak >= 0) {
        !           475:                pp->p_cloak = -1;
        !           476:                cgoto(pp, STAT_CLOAK_ROW, STAT_VALUE_COL);
        !           477:                outstr(pp, "   ", 3);
        !           478:        }
        !           479: 
        !           480:        showstat(pp);
        !           481: }
        !           482: 
        !           483: /*
        !           484:  * pickup:
        !           485:  *     check whether the object blew up or whether he picked it up
        !           486:  */
        !           487: pickup(pp, y, x, prob, obj)
        !           488: register PLAYER        *pp;
        !           489: register int   y, x;
        !           490: int            prob;
        !           491: int            obj;
        !           492: {
        !           493:        register int    req;
        !           494: 
        !           495:        switch (obj) {
        !           496:          case MINE:
        !           497:                req = BULREQ;
        !           498:                break;
        !           499:          case GMINE:
        !           500:                req = GRENREQ;
        !           501:                break;
        !           502:          default:
        !           503:                abort();
        !           504:        }
        !           505:        if (rand_num(100) < prob)
        !           506:                add_shot(obj, y, x, LEFTS, req, (PLAYER *) NULL,
        !           507:                        TRUE, pp->p_face);
        !           508:        else {
        !           509:                pp->p_ammo += req;
        !           510:                (void) sprintf(Buf, "%3d", pp->p_ammo);
        !           511:                cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
        !           512:                outstr(pp, Buf, 3);
        !           513:        }
        !           514: }

unix.superglobalmegacorp.com

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