Annotation of 43BSDTahoe/games/monop/houses.c, revision 1.1.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 the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: static char sccsid[] = "@(#)houses.c   5.4 (Berkeley) 6/18/88";
                     20: #endif /* not lint */
                     21: 
                     22: # include      "monop.ext"
                     23: 
                     24: static char    *names[N_MON+2],
                     25:                cur_prop[80];
                     26: 
                     27: static MON     *monops[N_MON];
                     28: 
                     29: /*
                     30:  *     These routines deal with buying and selling houses
                     31:  */
                     32: buy_houses() {
                     33: 
                     34:        reg int num_mon;
                     35:        reg MON *mp;
                     36:        reg OWN *op;
                     37:        bool    good,got_morg;
                     38:        int     i,p;
                     39: 
                     40: over:
                     41:        num_mon = 0;
                     42:        good = TRUE;
                     43:        got_morg = FALSE;
                     44:        for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
                     45:                continue;
                     46:        while (op)
                     47:                if (op->sqr->desc->monop) {
                     48:                        mp = op->sqr->desc->mon_desc;
                     49:                        names[num_mon] = (monops[num_mon]=mp)->name;
                     50:                        num_mon++;
                     51:                        got_morg = good = FALSE;
                     52:                        for (i = 0; i < mp->num_in; i++) {
                     53:                                if (op->sqr->desc->morg)
                     54:                                        got_morg++;
                     55:                                if (op->sqr->desc->houses != 5)
                     56:                                        good++;
                     57:                                op = op->next;
                     58:                        }
                     59:                        if (!good || got_morg)
                     60:                                --num_mon;
                     61:                }
                     62:                else
                     63:                        op = op->next;
                     64:        if (num_mon == 0) {
                     65:                if (got_morg)
                     66:                        printf("You can't build on mortgaged monopolies.\n");
                     67:                else if (!good)
                     68:                        printf("You can't build any more.\n");
                     69:                else
                     70:                        printf("But you don't have any monopolies!!\n");
                     71:                return;
                     72:        }
                     73:        if (num_mon == 1)
                     74:                buy_h(monops[0]);
                     75:        else {
                     76:                names[num_mon++] = "done";
                     77:                names[num_mon--] = 0;
                     78:                if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
                     79:                        return;
                     80:                buy_h(monops[p]);
                     81:                goto over;
                     82:        }
                     83: }
                     84: 
                     85: buy_h(mnp)
                     86: MON    *mnp; {
                     87: 
                     88:        reg int i;
                     89:        reg MON *mp;
                     90:        reg int price;
                     91:        shrt    input[3],temp[3];
                     92:        int     tot;
                     93:        PROP    *pp;
                     94: 
                     95:        mp = mnp;
                     96:        price = mp->h_cost * 50;
                     97: blew_it:
                     98:        list_cur(mp);
                     99:        printf("Houses will cost $%d\n", price);
                    100:        printf("How many houses do you wish to buy for\n");
                    101:        for (i = 0; i < mp->num_in; i++) {
                    102:                pp = mp->sq[i]->desc;
                    103: over:
                    104:                if (pp->houses == 5) {
                    105:                        printf("%s (H):\n", mp->sq[i]->name);
                    106:                        input[i] = 0;
                    107:                        temp[i] = 5;
                    108:                        continue;
                    109:                }
                    110:                (void)sprintf(cur_prop, "%s (%d): ",
                    111:                        mp->sq[i]->name, pp->houses);
                    112:                input[i] = get_int(cur_prop);
                    113:                temp[i] = input[i] + pp->houses;
                    114:                if (temp[i] > 5) {
                    115:                        printf("That's too many.  The most you can buy is %d\n",
                    116:                                5 - pp->houses);
                    117:                                goto over;
                    118:                        }
                    119:        }
                    120:        if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
                    121:            abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
                    122: err:           printf("That makes the spread too wide.  Try again\n");
                    123:                goto blew_it;
                    124:        }
                    125:        else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
                    126:                goto err;
                    127:        for (tot = i = 0; i < mp->num_in; i++)
                    128:                tot += input[i];
                    129:        if (tot) {
                    130:                printf("You asked for %d houses for $%d\n", tot, tot * price);
                    131:                if (getyn("Is that ok? ", yn) == 0) {
                    132:                        cur_p->money -= tot * price;
                    133:                        for (tot = i = 0; i < mp->num_in; i++)
                    134:                                mp->sq[i]->desc->houses = temp[i];
                    135:                }
                    136:        }
                    137: }
                    138: 
                    139: /*
                    140:  *     This routine sells houses.
                    141:  */
                    142: sell_houses() {
                    143: 
                    144:        reg int num_mon;
                    145:        reg MON *mp;
                    146:        reg OWN *op;
                    147:        bool    good;
                    148:        int     p;
                    149: 
                    150: over:
                    151:        num_mon = 0;
                    152:        good = TRUE;
                    153:        for (op = cur_p->own_list; op; op = op->next)
                    154:                if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
                    155:                        mp = op->sqr->desc->mon_desc;
                    156:                        names[num_mon] = (monops[num_mon]=mp)->name;
                    157:                        num_mon++;
                    158:                        good = 0;
                    159:                        do
                    160:                                if (!good && op->sqr->desc->houses != 0)
                    161:                                        good++;
                    162:                        while (op->next && op->sqr->desc->mon_desc == mp
                    163:                            && (op=op->next));
                    164:                        if (!good)
                    165:                                --num_mon;
                    166:                }
                    167:        if (num_mon == 0) {
                    168:                printf("You don't have any houses to sell!!\n");
                    169:                return;
                    170:        }
                    171:        if (num_mon == 1)
                    172:                sell_h(monops[0]);
                    173:        else {
                    174:                names[num_mon++] = "done";
                    175:                names[num_mon--] = 0;
                    176:                if ((p=getinp("Which property do you wish to sell houses from? ", names)) == num_mon)
                    177:                        return;
                    178:                sell_h(monops[p]);
                    179:                notify();
                    180:                goto over;
                    181:        }
                    182: }
                    183: 
                    184: sell_h(mnp)
                    185: MON    *mnp; {
                    186: 
                    187:        reg int i;
                    188:        reg MON *mp;
                    189:        reg int price;
                    190:        shrt    input[3],temp[3];
                    191:        int     tot;
                    192:        PROP    *pp;
                    193: 
                    194:        mp = mnp;
                    195:        price = mp->h_cost * 25;
                    196: blew_it:
                    197:        printf("Houses will get you $%d apiece\n", price);
                    198:        list_cur(mp);
                    199:        printf("How many houses do you wish to sell from\n");
                    200:        for (i = 0; i < mp->num_in; i++) {
                    201:                pp = mp->sq[i]->desc;
                    202: over:
                    203:                if (pp->houses == 0) {
                    204:                        printf("%s (0):\n", mp->sq[i]->name);
                    205:                        input[i] = temp[i] = 0;
                    206:                        continue;
                    207:                }
                    208:                if (pp->houses < 5)
                    209:                        (void)sprintf(cur_prop,"%s (%d): ",
                    210:                                mp->sq[i]->name,pp->houses);
                    211:                else
                    212:                        (void)sprintf(cur_prop,"%s (H): ",mp->sq[i]->name);
                    213:                input[i] = get_int(cur_prop);
                    214:                temp[i] = pp->houses - input[i];
                    215:                if (temp[i] < 0) {
                    216:                        printf("That's too many.  The most you can sell is %d\n", pp->houses);
                    217:                                goto over;
                    218:                        }
                    219:        }
                    220:        if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
                    221:            abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
                    222: err:           printf("That makes the spread too wide.  Try again\n");
                    223:                goto blew_it;
                    224:        }
                    225:        else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
                    226:                goto err;
                    227:        for (tot = i = 0; i < mp->num_in; i++)
                    228:                tot += input[i];
                    229:        if (tot) {
                    230:                printf("You asked to sell %d houses for $%d\n",tot,tot * price);
                    231:                if (getyn("Is that ok? ", yn) == 0) {
                    232:                        cur_p->money += tot * price;
                    233:                        for (tot = i = 0; i < mp->num_in; i++)
                    234:                                mp->sq[i]->desc->houses = temp[i];
                    235:                }
                    236:        }
                    237: }
                    238: 
                    239: list_cur(mp)
                    240: reg MON        *mp; {
                    241: 
                    242:        reg int         i;
                    243:        reg SQUARE      *sqp;
                    244: 
                    245:        for (i = 0; i < mp->num_in; i++) {
                    246:                sqp = mp->sq[i];
                    247:                if (sqp->desc->houses == 5)
                    248:                        printf("%s (H) ", sqp->name);
                    249:                else
                    250:                        printf("%s (%d) ", sqp->name, sqp->desc->houses);
                    251:        }
                    252:        putchar('\n');
                    253: }

unix.superglobalmegacorp.com

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