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