]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - atc/graphics.c
1 /* $NetBSD: graphics.c,v 1.4 1997/10/10 02:07:11 lukem 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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
42 * Copy permission is hereby granted provided that this notice is
43 * retained on all partial or complete copies.
45 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
48 #include <sys/cdefs.h>
51 static char sccsid
[] = "@(#)graphics.c 8.1 (Berkeley) 5/31/93";
53 __RCSID("$NetBSD: graphics.c,v 1.4 1997/10/10 02:07:11 lukem Exp $");
59 #define C_TOPBOTTOM '-'
60 #define C_LEFTRIGHT '|'
63 #define C_BACKROUND '.'
67 WINDOW
*radar
, *cleanradar
, *credit
, *input
, *planes
;
78 while ((c
= getchar()) == -1 && errno
== EINTR
) ;
88 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
89 wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2);
90 wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
91 waddch(radar
, winch(cleanradar
));
92 wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2 + 1);
93 wmove(radar
, pp
->ypos
, pp
->xpos
* 2 + 1);
94 waddch(radar
, winch(cleanradar
));
103 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
104 if (pp
->status
== S_MARKED
)
106 wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
107 waddch(radar
, name(pp
));
108 waddch(radar
, '0' + pp
->altitude
);
109 if (pp
->status
== S_MARKED
)
114 wrefresh(input
); /* return cursor */
121 static char buffer
[BUFSIZ
];
124 setbuf(stdout
, buffer
);
125 input
= newwin(INPUT_LINES
, COLS
- PLANE_COLS
, LINES
- INPUT_LINES
, 0);
126 credit
= newwin(INPUT_LINES
, PLANE_COLS
, LINES
- INPUT_LINES
,
128 planes
= newwin(LINES
- INPUT_LINES
, PLANE_COLS
, 0, COLS
- PLANE_COLS
);
136 char str
[3], *airstr
;
142 radar
= newwin(scp
->height
, scp
->width
* 2, 0, 0);
144 if (cleanradar
!= NULL
)
146 cleanradar
= newwin(scp
->height
, scp
->width
* 2, 0, 0);
148 /* minus one here to prevent a scroll */
149 for (i
= 0; i
< PLANE_COLS
- 1; i
++) {
151 waddch(credit
, C_CREDIT
);
152 wmove(credit
, INPUT_LINES
- 1, i
);
153 waddch(credit
, C_CREDIT
);
155 wmove(credit
, INPUT_LINES
/ 2, 1);
156 waddstr(credit
, AUTHOR_STR
);
158 for (i
= 1; i
< scp
->height
- 1; i
++) {
159 for (j
= 1; j
< scp
->width
- 1; j
++) {
160 wmove(radar
, i
, j
* 2);
161 waddch(radar
, C_BACKROUND
);
166 * Draw the lines first, since people like to draw lines
167 * through beacons and exit points.
170 for (i
= 0; i
< scp
->num_lines
; i
++) {
172 draw_line(radar
, scp
->line
[i
].p1
.x
, scp
->line
[i
].p1
.y
,
173 scp
->line
[i
].p2
.x
, scp
->line
[i
].p2
.y
, str
);
176 str
[0] = C_TOPBOTTOM
;
177 str
[1] = C_TOPBOTTOM
;
179 for (i
= 0; i
< scp
->width
- 1; i
++)
181 waddch(radar
, C_TOPBOTTOM
);
183 str
[0] = C_TOPBOTTOM
;
184 str
[1] = C_TOPBOTTOM
;
185 wmove(radar
, scp
->height
- 1, 0);
186 for (i
= 0; i
< scp
->width
- 1; i
++)
188 waddch(radar
, C_TOPBOTTOM
);
190 for (i
= 1; i
< scp
->height
- 1; i
++) {
192 waddch(radar
, C_LEFTRIGHT
);
193 wmove(radar
, i
, (scp
->width
- 1) * 2);
194 waddch(radar
, C_LEFTRIGHT
);
198 for (i
= 0; i
< scp
->num_beacons
; i
++) {
200 wmove(radar
, scp
->beacon
[i
].y
, scp
->beacon
[i
].x
* 2);
204 for (i
= 0; i
< scp
->num_exits
; i
++) {
205 wmove(radar
, scp
->exit
[i
].y
, scp
->exit
[i
].x
* 2);
206 waddch(radar
, '0' + i
);
210 for (i
= 0; i
< scp
->num_airports
; i
++) {
211 str
[0] = airstr
[scp
->airport
[i
].dir
];
213 wmove(radar
, scp
->airport
[i
].y
, scp
->airport
[i
].x
* 2);
217 overwrite(radar
, cleanradar
);
224 draw_line(w
, x
, y
, lx
, ly
, s
)
236 if (x
== lx
&& y
== ly
)
247 wmove(input
, 0, pos
);
257 wmove(input
, 0, pos
);
267 wmove(input
, 0, pos
);
282 ioerror(pos
, len
, str
)
288 wmove(input
, 1, pos
);
289 for (i
= 0; i
< len
; i
++)
303 struct itimerval itv
;
308 waddstr(input
, "Really quit? (y/n) ");
314 if (c
== EOF
|| c
== 'y') {
317 itv
.it_value
.tv_sec
= 0;
318 itv
.it_value
.tv_usec
= 0;
319 setitimer(ITIMER_REAL
, &itv
, NULL
);
353 wprintw(planes
, "Time: %-4d Safe: %d", clck
, safe_planes
);
356 waddstr(planes
, "pl dt comm");
357 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
358 if (waddch(planes
, '\n') == ERR
) {
362 waddstr(planes
, command(pp
));
364 waddch(planes
, '\n');
365 for (pp
= ground
.head
; pp
!= NULL
; pp
= pp
->next
) {
366 if (waddch(planes
, '\n') == ERR
) {
370 waddstr(planes
, command(pp
));
373 wmove(planes
, LINES
- INPUT_LINES
- 1, 0);
374 waddstr(planes
, "---- more ----");
388 struct itimerval itv
;
393 itv
.it_value
.tv_sec
= 0;
394 itv
.it_value
.tv_usec
= 0;
395 setitimer(ITIMER_REAL
, &itv
, NULL
);
403 wprintw(input
, "Plane '%c' %s\n\nHit space for top players list...",
407 while ((c
= getchar()) != EOF
&& c
!= ' ')
409 clear(); /* move to top of screen */
429 /* refresh input last to get cursor in right place */
440 endwin(); /* clean up curses */