Annotation of 43BSD/games/monop/trade.c, revision 1.1

1.1     ! root        1: # include      "monop.ext"
        !             2: 
        !             3: static struct  trd_st {        /* how much to give to other player     */
        !             4:        int     trader;                 /* trader number                */
        !             5:        int     cash;                   /* amount of cash               */
        !             6:        int     gojf;                   /* # get-out-of-jail-free cards */
        !             7:        OWN     *prop_list;             /* property list                */
        !             8: };
        !             9: 
        !            10: typedef        struct trd_st   TRADE;
        !            11: 
        !            12: static char    *list[MAX_PRP+2];
        !            13: 
        !            14: static int     used[MAX_PRP];
        !            15: 
        !            16: static TRADE   trades[2];
        !            17: 
        !            18: trade() {
        !            19: 
        !            20:        reg int tradee, i;
        !            21: 
        !            22:        trading = TRUE;
        !            23:        for (i = 0; i < 2; i++) {
        !            24:                trades[i].cash = 0;
        !            25:                trades[i].gojf = FALSE;
        !            26:                trades[i].prop_list = NULL;
        !            27:        }
        !            28: over:
        !            29:        if (num_play == 1) {
        !            30:                printf("There ain't no-one around to trade WITH!!\n");
        !            31:                return;
        !            32:        }
        !            33:        if (num_play > 2) {
        !            34:                tradee = getinp("Which player do you wish to trade with? ",
        !            35:                    name_list);
        !            36:                if (tradee == num_play)
        !            37:                        return;
        !            38:                if (tradee == player) {
        !            39:                        printf("You can't trade with yourself!\n");
        !            40:                        goto over;
        !            41:                }
        !            42:        }
        !            43:        else
        !            44:                tradee = 1 - player;
        !            45:        get_list(0, player);
        !            46:        get_list(1, tradee);
        !            47:        if (getyn("Do you wish a summary? ") == 0)
        !            48:                summate();
        !            49:        if (getyn("Is the trade ok? ") == 0)
        !            50:                do_trade();
        !            51: }
        !            52: /*
        !            53:  *     This routine gets the list of things to be trader for the
        !            54:  * player, and puts in the structure given.
        !            55:  */
        !            56: get_list(struct_no, play_no)
        !            57: int    struct_no, play_no; {
        !            58: 
        !            59:        reg int         sn, pn;
        !            60:        reg PLAY        *pp;
        !            61:        int             numin, prop, num_prp;
        !            62:        OWN             *op;
        !            63:        TRADE           *tp;
        !            64: 
        !            65:        for (numin = 0; numin < MAX_PRP; numin++)
        !            66:                used[numin] = FALSE;
        !            67:        sn = struct_no, pn = play_no;
        !            68:        pp = &play[pn];
        !            69:        tp = &trades[sn];
        !            70:        tp->trader = pn;
        !            71:        printf("player %s (%d):\n", pp->name, pn+1);
        !            72:        if (pp->own_list) {
        !            73:                numin = set_list(pp->own_list);
        !            74:                for (num_prp = numin; num_prp; ) {
        !            75:                        prop = getinp("Which property do you wish to trade? ",
        !            76:                            list);
        !            77:                        if (prop == numin)
        !            78:                                break;
        !            79:                        else if (used[prop])
        !            80:                                printf("You've already allocated that.\n");
        !            81:                        else {
        !            82:                                num_prp--;
        !            83:                                used[prop] = TRUE;
        !            84:                                for (op = pp->own_list; prop--; op = op->next)
        !            85:                                        continue;
        !            86:                                add_list(pn, &(tp->prop_list), sqnum(op->sqr));
        !            87:                        }
        !            88:                }
        !            89:        }
        !            90:        if (pp->money > 0) {
        !            91:                printf("You have $%d.  ", pp->money);
        !            92:                tp->cash = get_int("How much are you trading? ");
        !            93:        }
        !            94:        if (pp->num_gojf > 0) {
        !            95: once_more:
        !            96:                printf("You have %d get-out-of-jail-free cards. ",pp->num_gojf);
        !            97:                tp->gojf = get_int("How many are you trading? ");
        !            98:                if (tp->gojf > pp->num_gojf) {
        !            99:                        printf("You don't have that many.  Try again.\n");
        !           100:                        goto once_more;
        !           101:                }
        !           102:        }
        !           103: }
        !           104: /*
        !           105:  *     This routine sets up the list of tradable property.
        !           106:  */
        !           107: set_list(the_list)
        !           108: reg OWN        *the_list; {
        !           109: 
        !           110:        reg int i;
        !           111:        reg OWN *op;
        !           112: 
        !           113:        i = 0;
        !           114:        for (op = the_list; op; op = op->next)
        !           115:                if (!used[i])
        !           116:                        list[i++] = op->sqr->name;
        !           117:        list[i++] = "done";
        !           118:        list[i--] = 0;
        !           119:        return i;
        !           120: }
        !           121: /*
        !           122:  *     This routine summates the trade.
        !           123:  */
        !           124: summate() {
        !           125: 
        !           126:        reg bool        some;
        !           127:        reg int         i;
        !           128:        reg TRADE       *tp;
        !           129:        OWN     *op;
        !           130: 
        !           131:        for (i = 0; i < 2; i++) {
        !           132:                tp = &trades[i];
        !           133:                some = FALSE;
        !           134:                printf("Player %s (%d) gives:\n", play[tp->trader].name,
        !           135:                        tp->trader+1);
        !           136:                if (tp->cash > 0)
        !           137:                        printf("\t$%d\n", tp->cash), some++;
        !           138:                if (tp->gojf > 0)
        !           139:                        printf("\t%d get-out-of-jail-free card(s)\n", tp->gojf),
        !           140:                        some++;
        !           141:                if (tp->prop_list) {
        !           142:                        for (op = tp->prop_list; op; op = op->next)
        !           143:                                putchar('\t'), printsq(sqnum(op->sqr), TRUE);
        !           144:                        some++;
        !           145:                }
        !           146:                if (!some)
        !           147:                        printf("\t-- Nothing --\n");
        !           148:        }
        !           149: }
        !           150: /*
        !           151:  *     This routine actually executes the trade.
        !           152:  */
        !           153: do_trade() {
        !           154: 
        !           155:        move_em(&trades[0], &trades[1]);
        !           156:        move_em(&trades[1], &trades[0]);
        !           157: }
        !           158: /*
        !           159:  *     This routine does a switch from one player to another
        !           160:  */
        !           161: move_em(from, to)
        !           162: TRADE  *from, *to; {
        !           163: 
        !           164:        reg PLAY        *pl_fr, *pl_to;
        !           165:        reg OWN         *op;
        !           166: 
        !           167:        pl_fr = &play[from->trader];
        !           168:        pl_to = &play[to->trader];
        !           169: 
        !           170:        pl_fr->money -= from->cash;
        !           171:        pl_to->money += from->cash;
        !           172:        pl_fr->num_gojf -= from->gojf;
        !           173:        pl_to->num_gojf += from->gojf;
        !           174:        for (op = from->prop_list; op; op = op->next) {
        !           175:                add_list(to->trader, &(pl_to->own_list), sqnum(op->sqr));
        !           176:                op->sqr->owner = to->trader;
        !           177:                del_list(from->trader, &(pl_fr->own_list), sqnum(op->sqr));
        !           178:        }
        !           179:        set_ownlist(to->trader);
        !           180: }
        !           181: /*
        !           182:  *     This routine lets a player resign
        !           183:  */
        !           184: resign() {
        !           185: 
        !           186:        reg int i, new_own;
        !           187:        reg OWN *op;
        !           188:        SQUARE  *sqp;
        !           189: 
        !           190:        if (cur_p->money <= 0) {
        !           191:                switch (board[cur_p->loc].type) {
        !           192:                  case UTIL:
        !           193:                  case RR:
        !           194:                  case PRPTY:
        !           195:                        new_own = board[cur_p->loc].owner;
        !           196:                        break;
        !           197:                  case SPEC:
        !           198:                  case CC:
        !           199:                  case CHANCE:
        !           200:                        new_own = num_play;
        !           201:                        break;
        !           202:                }
        !           203:                if (new_own == num_play)
        !           204:                        printf("You would resign to the bank\n");
        !           205:                else
        !           206:                        printf("You would resign to %s\n", name_list[new_own]);
        !           207:        }
        !           208:        else if (num_play == 1) {
        !           209:                new_own = num_play;
        !           210:                printf("You would resign to the bank\n");
        !           211:        }
        !           212:        else {
        !           213:                name_list[num_play] = "bank";
        !           214:                do {
        !           215:                        new_own = getinp("Who do you wish to resign to? ",
        !           216:                            name_list);
        !           217:                        if (new_own == player)
        !           218:                                printf("You can't resign to yourself!!\n");
        !           219:                } while (new_own == player);
        !           220:                name_list[num_play] = "done";
        !           221:        }
        !           222:        if (getyn("Do you really want to resign? ", yn) != 0)
        !           223:                return;
        !           224:        if (num_play == 1) {
        !           225:                printf("Then NOBODY wins (not even YOU!)\n");
        !           226:                exit(0);
        !           227:        }
        !           228:        if (new_own < num_play) {       /* resign to player             */
        !           229:                printf("resigning to player\n");
        !           230:                trades[0].trader = new_own;
        !           231:                trades[0].cash = trades[0].gojf = 0;
        !           232:                trades[0].prop_list = NULL;
        !           233:                trades[1].trader = player;
        !           234:                trades[1].cash = cur_p->money > 0 ? cur_p->money : 0;
        !           235:                trades[1].gojf = cur_p->num_gojf;
        !           236:                trades[1].prop_list = cur_p->own_list;
        !           237:                do_trade();
        !           238:        }
        !           239:        else {                          /* resign to bank               */
        !           240:                printf("resigning to bank\n");
        !           241:                for (op = cur_p->own_list; op; op = op->next) {
        !           242:                        sqp = op->sqr;
        !           243:                        sqp->owner = -1;
        !           244:                        sqp->desc->morg = FALSE;
        !           245:                        if (op->type == PRPTY) {
        !           246:                                isnot_monop(sqp->desc->mon_desc);
        !           247:                                sqp->desc->houses = 0;
        !           248:                        }
        !           249:                }
        !           250:                if (cur_p->num_gojf)
        !           251:                        ret_card(cur_p);
        !           252:        }
        !           253:        for (i = player; i < num_play; i++) {
        !           254:                name_list[i] = name_list[i+1];
        !           255:                if (i + 1 < num_play)
        !           256:                        cpy_st(&play[i], &play[i+1], sizeof (PLAY));
        !           257:        }
        !           258:        name_list[num_play--] = 0;
        !           259:        for (i = 0; i < N_SQRS; i++)
        !           260:                if (board[i].owner > player)
        !           261:                        --board[i].owner;
        !           262:        player = --player < 0 ? num_play - 1 : player;
        !           263:        next_play();
        !           264:        if (num_play < 2) {
        !           265:                printf("\nThen %s WINS!!!!!\n", play[0].name);
        !           266:                printhold(0);
        !           267:                printf("That's a grand worth of $%d.\n",
        !           268:                        play[0].money+prop_worth(&play[0]));
        !           269:                exit(0);
        !           270:        }
        !           271: }

unix.superglobalmegacorp.com

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