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