1*32479Sbostic #ifndef lint 2*32479Sbostic static char sccsid[] = "@(#)prop.c 5.1 (Berkeley) 10/22/87"; 3*32479Sbostic #endif not lint 4*32479Sbostic 5*32479Sbostic # include "monop.ext" 6*32479Sbostic 7*32479Sbostic /* 8*32479Sbostic * This routine deals with buying property, setting all the 9*32479Sbostic * appropriate flags. 10*32479Sbostic */ 11*32479Sbostic buy(player, sqrp) 12*32479Sbostic reg int player; 13*32479Sbostic reg SQUARE *sqrp; { 14*32479Sbostic 15*32479Sbostic trading = FALSE; 16*32479Sbostic sqrp->owner = player; 17*32479Sbostic add_list(player, &(play[player].own_list), cur_p->loc); 18*32479Sbostic } 19*32479Sbostic /* 20*32479Sbostic * This routine adds an item to the list. 21*32479Sbostic */ 22*32479Sbostic add_list(plr, head, op_sqr) 23*32479Sbostic int plr; 24*32479Sbostic OWN **head; 25*32479Sbostic int op_sqr; { 26*32479Sbostic 27*32479Sbostic reg int val; 28*32479Sbostic reg OWN *tp, *last_tp; 29*32479Sbostic MON *mp; 30*32479Sbostic OWN *op; 31*32479Sbostic 32*32479Sbostic op = calloc(1, sizeof (OWN)); 33*32479Sbostic op->sqr = &board[op_sqr]; 34*32479Sbostic val = value(op->sqr); 35*32479Sbostic last_tp = NULL; 36*32479Sbostic for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next) 37*32479Sbostic if (val == value(tp->sqr)) { 38*32479Sbostic cfree(op); 39*32479Sbostic return; 40*32479Sbostic } 41*32479Sbostic else 42*32479Sbostic last_tp = tp; 43*32479Sbostic op->next = tp; 44*32479Sbostic if (last_tp != NULL) 45*32479Sbostic last_tp->next = op; 46*32479Sbostic else 47*32479Sbostic *head = op; 48*32479Sbostic if (!trading) 49*32479Sbostic set_ownlist(plr); 50*32479Sbostic } 51*32479Sbostic /* 52*32479Sbostic * This routine deletes property from the list. 53*32479Sbostic */ 54*32479Sbostic del_list(plr, head, op_sqr) 55*32479Sbostic int plr; 56*32479Sbostic OWN **head; 57*32479Sbostic shrt op_sqr; { 58*32479Sbostic 59*32479Sbostic reg int i; 60*32479Sbostic reg OWN *op, *last_op; 61*32479Sbostic 62*32479Sbostic switch (board[op_sqr].type) { 63*32479Sbostic case PRPTY: 64*32479Sbostic board[op_sqr].desc->mon_desc->num_own--; 65*32479Sbostic break; 66*32479Sbostic case RR: 67*32479Sbostic play[plr].num_rr--; 68*32479Sbostic break; 69*32479Sbostic case UTIL: 70*32479Sbostic play[plr].num_util--; 71*32479Sbostic break; 72*32479Sbostic } 73*32479Sbostic last_op = NULL; 74*32479Sbostic for (op = *head; op; op = op->next) 75*32479Sbostic if (op->sqr == &board[op_sqr]) 76*32479Sbostic break; 77*32479Sbostic else 78*32479Sbostic last_op = op; 79*32479Sbostic if (last_op == NULL) 80*32479Sbostic *head = op->next; 81*32479Sbostic else { 82*32479Sbostic last_op->next = op->next; 83*32479Sbostic cfree(op); 84*32479Sbostic } 85*32479Sbostic } 86*32479Sbostic /* 87*32479Sbostic * This routine calculates the value for sorting of the 88*32479Sbostic * given square. 89*32479Sbostic */ 90*32479Sbostic value(sqp) 91*32479Sbostic reg SQUARE *sqp; { 92*32479Sbostic 93*32479Sbostic reg int sqr; 94*32479Sbostic 95*32479Sbostic sqr = sqnum(sqp); 96*32479Sbostic switch (sqp->type) { 97*32479Sbostic case SAFE: 98*32479Sbostic return 0; 99*32479Sbostic case SPEC: 100*32479Sbostic return 1; 101*32479Sbostic case UTIL: 102*32479Sbostic if (sqr == 12) 103*32479Sbostic return 2; 104*32479Sbostic else 105*32479Sbostic return 3; 106*32479Sbostic case RR: 107*32479Sbostic return 4 + sqr/10; 108*32479Sbostic case PRPTY: 109*32479Sbostic return 8 + (PROP *)(sqp->desc) - prop; 110*32479Sbostic } 111*32479Sbostic } 112*32479Sbostic /* 113*32479Sbostic * This routine accepts bids for the current peice 114*32479Sbostic * of property. 115*32479Sbostic */ 116*32479Sbostic bid() { 117*32479Sbostic 118*32479Sbostic static bool in[MAX_PL]; 119*32479Sbostic reg int i, num_in, cur_max; 120*32479Sbostic char buf[80]; 121*32479Sbostic int cur_bid; 122*32479Sbostic 123*32479Sbostic printf("\nSo it goes up for auction. Type your bid after your name\n"); 124*32479Sbostic for (i = 0; i < num_play; i++) 125*32479Sbostic in[i] = TRUE; 126*32479Sbostic i = -1; 127*32479Sbostic cur_max = 0; 128*32479Sbostic num_in = num_play; 129*32479Sbostic while (num_in > 1 || (cur_max == 0 && num_in > 0)) { 130*32479Sbostic i = ++i % num_play; 131*32479Sbostic if (in[i]) { 132*32479Sbostic do { 133*32479Sbostic sprintf(buf, "%s: ", name_list[i]); 134*32479Sbostic cur_bid = get_int(buf); 135*32479Sbostic if (cur_bid == 0) { 136*32479Sbostic in[i] = FALSE; 137*32479Sbostic if (--num_in == 0) 138*32479Sbostic break; 139*32479Sbostic } 140*32479Sbostic else if (cur_bid <= cur_max) { 141*32479Sbostic printf("You must bid higher than %d to stay in\n", cur_max); 142*32479Sbostic printf("(bid of 0 drops you out)\n"); 143*32479Sbostic } 144*32479Sbostic } while (cur_bid != 0 && cur_bid <= cur_max); 145*32479Sbostic cur_max = (cur_bid ? cur_bid : cur_max); 146*32479Sbostic } 147*32479Sbostic } 148*32479Sbostic if (cur_max != 0) { 149*32479Sbostic while (!in[i]) 150*32479Sbostic i = ++i % num_play; 151*32479Sbostic printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max); 152*32479Sbostic buy(i, &board[cur_p->loc]); 153*32479Sbostic play[i].money -= cur_max; 154*32479Sbostic } 155*32479Sbostic else 156*32479Sbostic printf("Nobody seems to want it, so we'll leave it for later\n"); 157*32479Sbostic } 158*32479Sbostic /* 159*32479Sbostic * This routine calculates the value of the property 160*32479Sbostic * of given player. 161*32479Sbostic */ 162*32479Sbostic prop_worth(plp) 163*32479Sbostic reg PLAY *plp; { 164*32479Sbostic 165*32479Sbostic reg OWN *op; 166*32479Sbostic reg int worth; 167*32479Sbostic 168*32479Sbostic worth = 0; 169*32479Sbostic for (op = plp->own_list; op; op = op->next) { 170*32479Sbostic if (op->sqr->type == PRPTY && op->sqr->desc->monop) 171*32479Sbostic worth += op->sqr->desc->mon_desc->h_cost * 50 * 172*32479Sbostic op->sqr->desc->houses; 173*32479Sbostic worth += op->sqr->cost; 174*32479Sbostic } 175*32479Sbostic return worth; 176*32479Sbostic } 177