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 = Expl[0];
33: Expl[0] = 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 MONITOR
50: switch (Maze[y][x]) {
51: case WALL1:
52: case WALL2:
53: case WALL3:
54: # ifdef RANDOM
55: case DOOR:
56: # endif RANDOM
57: # ifdef REFLECT
58: case WALL4:
59: case WALL5:
60: # endif REFLECT
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 MONITOR
98: free((char *) ep);
99: }
100: for (x = EXPLEN - 1; x > 0; x--)
101: Expl[x] = Expl[x - 1];
102: 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 MONITOR || FLY
124: # ifdef FLY
125: register char save_char;
126: # endif FLY
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 FLY
142: if (Maze[r->r_y][r->r_x] == SPACE)
143: break;
144: # endif FLY
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 FLY
170: Maze[r->r_y][r->r_x] = Orig_maze[r->r_y][r->r_x];
171: # endif FLY
172: # ifdef RANDOM
173: if (rand_num(100) == 0)
174: Maze[r->r_y][r->r_x] = DOOR;
175: # endif RANDOM
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 REFLECT
180: # ifdef MONITOR
181: for (pp = Monitor; pp < End_monitor; pp++)
182: check(pp, r->r_y, r->r_x);
183: # endif MONITOR
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 MONITOR
198: }
Defined functions
Defined variables
Defined macros