prop.c 5.1 KB

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