1 /* $NetBSD: draw.c,v 1.7 2009/07/04 04:29:54 dholland Exp $ */
3 * Copyright (c) 1983-2003, Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * + Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * + Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * + Neither the name of the University of California, San Francisco nor
16 * the names of its contributors may be used to endorse or promote
17 * products derived from this software without specific prior written
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
35 __RCSID("$NetBSD: draw.c,v 1.7 2009/07/04 04:29:54 dholland Exp $");
40 static void drawstatus(PLAYER
*);
41 static void see(PLAYER
*, int);
42 static char translate(char);
43 static int player_sym(PLAYER
*, int, int);
54 outstr(pp
, pp
->p_maze
[0], WIDTH
);
55 for (y
= 1; y
< HEIGHT
- 1; y
++) {
56 endp
= &pp
->p_maze
[y
][WIDTH
];
57 for (x
= 0, sp
= pp
->p_maze
[y
]; sp
< endp
; x
++, sp
++)
60 if (pp
->p_x
== x
&& pp
->p_y
== y
)
61 outch(pp
, translate(*sp
));
62 else if (isplayer(*sp
))
63 outch(pp
, player_sym(pp
, y
, x
));
68 cgoto(pp
, HEIGHT
- 1, 0);
69 outstr(pp
, pp
->p_maze
[HEIGHT
- 1], WIDTH
);
74 * drawstatus - put up the status lines (this assumes the screen
75 * size is 80x24 with the maze being 64x24)
78 drawstatus(PLAYER
*pp
)
83 cgoto(pp
, STAT_AMMO_ROW
, STAT_LABEL_COL
);
84 outstr(pp
, "Ammo:", 5);
85 (void) snprintf(Buf
, sizeof(Buf
), "%3d", pp
->p_ammo
);
86 cgoto(pp
, STAT_AMMO_ROW
, STAT_VALUE_COL
);
89 cgoto(pp
, STAT_GUN_ROW
, STAT_LABEL_COL
);
90 outstr(pp
, "Gun:", 4);
91 cgoto(pp
, STAT_GUN_ROW
, STAT_VALUE_COL
);
92 outstr(pp
, (pp
->p_ncshot
< MAXNCSHOT
) ? " ok" : " ", 3);
94 cgoto(pp
, STAT_DAM_ROW
, STAT_LABEL_COL
);
95 outstr(pp
, "Damage:", 7);
96 (void) snprintf(Buf
, sizeof(Buf
), "%2d/%2d", pp
->p_damage
,
98 cgoto(pp
, STAT_DAM_ROW
, STAT_VALUE_COL
);
101 cgoto(pp
, STAT_KILL_ROW
, STAT_LABEL_COL
);
102 outstr(pp
, "Kills:", 6);
103 (void) snprintf(Buf
, sizeof(Buf
), "%3d", (pp
->p_damcap
- MAXDAM
) / 2);
104 cgoto(pp
, STAT_KILL_ROW
, STAT_VALUE_COL
);
107 cgoto(pp
, STAT_PLAY_ROW
, STAT_LABEL_COL
);
108 outstr(pp
, "Player:", 7);
109 for (i
= STAT_PLAY_ROW
+ 1, np
= Player
; np
< End_player
; np
++) {
110 (void) snprintf(Buf
, sizeof(Buf
), "%5.2f%c%-10.10s %c",
111 np
->p_ident
->i_score
,
112 stat_char(np
), np
->p_ident
->i_name
,
113 np
->p_ident
->i_team
);
114 cgoto(pp
, i
++, STAT_NAME_COL
);
115 outstr(pp
, Buf
, STAT_NAME_LEN
);
119 cgoto(pp
, STAT_MON_ROW
, STAT_LABEL_COL
);
120 outstr(pp
, "Monitor:", 8);
121 for (i
= STAT_MON_ROW
+ 1, np
= Monitor
; np
< End_monitor
; np
++) {
122 (void) snprintf(Buf
, sizeof(Buf
), "%5.5s %-10.10s %c", " ",
123 np
->p_ident
->i_name
, np
->p_ident
->i_team
);
124 cgoto(pp
, i
++, STAT_NAME_COL
);
125 outstr(pp
, Buf
, STAT_NAME_LEN
);
138 check(pp
, y
- 1, x
- 1);
139 check(pp
, y
- 1, x
);
140 check(pp
, y
- 1, x
+ 1);
141 check(pp
, y
, x
- 1);
143 check(pp
, y
, x
+ 1);
144 check(pp
, y
+ 1, x
- 1);
145 check(pp
, y
+ 1, x
);
146 check(pp
, y
+ 1, x
+ 1);
148 switch (pp
->p_face
) {
178 see(PLAYER
*pp
, int face
)
189 for (i
= 0; See_over
[(int)*--sp
]; i
++)
213 for (i
= 0; See_over
[(int)*sp
++]; i
++)
237 if (!See_over
[(int)*sp
])
241 sp
-= sizeof Maze
[0];
245 } while (See_over
[(int)*sp
]);
249 if (!See_over
[(int)*sp
])
253 sp
+= sizeof Maze
[0];
257 } while (See_over
[(int)*sp
]);
263 check(PLAYER
*pp
, int y
, int x
)
269 indx
= y
* sizeof Maze
[0] + x
;
270 ch
= ((char *) Maze
)[indx
];
271 if (ch
!= ((char *) pp
->p_maze
)[indx
]) {
274 if (x
== rpp
->p_x
&& y
== rpp
->p_y
)
275 outch(rpp
, translate(ch
));
276 else if (isplayer(ch
))
277 outch(rpp
, player_sym(rpp
, y
, x
));
280 ((char *) rpp
->p_maze
)[indx
] = ch
;
286 * Update the status of players
295 y
= STAT_PLAY_ROW
+ 1 + (pp
- Player
);
298 for (np
= Monitor
; np
< End_monitor
; np
++) {
299 cgoto(np
, y
, STAT_SCAN_COL
);
303 for (np
= Player
; np
< End_player
; np
++) {
304 cgoto(np
, y
, STAT_SCAN_COL
);
311 * Draw the player on the screen and show him to everyone who's scanning
312 * unless he is cloaked.
315 drawplayer(PLAYER
*pp
, FLAG draw
)
322 Maze
[y
][x
] = draw
? pp
->p_face
: pp
->p_over
;
325 for (newp
= Monitor
; newp
< End_monitor
; newp
++)
329 for (newp
= Player
; newp
< End_player
; newp
++) {
330 if (!draw
|| newp
== pp
) {
334 if (newp
->p_scan
== 0) {
338 else if (newp
->p_scan
> 0) {
344 if (!draw
|| pp
->p_cloak
< 0)
346 if (pp
->p_cloak
-- == 0)
351 message(PLAYER
*pp
, const char *s
)
353 cgoto(pp
, HEIGHT
, 0);
354 outstr(pp
, s
, strlen(s
));
360 * Turn a character into the right direction character if we are
361 * looking at the current player.
381 * Return the player symbol
384 player_sym(PLAYER
*pp
, int y
, int x
)
389 if (npp
->p_ident
->i_team
== ' ')
392 if (pp
->p_ident
->i_team
== '*')
393 return npp
->p_ident
->i_team
;
395 if (pp
->p_ident
->i_team
!= npp
->p_ident
->i_team
)
397 return pp
->p_ident
->i_team
;