Annotation of 43BSDTahoe/games/atc/graphics.c, revision 1.1

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

unix.superglobalmegacorp.com

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