Annotation of 43BSDReno/games/monop/cards.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[] = "@(#)cards.c    5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: # include      "monop.ext"
        !            25: # include      "pathnames.h"
        !            26: 
        !            27: /*
        !            28:  *     These routine deal with the card decks
        !            29:  */
        !            30: 
        !            31: # define       GOJF    'F'     /* char for get-out-of-jail-free cards  */
        !            32: 
        !            33: # ifndef DEV
        !            34: static char    *cardfile       = _PATH_CARDS;
        !            35: # else
        !            36: static char    *cardfile       = "cards.pck";
        !            37: # endif
        !            38: 
        !            39: static FILE    *deckf;
        !            40: 
        !            41: /*
        !            42:  *     This routine initializes the decks from the data file,
        !            43:  * which it opens.
        !            44:  */
        !            45: init_decks() {
        !            46: 
        !            47:        if ((deckf=fopen(cardfile, "r")) == NULL) {
        !            48: file_err:
        !            49:                perror(cardfile);
        !            50:                exit(1);
        !            51:        }
        !            52:        if (fread(deck, sizeof (DECK), 2, deckf) != 2)
        !            53:                goto file_err;
        !            54:        set_up(&CC_D);
        !            55:        set_up(&CH_D);
        !            56: }
        !            57: /*
        !            58:  *     This routine sets up the offset pointers for the given deck.
        !            59:  */
        !            60: set_up(dp)
        !            61: DECK   *dp; {
        !            62: 
        !            63:        reg int r1, r2;
        !            64:        int     i;
        !            65: 
        !            66:        dp->offsets = (long *) calloc(sizeof (long), dp->num_cards);
        !            67:        if (fread(dp->offsets, sizeof(long), dp->num_cards, deckf) != dp->num_cards) {
        !            68:                perror(cardfile);
        !            69:                exit(1);
        !            70:        }
        !            71:        dp->last_card = 0;
        !            72:        dp->gojf_used = FALSE;
        !            73:        for (i = 0; i < dp->num_cards; i++) {
        !            74:                reg long        temp;
        !            75: 
        !            76:                r1 = roll(1, dp->num_cards) - 1;
        !            77:                r2 = roll(1, dp->num_cards) - 1;
        !            78:                temp = dp->offsets[r2];
        !            79:                dp->offsets[r2] = dp->offsets[r1];
        !            80:                dp->offsets[r1] = temp;
        !            81:        }
        !            82: }
        !            83: /*
        !            84:  *     This routine draws a card from the given deck
        !            85:  */
        !            86: get_card(dp)
        !            87: DECK   *dp; {
        !            88: 
        !            89:        reg char        type_maj, type_min;
        !            90:        reg int         num;
        !            91:        int             i, per_h, per_H, num_h, num_H;
        !            92:        OWN             *op;
        !            93: 
        !            94:        do {
        !            95:                fseek(deckf, dp->offsets[dp->last_card], 0);
        !            96:                dp->last_card = ++(dp->last_card) % dp->num_cards;
        !            97:                type_maj = getc(deckf);
        !            98:        } while (dp->gojf_used && type_maj == GOJF);
        !            99:        type_min = getc(deckf);
        !           100:        num = getw(deckf);
        !           101:        printmes();
        !           102:        switch (type_maj) {
        !           103:          case '+':             /* get money            */
        !           104:                if (type_min == 'A') {
        !           105:                        for (i = 0; i < num_play; i++)
        !           106:                                if (i != player)
        !           107:                                        play[i].money -= num;
        !           108:                        num = num * (num_play - 1);
        !           109:                }
        !           110:                cur_p->money += num;
        !           111:                break;
        !           112:          case '-':             /* lose money           */
        !           113:                if (type_min == 'A') {
        !           114:                        for (i = 0; i < num_play; i++)
        !           115:                                if (i != player)
        !           116:                                        play[i].money += num;
        !           117:                        num = num * (num_play - 1);
        !           118:                }
        !           119:                cur_p->money -= num;
        !           120:                break;
        !           121:          case 'M':             /* move somewhere       */
        !           122:                switch (type_min) {
        !           123:                  case 'F':             /* move forward */
        !           124:                        num -= cur_p->loc;
        !           125:                        if (num < 0)
        !           126:                                num += 40;
        !           127:                        break;
        !           128:                  case 'J':             /* move to jail */
        !           129:                        goto_jail();
        !           130:                        return;
        !           131:                  case 'R':             /* move to railroad     */
        !           132:                        spec = TRUE;
        !           133:                        num = (int)((cur_p->loc + 5)/10)*10 + 5 - cur_p->loc;
        !           134:                        break;
        !           135:                  case 'U':             /* move to utility      */
        !           136:                        spec = TRUE;
        !           137:                        if (cur_p->loc >= 12 && cur_p->loc < 28)
        !           138:                                num = 28 - cur_p->loc;
        !           139:                        else {
        !           140:                                num = 12 - cur_p->loc;
        !           141:                                if (num < 0)
        !           142:                                        num += 40;
        !           143:                        }
        !           144:                        break;
        !           145:                  case 'B':
        !           146:                        num = -num;
        !           147:                        break;
        !           148:                }
        !           149:                move(num);
        !           150:                break;
        !           151:          case 'T':                     /* tax                  */
        !           152:                if (dp == &CC_D) {
        !           153:                        per_h = 40;
        !           154:                        per_H = 115;
        !           155:                }
        !           156:                else {
        !           157:                        per_h = 25;
        !           158:                        per_H = 100;
        !           159:                }
        !           160:                num_h = num_H = 0;
        !           161:                for (op = cur_p->own_list; op; op = op->next)
        !           162:                        if (op->sqr->type == PRPTY)
        !           163:                                if (op->sqr->desc->houses == 5)
        !           164:                                        ++num_H;
        !           165:                                else
        !           166:                                        num_h += op->sqr->desc->houses;
        !           167:                num = per_h * num_h + per_H * num_H;
        !           168:                printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h, num_H, num);
        !           169:                if (num == 0)
        !           170:                        lucky("");
        !           171:                else
        !           172:                        cur_p->money -= num;
        !           173:                break;
        !           174:          case GOJF:            /* get-out-of-jail-free card    */
        !           175:                cur_p->num_gojf++;
        !           176:                dp->gojf_used = TRUE;
        !           177:                break;
        !           178:        }
        !           179:        spec = FALSE;
        !           180: }
        !           181: /*
        !           182:  *     This routine prints out the message on the card
        !           183:  */
        !           184: printmes() {
        !           185: 
        !           186:        reg char        c;
        !           187: 
        !           188:        printline();
        !           189:        fflush(stdout);
        !           190:        while ((c = getc(deckf)) != '\0')
        !           191:                putchar(c);
        !           192:        printline();
        !           193:        fflush(stdout);
        !           194: }

unix.superglobalmegacorp.com

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