1 /* 2 * Copyright (c) 1980 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)morg.c 5.3 (Berkeley) 06/01/90"; 10 #endif /* not lint */ 11 12 # include "monop.ext" 13 14 /* 15 * These routines deal with mortgaging. 16 */ 17 18 static char *names[MAX_PRP+2], 19 *morg_coms[] = { 20 "quit", /* 0 */ 21 "print", /* 1 */ 22 "where", /* 2 */ 23 "own holdings", /* 3 */ 24 "holdings", /* 4 */ 25 "shell", /* 5 */ 26 "mortgage", /* 6 */ 27 "unmortgage", /* 7 */ 28 "buy", /* 8 */ 29 "sell", /* 9 */ 30 "card", /* 10 */ 31 "pay", /* 11 */ 32 "trade", /* 12 */ 33 "resign", /* 13 */ 34 "save game", /* 14 */ 35 "restore game", /* 15 */ 36 0 37 }; 38 39 static shrt square[MAX_PRP+2]; 40 41 static int num_good,got_houses; 42 43 /* 44 * This routine is the command level response the mortgage command. 45 * it gets the list of mortgageable property and asks which are to 46 * be mortgaged. 47 */ 48 mortgage() { 49 50 reg int prop; 51 52 for (;;) { 53 if (set_mlist() == 0) { 54 if (got_houses) 55 printf("You can't mortgage property with houses on it.\n"); 56 else 57 printf("You don't have any un-mortgaged property.\n"); 58 return; 59 } 60 if (num_good == 1) { 61 printf("Your only mortageable property is %s\n",names[0]); 62 if (getyn("Do you want to mortgage it? ") == 0) 63 m(square[0]); 64 return; 65 } 66 prop = getinp("Which property do you want to mortgage? ",names); 67 if (prop == num_good) 68 return; 69 m(square[prop]); 70 notify(cur_p); 71 } 72 } 73 /* 74 * This routine sets up the list of mortgageable property 75 */ 76 set_mlist() { 77 78 reg OWN *op; 79 80 num_good = 0; 81 for (op = cur_p->own_list; op; op = op->next) 82 if (!op->sqr->desc->morg) 83 if (op->sqr->type == PRPTY && op->sqr->desc->houses) 84 got_houses++; 85 else { 86 names[num_good] = op->sqr->name; 87 square[num_good++] = sqnum(op->sqr); 88 } 89 names[num_good++] = "done"; 90 names[num_good--] = 0; 91 return num_good; 92 } 93 /* 94 * This routine actually mortgages the property. 95 */ 96 m(prop) 97 reg int prop; { 98 99 reg int price; 100 101 price = board[prop].cost/2; 102 board[prop].desc->morg = TRUE; 103 printf("That got you $%d\n",price); 104 cur_p->money += price; 105 } 106 /* 107 * This routine is the command level repsponse to the unmortgage 108 * command. It gets the list of mortgaged property and asks which are 109 * to be unmortgaged. 110 */ 111 unmortgage() { 112 113 reg int prop; 114 115 for (;;) { 116 if (set_umlist() == 0) { 117 printf("You don't have any mortgaged property.\n"); 118 return; 119 } 120 if (num_good == 1) { 121 printf("Your only mortaged property is %s\n",names[0]); 122 if (getyn("Do you want to unmortgage it? ") == 0) 123 unm(square[0]); 124 return; 125 } 126 prop = getinp("Which property do you want to unmortgage? ",names); 127 if (prop == num_good) 128 return; 129 unm(square[prop]); 130 } 131 } 132 /* 133 * This routine sets up the list of mortgaged property 134 */ 135 set_umlist() { 136 137 reg OWN *op; 138 139 num_good = 0; 140 for (op = cur_p->own_list; op; op = op->next) 141 if (op->sqr->desc->morg) { 142 names[num_good] = op->sqr->name; 143 square[num_good++] = sqnum(op->sqr); 144 } 145 names[num_good++] = "done"; 146 names[num_good--] = 0; 147 return num_good; 148 } 149 /* 150 * This routine actually unmortgages the property 151 */ 152 unm(prop) 153 reg int prop; { 154 155 reg int price; 156 157 price = board[prop].cost/2; 158 board[prop].desc->morg = FALSE; 159 price += price/10; 160 printf("That cost you $%d\n",price); 161 cur_p->money -= price; 162 set_umlist(); 163 } 164 /* 165 * This routine forces the indebted player to fix his 166 * financial woes. 167 */ 168 force_morg() { 169 170 told_em = fixing = TRUE; 171 while (cur_p->money <= 0) 172 fix_ex(getinp("How are you going to fix it up? ",morg_coms)); 173 fixing = FALSE; 174 } 175 /* 176 * This routine is a special execute for the force_morg routine 177 */ 178 fix_ex(com_num) 179 reg int com_num; { 180 181 told_em = FALSE; 182 (*func[com_num])(); 183 notify(); 184 } 185