Annotation of 43BSDReno/games/mille/misc.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[] = "@(#)misc.c     5.6 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include       "mille.h"
        !            25: #ifndef        unctrl
        !            26: #include       "unctrl.h"
        !            27: #endif
        !            28: 
        !            29: # include      <sys/file.h>
        !            30: 
        !            31: # ifdef        attron
        !            32: #      include <term.h>
        !            33: #      define  _tty    cur_term->Nttyb
        !            34: # endif        attron
        !            35: 
        !            36: /*
        !            37:  * @(#)misc.c  1.2 (Berkeley) 3/28/83
        !            38:  */
        !            39: 
        !            40: #define        NUMSAFE 4
        !            41: 
        !            42: /* VARARGS1 */
        !            43: error(str, arg)
        !            44: char   *str;
        !            45: {
        !            46:        stdscr = Score;
        !            47:        mvprintw(ERR_Y, ERR_X, str, arg);
        !            48:        clrtoeol();
        !            49:        putchar('\07');
        !            50:        refresh();
        !            51:        stdscr = Board;
        !            52:        return FALSE;
        !            53: }
        !            54: 
        !            55: CARD
        !            56: getcard()
        !            57: {
        !            58:        reg int         c, c1;
        !            59: 
        !            60:        for (;;) {
        !            61:                while ((c = readch()) == '\n' || c == '\r' || c == ' ')
        !            62:                        continue;
        !            63:                if (islower(c))
        !            64:                        c = toupper(c);
        !            65:                if (c == killchar() || c == erasechar())
        !            66:                        return -1;
        !            67:                addstr(unctrl(c));
        !            68:                clrtoeol();
        !            69:                switch (c) {
        !            70:                  case '1':     case '2':       case '3':
        !            71:                  case '4':     case '5':       case '6':
        !            72:                        c -= '0';
        !            73:                        break;
        !            74:                  case '0':     case 'P':       case 'p':
        !            75:                        c = 0;
        !            76:                        break;
        !            77:                  default:
        !            78:                        putchar('\07');
        !            79:                        addch('\b');
        !            80:                        if (!isprint(c))
        !            81:                                addch('\b');
        !            82:                        c = -1;
        !            83:                        break;
        !            84:                }
        !            85:                refresh();
        !            86:                if (c >= 0) {
        !            87:                        while ((c1=readch()) != '\r' && c1 != '\n' && c1 != ' ')
        !            88:                                if (c1 == killchar())
        !            89:                                        return -1;
        !            90:                                else if (c1 == erasechar()) {
        !            91:                                        addch('\b');
        !            92:                                        clrtoeol();
        !            93:                                        refresh();
        !            94:                                        goto cont;
        !            95:                                }
        !            96:                                else
        !            97:                                        write(0, "\07", 1);
        !            98:                        return c;
        !            99:                }
        !           100: cont:          ;
        !           101:        }
        !           102: }
        !           103: 
        !           104: check_ext(forcomp)
        !           105: reg bool       forcomp; {
        !           106: 
        !           107: 
        !           108:        if (End == 700)
        !           109:                if (Play == PLAYER) {
        !           110:                        if (getyn(EXTENSIONPROMPT)) {
        !           111: extend:
        !           112:                                if (!forcomp)
        !           113:                                        End = 1000;
        !           114:                                return TRUE;
        !           115:                        }
        !           116:                        else {
        !           117: done:
        !           118:                                if (!forcomp)
        !           119:                                        Finished = TRUE;
        !           120:                                return FALSE;
        !           121:                        }
        !           122:                }
        !           123:                else {
        !           124:                        reg PLAY        *pp, *op;
        !           125:                        reg int         i, safe, miles;
        !           126: 
        !           127:                        pp = &Player[COMP];
        !           128:                        op = &Player[PLAYER];
        !           129:                        for (safe = 0, i = 0; i < NUMSAFE; i++)
        !           130:                                if (pp->safety[i] != S_UNKNOWN)
        !           131:                                        safe++;
        !           132:                        if (safe < 2)
        !           133:                                goto done;
        !           134:                        if (op->mileage == 0 || onecard(op)
        !           135:                            || (op->can_go && op->mileage >= 500))
        !           136:                                goto done;
        !           137:                        for (miles = 0, i = 0; i < NUMSAFE; i++)
        !           138:                                if (op->safety[i] != S_PLAYED
        !           139:                                    && pp->safety[i] == S_UNKNOWN)
        !           140:                                        miles++;
        !           141:                        if (miles + safe == NUMSAFE)
        !           142:                                goto extend;
        !           143:                        for (miles = 0, i = 0; i < HAND_SZ; i++)
        !           144:                                if ((safe = pp->hand[i]) <= C_200)
        !           145:                                        miles += Value[safe]; 
        !           146:                        if (miles + (Topcard - Deck) * 3 > 1000)
        !           147:                                goto extend;
        !           148:                        goto done;
        !           149:                }
        !           150:        else
        !           151:                goto done;
        !           152: }
        !           153: 
        !           154: /*
        !           155:  *     Get a yes or no answer to the given question.  Saves are
        !           156:  * also allowed.  Return TRUE if the answer was yes, FALSE if no.
        !           157:  */
        !           158: getyn(promptno)
        !           159: register int   promptno; {
        !           160: 
        !           161:        reg char        c;
        !           162: 
        !           163:        Saved = FALSE;
        !           164:        for (;;) {
        !           165:                leaveok(Board, FALSE);
        !           166:                prompt(promptno);
        !           167:                clrtoeol();
        !           168:                refresh();
        !           169:                switch (c = readch()) {
        !           170:                  case 'n':     case 'N':
        !           171:                        addch('N');
        !           172:                        refresh();
        !           173:                        leaveok(Board, TRUE);
        !           174:                        return FALSE;
        !           175:                  case 'y':     case 'Y':
        !           176:                        addch('Y');
        !           177:                        refresh();
        !           178:                        leaveok(Board, TRUE);
        !           179:                        return TRUE;
        !           180:                  case 's':     case 'S':
        !           181:                        addch('S');
        !           182:                        refresh();
        !           183:                        Saved = save();
        !           184:                        continue;
        !           185:                  default:
        !           186:                        addstr(unctrl(c));
        !           187:                        refresh();
        !           188:                        putchar('\07');
        !           189:                        break;
        !           190:                }
        !           191:        }
        !           192: }
        !           193: 
        !           194: /*
        !           195:  *     Check to see if more games are desired.  If not, and game
        !           196:  * came from a saved file, make sure that they don't want to restore
        !           197:  * it.  Exit appropriately.
        !           198:  */
        !           199: check_more() {
        !           200: 
        !           201:        flush_input();
        !           202: 
        !           203:        On_exit = TRUE;
        !           204:        if (Player[PLAYER].total >= 5000 || Player[COMP].total >= 5000)
        !           205:                if (getyn(ANOTHERGAMEPROMPT))
        !           206:                        return;
        !           207:                else {
        !           208:                        /*
        !           209:                         * must do accounting normally done in main()
        !           210:                         */
        !           211:                        if (Player[PLAYER].total > Player[COMP].total)
        !           212:                                Player[PLAYER].games++;
        !           213:                        else if (Player[PLAYER].total < Player[COMP].total)
        !           214:                                Player[COMP].games++;
        !           215:                        Player[COMP].total = 0;
        !           216:                        Player[PLAYER].total = 0;
        !           217:                }
        !           218:        else
        !           219:                if (getyn(ANOTHERHANDPROMPT))
        !           220:                        return;
        !           221:        if (!Saved && getyn(SAVEGAMEPROMPT))
        !           222:                if (!save())
        !           223:                        return;
        !           224:        die();
        !           225: }
        !           226: 
        !           227: readch()
        !           228: {
        !           229:        reg int         cnt;
        !           230:        static char     c;
        !           231: 
        !           232:        for (cnt = 0; read(0, &c, 1) <= 0; cnt++)
        !           233:                if (cnt > 100)
        !           234:                        exit(1);
        !           235:        return c;
        !           236: }
        !           237: 
        !           238: flush_input()
        !           239: {
        !           240: # ifdef        TIOCFLUSH
        !           241:        static int      ioctl_args = O_RDONLY;
        !           242: 
        !           243:        (void) ioctl(fileno(stdin), TIOCFLUSH, &ioctl_args);
        !           244: # else
        !           245:        fflush(stdin);
        !           246: # endif
        !           247: }

unix.superglobalmegacorp.com

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