|
|
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[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90"; ! 22: #endif /* not lint */ ! 23: ! 24: # include "monop.ext" ! 25: ! 26: struct trd_st { /* how much to give to other player */ ! 27: int trader; /* trader number */ ! 28: int cash; /* amount of cash */ ! 29: int gojf; /* # get-out-of-jail-free cards */ ! 30: OWN *prop_list; /* property list */ ! 31: }; ! 32: ! 33: typedef struct trd_st TRADE; ! 34: ! 35: static char *list[MAX_PRP+2]; ! 36: ! 37: static int used[MAX_PRP]; ! 38: ! 39: static TRADE trades[2]; ! 40: ! 41: trade() { ! 42: ! 43: reg int tradee, i; ! 44: ! 45: trading = TRUE; ! 46: for (i = 0; i < 2; i++) { ! 47: trades[i].cash = 0; ! 48: trades[i].gojf = FALSE; ! 49: trades[i].prop_list = NULL; ! 50: } ! 51: over: ! 52: if (num_play == 1) { ! 53: printf("There ain't no-one around to trade WITH!!\n"); ! 54: return; ! 55: } ! 56: if (num_play > 2) { ! 57: tradee = getinp("Which player do you wish to trade with? ", ! 58: name_list); ! 59: if (tradee == num_play) ! 60: return; ! 61: if (tradee == player) { ! 62: printf("You can't trade with yourself!\n"); ! 63: goto over; ! 64: } ! 65: } ! 66: else ! 67: tradee = 1 - player; ! 68: get_list(0, player); ! 69: get_list(1, tradee); ! 70: if (getyn("Do you wish a summary? ") == 0) ! 71: summate(); ! 72: if (getyn("Is the trade ok? ") == 0) ! 73: do_trade(); ! 74: } ! 75: /* ! 76: * This routine gets the list of things to be trader for the ! 77: * player, and puts in the structure given. ! 78: */ ! 79: get_list(struct_no, play_no) ! 80: int struct_no, play_no; { ! 81: ! 82: reg int sn, pn; ! 83: reg PLAY *pp; ! 84: int numin, prop, num_prp; ! 85: OWN *op; ! 86: TRADE *tp; ! 87: ! 88: for (numin = 0; numin < MAX_PRP; numin++) ! 89: used[numin] = FALSE; ! 90: sn = struct_no, pn = play_no; ! 91: pp = &play[pn]; ! 92: tp = &trades[sn]; ! 93: tp->trader = pn; ! 94: printf("player %s (%d):\n", pp->name, pn+1); ! 95: if (pp->own_list) { ! 96: numin = set_list(pp->own_list); ! 97: for (num_prp = numin; num_prp; ) { ! 98: prop = getinp("Which property do you wish to trade? ", ! 99: list); ! 100: if (prop == numin) ! 101: break; ! 102: else if (used[prop]) ! 103: printf("You've already allocated that.\n"); ! 104: else { ! 105: num_prp--; ! 106: used[prop] = TRUE; ! 107: for (op = pp->own_list; prop--; op = op->next) ! 108: continue; ! 109: add_list(pn, &(tp->prop_list), sqnum(op->sqr)); ! 110: } ! 111: } ! 112: } ! 113: if (pp->money > 0) { ! 114: printf("You have $%d. ", pp->money); ! 115: tp->cash = get_int("How much are you trading? "); ! 116: } ! 117: if (pp->num_gojf > 0) { ! 118: once_more: ! 119: printf("You have %d get-out-of-jail-free cards. ",pp->num_gojf); ! 120: tp->gojf = get_int("How many are you trading? "); ! 121: if (tp->gojf > pp->num_gojf) { ! 122: printf("You don't have that many. Try again.\n"); ! 123: goto once_more; ! 124: } ! 125: } ! 126: } ! 127: /* ! 128: * This routine sets up the list of tradable property. ! 129: */ ! 130: set_list(the_list) ! 131: reg OWN *the_list; { ! 132: ! 133: reg int i; ! 134: reg OWN *op; ! 135: ! 136: i = 0; ! 137: for (op = the_list; op; op = op->next) ! 138: if (!used[i]) ! 139: list[i++] = op->sqr->name; ! 140: list[i++] = "done"; ! 141: list[i--] = 0; ! 142: return i; ! 143: } ! 144: /* ! 145: * This routine summates the trade. ! 146: */ ! 147: summate() { ! 148: ! 149: reg bool some; ! 150: reg int i; ! 151: reg TRADE *tp; ! 152: OWN *op; ! 153: ! 154: for (i = 0; i < 2; i++) { ! 155: tp = &trades[i]; ! 156: some = FALSE; ! 157: printf("Player %s (%d) gives:\n", play[tp->trader].name, ! 158: tp->trader+1); ! 159: if (tp->cash > 0) ! 160: printf("\t$%d\n", tp->cash), some++; ! 161: if (tp->gojf > 0) ! 162: printf("\t%d get-out-of-jail-free card(s)\n", tp->gojf), ! 163: some++; ! 164: if (tp->prop_list) { ! 165: for (op = tp->prop_list; op; op = op->next) ! 166: putchar('\t'), printsq(sqnum(op->sqr), TRUE); ! 167: some++; ! 168: } ! 169: if (!some) ! 170: printf("\t-- Nothing --\n"); ! 171: } ! 172: } ! 173: /* ! 174: * This routine actually executes the trade. ! 175: */ ! 176: do_trade() { ! 177: ! 178: move_em(&trades[0], &trades[1]); ! 179: move_em(&trades[1], &trades[0]); ! 180: } ! 181: /* ! 182: * This routine does a switch from one player to another ! 183: */ ! 184: move_em(from, to) ! 185: TRADE *from, *to; { ! 186: ! 187: reg PLAY *pl_fr, *pl_to; ! 188: reg OWN *op; ! 189: ! 190: pl_fr = &play[from->trader]; ! 191: pl_to = &play[to->trader]; ! 192: ! 193: pl_fr->money -= from->cash; ! 194: pl_to->money += from->cash; ! 195: pl_fr->num_gojf -= from->gojf; ! 196: pl_to->num_gojf += from->gojf; ! 197: for (op = from->prop_list; op; op = op->next) { ! 198: add_list(to->trader, &(pl_to->own_list), sqnum(op->sqr)); ! 199: op->sqr->owner = to->trader; ! 200: del_list(from->trader, &(pl_fr->own_list), sqnum(op->sqr)); ! 201: } ! 202: set_ownlist(to->trader); ! 203: } ! 204: /* ! 205: * This routine lets a player resign ! 206: */ ! 207: resign() { ! 208: ! 209: reg int i, new_own; ! 210: reg OWN *op; ! 211: SQUARE *sqp; ! 212: ! 213: if (cur_p->money <= 0) { ! 214: switch (board[cur_p->loc].type) { ! 215: case UTIL: ! 216: case RR: ! 217: case PRPTY: ! 218: new_own = board[cur_p->loc].owner; ! 219: break; ! 220: default: /* Chance, taxes, etc */ ! 221: new_own = num_play; ! 222: break; ! 223: } ! 224: if (new_own == num_play) ! 225: printf("You would resign to the bank\n"); ! 226: else ! 227: printf("You would resign to %s\n", name_list[new_own]); ! 228: } ! 229: else if (num_play == 1) { ! 230: new_own = num_play; ! 231: printf("You would resign to the bank\n"); ! 232: } ! 233: else { ! 234: name_list[num_play] = "bank"; ! 235: do { ! 236: new_own = getinp("Who do you wish to resign to? ", ! 237: name_list); ! 238: if (new_own == player) ! 239: printf("You can't resign to yourself!!\n"); ! 240: } while (new_own == player); ! 241: name_list[num_play] = "done"; ! 242: } ! 243: if (getyn("Do you really want to resign? ", yn) != 0) ! 244: return; ! 245: if (num_play == 1) { ! 246: printf("Then NOBODY wins (not even YOU!)\n"); ! 247: exit(0); ! 248: } ! 249: if (new_own < num_play) { /* resign to player */ ! 250: printf("resigning to player\n"); ! 251: trades[0].trader = new_own; ! 252: trades[0].cash = trades[0].gojf = 0; ! 253: trades[0].prop_list = NULL; ! 254: trades[1].trader = player; ! 255: trades[1].cash = cur_p->money > 0 ? cur_p->money : 0; ! 256: trades[1].gojf = cur_p->num_gojf; ! 257: trades[1].prop_list = cur_p->own_list; ! 258: do_trade(); ! 259: } ! 260: else { /* resign to bank */ ! 261: printf("resigning to bank\n"); ! 262: for (op = cur_p->own_list; op; op = op->next) { ! 263: sqp = op->sqr; ! 264: sqp->owner = -1; ! 265: sqp->desc->morg = FALSE; ! 266: if (sqp->type == PRPTY) { ! 267: isnot_monop(sqp->desc->mon_desc); ! 268: sqp->desc->houses = 0; ! 269: } ! 270: } ! 271: if (cur_p->num_gojf) ! 272: ret_card(cur_p); ! 273: } ! 274: for (i = player; i < num_play; i++) { ! 275: name_list[i] = name_list[i+1]; ! 276: if (i + 1 < num_play) ! 277: cpy_st(&play[i], &play[i+1], sizeof (PLAY)); ! 278: } ! 279: name_list[num_play--] = 0; ! 280: for (i = 0; i < N_SQRS; i++) ! 281: if (board[i].owner > player) ! 282: --board[i].owner; ! 283: player = --player < 0 ? num_play - 1 : player; ! 284: next_play(); ! 285: if (num_play < 2) { ! 286: printf("\nThen %s WINS!!!!!\n", play[0].name); ! 287: printhold(0); ! 288: printf("That's a grand worth of $%d.\n", ! 289: play[0].money+prop_worth(&play[0])); ! 290: exit(0); ! 291: } ! 292: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.