]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - atc/graphics.c
1 /* $NetBSD: graphics.c,v 1.20 2015/06/25 05:33:02 dholland 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.20 2015/06/25 05:33:02 dholland Exp $");
64 #define C_TOPBOTTOM '-'
65 #define C_LEFTRIGHT '|'
68 #define C_BACKROUND '.'
72 static void draw_line(WINDOW
*, int, int, int, int, const char *);
74 static WINDOW
*radar
, *cleanradar
, *credit
, *input
, *planes
;
82 while ((c
= getchar()) == EOF
&& errno
== EINTR
) {
94 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
95 (void)wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2);
96 (void)wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
97 (void)waddch(radar
, winch(cleanradar
));
98 (void)wmove(cleanradar
, pp
->ypos
, pp
->xpos
* 2 + 1);
99 (void)wmove(radar
, pp
->ypos
, pp
->xpos
* 2 + 1);
100 (void)waddch(radar
, winch(cleanradar
));
109 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
110 if (pp
->status
== S_MARKED
)
111 (void)wstandout(radar
);
112 (void)wmove(radar
, pp
->ypos
, pp
->xpos
* 2);
113 (void)waddch(radar
, name(pp
));
114 (void)waddch(radar
, '0' + pp
->altitude
);
115 if (pp
->status
== S_MARKED
)
116 (void)wstandend(radar
);
118 (void)wrefresh(radar
);
120 (void)wrefresh(input
); /* return cursor */
121 (void)fflush(stdout
);
127 static char buffer
[BUFSIZ
];
130 errx(0, "couldn't initialize screen");
131 setbuf(stdout
, buffer
);
132 input
= newwin(INPUT_LINES
, COLS
- PLANE_COLS
, LINES
- INPUT_LINES
, 0);
133 credit
= newwin(INPUT_LINES
, PLANE_COLS
, LINES
- INPUT_LINES
,
135 planes
= newwin(LINES
- INPUT_LINES
, PLANE_COLS
, 0, COLS
- PLANE_COLS
);
141 (void)clear(); /* move to top of screen */
143 (void)fflush(stdout
);
148 setup_screen(const C_SCREEN
*scp
)
159 radar
= newwin(scp
->height
, scp
->width
* 2, 0, 0);
161 if (cleanradar
!= NULL
)
162 (void)delwin(cleanradar
);
163 cleanradar
= newwin(scp
->height
, scp
->width
* 2, 0, 0);
165 /* minus one here to prevent a scroll */
166 for (i
= 0; i
< PLANE_COLS
- 1; i
++) {
167 (void)wmove(credit
, 0, i
);
168 (void)waddch(credit
, C_CREDIT
);
169 (void)wmove(credit
, INPUT_LINES
- 1, i
);
170 (void)waddch(credit
, C_CREDIT
);
172 (void)wmove(credit
, INPUT_LINES
/ 2, 1);
173 (void)waddstr(credit
, AUTHOR_STR
);
175 for (i
= 1; i
< scp
->height
- 1; i
++) {
176 for (j
= 1; j
< scp
->width
- 1; j
++) {
177 (void)wmove(radar
, i
, j
* 2);
178 (void)waddch(radar
, C_BACKROUND
);
183 * Draw the lines first, since people like to draw lines
184 * through beacons and exit points.
187 for (iu
= 0; iu
< scp
->num_lines
; iu
++) {
189 draw_line(radar
, scp
->line
[iu
].p1
.x
, scp
->line
[iu
].p1
.y
,
190 scp
->line
[iu
].p2
.x
, scp
->line
[iu
].p2
.y
, str
);
193 str
[0] = C_TOPBOTTOM
;
194 str
[1] = C_TOPBOTTOM
;
195 (void)wmove(radar
, 0, 0);
196 for (i
= 0; i
< scp
->width
- 1; i
++)
197 (void)waddstr(radar
, str
);
198 (void)waddch(radar
, C_TOPBOTTOM
);
200 str
[0] = C_TOPBOTTOM
;
201 str
[1] = C_TOPBOTTOM
;
202 (void)wmove(radar
, scp
->height
- 1, 0);
203 for (i
= 0; i
< scp
->width
- 1; i
++)
204 (void)waddstr(radar
, str
);
205 (void)waddch(radar
, C_TOPBOTTOM
);
207 for (i
= 1; i
< scp
->height
- 1; i
++) {
208 (void)wmove(radar
, i
, 0);
209 (void)waddch(radar
, C_LEFTRIGHT
);
210 (void)wmove(radar
, i
, (scp
->width
- 1) * 2);
211 (void)waddch(radar
, C_LEFTRIGHT
);
215 for (iu
= 0; iu
< scp
->num_beacons
; iu
++) {
217 (void)wmove(radar
, scp
->beacon
[iu
].y
, scp
->beacon
[iu
].x
* 2);
218 (void)waddstr(radar
, str
);
221 for (iu
= 0; iu
< scp
->num_exits
; iu
++) {
222 (void)wmove(radar
, scp
->exit
[iu
].y
, scp
->exit
[iu
].x
* 2);
223 (void)waddch(radar
, '0' + iu
);
227 for (iu
= 0; iu
< scp
->num_airports
; iu
++) {
228 str
[0] = airstr
[scp
->airport
[iu
].dir
];
230 (void)wmove(radar
, scp
->airport
[iu
].y
, scp
->airport
[iu
].x
* 2);
231 (void)waddstr(radar
, str
);
234 (void)overwrite(radar
, cleanradar
);
235 (void)wrefresh(radar
);
236 (void)wrefresh(credit
);
237 (void)fflush(stdout
);
241 draw_line(WINDOW
*w
, int x
, int y
, int lx
, int ly
, const char *s
)
248 (void)wmove(w
, y
, x
* 2);
250 if (x
== lx
&& y
== ly
)
260 (void)wmove(input
, 0, pos
);
261 (void)wclrtoeol(input
);
262 (void)wrefresh(input
);
263 (void)fflush(stdout
);
269 (void)wmove(input
, 0, pos
);
270 (void)wrefresh(input
);
271 (void)fflush(stdout
);
275 ioaddstr(int pos
, const char *str
)
277 (void)wmove(input
, 0, pos
);
278 (void)waddstr(input
, str
);
279 (void)wrefresh(input
);
280 (void)fflush(stdout
);
286 (void)wclrtobot(input
);
287 (void)wrefresh(input
);
288 (void)fflush(stdout
);
292 ioerror(int pos
, int len
, const char *str
)
296 (void)wmove(input
, 1, pos
);
297 for (i
= 0; i
< len
; i
++)
298 (void)waddch(input
, '^');
299 (void)wmove(input
, 2, 0);
300 (void)waddstr(input
, str
);
301 (void)wrefresh(input
);
302 (void)fflush(stdout
);
305 static int ioquit_x
, ioquit_y
;
310 getyx(input
, ioquit_y
, ioquit_x
);
311 (void)wmove(input
, 2, 0);
312 (void)waddstr(input
, "Really quit? (y/n) ");
313 (void)wclrtobot(input
);
314 (void)wrefresh(input
);
315 (void)fflush(stdout
);
321 (void)wmove(input
, 2, 0);
322 (void)wclrtobot(input
);
323 (void)wmove(input
, ioquit_y
, ioquit_x
);
324 (void)wrefresh(input
);
325 (void)fflush(stdout
);
335 (void)wclear(planes
);
338 (void)wmove(planes
, 0,0);
343 (void)wprintw(planes
, "Time: %-4d Safe: %d", clck
, safe_planes
);
344 (void)wmove(planes
, 2, 0);
346 (void)waddstr(planes
, "pl dt comm");
347 for (pp
= air
.head
; pp
!= NULL
; pp
= pp
->next
) {
348 if (waddch(planes
, '\n') == ERR
) {
352 (void)waddstr(planes
, command(pp
));
354 (void)waddch(planes
, '\n');
355 for (pp
= ground
.head
; pp
!= NULL
; pp
= pp
->next
) {
356 if (waddch(planes
, '\n') == ERR
) {
360 (void)waddstr(planes
, command(pp
));
363 (void)wmove(planes
, LINES
- INPUT_LINES
- 1, 0);
364 (void)waddstr(planes
, "---- more ----");
365 (void)wclrtoeol(planes
);
367 (void)wrefresh(planes
);
368 (void)fflush(stdout
);
372 losermsg(const PLANE
*p
, const char *msg
)
374 (void)wmove(input
, 0, 0);
375 (void)wclrtobot(input
);
376 /* p may be NULL if we ran out of memory */
378 (void)wprintw(input
, "%s\n\nHit space for top players list...",
381 (void)wprintw(input
, "Plane '%c' %s\n\n", name(p
), msg
);
382 (void)wprintw(input
, "Hit space for top players list...");
384 (void)wrefresh(input
);
385 (void)fflush(stdout
);
394 (void)touchwin(radar
);
395 (void)wrefresh(radar
);
396 (void)touchwin(planes
);
397 (void)wrefresh(planes
);
398 (void)touchwin(credit
);
399 (void)wrefresh(credit
);
401 /* refresh input last to get cursor in right place */
402 (void)touchwin(input
);
403 (void)wrefresh(input
);
404 (void)fflush(stdout
);
412 (void)endwin(); /* clean up curses */