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