]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - monop/prop.c
cgram: add advanced cursor movement with tab, shift+tab, return
[bsdgames-darwin.git] / monop / prop.c
index 86c15958121a5b3e804bf64f55e1d405dca632b1..0b6bef81dd0eb2efa1606e4281503882c380e460 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: prop.c,v 1.20 2012/06/19 05:35:32 dholland Exp $       */
+
 /*
- * Copyright (c) 1980 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-static char sccsid[] = "@(#)prop.c     5.6 (Berkeley) 6/1/90";
+#if 0
+static char sccsid[] = "@(#)prop.c     8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: prop.c,v 1.20 2012/06/19 05:35:32 dholland Exp $");
+#endif
 #endif /* not lint */
 
-# include      "monop.ext"
+#include <stdlib.h>
+
+#include "monop.h"
 
-extern char *calloc();
+static int value(SQUARE *);
 
 /*
  *     This routine deals with buying property, setting all the
  * appropriate flags.
  */
-buy(player, sqrp)
-reg int                player;
-reg SQUARE     *sqrp; {
-
+void
+buy(int playernum, SQUARE *sqrp)
+{
        trading = FALSE;
-       sqrp->owner = player;
-       add_list(player, &(play[player].own_list), cur_p->loc);
+       sqrp->owner = playernum;
+       add_list(playernum, &(play[playernum].own_list), cur_p->loc);
 }
+
 /*
  *     This routine adds an item to the list.
  */
-add_list(plr, head, op_sqr)
-int    plr;
-OWN    **head;
-int    op_sqr; {
+void
+add_list(int plr, OWN **head, int op_sqr)
+{
+       int val;
+       OWN *tp, *last_tp;
+       OWN *op;
 
-       reg int val;
-       reg OWN *tp, *last_tp;
-       MON     *mp;
-       OWN     *op;
-
-       op = (OWN *)calloc(1, sizeof (OWN));
+       op = calloc(1, sizeof (OWN));
+       if (op == NULL)
+               errx(1, "out of memory");
        op->sqr = &board[op_sqr];
        val = value(op->sqr);
        last_tp = NULL;
        for (tp = *head; tp && value(tp->sqr) < val; tp = tp->next)
                if (val == value(tp->sqr)) {
-                       cfree(op);
+                       free(op);
                        return;
                }
                else
@@ -83,16 +87,14 @@ int op_sqr; {
        if (!trading)
                set_ownlist(plr);
 }
+
 /*
  *     This routine deletes property from the list.
  */
-del_list(plr, head, op_sqr)
-int    plr;
-OWN    **head;
-shrt   op_sqr; {
-
-       reg int i;
-       reg OWN *op, *last_op;
+void
+del_list(int plr, OWN **head, short op_sqr)
+{
+       OWN *op, *last_op;
 
        switch (board[op_sqr].type) {
          case PRPTY:
@@ -111,21 +113,24 @@ shrt      op_sqr; {
                        break;
                else
                        last_op = op;
+       if (op == NULL)
+               return;
        if (last_op == NULL)
                *head = op->next;
        else {
                last_op->next = op->next;
-               cfree(op);
+               free(op);
        }
 }
+
 /*
  *     This routine calculates the value for sorting of the
  * given square.
  */
-value(sqp)
-reg SQUARE     *sqp; {
-
-       reg int sqr;
+static int
+value(SQUARE *sqp)
+{
+       int sqr;
 
        sqr = sqnum(sqp);
        switch (sqp->type) {
@@ -144,16 +149,17 @@ reg SQUARE        *sqp; {
                return 8 + (sqp->desc) - prop;
        }
 }
+
 /*
- *     This routine accepts bids for the current peice
- * of property.
+ * This routine accepts bids for the current piece of property.
  */
-bid() {
-
-       static bool     in[MAX_PL];
-       reg int         i, num_in, cur_max;
-       char            buf[80];
-       int             cur_bid;
+void
+bid(void)
+{
+       static bool in[MAX_PL];
+       int i, num_in, cur_max;
+       char buf[257];
+       int cur_bid;
 
        printf("\nSo it goes up for auction.  Type your bid after your name\n");
        for (i = 0; i < num_play; i++)
@@ -162,19 +168,24 @@ bid() {
        cur_max = 0;
        num_in = num_play;
        while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
-               i = ++i % num_play;
+               i = (i + 1) % num_play;
                if (in[i]) {
                        do {
-                               (void)sprintf(buf, "%s: ", name_list[i]);
+                               (void)snprintf(buf, sizeof(buf), "%s: ",
+                                   name_list[i]);
                                cur_bid = get_int(buf);
                                if (cur_bid == 0) {
                                        in[i] = FALSE;
                                        if (--num_in == 0)
                                                break;
-                               }
-                               else if (cur_bid <= cur_max) {
-                                       printf("You must bid higher than %d to stay in\n", cur_max);
+                               } else if (cur_bid <= cur_max) {
+                                       printf("You must bid higher than %d "
+                                           "to stay in\n", cur_max);
                                        printf("(bid of 0 drops you out)\n");
+                               } else if (cur_bid > play[i].money) {
+                                       printf("You can't bid more than your cash ($%d)\n",
+                                           play[i].money);
+                                       cur_bid = -1;
                                }
                        } while (cur_bid != 0 && cur_bid <= cur_max);
                        cur_max = (cur_bid ? cur_bid : cur_max);
@@ -182,23 +193,25 @@ bid() {
        }
        if (cur_max != 0) {
                while (!in[i])
-                       i = ++i % num_play;
+                       i = (i + 1) % num_play;
                printf("It goes to %s (%d) for $%d\n",play[i].name,i+1,cur_max);
                buy(i, &board[cur_p->loc]);
                play[i].money -= cur_max;
        }
        else
-               printf("Nobody seems to want it, so we'll leave it for later\n");
+               printf("Nobody seems to want it, so we'll leave it for "
+                   "later\n");
 }
+
 /*
  *     This routine calculates the value of the property
  * of given player.
  */
-prop_worth(plp)
-reg PLAY       *plp; {
-
-       reg OWN *op;
-       reg int worth;
+int
+prop_worth(PLAY *plp)
+{
+       OWN *op;
+       int worth;
 
        worth = 0;
        for (op = plp->own_list; op; op = op->next) {