2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)graphics.c 8.1 (Berkeley) 5/31/93
37 * $FreeBSD: src/games/atc/graphics.c,v 1.7 1999/11/30 03:48:19 billf Exp $
38 * $DragonFly: src/games/atc/graphics.c,v 1.3 2006/08/08 15:03:02 pavalos Exp $
42 * Copyright (c) 1987 by Ed James, UC Berkeley. All rights reserved.
44 * Copy permission is hereby granted provided that this notice is
45 * retained on all partial or complete copies.
47 * For more info on this and all of my stuff, mail edjames@berkeley.edu.
54 #define C_TOPBOTTOM '-'
55 #define C_LEFTRIGHT '|'
58 #define C_BACKROUND '.'
62 WINDOW *radar, *cleanradar, *credit, *input, *planes;
64 static void draw_line(WINDOW *, int, int, int, int, const char *);
73 while ((c = getchar()) == -1 && errno == EINTR) {
85 for (pp = air.head; pp != NULL; pp = pp->next) {
86 wmove(cleanradar, pp->ypos, pp->xpos * 2);
87 wmove(radar, pp->ypos, pp->xpos * 2);
88 waddch(radar, winch(cleanradar));
89 wmove(cleanradar, pp->ypos, pp->xpos * 2 + 1);
90 wmove(radar, pp->ypos, pp->xpos * 2 + 1);
91 waddch(radar, winch(cleanradar));
100 for (pp = air.head; pp != NULL; pp = pp->next) {
101 if (pp->status == S_MARKED)
103 wmove(radar, pp->ypos, pp->xpos * 2);
104 waddch(radar, name(pp));
105 waddch(radar, '0' + pp->altitude);
106 if (pp->status == S_MARKED)
111 wrefresh(input); /* return cursor */
118 static char buffer[BUFSIZ];
121 setbuf(stdout, buffer);
122 input = newwin(INPUT_LINES, COLS - PLANE_COLS, LINES - INPUT_LINES, 0);
123 credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES,
125 planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS);
129 setup_screen(const C_SCREEN *scp)
139 radar = newwin(scp->height, scp->width * 2, 0, 0);
141 if (cleanradar != NULL)
143 cleanradar = newwin(scp->height, scp->width * 2, 0, 0);
145 /* minus one here to prevent a scroll */
146 for (i = 0; i < PLANE_COLS - 1; i++) {
148 waddch(credit, C_CREDIT);
149 wmove(credit, INPUT_LINES - 1, i);
150 waddch(credit, C_CREDIT);
152 wmove(credit, INPUT_LINES / 2, 1);
153 waddstr(credit, AUTHOR_STR);
155 for (i = 1; i < scp->height - 1; i++) {
156 for (j = 1; j < scp->width - 1; j++) {
157 wmove(radar, i, j * 2);
158 waddch(radar, C_BACKROUND);
163 * Draw the lines first, since people like to draw lines
164 * through beacons and exit points.
167 for (i = 0; i < scp->num_lines; i++) {
169 draw_line(radar, scp->line[i].p1.x, scp->line[i].p1.y,
170 scp->line[i].p2.x, scp->line[i].p2.y, str);
173 str[0] = C_TOPBOTTOM;
174 str[1] = C_TOPBOTTOM;
176 for (i = 0; i < scp->width - 1; i++)
178 waddch(radar, C_TOPBOTTOM);
180 str[0] = C_TOPBOTTOM;
181 str[1] = C_TOPBOTTOM;
182 wmove(radar, scp->height - 1, 0);
183 for (i = 0; i < scp->width - 1; i++)
185 waddch(radar, C_TOPBOTTOM);
187 for (i = 1; i < scp->height - 1; i++) {
189 waddch(radar, C_LEFTRIGHT);
190 wmove(radar, i, (scp->width - 1) * 2);
191 waddch(radar, C_LEFTRIGHT);
195 for (i = 0; i < scp->num_beacons; i++) {
197 wmove(radar, scp->beacon[i].y, scp->beacon[i].x * 2);
201 for (i = 0; i < scp->num_exits; i++) {
202 wmove(radar, scp->exit[i].y, scp->exit[i].x * 2);
203 waddch(radar, '0' + i);
207 for (i = 0; i < scp->num_airports; i++) {
208 str[0] = airstr[scp->airport[i].dir];
210 wmove(radar, scp->airport[i].y, scp->airport[i].x * 2);
214 overwrite(radar, cleanradar);
221 draw_line(WINDOW *w, int x, int y, int lx, int ly, const char *s)
230 if (x == lx && y == ly)
240 wmove(input, 0, pos);
249 wmove(input, 0, pos);
255 ioaddstr(int pos, const char *str)
257 wmove(input, 0, pos);
272 ioerror(int pos, int len, const char *str)
276 wmove(input, 1, pos);
277 for (i = 0; i < len; i++)
289 struct itimerval itv;
293 waddstr(input, "Really quit? (y/n) ");
299 if (c == EOF || c == 'y') {
301 itv.it_value.tv_sec = 0;
302 itv.it_value.tv_usec = 0;
303 setitimer(ITIMER_REAL, &itv, NULL);
327 wprintw(planes, "Time: %-4d Safe: %d", clck, safe_planes);
329 waddstr(planes, "pl dt comm");
330 for (pp = air.head; pp != NULL; pp = pp->next) {
331 if (waddch(planes, '\n') == ERR) {
335 waddstr(planes, command(pp));
337 waddch(planes, '\n');
338 for (pp = ground.head; pp != NULL; pp = pp->next) {
339 if (waddch(planes, '\n') == ERR) {
343 waddstr(planes, command(pp));
346 wmove(planes, LINES - INPUT_LINES - 1, 0);
347 waddstr(planes, "---- more ----");
355 loser(const PLANE *p, const char *s)
358 struct itimerval itv;
361 itv.it_value.tv_sec = 0;
362 itv.it_value.tv_usec = 0;
363 setitimer(ITIMER_REAL, &itv, NULL);
367 wprintw(input, "Plane '%c' %s\n\nHit space for top players list...",
371 while ((c = getchar()) != EOF && c != ' ')
373 clear(); /* move to top of screen */
393 /* refresh input last to get cursor in right place */
404 endwin(); /* clean up curses */