draw.c revision 1.3 1 1.3 wiz /* $NetBSD: draw.c,v 1.3 2003/06/11 12:00:22 wiz Exp $ */
2 1.1 mrg /*
3 1.3 wiz * Copyright (c) 1983-2003, Regents of the University of California.
4 1.3 wiz * All rights reserved.
5 1.3 wiz *
6 1.3 wiz * Redistribution and use in source and binary forms, with or without
7 1.3 wiz * modification, are permitted provided that the following conditions are
8 1.3 wiz * met:
9 1.3 wiz *
10 1.3 wiz * + Redistributions of source code must retain the above copyright
11 1.3 wiz * notice, this list of conditions and the following disclaimer.
12 1.3 wiz * + Redistributions in binary form must reproduce the above copyright
13 1.3 wiz * notice, this list of conditions and the following disclaimer in the
14 1.3 wiz * documentation and/or other materials provided with the distribution.
15 1.3 wiz * + Neither the name of the University of California, San Francisco nor
16 1.3 wiz * the names of its contributors may be used to endorse or promote
17 1.3 wiz * products derived from this software without specific prior written
18 1.3 wiz * permission.
19 1.3 wiz *
20 1.3 wiz * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 1.3 wiz * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.3 wiz * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 1.3 wiz * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 1.3 wiz * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 1.3 wiz * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 1.3 wiz * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.3 wiz * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.3 wiz * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.3 wiz * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 1.3 wiz * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 mrg */
32 1.1 mrg
33 1.2 lukem #include <sys/cdefs.h>
34 1.2 lukem #ifndef lint
35 1.3 wiz __RCSID("$NetBSD: draw.c,v 1.3 2003/06/11 12:00:22 wiz Exp $");
36 1.2 lukem #endif /* not lint */
37 1.2 lukem
38 1.1 mrg # include "hunt.h"
39 1.1 mrg
40 1.2 lukem void
41 1.1 mrg drawmaze(pp)
42 1.2 lukem PLAYER *pp;
43 1.1 mrg {
44 1.2 lukem int x;
45 1.2 lukem char *sp;
46 1.2 lukem int y;
47 1.2 lukem char *endp;
48 1.1 mrg
49 1.1 mrg clrscr(pp);
50 1.1 mrg outstr(pp, pp->p_maze[0], WIDTH);
51 1.1 mrg for (y = 1; y < HEIGHT - 1; y++) {
52 1.1 mrg endp = &pp->p_maze[y][WIDTH];
53 1.1 mrg for (x = 0, sp = pp->p_maze[y]; sp < endp; x++, sp++)
54 1.1 mrg if (*sp != SPACE) {
55 1.1 mrg cgoto(pp, y, x);
56 1.1 mrg if (pp->p_x == x && pp->p_y == y)
57 1.1 mrg outch(pp, translate(*sp));
58 1.1 mrg else if (isplayer(*sp))
59 1.1 mrg outch(pp, player_sym(pp, y, x));
60 1.1 mrg else
61 1.1 mrg outch(pp, *sp);
62 1.1 mrg }
63 1.1 mrg }
64 1.1 mrg cgoto(pp, HEIGHT - 1, 0);
65 1.1 mrg outstr(pp, pp->p_maze[HEIGHT - 1], WIDTH);
66 1.1 mrg drawstatus(pp);
67 1.1 mrg }
68 1.1 mrg
69 1.1 mrg /*
70 1.1 mrg * drawstatus - put up the status lines (this assumes the screen
71 1.1 mrg * size is 80x24 with the maze being 64x24)
72 1.1 mrg */
73 1.2 lukem void
74 1.1 mrg drawstatus(pp)
75 1.2 lukem PLAYER *pp;
76 1.1 mrg {
77 1.2 lukem int i;
78 1.2 lukem PLAYER *np;
79 1.1 mrg
80 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_LABEL_COL);
81 1.1 mrg outstr(pp, "Ammo:", 5);
82 1.1 mrg (void) sprintf(Buf, "%3d", pp->p_ammo);
83 1.1 mrg cgoto(pp, STAT_AMMO_ROW, STAT_VALUE_COL);
84 1.1 mrg outstr(pp, Buf, 3);
85 1.1 mrg
86 1.1 mrg cgoto(pp, STAT_GUN_ROW, STAT_LABEL_COL);
87 1.1 mrg outstr(pp, "Gun:", 4);
88 1.1 mrg cgoto(pp, STAT_GUN_ROW, STAT_VALUE_COL);
89 1.1 mrg outstr(pp, (pp->p_ncshot < MAXNCSHOT) ? " ok" : " ", 3);
90 1.1 mrg
91 1.1 mrg cgoto(pp, STAT_DAM_ROW, STAT_LABEL_COL);
92 1.1 mrg outstr(pp, "Damage:", 7);
93 1.1 mrg (void) sprintf(Buf, "%2d/%2d", pp->p_damage, pp->p_damcap);
94 1.1 mrg cgoto(pp, STAT_DAM_ROW, STAT_VALUE_COL);
95 1.1 mrg outstr(pp, Buf, 5);
96 1.1 mrg
97 1.1 mrg cgoto(pp, STAT_KILL_ROW, STAT_LABEL_COL);
98 1.1 mrg outstr(pp, "Kills:", 6);
99 1.1 mrg (void) sprintf(Buf, "%3d", (pp->p_damcap - MAXDAM) / 2);
100 1.1 mrg cgoto(pp, STAT_KILL_ROW, STAT_VALUE_COL);
101 1.1 mrg outstr(pp, Buf, 3);
102 1.1 mrg
103 1.1 mrg cgoto(pp, STAT_PLAY_ROW, STAT_LABEL_COL);
104 1.1 mrg outstr(pp, "Player:", 7);
105 1.1 mrg for (i = STAT_PLAY_ROW + 1, np = Player; np < End_player; np++) {
106 1.1 mrg (void) sprintf(Buf, "%5.2f%c%-10.10s %c", np->p_ident->i_score,
107 1.1 mrg stat_char(np), np->p_ident->i_name,
108 1.1 mrg np->p_ident->i_team);
109 1.1 mrg cgoto(pp, i++, STAT_NAME_COL);
110 1.1 mrg outstr(pp, Buf, STAT_NAME_LEN);
111 1.1 mrg }
112 1.1 mrg
113 1.1 mrg # ifdef MONITOR
114 1.1 mrg cgoto(pp, STAT_MON_ROW, STAT_LABEL_COL);
115 1.1 mrg outstr(pp, "Monitor:", 8);
116 1.1 mrg for (i = STAT_MON_ROW + 1, np = Monitor; np < End_monitor; np++) {
117 1.1 mrg (void) sprintf(Buf, "%5.5s %-10.10s %c", " ",
118 1.1 mrg np->p_ident->i_name, np->p_ident->i_team);
119 1.1 mrg cgoto(pp, i++, STAT_NAME_COL);
120 1.1 mrg outstr(pp, Buf, STAT_NAME_LEN);
121 1.1 mrg }
122 1.1 mrg # endif
123 1.1 mrg }
124 1.1 mrg
125 1.2 lukem void
126 1.1 mrg look(pp)
127 1.2 lukem PLAYER *pp;
128 1.1 mrg {
129 1.2 lukem int x, y;
130 1.1 mrg
131 1.1 mrg x = pp->p_x;
132 1.1 mrg y = pp->p_y;
133 1.1 mrg
134 1.1 mrg check(pp, y - 1, x - 1);
135 1.1 mrg check(pp, y - 1, x );
136 1.1 mrg check(pp, y - 1, x + 1);
137 1.1 mrg check(pp, y , x - 1);
138 1.1 mrg check(pp, y , x );
139 1.1 mrg check(pp, y , x + 1);
140 1.1 mrg check(pp, y + 1, x - 1);
141 1.1 mrg check(pp, y + 1, x );
142 1.1 mrg check(pp, y + 1, x + 1);
143 1.1 mrg
144 1.1 mrg switch (pp->p_face) {
145 1.1 mrg case LEFTS:
146 1.1 mrg see(pp, LEFTS);
147 1.1 mrg see(pp, ABOVE);
148 1.1 mrg see(pp, BELOW);
149 1.1 mrg break;
150 1.1 mrg case RIGHT:
151 1.1 mrg see(pp, RIGHT);
152 1.1 mrg see(pp, ABOVE);
153 1.1 mrg see(pp, BELOW);
154 1.1 mrg break;
155 1.1 mrg case ABOVE:
156 1.1 mrg see(pp, ABOVE);
157 1.1 mrg see(pp, LEFTS);
158 1.1 mrg see(pp, RIGHT);
159 1.1 mrg break;
160 1.1 mrg case BELOW:
161 1.1 mrg see(pp, BELOW);
162 1.1 mrg see(pp, LEFTS);
163 1.1 mrg see(pp, RIGHT);
164 1.1 mrg break;
165 1.1 mrg # ifdef FLY
166 1.1 mrg case FLYER:
167 1.1 mrg break;
168 1.1 mrg # endif
169 1.1 mrg }
170 1.1 mrg cgoto(pp, y, x);
171 1.1 mrg }
172 1.1 mrg
173 1.2 lukem void
174 1.1 mrg see(pp, face)
175 1.2 lukem PLAYER *pp;
176 1.2 lukem int face;
177 1.1 mrg {
178 1.2 lukem char *sp;
179 1.2 lukem int y, x, i, cnt;
180 1.1 mrg
181 1.1 mrg x = pp->p_x;
182 1.1 mrg y = pp->p_y;
183 1.1 mrg
184 1.1 mrg switch (face) {
185 1.1 mrg case LEFTS:
186 1.1 mrg sp = &Maze[y][x];
187 1.2 lukem for (i = 0; See_over[(int)*--sp]; i++)
188 1.1 mrg continue;
189 1.1 mrg
190 1.1 mrg if (i == 0)
191 1.1 mrg break;
192 1.1 mrg
193 1.1 mrg cnt = i;
194 1.1 mrg x = pp->p_x - 1;
195 1.1 mrg --y;
196 1.1 mrg while (i--)
197 1.1 mrg check(pp, y, --x);
198 1.1 mrg i = cnt;
199 1.1 mrg x = pp->p_x - 1;
200 1.1 mrg ++y;
201 1.1 mrg while (i--)
202 1.1 mrg check(pp, y, --x);
203 1.1 mrg i = cnt;
204 1.1 mrg x = pp->p_x - 1;
205 1.1 mrg ++y;
206 1.1 mrg while (i--)
207 1.1 mrg check(pp, y, --x);
208 1.1 mrg break;
209 1.1 mrg case RIGHT:
210 1.1 mrg sp = &Maze[y][++x];
211 1.2 lukem for (i = 0; See_over[(int)*sp++]; i++)
212 1.1 mrg continue;
213 1.1 mrg
214 1.1 mrg if (i == 0)
215 1.1 mrg break;
216 1.1 mrg
217 1.1 mrg cnt = i;
218 1.1 mrg x = pp->p_x + 1;
219 1.1 mrg --y;
220 1.1 mrg while (i--)
221 1.1 mrg check(pp, y, ++x);
222 1.1 mrg i = cnt;
223 1.1 mrg x = pp->p_x + 1;
224 1.1 mrg ++y;
225 1.1 mrg while (i--)
226 1.1 mrg check(pp, y, ++x);
227 1.1 mrg i = cnt;
228 1.1 mrg x = pp->p_x + 1;
229 1.1 mrg ++y;
230 1.1 mrg while (i--)
231 1.1 mrg check(pp, y, ++x);
232 1.1 mrg break;
233 1.1 mrg case ABOVE:
234 1.1 mrg sp = &Maze[--y][x];
235 1.2 lukem if (!See_over[(int)*sp])
236 1.1 mrg break;
237 1.1 mrg do {
238 1.1 mrg --y;
239 1.1 mrg sp -= sizeof Maze[0];
240 1.1 mrg check(pp, y, x - 1);
241 1.1 mrg check(pp, y, x );
242 1.1 mrg check(pp, y, x + 1);
243 1.2 lukem } while (See_over[(int)*sp]);
244 1.1 mrg break;
245 1.1 mrg case BELOW:
246 1.1 mrg sp = &Maze[++y][x];
247 1.2 lukem if (!See_over[(int)*sp])
248 1.1 mrg break;
249 1.1 mrg do {
250 1.1 mrg y++;
251 1.1 mrg sp += sizeof Maze[0];
252 1.1 mrg check(pp, y, x - 1);
253 1.1 mrg check(pp, y, x );
254 1.1 mrg check(pp, y, x + 1);
255 1.2 lukem } while (See_over[(int)*sp]);
256 1.1 mrg break;
257 1.1 mrg }
258 1.1 mrg }
259 1.1 mrg
260 1.2 lukem void
261 1.1 mrg check(pp, y, x)
262 1.2 lukem PLAYER *pp;
263 1.2 lukem int y, x;
264 1.1 mrg {
265 1.2 lukem int index;
266 1.2 lukem int ch;
267 1.2 lukem PLAYER *rpp;
268 1.1 mrg
269 1.1 mrg index = y * sizeof Maze[0] + x;
270 1.1 mrg ch = ((char *) Maze)[index];
271 1.1 mrg if (ch != ((char *) pp->p_maze)[index]) {
272 1.1 mrg rpp = pp;
273 1.1 mrg cgoto(rpp, y, x);
274 1.1 mrg if (x == rpp->p_x && y == rpp->p_y)
275 1.1 mrg outch(rpp, translate(ch));
276 1.1 mrg else if (isplayer(ch))
277 1.1 mrg outch(rpp, player_sym(rpp, y, x));
278 1.1 mrg else
279 1.1 mrg outch(rpp, ch);
280 1.1 mrg ((char *) rpp->p_maze)[index] = ch;
281 1.1 mrg }
282 1.1 mrg }
283 1.1 mrg
284 1.1 mrg /*
285 1.1 mrg * showstat
286 1.1 mrg * Update the status of players
287 1.1 mrg */
288 1.2 lukem void
289 1.1 mrg showstat(pp)
290 1.2 lukem PLAYER *pp;
291 1.1 mrg {
292 1.2 lukem PLAYER *np;
293 1.2 lukem int y;
294 1.2 lukem char c;
295 1.1 mrg
296 1.1 mrg y = STAT_PLAY_ROW + 1 + (pp - Player);
297 1.1 mrg c = stat_char(pp);
298 1.1 mrg # ifdef MONITOR
299 1.1 mrg for (np = Monitor; np < End_monitor; np++) {
300 1.1 mrg cgoto(np, y, STAT_SCAN_COL);
301 1.1 mrg outch(np, c);
302 1.1 mrg }
303 1.1 mrg # endif
304 1.1 mrg for (np = Player; np < End_player; np++) {
305 1.1 mrg cgoto(np, y, STAT_SCAN_COL);
306 1.1 mrg outch(np, c);
307 1.1 mrg }
308 1.1 mrg }
309 1.1 mrg
310 1.1 mrg /*
311 1.1 mrg * drawplayer:
312 1.1 mrg * Draw the player on the screen and show him to everyone who's scanning
313 1.1 mrg * unless he is cloaked.
314 1.1 mrg */
315 1.2 lukem void
316 1.1 mrg drawplayer(pp, draw)
317 1.2 lukem PLAYER *pp;
318 1.2 lukem FLAG draw;
319 1.1 mrg {
320 1.2 lukem PLAYER *newp;
321 1.2 lukem int x, y;
322 1.1 mrg
323 1.1 mrg x = pp->p_x;
324 1.1 mrg y = pp->p_y;
325 1.1 mrg Maze[y][x] = draw ? pp->p_face : pp->p_over;
326 1.1 mrg
327 1.1 mrg # ifdef MONITOR
328 1.1 mrg for (newp = Monitor; newp < End_monitor; newp++)
329 1.1 mrg check(newp, y, x);
330 1.1 mrg # endif
331 1.1 mrg
332 1.1 mrg for (newp = Player; newp < End_player; newp++) {
333 1.1 mrg if (!draw || newp == pp) {
334 1.1 mrg check(newp, y, x);
335 1.1 mrg continue;
336 1.1 mrg }
337 1.1 mrg if (newp->p_scan == 0) {
338 1.1 mrg newp->p_scan--;
339 1.1 mrg showstat(newp);
340 1.1 mrg }
341 1.1 mrg else if (newp->p_scan > 0) {
342 1.1 mrg if (pp->p_cloak < 0)
343 1.1 mrg check(newp, y, x);
344 1.1 mrg newp->p_scan--;
345 1.1 mrg }
346 1.1 mrg }
347 1.1 mrg if (!draw || pp->p_cloak < 0)
348 1.1 mrg return;
349 1.1 mrg if (pp->p_cloak-- == 0)
350 1.1 mrg showstat(pp);
351 1.1 mrg }
352 1.1 mrg
353 1.2 lukem void
354 1.1 mrg message(pp, s)
355 1.2 lukem PLAYER *pp;
356 1.2 lukem char *s;
357 1.1 mrg {
358 1.1 mrg cgoto(pp, HEIGHT, 0);
359 1.1 mrg outstr(pp, s, strlen(s));
360 1.1 mrg ce(pp);
361 1.1 mrg }
362 1.1 mrg
363 1.1 mrg /*
364 1.1 mrg * translate:
365 1.1 mrg * Turn a character into the right direction character if we are
366 1.1 mrg * looking at the current player.
367 1.1 mrg */
368 1.2 lukem char
369 1.1 mrg translate(ch)
370 1.2 lukem char ch;
371 1.1 mrg {
372 1.1 mrg switch (ch) {
373 1.1 mrg case LEFTS:
374 1.1 mrg return '<';
375 1.1 mrg case RIGHT:
376 1.1 mrg return '>';
377 1.1 mrg case ABOVE:
378 1.1 mrg return '^';
379 1.1 mrg case BELOW:
380 1.1 mrg return 'v';
381 1.1 mrg }
382 1.1 mrg return ch;
383 1.1 mrg }
384 1.1 mrg
385 1.1 mrg /*
386 1.1 mrg * player_sym:
387 1.1 mrg * Return the player symbol
388 1.1 mrg */
389 1.2 lukem int
390 1.1 mrg player_sym(pp, y, x)
391 1.2 lukem PLAYER *pp;
392 1.2 lukem int y, x;
393 1.1 mrg {
394 1.2 lukem PLAYER *npp;
395 1.1 mrg
396 1.1 mrg npp = play_at(y, x);
397 1.1 mrg if (npp->p_ident->i_team == ' ')
398 1.1 mrg return Maze[y][x];
399 1.1 mrg #ifdef MONITOR
400 1.1 mrg if (pp->p_ident->i_team == '*')
401 1.1 mrg return npp->p_ident->i_team;
402 1.1 mrg #endif
403 1.1 mrg if (pp->p_ident->i_team != npp->p_ident->i_team)
404 1.1 mrg return Maze[y][x];
405 1.1 mrg return pp->p_ident->i_team;
406 1.1 mrg }
407