]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - atc/graphics.c
1 /* $NetBSD: graphics.c,v 1.13 2006/06/07 09:22:52 jnemeth Exp $ */
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
38 * Copy permission is hereby granted provided that this notice is
39 * retained on all partial or complete copies.
41 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
44 #include <sys/cdefs.h>
47 static char sccsid
[] = "@(#)graphics.c 8.1 (Berkeley) 5/31/93";
49 __RCSID("$NetBSD: graphics.c,v 1.13 2006/06/07 09:22:52 jnemeth Exp $");
55 #define C_TOPBOTTOM '-'
56 #define C_LEFTRIGHT '|'
59 #define C_BACKROUND '.'
63 WINDOW
*radar
, *cleanradar
, *credit
, *input
, *planes
;
71 while ((c
= getchar()) == EOF
&& errno
== EINTR
) {
83 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
84 (void)wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2);
85 (void)wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
86 (void)waddch(radar
, winch(cleanradar
));
87 (void)wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2 + 1);
88 (void)wmove(radar
, pp
->ypos
, pp
->xpos
* 2 + 1);
89 (void)waddch(radar
, winch(cleanradar
));
98 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
99 if (pp
->status
== S_MARKED
)
100 (void)wstandout(radar
);
101 (void)wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
102 (void)waddch(radar
, name(pp
));
103 (void)waddch(radar
, '0' + pp
->altitude
);
104 if (pp
->status
== S_MARKED
)
105 (void)wstandend(radar
);
107 (void)wrefresh(radar
);
109 (void)wrefresh(input
); /* return cursor */
110 (void)fflush(stdout
);
116 static char buffer
[BUFSIZ
];
119 setbuf(stdout
, buffer
);
120 input
= newwin(INPUT_LINES
, COLS
- PLANE_COLS
, LINES
- INPUT_LINES
, 0);
121 credit
= newwin(INPUT_LINES
, PLANE_COLS
, LINES
- INPUT_LINES
,
123 planes
= newwin(LINES
- INPUT_LINES
, PLANE_COLS
, 0, COLS
- PLANE_COLS
);
127 setup_screen(const C_SCREEN
*scp
)
137 radar
= newwin(scp
->height
, scp
->width
* 2, 0, 0);
139 if (cleanradar
!= NULL
)
140 (void)delwin(cleanradar
);
141 cleanradar
= newwin(scp
->height
, scp
->width
* 2, 0, 0);
143 /* minus one here to prevent a scroll */
144 for (i
= 0; i
< PLANE_COLS
- 1; i
++) {
145 (void)wmove(credit
, 0, i
);
146 (void)waddch(credit
, C_CREDIT
);
147 (void)wmove(credit
, INPUT_LINES
- 1, i
);
148 (void)waddch(credit
, C_CREDIT
);
150 (void)wmove(credit
, INPUT_LINES
/ 2, 1);
151 (void)waddstr(credit
, AUTHOR_STR
);
153 for (i
= 1; i
< scp
->height
- 1; i
++) {
154 for (j
= 1; j
< scp
->width
- 1; j
++) {
155 (void)wmove(radar
, i
, j
* 2);
156 (void)waddch(radar
, C_BACKROUND
);
161 * Draw the lines first, since people like to draw lines
162 * through beacons and exit points.
165 for (i
= 0; i
< scp
->num_lines
; i
++) {
167 draw_line(radar
, scp
->line
[i
].p1
.x
, scp
->line
[i
].p1
.y
,
168 scp
->line
[i
].p2
.x
, scp
->line
[i
].p2
.y
, str
);
171 str
[0] = C_TOPBOTTOM
;
172 str
[1] = C_TOPBOTTOM
;
173 (void)wmove(radar
, 0, 0);
174 for (i
= 0; i
< scp
->width
- 1; i
++)
175 (void)waddstr(radar
, str
);
176 (void)waddch(radar
, C_TOPBOTTOM
);
178 str
[0] = C_TOPBOTTOM
;
179 str
[1] = C_TOPBOTTOM
;
180 (void)wmove(radar
, scp
->height
- 1, 0);
181 for (i
= 0; i
< scp
->width
- 1; i
++)
182 (void)waddstr(radar
, str
);
183 (void)waddch(radar
, C_TOPBOTTOM
);
185 for (i
= 1; i
< scp
->height
- 1; i
++) {
186 (void)wmove(radar
, i
, 0);
187 (void)waddch(radar
, C_LEFTRIGHT
);
188 (void)wmove(radar
, i
, (scp
->width
- 1) * 2);
189 (void)waddch(radar
, C_LEFTRIGHT
);
193 for (i
= 0; i
< scp
->num_beacons
; i
++) {
195 (void)wmove(radar
, scp
->beacon
[i
].y
, scp
->beacon
[i
].x
* 2);
196 (void)waddstr(radar
, str
);
199 for (i
= 0; i
< scp
->num_exits
; i
++) {
200 (void)wmove(radar
, scp
->exit
[i
].y
, scp
->exit
[i
].x
* 2);
201 (void)waddch(radar
, '0' + i
);
205 for (i
= 0; i
< scp
->num_airports
; i
++) {
206 str
[0] = airstr
[scp
->airport
[i
].dir
];
208 (void)wmove(radar
, scp
->airport
[i
].y
, scp
->airport
[i
].x
* 2);
209 (void)waddstr(radar
, str
);
212 (void)overwrite(radar
, cleanradar
);
213 (void)wrefresh(radar
);
214 (void)wrefresh(credit
);
215 (void)fflush(stdout
);
219 draw_line(WINDOW
*w
, int x
, int y
, int lx
, int ly
, const char *s
)
226 (void)wmove(w
, y
, x
* 2);
228 if (x
== lx
&& y
== ly
)
238 (void)wmove(input
, 0, pos
);
239 (void)wclrtoeol(input
);
240 (void)wrefresh(input
);
241 (void)fflush(stdout
);
247 (void)wmove(input
, 0, pos
);
248 (void)wrefresh(input
);
249 (void)fflush(stdout
);
253 ioaddstr(int pos
, const char *str
)
255 (void)wmove(input
, 0, pos
);
256 (void)waddstr(input
, str
);
257 (void)wrefresh(input
);
258 (void)fflush(stdout
);
264 (void)wclrtobot(input
);
265 (void)wrefresh(input
);
266 (void)fflush(stdout
);
270 ioerror(int pos
, int len
, const char *str
)
274 (void)wmove(input
, 1, pos
);
275 for (i
= 0; i
< len
; i
++)
276 (void)waddch(input
, '^');
277 (void)wmove(input
, 2, 0);
278 (void)waddstr(input
, str
);
279 (void)wrefresh(input
);
280 (void)fflush(stdout
);
285 quit(int dummy
__attribute__((__unused__
)))
289 struct itimerval itv
;
293 (void)wmove(input
, 2, 0);
294 (void)waddstr(input
, "Really quit? (y/n) ");
295 (void)wclrtobot(input
);
296 (void)wrefresh(input
);
297 (void)fflush(stdout
);
300 if (c
== EOF
|| c
== 'y') {
303 itv
.it_value
.tv_sec
= 0;
304 itv
.it_value
.tv_usec
= 0;
305 (void)setitimer(ITIMER_REAL
, &itv
, NULL
);
310 (void)fflush(stdout
);
317 (void)wmove(input
, 2, 0);
318 (void)wclrtobot(input
);
319 (void)wmove(input
, y
, x
);
320 (void)wrefresh(input
);
321 (void)fflush(stdout
);
331 (void)wclear(planes
);
334 (void)wmove(planes
, 0,0);
339 (void)wprintw(planes
, "Time: %-4d Safe: %d", clck
, safe_planes
);
340 (void)wmove(planes
, 2, 0);
342 (void)waddstr(planes
, "pl dt comm");
343 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
344 if (waddch(planes
, '\n') == ERR
) {
348 (void)waddstr(planes
, command(pp
));
350 (void)waddch(planes
, '\n');
351 for (pp
= ground
.head
; pp
!= NULL
; pp
= pp
->next
) {
352 if (waddch(planes
, '\n') == ERR
) {
356 (void)waddstr(planes
, command(pp
));
359 (void)wmove(planes
, LINES
- INPUT_LINES
- 1, 0);
360 (void)waddstr(planes
, "---- more ----");
361 (void)wclrtoeol(planes
);
363 (void)wrefresh(planes
);
364 (void)fflush(stdout
);
368 loser(const PLANE
*p
, const char *s
)
372 struct itimerval itv
;
377 itv
.it_value
.tv_sec
= 0;
378 itv
.it_value
.tv_usec
= 0;
379 (void)setitimer(ITIMER_REAL
, &itv
, NULL
);
385 (void)wmove(input
, 0, 0);
386 (void)wclrtobot(input
);
387 /* p may be NULL if we ran out of memory */
389 (void)wprintw(input
, "%s\n\nHit space for top players list...",
392 (void)wprintw(input
, "Plane '%c' %s\n\n", name(p
), s
);
393 (void)wprintw(input
, "Hit space for top players list...");
395 (void)wrefresh(input
);
396 (void)fflush(stdout
);
397 while ((c
= getchar()) != EOF
&& c
!= ' ')
399 (void)clear(); /* move to top of screen */
412 (void)touchwin(radar
);
413 (void)wrefresh(radar
);
414 (void)touchwin(planes
);
415 (void)wrefresh(planes
);
416 (void)touchwin(credit
);
417 (void)wrefresh(credit
);
419 /* refresh input last to get cursor in right place */
420 (void)touchwin(input
);
421 (void)wrefresh(input
);
422 (void)fflush(stdout
);
430 (void)endwin(); /* clean up curses */