Annotation of 43BSDReno/games/sail/pl_7.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1983 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)pl_7.c     5.6 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include "player.h"
        !            25: 
        !            26: /*
        !            27:  * Display interface
        !            28:  */
        !            29: 
        !            30: static char sc_hasprompt;
        !            31: static char *sc_prompt;
        !            32: static char *sc_buf;
        !            33: static int sc_line;
        !            34: 
        !            35: initscreen()
        !            36: {
        !            37:        /* initscr() already done in SCREENTEST() */
        !            38:        view_w = newwin(VIEW_Y, VIEW_X, VIEW_T, VIEW_L);
        !            39:        slot_w = newwin(SLOT_Y, SLOT_X, SLOT_T, SLOT_L);
        !            40:        scroll_w = newwin(SCROLL_Y, SCROLL_X, SCROLL_T, SCROLL_L);
        !            41:        stat_w = newwin(STAT_Y, STAT_X, STAT_T, STAT_L);
        !            42:        turn_w = newwin(TURN_Y, TURN_X, TURN_T, TURN_L);
        !            43:        done_curses++;
        !            44:        (void) leaveok(view_w, 1);
        !            45:        (void) leaveok(slot_w, 1);
        !            46:        (void) leaveok(stat_w, 1);
        !            47:        (void) leaveok(turn_w, 1);
        !            48: #ifdef SIGTSTP
        !            49:        {
        !            50:                int susp();
        !            51:                (void) signal(SIGTSTP, susp);
        !            52:        }
        !            53: #endif
        !            54:        noecho();
        !            55:        crmode();
        !            56: }
        !            57: 
        !            58: cleanupscreen()
        !            59: {
        !            60:        /* alarm already turned off */
        !            61:        if (done_curses) {
        !            62:                (void) wmove(scroll_w, SCROLL_Y - 1, 0);
        !            63:                (void) wclrtoeol(scroll_w);
        !            64:                draw_screen();
        !            65:                endwin();
        !            66:        }
        !            67: }
        !            68: 
        !            69: newturn()
        !            70: {
        !            71:        repaired = loaded = fired = changed = 0;
        !            72:        movebuf[0] = '\0';
        !            73: 
        !            74:        (void) alarm(0);
        !            75:        if (mf->readyL & R_LOADING)
        !            76:                if (mf->readyL & R_DOUBLE)
        !            77:                        mf->readyL = R_LOADING;
        !            78:                else
        !            79:                        mf->readyL = R_LOADED;
        !            80:        if (mf->readyR & R_LOADING)
        !            81:                if (mf->readyR & R_DOUBLE)
        !            82:                        mf->readyR = R_LOADING;
        !            83:                else
        !            84:                        mf->readyR = R_LOADED;
        !            85:        if (!hasdriver)
        !            86:                Write(W_DDEAD, SHIP(0), 0, 0, 0, 0, 0);
        !            87: 
        !            88:        if (sc_hasprompt) {
        !            89:                (void) wmove(scroll_w, sc_line, 0);
        !            90:                (void) wclrtoeol(scroll_w);
        !            91:        }
        !            92:        if (Sync() < 0)
        !            93:                leave(LEAVE_SYNC);
        !            94:        if (!hasdriver)
        !            95:                leave(LEAVE_DRIVER);
        !            96:        if (sc_hasprompt)
        !            97:                (void) wprintw(scroll_w, "%s%s", sc_prompt, sc_buf);
        !            98: 
        !            99:        if (turn % 50 == 0)
        !           100:                Write(W_ALIVE, SHIP(0), 0, 0, 0, 0, 0);
        !           101:        if (mf->FS && (!mc->rig1 || windspeed == 6))
        !           102:                Write(W_FS, ms, 0, 0, 0, 0, 0);
        !           103:        if (mf->FS == 1)
        !           104:                Write(W_FS, ms, 0, 2, 0, 0, 0);
        !           105: 
        !           106:        if (mf->struck)
        !           107:                leave(LEAVE_QUIT);
        !           108:        if (mf->captured != 0)
        !           109:                leave(LEAVE_CAPTURED);
        !           110:        if (windspeed == 7)
        !           111:                leave(LEAVE_HURRICAN);
        !           112: 
        !           113:        adjustview();
        !           114:        draw_screen();
        !           115: 
        !           116:        (void) signal(SIGALRM, newturn);
        !           117:        (void) alarm(7);
        !           118: }
        !           119: 
        !           120: /*VARARGS2*/
        !           121: Signal(fmt, ship, a, b, c, d)
        !           122: char *fmt;
        !           123: register struct ship *ship;
        !           124: int a, b, c, d;
        !           125: {
        !           126:        if (!done_curses)
        !           127:                return;
        !           128:        if (*fmt == '\7')
        !           129:                putchar(*fmt++);
        !           130:        if (ship == 0)
        !           131:                (void) wprintw(scroll_w, fmt, a, b, c, d);
        !           132:        else
        !           133:                (void) wprintw(scroll_w, fmt, ship->shipname,
        !           134:                        colours(ship), sterncolour(ship), a, b, c, d);
        !           135:        Scroll();
        !           136: }
        !           137: 
        !           138: Scroll()
        !           139: {
        !           140:        if (++sc_line >= SCROLL_Y)
        !           141:                sc_line = 0;
        !           142:        (void) wmove(scroll_w, sc_line, 0);
        !           143:        (void) wclrtoeol(scroll_w);
        !           144: }
        !           145: 
        !           146: prompt(p, ship)
        !           147: register char *p;
        !           148: struct ship *ship;
        !           149: {
        !           150:        static char buf[60];
        !           151: 
        !           152:        if (ship != 0) {
        !           153:                (void)sprintf(buf, p, ship->shipname, colours(ship),
        !           154:                        sterncolour(ship));
        !           155:                p = buf;
        !           156:        }
        !           157:        sc_prompt = p;
        !           158:        sc_buf = "";
        !           159:        sc_hasprompt = 1;
        !           160:        (void) waddstr(scroll_w, p);
        !           161: }
        !           162: 
        !           163: endprompt(flag)
        !           164: char flag;
        !           165: {
        !           166:        sc_hasprompt = 0;
        !           167:        if (flag)
        !           168:                Scroll();
        !           169: }
        !           170: 
        !           171: sgetch(p, ship, flag)
        !           172: char *p;
        !           173: struct ship *ship;
        !           174: char flag;
        !           175: {
        !           176:        register c;
        !           177: 
        !           178:        prompt(p, ship);
        !           179:        blockalarm();
        !           180:        (void) wrefresh(scroll_w);
        !           181:        unblockalarm();
        !           182:        while ((c = wgetch(scroll_w)) == EOF)
        !           183:                ;
        !           184:        if (flag && c >= ' ' && c < 0x7f)
        !           185:                (void) waddch(scroll_w, c);
        !           186:        endprompt(flag);
        !           187:        return c;
        !           188: }
        !           189: 
        !           190: sgetstr(pr, buf, n)
        !           191: char *pr;
        !           192: register char *buf;
        !           193: register n;
        !           194: {
        !           195:        register c;
        !           196:        register char *p = buf;
        !           197: 
        !           198:        prompt(pr, (struct ship *)0);
        !           199:        sc_buf = buf;
        !           200:        for (;;) {
        !           201:                *p = 0;
        !           202:                blockalarm();
        !           203:                (void) wrefresh(scroll_w);
        !           204:                unblockalarm();
        !           205:                while ((c = wgetch(scroll_w)) == EOF)
        !           206:                        ;
        !           207:                switch (c) {
        !           208:                case '\n':
        !           209:                case '\r':
        !           210:                        endprompt(1);
        !           211:                        return;
        !           212:                case '\b':
        !           213:                        if (p > buf) {
        !           214:                                (void) waddstr(scroll_w, "\b \b");
        !           215:                                p--;
        !           216:                        }
        !           217:                        break;
        !           218:                default:
        !           219:                        if (c >= ' ' && c < 0x7f && p < buf + n - 1) {
        !           220:                                *p++ = c;
        !           221:                                (void) waddch(scroll_w, c);
        !           222:                        } else
        !           223:                                (void) putchar(CTRL('g'));
        !           224:                }
        !           225:        }
        !           226: }
        !           227: 
        !           228: draw_screen()
        !           229: {
        !           230:        draw_view();
        !           231:        draw_turn();
        !           232:        draw_stat();
        !           233:        draw_slot();
        !           234:        (void) wrefresh(scroll_w);              /* move the cursor */
        !           235: }
        !           236: 
        !           237: draw_view()
        !           238: {
        !           239:        register struct ship *sp;
        !           240: 
        !           241:        (void) werase(view_w);
        !           242:        foreachship(sp) {
        !           243:                if (sp->file->dir
        !           244:                    && sp->file->row > viewrow
        !           245:                    && sp->file->row < viewrow + VIEW_Y
        !           246:                    && sp->file->col > viewcol
        !           247:                    && sp->file->col < viewcol + VIEW_X) {
        !           248:                        (void) wmove(view_w, sp->file->row - viewrow,
        !           249:                                sp->file->col - viewcol);
        !           250:                        (void) waddch(view_w, colours(sp));
        !           251:                        (void) wmove(view_w,
        !           252:                                sternrow(sp) - viewrow,
        !           253:                                sterncol(sp) - viewcol);
        !           254:                        (void) waddch(view_w, sterncolour(sp));
        !           255:                }
        !           256:        }
        !           257:        (void) wrefresh(view_w);
        !           258: }
        !           259: 
        !           260: draw_turn()
        !           261: {
        !           262:        (void) wmove(turn_w, 0, 0);
        !           263:        (void) wprintw(turn_w, "%cTurn %d", dont_adjust?'*':'-', turn);
        !           264:        (void) wrefresh(turn_w);
        !           265: }
        !           266: 
        !           267: draw_stat()
        !           268: {
        !           269:        (void) wmove(stat_w, STAT_1, 0);
        !           270:        (void) wprintw(stat_w, "Points  %3d\n", mf->points);
        !           271:        (void) wprintw(stat_w, "Fouls    %2d\n", fouled(ms));
        !           272:        (void) wprintw(stat_w, "Grapples %2d\n", grappled(ms));
        !           273: 
        !           274:        (void) wmove(stat_w, STAT_2, 0);
        !           275:        (void) wprintw(stat_w, "    0 %c(%c)\n",
        !           276:                maxmove(ms, winddir + 3, -1) + '0',
        !           277:                maxmove(ms, winddir + 3, 1) + '0');
        !           278:        (void) waddstr(stat_w, "   \\|/\n");
        !           279:        (void) wprintw(stat_w, "   -^-%c(%c)\n",
        !           280:                maxmove(ms, winddir + 2, -1) + '0',
        !           281:                maxmove(ms, winddir + 2, 1) + '0');
        !           282:        (void) waddstr(stat_w, "   /|\\\n");
        !           283:        (void) wprintw(stat_w, "    | %c(%c)\n",
        !           284:                maxmove(ms, winddir + 1, -1) + '0',
        !           285:                maxmove(ms, winddir + 1, 1) + '0');
        !           286:        (void) wprintw(stat_w, "   %c(%c)\n",
        !           287:                maxmove(ms, winddir, -1) + '0',
        !           288:                maxmove(ms, winddir, 1) + '0');
        !           289: 
        !           290:        (void) wmove(stat_w, STAT_3, 0);
        !           291:        (void) wprintw(stat_w, "Load  %c%c %c%c\n",
        !           292:                loadname[mf->loadL], readyname(mf->readyL),
        !           293:                loadname[mf->loadR], readyname(mf->readyR));
        !           294:        (void) wprintw(stat_w, "Hull %2d\n", mc->hull);
        !           295:        (void) wprintw(stat_w, "Crew %2d %2d %2d\n",
        !           296:                mc->crew1, mc->crew2, mc->crew3);
        !           297:        (void) wprintw(stat_w, "Guns %2d %2d\n", mc->gunL, mc->gunR);
        !           298:        (void) wprintw(stat_w, "Carr %2d %2d\n", mc->carL, mc->carR);
        !           299:        (void) wprintw(stat_w, "Rigg %d %d %d ", mc->rig1, mc->rig2, mc->rig3);
        !           300:        if (mc->rig4 < 0)
        !           301:                (void) waddch(stat_w, '-');
        !           302:        else
        !           303:                (void) wprintw(stat_w, "%d", mc->rig4);
        !           304:        (void) wrefresh(stat_w);
        !           305: }
        !           306: 
        !           307: draw_slot()
        !           308: {
        !           309:        if (!boarding(ms, 0)) {
        !           310:                (void) mvwaddstr(slot_w, 0, 0, "   ");
        !           311:                (void) mvwaddstr(slot_w, 1, 0, "   ");
        !           312:        } else
        !           313:                (void) mvwaddstr(slot_w, 1, 0, "OBP");
        !           314:        if (!boarding(ms, 1)) {
        !           315:                (void) mvwaddstr(slot_w, 2, 0, "   ");
        !           316:                (void) mvwaddstr(slot_w, 3, 0, "   ");
        !           317:        } else
        !           318:                (void) mvwaddstr(slot_w, 3, 0, "DBP");
        !           319: 
        !           320:        (void) wmove(slot_w, SLOT_Y-4, 0);
        !           321:        if (mf->RH)
        !           322:                (void) wprintw(slot_w, "%dRH", mf->RH);
        !           323:        else
        !           324:                (void) waddstr(slot_w, "   ");
        !           325:        (void) wmove(slot_w, SLOT_Y-3, 0);
        !           326:        if (mf->RG)
        !           327:                (void) wprintw(slot_w, "%dRG", mf->RG);
        !           328:        else
        !           329:                (void) waddstr(slot_w, "   ");
        !           330:        (void) wmove(slot_w, SLOT_Y-2, 0);
        !           331:        if (mf->RR)
        !           332:                (void) wprintw(slot_w, "%dRR", mf->RR);
        !           333:        else
        !           334:                (void) waddstr(slot_w, "   ");
        !           335: 
        !           336: #define Y      (SLOT_Y/2)
        !           337:        (void) wmove(slot_w, 7, 1);
        !           338:        (void) wprintw(slot_w,"%d", windspeed);
        !           339:        (void) mvwaddch(slot_w, Y, 0, ' ');
        !           340:        (void) mvwaddch(slot_w, Y, 2, ' ');
        !           341:        (void) mvwaddch(slot_w, Y-1, 0, ' ');
        !           342:        (void) mvwaddch(slot_w, Y-1, 1, ' ');
        !           343:        (void) mvwaddch(slot_w, Y-1, 2, ' ');
        !           344:        (void) mvwaddch(slot_w, Y+1, 0, ' ');
        !           345:        (void) mvwaddch(slot_w, Y+1, 1, ' ');
        !           346:        (void) mvwaddch(slot_w, Y+1, 2, ' ');
        !           347:        (void) wmove(slot_w, Y - dr[winddir], 1 - dc[winddir]);
        !           348:        switch (winddir) {
        !           349:        case 1:
        !           350:        case 5:
        !           351:                (void) waddch(slot_w, '|');
        !           352:                break;
        !           353:        case 2:
        !           354:        case 6:
        !           355:                (void) waddch(slot_w, '/');
        !           356:                break;
        !           357:        case 3:
        !           358:        case 7:
        !           359:                (void) waddch(slot_w, '-');
        !           360:                break;
        !           361:        case 4:
        !           362:        case 8:
        !           363:                (void) waddch(slot_w, '\\');
        !           364:                break;
        !           365:        }
        !           366:        (void) mvwaddch(slot_w, Y + dr[winddir], 1 + dc[winddir], '+');
        !           367:        (void) wrefresh(slot_w);
        !           368: }
        !           369: 
        !           370: draw_board()
        !           371: {
        !           372:        register int n;
        !           373: 
        !           374:        (void) clear();
        !           375:        (void) werase(view_w);
        !           376:        (void) werase(slot_w);
        !           377:        (void) werase(scroll_w);
        !           378:        (void) werase(stat_w);
        !           379:        (void) werase(turn_w);
        !           380: 
        !           381:        sc_line = 0;
        !           382: 
        !           383:        (void) move(BOX_T, BOX_L);
        !           384:        for (n = 0; n < BOX_X; n++)
        !           385:                (void) addch('-');
        !           386:        (void) move(BOX_B, BOX_L);
        !           387:        for (n = 0; n < BOX_X; n++)
        !           388:                (void) addch('-');
        !           389:        for (n = BOX_T+1; n < BOX_B; n++) {
        !           390:                (void) mvaddch(n, BOX_L, '|');
        !           391:                (void) mvaddch(n, BOX_R, '|');
        !           392:        }
        !           393:        (void) mvaddch(BOX_T, BOX_L, '+');
        !           394:        (void) mvaddch(BOX_T, BOX_R, '+');
        !           395:        (void) mvaddch(BOX_B, BOX_L, '+');
        !           396:        (void) mvaddch(BOX_B, BOX_R, '+');
        !           397:        (void) refresh();
        !           398: 
        !           399: #define WSaIM "Wooden Ships & Iron Men"
        !           400:        (void) wmove(view_w, 2, (VIEW_X - sizeof WSaIM - 1) / 2);
        !           401:        (void) waddstr(view_w, WSaIM);
        !           402:        (void) wmove(view_w, 4, (VIEW_X - strlen(cc->name)) / 2);
        !           403:        (void) waddstr(view_w, cc->name);
        !           404:        (void) wrefresh(view_w);
        !           405: 
        !           406:        (void) move(LINE_T, LINE_L);
        !           407:        (void) printw("Class %d %s (%d guns) '%s' (%c%c)",
        !           408:                mc->class,
        !           409:                classname[mc->class],
        !           410:                mc->guns,
        !           411:                ms->shipname,
        !           412:                colours(ms),
        !           413:                sterncolour(ms));
        !           414:        (void) refresh();
        !           415: }
        !           416: 
        !           417: centerview()
        !           418: {
        !           419:        viewrow = mf->row - VIEW_Y / 2;
        !           420:        viewcol = mf->col - VIEW_X / 2;
        !           421: }
        !           422: 
        !           423: upview()
        !           424: {
        !           425:        viewrow -= VIEW_Y / 3;
        !           426: }
        !           427: 
        !           428: downview()
        !           429: {
        !           430:        viewrow += VIEW_Y / 3;
        !           431: }
        !           432: 
        !           433: leftview()
        !           434: {
        !           435:        viewcol -= VIEW_X / 5;
        !           436: }
        !           437: 
        !           438: rightview()
        !           439: {
        !           440:        viewcol += VIEW_X / 5;
        !           441: }
        !           442: 
        !           443: adjustview()
        !           444: {
        !           445:        if (dont_adjust)
        !           446:                return;
        !           447:        if (mf->row < viewrow + VIEW_Y/4)
        !           448:                viewrow = mf->row - (VIEW_Y - VIEW_Y/4);
        !           449:        else if (mf->row > viewrow + (VIEW_Y - VIEW_Y/4))
        !           450:                viewrow = mf->row - VIEW_Y/4;
        !           451:        if (mf->col < viewcol + VIEW_X/8)
        !           452:                viewcol = mf->col - (VIEW_X - VIEW_X/8);
        !           453:        else if (mf->col > viewcol + (VIEW_X - VIEW_X/8))
        !           454:                viewcol = mf->col - VIEW_X/8;
        !           455: }
        !           456: 
        !           457: #ifdef SIGTSTP
        !           458: susp()
        !           459: {
        !           460:        blockalarm();
        !           461:        tstp();
        !           462:        (void) signal(SIGTSTP, susp);
        !           463:        unblockalarm();
        !           464: }
        !           465: #endif

unix.superglobalmegacorp.com

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