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