home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / y / bsdgames / bsd-game.000 / bsd-game / games / hunt / expl.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  4.0 KB  |  212 lines

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