morg.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* $NetBSD: morg.c,v 1.10 2004/01/27 20:30:30 jsm Exp $ */
  2. /*
  3. * Copyright (c) 1980, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #include <sys/cdefs.h>
  31. #ifndef lint
  32. #if 0
  33. static char sccsid[] = "@(#)morg.c 8.1 (Berkeley) 5/31/93";
  34. #else
  35. __RCSID("$NetBSD: morg.c,v 1.10 2004/01/27 20:30:30 jsm Exp $");
  36. #endif
  37. #endif /* not lint */
  38. #include "monop.ext"
  39. /*
  40. * These routines deal with mortgaging.
  41. */
  42. static const char *names[MAX_PRP+2],
  43. *const morg_coms[] = {
  44. "quit", /* 0 */
  45. "print", /* 1 */
  46. "where", /* 2 */
  47. "own holdings", /* 3 */
  48. "holdings", /* 4 */
  49. "mortgage", /* 5 */
  50. "unmortgage", /* 6 */
  51. "buy", /* 7 */
  52. "sell", /* 8 */
  53. "card", /* 9 */
  54. "pay", /* 10 */
  55. "trade", /* 11 */
  56. "resign", /* 12 */
  57. "save game", /* 13 */
  58. "restore game", /* 14 */
  59. 0
  60. };
  61. static short square[MAX_PRP+2];
  62. static int num_good,got_houses;
  63. static int set_mlist(void);
  64. static void m(int);
  65. static int set_umlist(void);
  66. static void unm(int);
  67. static void fix_ex(int);
  68. /*
  69. * This routine is the command level response the mortgage command.
  70. * it gets the list of mortgageable property and asks which are to
  71. * be mortgaged.
  72. */
  73. void
  74. mortgage()
  75. {
  76. int prop;
  77. for (;;) {
  78. if (set_mlist() == 0) {
  79. if (got_houses)
  80. printf("You can't mortgage property with "
  81. "houses on it.\n");
  82. else
  83. printf("You don't have any un-mortgaged "
  84. "property.\n");
  85. return;
  86. }
  87. if (num_good == 1) {
  88. printf("Your only mortageable property is %s\n",
  89. names[0]);
  90. if (getyn("Do you want to mortgage it? ") == 0)
  91. m(square[0]);
  92. return;
  93. }
  94. prop = getinp("Which property do you want to mortgage? ",names);
  95. if (prop == num_good)
  96. return;
  97. m(square[prop]);
  98. notify();
  99. }
  100. }
  101. /*
  102. * This routine sets up the list of mortgageable property
  103. */
  104. static int
  105. set_mlist()
  106. {
  107. OWN *op;
  108. num_good = 0;
  109. for (op = cur_p->own_list; op; op = op->next)
  110. if (!op->sqr->desc->morg) {
  111. if (op->sqr->type == PRPTY && op->sqr->desc->houses)
  112. got_houses++;
  113. else {
  114. names[num_good] = op->sqr->name;
  115. square[num_good++] = sqnum(op->sqr);
  116. }
  117. }
  118. names[num_good++] = "done";
  119. names[num_good--] = 0;
  120. return num_good;
  121. }
  122. /*
  123. * This routine actually mortgages the property.
  124. */
  125. static void
  126. m(prop)
  127. int prop;
  128. {
  129. int price;
  130. price = board[prop].cost/2;
  131. board[prop].desc->morg = TRUE;
  132. printf("That got you $%d\n",price);
  133. cur_p->money += price;
  134. }
  135. /*
  136. * This routine is the command level repsponse to the unmortgage
  137. * command. It gets the list of mortgaged property and asks which are
  138. * to be unmortgaged.
  139. */
  140. void
  141. unmortgage()
  142. {
  143. int prop;
  144. for (;;) {
  145. if (set_umlist() == 0) {
  146. printf("You don't have any mortgaged property.\n");
  147. return;
  148. }
  149. if (num_good == 1) {
  150. printf("Your only mortaged property is %s\n",names[0]);
  151. if (getyn("Do you want to unmortgage it? ") == 0)
  152. unm(square[0]);
  153. return;
  154. }
  155. prop = getinp("Which property do you want to unmortgage? ",
  156. names);
  157. if (prop == num_good)
  158. return;
  159. unm(square[prop]);
  160. }
  161. }
  162. /*
  163. * This routine sets up the list of mortgaged property
  164. */
  165. static int
  166. set_umlist()
  167. {
  168. OWN *op;
  169. num_good = 0;
  170. for (op = cur_p->own_list; op; op = op->next)
  171. if (op->sqr->desc->morg) {
  172. names[num_good] = op->sqr->name;
  173. square[num_good++] = sqnum(op->sqr);
  174. }
  175. names[num_good++] = "done";
  176. names[num_good--] = 0;
  177. return num_good;
  178. }
  179. /*
  180. * This routine actually unmortgages the property
  181. */
  182. static void
  183. unm(prop)
  184. int prop;
  185. {
  186. int price;
  187. price = board[prop].cost/2;
  188. board[prop].desc->morg = FALSE;
  189. price += price/10;
  190. printf("That cost you $%d\n",price);
  191. cur_p->money -= price;
  192. set_umlist();
  193. }
  194. /*
  195. * This routine forces the indebted player to fix his
  196. * financial woes.
  197. */
  198. void
  199. force_morg()
  200. {
  201. told_em = fixing = TRUE;
  202. while (cur_p->money <= 0)
  203. fix_ex(getinp("How are you going to fix it up? ",morg_coms));
  204. fixing = FALSE;
  205. }
  206. /*
  207. * This routine is a special execute for the force_morg routine
  208. */
  209. static void
  210. fix_ex(com_num)
  211. int com_num;
  212. {
  213. told_em = FALSE;
  214. (*func[com_num])();
  215. notify();
  216. }