draw.c revision 1.1 1 1.1 mrg /*
2 1.1 mrg * Hunt
3 1.1 mrg * Copyright (c) 1985 Conrad C. Huang, Gregory S. Couch, Kenneth C.R.C. Arnold
4 1.1 mrg * San Francisco, California
5 1.1 mrg */
6 1.1 mrg
7 1.1 mrg # include "hunt.h"
8 1.1 mrg
9 1.1 mrg drawmaze(pp)
10 1.1 mrg register PLAYER *pp;
11 1.1 mrg {
12 1.1 mrg register int x;
13 1.1 mrg register char *sp;
14 1.1 mrg register int y;
15 1.1 mrg register char *endp;
16 1.1 mrg
17 1.1 mrg clrscr(pp);
18 1.1 mrg outstr(pp, pp->p_maze[0], WIDTH);
19 1.1 mrg for (y = 1; y < HEIGHT - 1; y++) {
20 1.1 mrg endp = &pp->p_maze[y][WIDTH];
21 1.1 mrg for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++)
22 1.1 mrg if (*sp != SPACE) {
23 1.1 mrg cgoto(pp, y, x);
24 1.1 mrg if (pp->p_x == x && pp->p_y == y)
25 1.1 mrg outch(pp, translate(*sp));
26 1.1 mrg else if (isplayer(*sp))
27 1.1 mrg outch(pp, player_sym(pp, y, x));
28 1.1 mrg else
29 1.1 mrg outch(pp, *sp);
30 1.1 mrg }
31 1.1 mrg }
32 1.1 mrg cgoto(pp, HEIGHT - 1, 0);
33 1.1 mrg outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH);
34 1.1 mrg drawstatus(pp);
35 1.1 mrg }
36 1.1 mrg
37 1.1 mrg /*
38 1.1 mrg * drawstatus - put up the status lines (this assumes the screen
39 1.1 mrg * size is 80x24 with the maze being 64x24)
40 1.1 mrg */
41 1.1 mrg drawstatus(pp)
42 1.1 mrg register PLAYER *pp;
43 1.1 mrg {
44 1.1 mrg register int i;
45 1.1 mrg register PLAYER *np;
46 1.1 mrg
47 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_LABEL_COL);
48 1.1 mrg outstr(pp, "Ammo:", 5);
49 1.1 mrg (void) sprintf(Buf, "%3d", pp->p_ammo);
50 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
51 1.1 mrg outstr(pp, Buf, 3);
52 1.1 mrg
53 1.1 mrg cgoto(pp, STAT_GUN_ROW, STAT_LABEL_COL);
54 1.1 mrg outstr(pp, "Gun:", 4);
55 1.1 mrg cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
56 1.1 mrg outstr(pp, (pp->p_ncshot < MAXNCSHOT) ? " ok" : " ", 3);
57 1.1 mrg
58 1.1 mrg cgoto(pp, STAT_DAM_ROW, STAT_LABEL_COL);
59 1.1 mrg outstr(pp, "Damage:", 7);
60 1.1 mrg (void) sprintf(Buf, "%2d/%2d", pp->p_damage, pp->p_damcap);
61 1.1 mrg cgoto(pp, STAT_DAM_ROW, STAT_VALUE_COL);
62 1.1 mrg outstr(pp, Buf, 5);
63 1.1 mrg
64 1.1 mrg cgoto(pp, STAT_KILL_ROW, STAT_LABEL_COL);
65 1.1 mrg outstr(pp, "Kills:", 6);
66 1.1 mrg (void) sprintf(Buf, "%3d", (pp->p_damcap - MAXDAM) / 2);
67 1.1 mrg cgoto(pp, STAT_KILL_ROW, STAT_VALUE_COL);
68 1.1 mrg outstr(pp, Buf, 3);
69 1.1 mrg
70 1.1 mrg cgoto(pp, STAT_PLAY_ROW, STAT_LABEL_COL);
71 1.1 mrg outstr(pp, "Player:", 7);
72 1.1 mrg for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++) {
73 1.1 mrg (void) sprintf(Buf, "%5.2f%c%-10.10s %c", np->p_ident->i_score,
74 1.1 mrg stat_char(np), np->p_ident->i_name,
75 1.1 mrg np->p_ident->i_team);
76 1.1 mrg cgoto(pp, i++, STAT_NAME_COL);
77 1.1 mrg outstr(pp, Buf, STAT_NAME_LEN);
78 1.1 mrg }
79 1.1 mrg
80 1.1 mrg # ifdef MONITOR
81 1.1 mrg cgoto(pp, STAT_MON_ROW, STAT_LABEL_COL);
82 1.1 mrg outstr(pp, "Monitor:", 8);
83 1.1 mrg for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++) {
84 1.1 mrg (void) sprintf(Buf, "%5.5s %-10.10s %c", " ",
85 1.1 mrg np->p_ident->i_name, np->p_ident->i_team);
86 1.1 mrg cgoto(pp, i++, STAT_NAME_COL);
87 1.1 mrg outstr(pp, Buf, STAT_NAME_LEN);
88 1.1 mrg }
89 1.1 mrg # endif
90 1.1 mrg }
91 1.1 mrg
92 1.1 mrg look(pp)
93 1.1 mrg register PLAYER *pp;
94 1.1 mrg {
95 1.1 mrg register int x, y;
96 1.1 mrg
97 1.1 mrg x = pp->p_x;
98 1.1 mrg y = pp->p_y;
99 1.1 mrg
100 1.1 mrg check(pp, y - 1, x - 1);
101 1.1 mrg check(pp, y - 1, x );
102 1.1 mrg check(pp, y - 1, x + 1);
103 1.1 mrg check(pp, y , x - 1);
104 1.1 mrg check(pp, y , x );
105 1.1 mrg check(pp, y , x + 1);
106 1.1 mrg check(pp, y + 1, x - 1);
107 1.1 mrg check(pp, y + 1, x );
108 1.1 mrg check(pp, y + 1, x + 1);
109 1.1 mrg
110 1.1 mrg switch (pp->p_face) {
111 1.1 mrg case LEFTS:
112 1.1 mrg see(pp, LEFTS);
113 1.1 mrg see(pp, ABOVE);
114 1.1 mrg see(pp, BELOW);
115 1.1 mrg break;
116 1.1 mrg case RIGHT:
117 1.1 mrg see(pp, RIGHT);
118 1.1 mrg see(pp, ABOVE);
119 1.1 mrg see(pp, BELOW);
120 1.1 mrg break;
121 1.1 mrg case ABOVE:
122 1.1 mrg see(pp, ABOVE);
123 1.1 mrg see(pp, LEFTS);
124 1.1 mrg see(pp, RIGHT);
125 1.1 mrg break;
126 1.1 mrg case BELOW:
127 1.1 mrg see(pp, BELOW);
128 1.1 mrg see(pp, LEFTS);
129 1.1 mrg see(pp, RIGHT);
130 1.1 mrg break;
131 1.1 mrg # ifdef FLY
132 1.1 mrg case FLYER:
133 1.1 mrg break;
134 1.1 mrg # endif
135 1.1 mrg }
136 1.1 mrg cgoto(pp, y, x);
137 1.1 mrg }
138 1.1 mrg
139 1.1 mrg see(pp, face)
140 1.1 mrg register PLAYER *pp;
141 1.1 mrg int face;
142 1.1 mrg {
143 1.1 mrg register char *sp;
144 1.1 mrg register int y, x, i, cnt;
145 1.1 mrg
146 1.1 mrg x = pp->p_x;
147 1.1 mrg y = pp->p_y;
148 1.1 mrg
149 1.1 mrg switch (face) {
150 1.1 mrg case LEFTS:
151 1.1 mrg sp = &Maze[y][x];
152 1.1 mrg for (i = 0; See_over[*--sp]; i++)
153 1.1 mrg continue;
154 1.1 mrg
155 1.1 mrg if (i == 0)
156 1.1 mrg break;
157 1.1 mrg
158 1.1 mrg cnt = i;
159 1.1 mrg x = pp->p_x - 1;
160 1.1 mrg --y;
161 1.1 mrg while (i--)
162 1.1 mrg check(pp, y, --x);
163 1.1 mrg i = cnt;
164 1.1 mrg x = pp->p_x - 1;
165 1.1 mrg ++y;
166 1.1 mrg while (i--)
167 1.1 mrg check(pp, y, --x);
168 1.1 mrg i = cnt;
169 1.1 mrg x = pp->p_x - 1;
170 1.1 mrg ++y;
171 1.1 mrg while (i--)
172 1.1 mrg check(pp, y, --x);
173 1.1 mrg break;
174 1.1 mrg case RIGHT:
175 1.1 mrg sp = &Maze[y][++x];
176 1.1 mrg for (i = 0; See_over[*sp++]; i++)
177 1.1 mrg continue;
178 1.1 mrg
179 1.1 mrg if (i == 0)
180 1.1 mrg break;
181 1.1 mrg
182 1.1 mrg cnt = i;
183 1.1 mrg x = pp->p_x + 1;
184 1.1 mrg --y;
185 1.1 mrg while (i--)
186 1.1 mrg check(pp, y, ++x);
187 1.1 mrg i = cnt;
188 1.1 mrg x = pp->p_x + 1;
189 1.1 mrg ++y;
190 1.1 mrg while (i--)
191 1.1 mrg check(pp, y, ++x);
192 1.1 mrg i = cnt;
193 1.1 mrg x = pp->p_x + 1;
194 1.1 mrg ++y;
195 1.1 mrg while (i--)
196 1.1 mrg check(pp, y, ++x);
197 1.1 mrg break;
198 1.1 mrg case ABOVE:
199 1.1 mrg sp = &Maze[--y][x];
200 1.1 mrg if (!See_over[*sp])
201 1.1 mrg break;
202 1.1 mrg do {
203 1.1 mrg --y;
204 1.1 mrg sp -= sizeof Maze[0];
205 1.1 mrg check(pp, y, x - 1);
206 1.1 mrg check(pp, y, x );
207 1.1 mrg check(pp, y, x + 1);
208 1.1 mrg } while (See_over[*sp]);
209 1.1 mrg break;
210 1.1 mrg case BELOW:
211 1.1 mrg sp = &Maze[++y][x];
212 1.1 mrg if (!See_over[*sp])
213 1.1 mrg break;
214 1.1 mrg do {
215 1.1 mrg y++;
216 1.1 mrg sp += sizeof Maze[0];
217 1.1 mrg check(pp, y, x - 1);
218 1.1 mrg check(pp, y, x );
219 1.1 mrg check(pp, y, x + 1);
220 1.1 mrg } while (See_over[*sp]);
221 1.1 mrg break;
222 1.1 mrg }
223 1.1 mrg }
224 1.1 mrg
225 1.1 mrg check(pp, y, x)
226 1.1 mrg PLAYER *pp;
227 1.1 mrg int y, x;
228 1.1 mrg {
229 1.1 mrg register int index;
230 1.1 mrg register int ch;
231 1.1 mrg register PLAYER *rpp;
232 1.1 mrg
233 1.1 mrg index = y * sizeof Maze[0] + x;
234 1.1 mrg ch = ((char *) Maze)[index];
235 1.1 mrg if (ch != ((char *) pp->p_maze)[index]) {
236 1.1 mrg rpp = pp;
237 1.1 mrg cgoto(rpp, y, x);
238 1.1 mrg if (x == rpp->p_x && y == rpp->p_y)
239 1.1 mrg outch(rpp, translate(ch));
240 1.1 mrg else if (isplayer(ch))
241 1.1 mrg outch(rpp, player_sym(rpp, y, x));
242 1.1 mrg else
243 1.1 mrg outch(rpp, ch);
244 1.1 mrg ((char *) rpp->p_maze)[index] = ch;
245 1.1 mrg }
246 1.1 mrg }
247 1.1 mrg
248 1.1 mrg /*
249 1.1 mrg * showstat
250 1.1 mrg * Update the status of players
251 1.1 mrg */
252 1.1 mrg showstat(pp)
253 1.1 mrg register PLAYER *pp;
254 1.1 mrg {
255 1.1 mrg register PLAYER *np;
256 1.1 mrg register int y;
257 1.1 mrg register char c;
258 1.1 mrg
259 1.1 mrg y = STAT_PLAY_ROW + 1 + (pp - Player);
260 1.1 mrg c = stat_char(pp);
261 1.1 mrg # ifdef MONITOR
262 1.1 mrg for (np = Monitor; np < End_monitor; np++) {
263 1.1 mrg cgoto(np, y, STAT_SCAN_COL);
264 1.1 mrg outch(np, c);
265 1.1 mrg }
266 1.1 mrg # endif
267 1.1 mrg for (np = Player; np < End_player; np++) {
268 1.1 mrg cgoto(np, y, STAT_SCAN_COL);
269 1.1 mrg outch(np, c);
270 1.1 mrg }
271 1.1 mrg }
272 1.1 mrg
273 1.1 mrg /*
274 1.1 mrg * drawplayer:
275 1.1 mrg * Draw the player on the screen and show him to everyone who's scanning
276 1.1 mrg * unless he is cloaked.
277 1.1 mrg */
278 1.1 mrg drawplayer(pp, draw)
279 1.1 mrg PLAYER *pp;
280 1.1 mrg FLAG draw;
281 1.1 mrg {
282 1.1 mrg register PLAYER *newp;
283 1.1 mrg register int x, y;
284 1.1 mrg
285 1.1 mrg x = pp->p_x;
286 1.1 mrg y = pp->p_y;
287 1.1 mrg Maze[y][x] = draw ? pp->p_face : pp->p_over;
288 1.1 mrg
289 1.1 mrg # ifdef MONITOR
290 1.1 mrg for (newp = Monitor; newp < End_monitor; newp++)
291 1.1 mrg check(newp, y, x);
292 1.1 mrg # endif
293 1.1 mrg
294 1.1 mrg for (newp = Player; newp < End_player; newp++) {
295 1.1 mrg if (!draw || newp == pp) {
296 1.1 mrg check(newp, y, x);
297 1.1 mrg continue;
298 1.1 mrg }
299 1.1 mrg if (newp->p_scan == 0) {
300 1.1 mrg newp->p_scan--;
301 1.1 mrg showstat(newp);
302 1.1 mrg }
303 1.1 mrg else if (newp->p_scan > 0) {
304 1.1 mrg if (pp->p_cloak < 0)
305 1.1 mrg check(newp, y, x);
306 1.1 mrg newp->p_scan--;
307 1.1 mrg }
308 1.1 mrg }
309 1.1 mrg if (!draw || pp->p_cloak < 0)
310 1.1 mrg return;
311 1.1 mrg if (pp->p_cloak-- == 0)
312 1.1 mrg showstat(pp);
313 1.1 mrg }
314 1.1 mrg
315 1.1 mrg message(pp, s)
316 1.1 mrg register PLAYER *pp;
317 1.1 mrg char *s;
318 1.1 mrg {
319 1.1 mrg cgoto(pp, HEIGHT, 0);
320 1.1 mrg outstr(pp, s, strlen(s));
321 1.1 mrg ce(pp);
322 1.1 mrg }
323 1.1 mrg
324 1.1 mrg /*
325 1.1 mrg * translate:
326 1.1 mrg * Turn a character into the right direction character if we are
327 1.1 mrg * looking at the current player.
328 1.1 mrg */
329 1.1 mrg translate(ch)
330 1.1 mrg char ch;
331 1.1 mrg {
332 1.1 mrg switch (ch) {
333 1.1 mrg case LEFTS:
334 1.1 mrg return '<';
335 1.1 mrg case RIGHT:
336 1.1 mrg return '>';
337 1.1 mrg case ABOVE:
338 1.1 mrg return '^';
339 1.1 mrg case BELOW:
340 1.1 mrg return 'v';
341 1.1 mrg }
342 1.1 mrg return ch;
343 1.1 mrg }
344 1.1 mrg
345 1.1 mrg /*
346 1.1 mrg * player_sym:
347 1.1 mrg * Return the player symbol
348 1.1 mrg */
349 1.1 mrg player_sym(pp, y, x)
350 1.1 mrg PLAYER *pp;
351 1.1 mrg int y, x;
352 1.1 mrg {
353 1.1 mrg register PLAYER *npp;
354 1.1 mrg
355 1.1 mrg npp = play_at(y, x);
356 1.1 mrg if (npp->p_ident->i_team == ' ')
357 1.1 mrg return Maze[y][x];
358 1.1 mrg #ifdef MONITOR
359 1.1 mrg if (pp->p_ident->i_team == '*')
360 1.1 mrg return npp->p_ident->i_team;
361 1.1 mrg #endif
362 1.1 mrg if (pp->p_ident->i_team != npp->p_ident->i_team)
363 1.1 mrg return Maze[y][x];
364 1.1 mrg return pp->p_ident->i_team;
365 1.1 mrg }
366