Annotation of 43BSDReno/games/hunt/NEW/expl.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: /*
                     14:  * showexpl:
                     15:  *     Show the explosions as they currently are
                     16:  */
                     17: showexpl(y, x, type)
                     18: register int   y, x;
                     19: char           type;
                     20: {
                     21:        register PLAYER *pp;
                     22:        register EXPL   *ep;
                     23: 
                     24:        if (y < 0 || y >= HEIGHT)
                     25:                return;
                     26:        if (x < 0 || x >= WIDTH)
                     27:                return;
                     28:        ep = (EXPL *) malloc(sizeof (EXPL));    /* NOSTRICT */
                     29:        ep->e_y = y;
                     30:        ep->e_x = x;
                     31:        ep->e_char = type;
                     32:        ep->e_next = NULL;
                     33:        if (Last_expl == NULL)
                     34:                Expl[0] = ep;
                     35:        else
                     36:                Last_expl->e_next = ep;
                     37:        Last_expl = ep;
                     38:        for (pp = Player; pp < End_player; pp++) {
                     39:                if (pp->p_maze[y][x] == type)
                     40:                        continue;
                     41:                pp->p_maze[y][x] = type;
                     42:                cgoto(pp, y, x);
                     43:                outch(pp, type);
                     44:        }
                     45: # ifdef MONITOR
                     46:        for (pp = Monitor; pp < End_monitor; pp++) {
                     47:                if (pp->p_maze[y][x] == type)
                     48:                        continue;
                     49:                pp->p_maze[y][x] = type;
                     50:                cgoto(pp, y, x);
                     51:                outch(pp, type);
                     52:        }
                     53: # endif MONITOR
                     54:        switch (Maze[y][x]) {
                     55:          case WALL1:
                     56:          case WALL2:
                     57:          case WALL3:
                     58: # ifdef RANDOM
                     59:          case DOOR:
                     60: # endif RANDOM
                     61: # ifdef REFLECT
                     62:          case WALL4:
                     63:          case WALL5:
                     64: # endif REFLECT
                     65:                if (y >= UBOUND && y < DBOUND && x >= LBOUND && x < RBOUND)
                     66:                        remove_wall(y, x);
                     67:                break;
                     68:        }
                     69: }
                     70: 
                     71: /*
                     72:  * rollexpl:
                     73:  *     Roll the explosions over, so the next one in the list is at the
                     74:  *     top
                     75:  */
                     76: rollexpl()
                     77: {
                     78:        register EXPL   *ep;
                     79:        register PLAYER *pp;
                     80:        register int    y, x;
                     81:        register char   c;
                     82:        register EXPL   *nextep;
                     83: 
                     84:        for (ep = Expl[EXPLEN - 1]; ep != NULL; ep = nextep) {
                     85:                nextep = ep->e_next;
                     86:                y = ep->e_y;
                     87:                x = ep->e_x;
                     88:                if (y < UBOUND || y >= DBOUND || x < LBOUND || x >= RBOUND)
                     89:                        c = Maze[y][x];
                     90:                else
                     91:                        c = SPACE;
                     92:                for (pp = Player; pp < End_player; pp++)
                     93:                        if (pp->p_maze[y][x] == ep->e_char) {
                     94:                                pp->p_maze[y][x] = c;
                     95:                                cgoto(pp, y, x);
                     96:                                outch(pp, c);
                     97:                        }
                     98: # ifdef MONITOR
                     99:                for (pp = Monitor; pp < End_monitor; pp++)
                    100:                        check(pp, y, x);
                    101: # endif MONITOR
                    102:                free((char *) ep);
                    103:        }
                    104:        for (x = EXPLEN - 1; x > 0; x--)
                    105:                Expl[x] = Expl[x - 1];
                    106:        Last_expl = Expl[0] = NULL;
                    107: }
                    108: 
                    109: /* There's about 700 walls in the initial maze.  So we pick a number
                    110:  * that keeps the maze relatively full. */
                    111: # define MAXREMOVE     40
                    112: 
                    113: static REGEN   removed[MAXREMOVE];
                    114: static REGEN   *rem_index = removed;
                    115: 
                    116: /*
                    117:  * remove_wall - add a location where the wall was blown away.
                    118:  *              if there is no space left over, put the a wall at
                    119:  *              the location currently pointed at.
                    120:  */
                    121: remove_wall(y, x)
                    122: int    y, x;
                    123: {
                    124:        register REGEN  *r;
                    125: # if defined(MONITOR) || defined(FLY)
                    126:        register PLAYER *pp;
                    127: # endif MONITOR || FLY
                    128: # ifdef        FLY
                    129:        register char   save_char;
                    130: # endif        FLY
                    131: 
                    132:        r = rem_index;
                    133:        while (r->r_y != 0) {
                    134: # ifdef FLY
                    135:                switch (Maze[r->r_y][r->r_x]) {
                    136:                  case SPACE:
                    137:                  case LEFTS:
                    138:                  case RIGHT:
                    139:                  case ABOVE:
                    140:                  case BELOW:
                    141:                  case FLYER:
                    142:                        save_char = Maze[r->r_y][r->r_x];
                    143:                        goto found;
                    144:                }
                    145: # else FLY
                    146:                if (Maze[r->r_y][r->r_x] == SPACE)
                    147:                        break;
                    148: # endif FLY
                    149:                if (++r >= &removed[MAXREMOVE])
                    150:                        r = removed;
                    151:        }
                    152: 
                    153: found:
                    154:        if (r->r_y != 0) {
                    155:                /* Slot being used, put back this wall */
                    156: # ifdef FLY
                    157:                if (save_char == SPACE)
                    158:                        Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
                    159:                else {
                    160:                        pp = play_at(r->r_y, r->r_x);
                    161:                        if (pp->p_flying >= 0)
                    162:                                pp->p_flying += rand_num(10);
                    163:                        else {
                    164:                                pp->p_flying = rand_num(20);
                    165:                                pp->p_flyx = 2 * rand_num(6) - 5;
                    166:                                pp->p_flyy = 2 * rand_num(6) - 5;
                    167:                        }
                    168:                        pp->p_over = Orig_maze[r->r_y][r->r_x];
                    169:                        pp->p_face = FLYER;
                    170:                        Maze[r->r_y][r->r_x] = FLYER;
                    171:                        showexpl(r->r_y, r->r_x, FLYER);
                    172:                }
                    173: # else FLY
                    174:                Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
                    175: # endif FLY
                    176: # ifdef RANDOM
                    177:                if (rand_num(100) == 0)
                    178:                        Maze[r->r_y][r->r_x] = DOOR;
                    179: # endif RANDOM
                    180: # ifdef REFLECT
                    181:                if (rand_num(100) == 0)         /* one percent of the time */
                    182:                        Maze[r->r_y][r->r_x] = WALL4;
                    183: # endif REFLECT
                    184: # ifdef MONITOR
                    185:                for (pp = Monitor; pp < End_monitor; pp++)
                    186:                        check(pp, r->r_y, r->r_x);
                    187: # endif MONITOR
                    188:        }
                    189: 
                    190:        r->r_y = y;
                    191:        r->r_x = x;
                    192:        if (++r >= &removed[MAXREMOVE])
                    193:                rem_index = removed;
                    194:        else
                    195:                rem_index = r;
                    196: 
                    197:        Maze[y][x] = SPACE;
                    198: # ifdef MONITOR
                    199:        for (pp = Monitor; pp < End_monitor; pp++)
                    200:                check(pp, y, x);
                    201: # endif MONITOR
                    202: }
                    203: 
                    204: /*
                    205:  * clearwalls:
                    206:  *     Clear out the walls array
                    207:  */
                    208: clearwalls()
                    209: {
                    210:        register REGEN  *rp;
                    211: 
                    212:        for (rp = removed; rp < &removed[MAXREMOVE]; rp++)
                    213:                rp->r_y = 0;
                    214:        rem_index = removed;
                    215: }

unix.superglobalmegacorp.com

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