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

unix.superglobalmegacorp.com

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