]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - atc/graphics.c
1 /* $NetBSD: graphics.c,v 1.11 2005/07/01 00:48:34 jmc 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.11 2005/07/01 00:48:34 jmc 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 wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2);
85 wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
86 waddch(radar
, winch(cleanradar
));
87 wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2 + 1);
88 wmove(radar
, pp
->ypos
, pp
->xpos
* 2 + 1);
89 waddch(radar
, winch(cleanradar
));
98 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
99 if (pp
->status
== S_MARKED
)
101 wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
102 waddch(radar
, name(pp
));
103 waddch(radar
, '0' + pp
->altitude
);
104 if (pp
->status
== S_MARKED
)
109 wrefresh(input
); /* return cursor */
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
)
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
++) {
146 waddch(credit
, C_CREDIT
);
147 wmove(credit
, INPUT_LINES
- 1, i
);
148 waddch(credit
, C_CREDIT
);
150 wmove(credit
, INPUT_LINES
/ 2, 1);
151 waddstr(credit
, AUTHOR_STR
);
153 for (i
= 1; i
< scp
->height
- 1; i
++) {
154 for (j
= 1; j
< scp
->width
- 1; j
++) {
155 wmove(radar
, i
, j
* 2);
156 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
;
174 for (i
= 0; i
< scp
->width
- 1; i
++)
176 waddch(radar
, C_TOPBOTTOM
);
178 str
[0] = C_TOPBOTTOM
;
179 str
[1] = C_TOPBOTTOM
;
180 wmove(radar
, scp
->height
- 1, 0);
181 for (i
= 0; i
< scp
->width
- 1; i
++)
183 waddch(radar
, C_TOPBOTTOM
);
185 for (i
= 1; i
< scp
->height
- 1; i
++) {
187 waddch(radar
, C_LEFTRIGHT
);
188 wmove(radar
, i
, (scp
->width
- 1) * 2);
189 waddch(radar
, C_LEFTRIGHT
);
193 for (i
= 0; i
< scp
->num_beacons
; i
++) {
195 wmove(radar
, scp
->beacon
[i
].y
, scp
->beacon
[i
].x
* 2);
199 for (i
= 0; i
< scp
->num_exits
; i
++) {
200 wmove(radar
, scp
->exit
[i
].y
, scp
->exit
[i
].x
* 2);
201 waddch(radar
, '0' + i
);
205 for (i
= 0; i
< scp
->num_airports
; i
++) {
206 str
[0] = airstr
[scp
->airport
[i
].dir
];
208 wmove(radar
, scp
->airport
[i
].y
, scp
->airport
[i
].x
* 2);
212 overwrite(radar
, cleanradar
);
219 draw_line(WINDOW
*w
, int x
, int y
, int lx
, int ly
, const char *s
)
228 if (x
== lx
&& y
== ly
)
238 wmove(input
, 0, pos
);
247 wmove(input
, 0, pos
);
253 ioaddstr(int pos
, const char *str
)
255 wmove(input
, 0, pos
);
270 ioerror(int pos
, int len
, const char *str
)
274 wmove(input
, 1, pos
);
275 for (i
= 0; i
< len
; i
++)
284 quit(int dummy
__attribute__((__unused__
)))
288 struct itimerval itv
;
293 waddstr(input
, "Really quit? (y/n) ");
299 if (c
== EOF
|| c
== 'y') {
302 itv
.it_value
.tv_sec
= 0;
303 itv
.it_value
.tv_usec
= 0;
304 setitimer(ITIMER_REAL
, &itv
, NULL
);
338 wprintw(planes
, "Time: %-4d Safe: %d", clck
, safe_planes
);
341 waddstr(planes
, "pl dt comm");
342 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
343 if (waddch(planes
, '\n') == ERR
) {
347 waddstr(planes
, command(pp
));
349 waddch(planes
, '\n');
350 for (pp
= ground
.head
; pp
!= NULL
; pp
= pp
->next
) {
351 if (waddch(planes
, '\n') == ERR
) {
355 waddstr(planes
, command(pp
));
358 wmove(planes
, LINES
- INPUT_LINES
- 1, 0);
359 waddstr(planes
, "---- more ----");
367 loser(const PLANE
*p
, const char *s
)
371 struct itimerval itv
;
376 itv
.it_value
.tv_sec
= 0;
377 itv
.it_value
.tv_usec
= 0;
378 setitimer(ITIMER_REAL
, &itv
, NULL
);
386 /* p may be NULL if we ran out of memory */
388 wprintw(input
, "%s\n\nHit space for top players list...", s
);
390 wprintw(input
, "Plane '%c' %s\n\n", name(p
), s
);
391 wprintw(input
, "Hit space for top players list...");
394 while ((c
= getchar()) != EOF
&& c
!= ' ')
396 clear(); /* move to top of screen */
416 /* refresh input last to get cursor in right place */
427 endwin(); /* clean up curses */