Annotation of 43BSDReno/games/monop/execute.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980 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[] = "@(#)execute.c  5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: # include      "monop.ext"
        !            25: # include      <sys/types.h>
        !            26: # include      <sys/stat.h>
        !            27: # include      <sys/time.h>
        !            28: 
        !            29: # define       SEGSIZE 8192
        !            30: 
        !            31: typedef        struct stat     STAT;
        !            32: typedef        struct tm       TIME;
        !            33: 
        !            34: extern char    etext[],        /* end of text space                    */
        !            35:                rub();
        !            36: 
        !            37: static char    buf[257],
        !            38:                *yn_only[]      = { "yes", "no"};
        !            39: 
        !            40: static bool    new_play;       /* set if move on to new player         */
        !            41: 
        !            42: /*
        !            43:  *     This routine executes the given command by index number
        !            44:  */
        !            45: execute(com_num)
        !            46: reg int        com_num; {
        !            47: 
        !            48:        new_play = FALSE;       /* new_play is true if fixing   */
        !            49:        (*func[com_num])();
        !            50:        notify();
        !            51:        force_morg();
        !            52:        if (new_play)
        !            53:                next_play();
        !            54:        else if (num_doub)
        !            55:                printf("%s rolled doubles.  Goes again\n", cur_p->name);
        !            56: }
        !            57: /*
        !            58:  *     This routine moves a piece around.
        !            59:  */
        !            60: do_move() {
        !            61: 
        !            62:        reg int         r1, r2;
        !            63:        reg bool        was_jail;
        !            64: 
        !            65:        new_play = was_jail = FALSE;
        !            66:        printf("roll is %d, %d\n", r1=roll(1, 6), r2=roll(1, 6));
        !            67:        if (cur_p->loc == JAIL) {
        !            68:                was_jail++;
        !            69:                if (!move_jail(r1, r2)) {
        !            70:                        new_play++;
        !            71:                        goto ret;
        !            72:                }
        !            73:        }
        !            74:        else {
        !            75:                if (r1 == r2 && ++num_doub == 3) {
        !            76:                        printf("That's 3 doubles.  You go to jail\n");
        !            77:                        goto_jail();
        !            78:                        new_play++;
        !            79:                        goto ret;
        !            80:                }
        !            81:                move(r1+r2);
        !            82:        }
        !            83:        if (r1 != r2 || was_jail)
        !            84:                new_play++;
        !            85: ret:
        !            86:        return;
        !            87: }
        !            88: /*
        !            89:  *     This routine moves a normal move
        !            90:  */
        !            91: move(rl)
        !            92: reg int        rl; {
        !            93: 
        !            94:        reg int old_loc;
        !            95: 
        !            96:        old_loc = cur_p->loc;
        !            97:        cur_p->loc = (cur_p->loc + rl) % N_SQRS;
        !            98:        if (cur_p->loc < old_loc && rl > 0) {
        !            99:                cur_p->money += 200;
        !           100:                printf("You pass %s and get $200\n", board[0].name);
        !           101:        }
        !           102:        show_move();
        !           103: }
        !           104: /*
        !           105:  *     This routine shows the results of a move
        !           106:  */
        !           107: show_move() {
        !           108: 
        !           109:        reg SQUARE      *sqp;
        !           110: 
        !           111:        sqp = &board[cur_p->loc];
        !           112:        printf("That puts you on %s\n", sqp->name);
        !           113:        switch (sqp->type) {
        !           114:          case SAFE:
        !           115:                printf("That is a safe place\n");
        !           116:                break;
        !           117:          case CC:
        !           118:                cc(); break;
        !           119:          case CHANCE:
        !           120:                chance(); break;
        !           121:          case INC_TAX:
        !           122:                inc_tax(); break;
        !           123:          case GOTO_J:
        !           124:                goto_jail(); break;
        !           125:          case LUX_TAX:
        !           126:                lux_tax(); break;
        !           127:          case PRPTY:
        !           128:          case RR:
        !           129:          case UTIL:
        !           130:                if (sqp->owner < 0) {
        !           131:                        printf("That would cost $%d\n", sqp->cost);
        !           132:                        if (getyn("Do you want to buy? ") == 0) {
        !           133:                                buy(player, sqp);
        !           134:                                cur_p->money -= sqp->cost;
        !           135:                        }
        !           136:                        else if (num_play > 2)
        !           137:                                bid(sqp);
        !           138:                }
        !           139:                else if (sqp->owner == player)
        !           140:                        printf("You own it.\n");
        !           141:                else
        !           142:                        rent(sqp);
        !           143:        }
        !           144: }
        !           145: /*
        !           146:  *     This routine saves the current game for use at a later date
        !           147:  */
        !           148: save() {
        !           149: 
        !           150:        reg char        *sp;
        !           151:        reg int         outf, num;
        !           152:        TIME            tme, *tp;
        !           153:        int             *dat_end, junk[18];
        !           154:        unsgn           start, end;
        !           155: 
        !           156:        tp = &tme;
        !           157:        printf("Which file do you wish to save it in? ");
        !           158:        sp = buf;
        !           159:        while ((*sp++=getchar()) != '\n')
        !           160:                continue;
        !           161:        *--sp = '\0';
        !           162: 
        !           163:        /*
        !           164:         * check for existing files, and confirm overwrite if needed
        !           165:         */
        !           166: 
        !           167:        if (stat(buf, junk) > -1
        !           168:            && getyn("File exists.  Do you wish to overwrite? ", yn_only) > 0)
        !           169:                return;
        !           170: 
        !           171:        if ((outf=creat(buf, 0644)) < 0) {
        !           172:                perror(buf);
        !           173:                return;
        !           174:        }
        !           175:        printf("\"%s\" ", buf);
        !           176:        time(tp);                       /* get current time             */
        !           177:        strcpy(buf, ctime(tp));
        !           178:        for (sp = buf; *sp != '\n'; sp++)
        !           179:                continue;
        !           180:        *sp = '\0';
        !           181: # if 0
        !           182:        start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
        !           183: # else
        !           184:        start = 0;
        !           185: # endif
        !           186:        end = sbrk(0);
        !           187:        while (start < end) {           /* write out entire data space */
        !           188:                num = start + 16 * 1024 > end ? end - start : 16 * 1024;
        !           189:                write(outf, start, num);
        !           190:                start += num;
        !           191:        }
        !           192:        close(outf);
        !           193:        printf("[%s]\n", buf);
        !           194: }
        !           195: /*
        !           196:  *     This routine restores an old game from a file
        !           197:  */
        !           198: restore() {
        !           199: 
        !           200:        reg char        *sp;
        !           201: 
        !           202:        printf("Which file do you wish to restore from? ");
        !           203:        for (sp = buf; (*sp=getchar()) != '\n'; sp++)
        !           204:                continue;
        !           205:        *sp = '\0';
        !           206:        rest_f(buf);
        !           207: }
        !           208: /*
        !           209:  *     This does the actual restoring.  It returns TRUE if the
        !           210:  * backup was successful, else false.
        !           211:  */
        !           212: rest_f(file)
        !           213: reg char       *file; {
        !           214: 
        !           215:        reg char        *sp;
        !           216:        reg int         inf, num;
        !           217:        char            buf[80];
        !           218:        unsgn           start, end;
        !           219:        STAT            sbuf;
        !           220: 
        !           221:        if ((inf=open(file, 0)) < 0) {
        !           222:                perror(file);
        !           223:                return FALSE;
        !           224:        }
        !           225:        printf("\"%s\" ", file);
        !           226:        if (fstat(inf, &sbuf) < 0) {            /* get file stats       */
        !           227:                perror(file);
        !           228:                exit(1);
        !           229:        }
        !           230: # if 0
        !           231:        start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
        !           232: # else
        !           233:        start = 0;
        !           234: # endif
        !           235:        brk(end = start + sbuf.st_size);
        !           236:        while (start < end) {           /* write out entire data space */
        !           237:                num = start + 16 * 1024 > end ? end - start : 16 * 1024;
        !           238:                read(inf, start, num);
        !           239:                start += num;
        !           240:        }
        !           241:        close(inf);
        !           242:        strcpy(buf, ctime(sbuf.st_mtime));
        !           243:        for (sp = buf; *sp != '\n'; sp++)
        !           244:                continue;
        !           245:        *sp = '\0';
        !           246:        printf("[%s]\n", buf);
        !           247:        return TRUE;
        !           248: }

unix.superglobalmegacorp.com

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