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