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