home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / games / monop / prop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-04-08  |  5.1 KB  |  212 lines

  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, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  */
  33.  
  34. #ifndef lint
  35. static char sccsid[] = "@(#)prop.c    5.6 (Berkeley) 6/1/90";
  36. #endif /* not lint */
  37.  
  38. # include    "monop.ext"
  39.  
  40. extern char *calloc();
  41.  
  42. /*
  43.  *    This routine deals with buying property, setting all the
  44.  * appropriate flags.
  45.  */
  46. buy(player, sqrp)
  47. reg int        player;
  48. reg 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. add_list(plr, head, op_sqr)
  58. int    plr;
  59. OWN    **head;
  60. int    op_sqr; {
  61.  
  62.     reg int    val;
  63.     reg OWN    *tp, *last_tp;
  64.     MON    *mp;
  65.     OWN    *op;
  66.  
  67.     op = (OWN *)calloc(1, sizeof (OWN));
  68.     op->sqr = &board[op_sqr];
  69.     val = value(op->sqr);
  70.     last_tp = NULL;
  71.     for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
  72.         if (val == value(tp->sqr)) {
  73.             cfree(op);
  74.             return;
  75.         }
  76.         else
  77.             last_tp = tp;
  78.     op->next = tp;
  79.     if (last_tp != NULL)
  80.         last_tp->next = op;
  81.     else
  82.         *head = op;
  83.     if (!trading)
  84.         set_ownlist(plr);
  85. }
  86. /*
  87.  *    This routine deletes property from the list.
  88.  */
  89. del_list(plr, head, op_sqr)
  90. int    plr;
  91. OWN    **head;
  92. shrt    op_sqr; {
  93.  
  94.     reg int    i;
  95.     reg OWN    *op, *last_op;
  96.  
  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.         cfree(op);
  119.     }
  120. }
  121. /*
  122.  *    This routine calculates the value for sorting of the
  123.  * given square.
  124.  */
  125. value(sqp)
  126. reg SQUARE    *sqp; {
  127.  
  128.     reg int    sqr;
  129.  
  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. bid() {
  152.  
  153.     static bool    in[MAX_PL];
  154.     reg int        i, num_in, cur_max;
  155.     char        buf[80];
  156.     int        cur_bid;
  157.  
  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 % 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 to stay in\n", cur_max);
  177.                     printf("(bid of 0 drops you out)\n");
  178.                 }
  179.             } while (cur_bid != 0 && cur_bid <= cur_max);
  180.             cur_max = (cur_bid ? cur_bid : cur_max);
  181.         }
  182.     }
  183.     if (cur_max != 0) {
  184.         while (!in[i])
  185.             i = ++i % num_play;
  186.         printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
  187.         buy(i, &board[cur_p->loc]);
  188.         play[i].money -= cur_max;
  189.     }
  190.     else
  191.         printf("Nobody seems to want it, so we'll leave it for later\n");
  192. }
  193. /*
  194.  *    This routine calculates the value of the property
  195.  * of given player.
  196.  */
  197. prop_worth(plp)
  198. reg PLAY    *plp; {
  199.  
  200.     reg OWN    *op;
  201.     reg int    worth;
  202.  
  203.     worth = 0;
  204.     for (op = plp->own_list; op; op = op->next) {
  205.         if (op->sqr->type == PRPTY && op->sqr->desc->monop)
  206.             worth += op->sqr->desc->mon_desc->h_cost * 50 *
  207.                 op->sqr->desc->houses;
  208.         worth += op->sqr->cost;
  209.     }
  210.     return worth;
  211. }
  212.