Annotation of 43BSDReno/games/atc/graphics.c, revision 1.1.1.1

1.1       root        1: /*-
                      2:  * Copyright (c) 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Ed James.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted
                      9:  * provided that: (1) source distributions retain this entire copyright
                     10:  * notice and comment, and (2) distributions including binaries display
                     11:  * the following acknowledgement:  ``This product includes software
                     12:  * developed by the University of California, Berkeley and its contributors''
                     13:  * in the documentation or other materials provided with the distribution
                     14:  * and in all advertising materials mentioning features or use of this
                     15:  * software. Neither the name of the University nor the names of its
                     16:  * contributors may be used to endorse or promote products derived
                     17:  * from this software without specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     19:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     20:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: /*
                     24:  * Copyright (c) 1987 by Ed James, UC Berkeley.  All rights reserved.
                     25:  *
                     26:  * Copy permission is hereby granted provided that this notice is
                     27:  * retained on all partial or complete copies.
                     28:  *
                     29:  * For more info on this and all of my stuff, mail [email protected].
                     30:  */
                     31: 
                     32: #ifndef lint
                     33: static char sccsid[] = "@(#)graphics.c 5.2 (Berkeley) 4/30/90";
                     34: #endif /* not lint */
                     35: 
                     36: #include "include.h"
                     37: #ifdef SYSV
                     38: #include <errno.h>
                     39: #endif
                     40: 
                     41: #define C_TOPBOTTOM            '-'
                     42: #define C_LEFTRIGHT            '|'
                     43: #define C_AIRPORT              '='
                     44: #define C_LINE                 '+'
                     45: #define C_BACKROUND            '.'
                     46: #define C_BEACON               '*'
                     47: #define C_CREDIT               '*'
                     48: 
                     49: WINDOW *radar, *cleanradar, *credit, *input, *planes;
                     50: 
                     51: getAChar()
                     52: {
                     53: #ifdef BSD
                     54:        return (getchar());
                     55: #endif
                     56: #ifdef SYSV
                     57:        int c;
                     58: 
                     59:        while ((c = getchar()) == -1 && errno == EINTR) ;
                     60:        return(c);
                     61: #endif
                     62: }
                     63: 
                     64: erase_all()
                     65: {
                     66:        PLANE   *pp;
                     67: 
                     68:        for (pp = air.head; pp != NULL; pp = pp->next) {
                     69:                wmove(cleanradar, pp->ypos, pp->xpos * 2);
                     70:                wmove(radar, pp->ypos, pp->xpos * 2);
                     71:                waddch(radar, winch(cleanradar));
                     72:                wmove(cleanradar, pp->ypos, pp->xpos * 2 + 1);
                     73:                wmove(radar, pp->ypos, pp->xpos * 2 + 1);
                     74:                waddch(radar, winch(cleanradar));
                     75:        }
                     76: }
                     77: 
                     78: draw_all()
                     79: {
                     80:        PLANE   *pp;
                     81: 
                     82:        for (pp = air.head; pp != NULL; pp = pp->next) {
                     83:                if (pp->status == S_MARKED)
                     84:                        wstandout(radar);
                     85:                wmove(radar, pp->ypos, pp->xpos * 2);
                     86:                waddch(radar, name(pp));
                     87:                waddch(radar, '0' + pp->altitude);
                     88:                if (pp->status == S_MARKED)
                     89:                        wstandend(radar);
                     90:        }
                     91:        wrefresh(radar);
                     92:        planewin();
                     93:        wrefresh(input);                /* return cursor */
                     94:        fflush(stdout);
                     95: }
                     96: 
                     97: init_gr()
                     98: {
                     99:        static char     buffer[BUFSIZ];
                    100: 
                    101:        initscr();
                    102:        setbuf(stdout, buffer);
                    103:        input = newwin(INPUT_LINES, COLS - PLANE_COLS, LINES - INPUT_LINES, 0);
                    104:        credit = newwin(INPUT_LINES, PLANE_COLS, LINES - INPUT_LINES, 
                    105:                COLS - PLANE_COLS);
                    106:        planes = newwin(LINES - INPUT_LINES, PLANE_COLS, 0, COLS - PLANE_COLS);
                    107: }
                    108: 
                    109: setup_screen(scp)
                    110:        C_SCREEN        *scp;
                    111: {
                    112:        register int    i, j;
                    113:        char            str[3], *airstr;
                    114: 
                    115:        str[2] = '\0';
                    116: 
                    117:        if (radar != NULL)
                    118:                delwin(radar);
                    119:        radar = newwin(scp->height, scp->width * 2, 0, 0);
                    120: 
                    121:        if (cleanradar != NULL)
                    122:                delwin(cleanradar);
                    123:        cleanradar = newwin(scp->height, scp->width * 2, 0, 0);
                    124: 
                    125:        /* minus one here to prevent a scroll */
                    126:        for (i = 0; i < PLANE_COLS - 1; i++) {
                    127:                wmove(credit, 0, i);
                    128:                waddch(credit, C_CREDIT);
                    129:                wmove(credit, INPUT_LINES - 1, i);
                    130:                waddch(credit, C_CREDIT);
                    131:        }
                    132:        wmove(credit, INPUT_LINES / 2, 1);
                    133:        waddstr(credit, AUTHOR_STR);
                    134: 
                    135:        for (i = 1; i < scp->height - 1; i++) {
                    136:                for (j = 1; j < scp->width - 1; j++) {
                    137:                        wmove(radar, i, j * 2);
                    138:                        waddch(radar, C_BACKROUND);
                    139:                }
                    140:        }
                    141: 
                    142:        /*
                    143:         * Draw the lines first, since people like to draw lines
                    144:         * through beacons and exit points.
                    145:         */
                    146:        str[0] = C_LINE;
                    147:        for (i = 0; i < scp->num_lines; i++) {
                    148:                str[1] = ' ';
                    149:                draw_line(radar, scp->line[i].p1.x, scp->line[i].p1.y,
                    150:                        scp->line[i].p2.x, scp->line[i].p2.y, str);
                    151:        }
                    152: 
                    153:        str[0] = C_TOPBOTTOM;
                    154:        str[1] = C_TOPBOTTOM;
                    155:        wmove(radar, 0, 0);
                    156:        for (i = 0; i < scp->width - 1; i++)
                    157:                waddstr(radar, str);
                    158:        waddch(radar, C_TOPBOTTOM);
                    159: 
                    160:        str[0] = C_TOPBOTTOM;
                    161:        str[1] = C_TOPBOTTOM;
                    162:        wmove(radar, scp->height - 1, 0);
                    163:        for (i = 0; i < scp->width - 1; i++)
                    164:                waddstr(radar, str);
                    165:        waddch(radar, C_TOPBOTTOM);
                    166: 
                    167:        for (i = 1; i < scp->height - 1; i++) {
                    168:                wmove(radar, i, 0);
                    169:                waddch(radar, C_LEFTRIGHT);
                    170:                wmove(radar, i, (scp->width - 1) * 2);
                    171:                waddch(radar, C_LEFTRIGHT);
                    172:        }
                    173: 
                    174:        str[0] = C_BEACON;
                    175:        for (i = 0; i < scp->num_beacons; i++) {
                    176:                str[1] = '0' + i;
                    177:                wmove(radar, scp->beacon[i].y, scp->beacon[i].x * 2);
                    178:                waddstr(radar, str);
                    179:        }
                    180: 
                    181:        for (i = 0; i < scp->num_exits; i++) {
                    182:                wmove(radar, scp->exit[i].y, scp->exit[i].x * 2);
                    183:                waddch(radar, '0' + i);
                    184:        }
                    185: 
                    186:        airstr = "^?>?v?<?";
                    187:        for (i = 0; i < scp->num_airports; i++) {
                    188:                str[0] = airstr[scp->airport[i].dir];
                    189:                str[1] = '0' + i;
                    190:                wmove(radar, scp->airport[i].y, scp->airport[i].x * 2);
                    191:                waddstr(radar, str);
                    192:        }
                    193:        
                    194:        overwrite(radar, cleanradar);
                    195:        wrefresh(radar);
                    196:        wrefresh(credit);
                    197:        fflush(stdout);
                    198: }
                    199: 
                    200: draw_line(w, x, y, lx, ly, s)
                    201:        WINDOW  *w;
                    202:        char    *s;
                    203: {
                    204:        int     dx, dy;
                    205: 
                    206:        dx = SGN(lx - x);
                    207:        dy = SGN(ly - y);
                    208:        for (;;) {
                    209:                wmove(w, y, x * 2);
                    210:                waddstr(w, s);
                    211:                if (x == lx && y == ly)
                    212:                        break;
                    213:                x += dx;
                    214:                y += dy;
                    215:        }
                    216: }
                    217: 
                    218: ioclrtoeol(pos)
                    219: {
                    220:        wmove(input, 0, pos);
                    221:        wclrtoeol(input);
                    222:        wrefresh(input);
                    223:        fflush(stdout);
                    224: }
                    225: 
                    226: iomove(pos)
                    227: {
                    228:        wmove(input, 0, pos);
                    229:        wrefresh(input);
                    230:        fflush(stdout);
                    231: }
                    232: 
                    233: ioaddstr(pos, str)
                    234:        char    *str;
                    235: {
                    236:        wmove(input, 0, pos);
                    237:        waddstr(input, str);
                    238:        wrefresh(input);
                    239:        fflush(stdout);
                    240: }
                    241: 
                    242: ioclrtobot()
                    243: {
                    244:        wclrtobot(input);
                    245:        wrefresh(input);
                    246:        fflush(stdout);
                    247: }
                    248: 
                    249: ioerror(pos, len, str)
                    250:        char    *str;
                    251: {
                    252:        int     i;
                    253: 
                    254:        wmove(input, 1, pos);
                    255:        for (i = 0; i < len; i++)
                    256:                waddch(input, '^');
                    257:        wmove(input, 2, 0);
                    258:        waddstr(input, str);
                    259:        wrefresh(input);
                    260:        fflush(stdout);
                    261: }
                    262: 
                    263: quit()
                    264: {
                    265:        int                     c, y, x;
                    266: #ifdef BSD
                    267:        struct itimerval        itv;
                    268: #endif
                    269: 
                    270:        getyx(input, y, x);
                    271:        wmove(input, 2, 0);
                    272:        waddstr(input, "Really quit? (y/n) ");
                    273:        wclrtobot(input);
                    274:        wrefresh(input);
                    275:        fflush(stdout);
                    276: 
                    277:        c = getchar();
                    278:        if (c == EOF || c == 'y') {
                    279:                /* disable timer */
                    280: #ifdef BSD
                    281:                itv.it_value.tv_sec = 0;
                    282:                itv.it_value.tv_usec = 0;
                    283:                setitimer(ITIMER_REAL, &itv, NULL);
                    284: #endif
                    285: #ifdef SYSV
                    286:                alarm(0);
                    287: #endif
                    288:                fflush(stdout);
                    289:                clear();
                    290:                refresh();
                    291:                endwin();
                    292:                log_score(0);
                    293:                exit(0);
                    294:        }
                    295:        wmove(input, 2, 0);
                    296:        wclrtobot(input);
                    297:        wmove(input, y, x);
                    298:        wrefresh(input);
                    299:        fflush(stdout);
                    300:        return;
                    301: }
                    302: 
                    303: planewin()
                    304: {
                    305:        PLANE   *pp;
                    306:        char    *command();
                    307:        int     warning = 0;
                    308: 
                    309: #ifdef BSD
                    310:        wclear(planes);
                    311: #endif
                    312: 
                    313:        wmove(planes, 0,0);
                    314: 
                    315: #ifdef SYSV
                    316:        wclrtobot(planes);
                    317: #endif
                    318:        wprintw(planes, "Time: %-4d Safe: %d", clock, safe_planes);
                    319:        wmove(planes, 2, 0);
                    320: 
                    321:        waddstr(planes, "pl dt  comm");
                    322:        for (pp = air.head; pp != NULL; pp = pp->next) {
                    323:                if (waddch(planes, '\n') == ERR) {
                    324:                        warning++;
                    325:                        break;
                    326:                }
                    327:                waddstr(planes, command(pp));
                    328:        }
                    329:        waddch(planes, '\n');
                    330:        for (pp = ground.head; pp != NULL; pp = pp->next) {
                    331:                if (waddch(planes, '\n') == ERR) {
                    332:                        warning++;
                    333:                        break;
                    334:                }
                    335:                waddstr(planes, command(pp));
                    336:        }
                    337:        if (warning) {
                    338:                wmove(planes, LINES - INPUT_LINES - 1, 0);
                    339:                waddstr(planes, "---- more ----");
                    340:                wclrtoeol(planes);
                    341:        }
                    342:        wrefresh(planes);
                    343:        fflush(stdout);
                    344: }
                    345: 
                    346: loser(p, s)
                    347:        PLANE   *p;
                    348:        char    *s;
                    349: {
                    350:        int                     c;
                    351: #ifdef BSD
                    352:        struct itimerval        itv;
                    353: #endif
                    354: 
                    355:        /* disable timer */
                    356: #ifdef BSD
                    357:        itv.it_value.tv_sec = 0;
                    358:        itv.it_value.tv_usec = 0;
                    359:        setitimer(ITIMER_REAL, &itv, NULL);
                    360: #endif
                    361: #ifdef SYSV
                    362:        alarm(0);
                    363: #endif
                    364: 
                    365:        wmove(input, 0, 0);
                    366:        wclrtobot(input);
                    367:        wprintw(input, "Plane '%c' %s\n\nHit space for top players list...",
                    368:                name(p), s);
                    369:        wrefresh(input);
                    370:        fflush(stdout);
                    371:        while ((c = getchar()) != EOF && c != ' ')
                    372:                ;
                    373:        clear();        /* move to top of screen */
                    374:        refresh();
                    375:        endwin();
                    376:        log_score(0);
                    377:        exit(0);
                    378: }
                    379: 
                    380: redraw()
                    381: {
                    382:        clear();
                    383:        refresh();
                    384: 
                    385:        touchwin(radar);
                    386:        wrefresh(radar);
                    387:        touchwin(planes);
                    388:        wrefresh(planes);
                    389:        touchwin(credit);
                    390:        wrefresh(credit);
                    391: 
                    392:        /* refresh input last to get cursor in right place */
                    393:        touchwin(input);
                    394:        wrefresh(input);
                    395:        fflush(stdout);
                    396: }
                    397: 
                    398: 
                    399: done_screen()
                    400: {
                    401:        clear();
                    402:        refresh();
                    403:        endwin();         /* clean up curses */
                    404: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.