NetBSD/games/monop/prop.c

231 lines
5.1 KiB
C
Raw Normal View History

2006-03-19 03:18:47 +03:00
/* $NetBSD: prop.c,v 1.11 2006/03/19 00:18:47 christos Exp $ */
1993-03-21 12:45:37 +03:00
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 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. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
1997-10-12 21:45:06 +04:00
#include <sys/cdefs.h>
1993-03-21 12:45:37 +03:00
#ifndef lint
#if 0
static char sccsid[] = "@(#)prop.c 8.1 (Berkeley) 5/31/93";
#else
2006-03-19 03:18:47 +03:00
__RCSID("$NetBSD: prop.c,v 1.11 2006/03/19 00:18:47 christos Exp $");
#endif
1993-03-21 12:45:37 +03:00
#endif /* not lint */
1997-10-12 21:45:06 +04:00
#include <stdlib.h>
#include "monop.ext"
1993-03-21 12:45:37 +03:00
2004-01-27 23:30:28 +03:00
static int value(SQUARE *);
1993-03-21 12:45:37 +03:00
/*
* This routine deals with buying property, setting all the
* appropriate flags.
*/
1997-10-12 21:45:06 +04:00
void
1993-03-21 12:45:37 +03:00
buy(player, sqrp)
1999-08-21 14:40:03 +04:00
int player;
SQUARE *sqrp;
1997-10-12 21:45:06 +04:00
{
1993-03-21 12:45:37 +03:00
trading = FALSE;
sqrp->owner = player;
add_list(player, &(play[player].own_list), cur_p->loc);
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine adds an item to the list.
*/
1997-10-12 21:45:06 +04:00
void
1993-03-21 12:45:37 +03:00
add_list(plr, head, op_sqr)
1999-08-21 14:40:03 +04:00
int plr;
OWN **head;
int op_sqr;
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
int val;
OWN *tp, *last_tp;
OWN *op;
1993-03-21 12:45:37 +03:00
op = (OWN *)calloc(1, sizeof (OWN));
if (op == NULL)
errx(1, "out of memory");
1993-03-21 12:45:37 +03:00
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)) {
1997-10-12 21:45:06 +04:00
free(op);
1993-03-21 12:45:37 +03:00
return;
}
else
last_tp = tp;
op->next = tp;
if (last_tp != NULL)
last_tp->next = op;
else
*head = op;
if (!trading)
set_ownlist(plr);
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine deletes property from the list.
*/
1997-10-12 21:45:06 +04:00
void
1993-03-21 12:45:37 +03:00
del_list(plr, head, op_sqr)
1999-08-21 14:40:03 +04:00
int plr;
OWN **head;
short op_sqr;
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
OWN *op, *last_op;
1993-03-21 12:45:37 +03:00
switch (board[op_sqr].type) {
case PRPTY:
board[op_sqr].desc->mon_desc->num_own--;
break;
case RR:
play[plr].num_rr--;
break;
case UTIL:
play[plr].num_util--;
break;
}
last_op = NULL;
for (op = *head; op; op = op->next)
if (op->sqr == &board[op_sqr])
break;
else
last_op = op;
2006-03-19 03:18:47 +03:00
if (op == NULL)
2006-03-19 03:05:05 +03:00
return;
1993-03-21 12:45:37 +03:00
if (last_op == NULL)
*head = op->next;
else {
last_op->next = op->next;
1997-10-12 21:45:06 +04:00
free(op);
1993-03-21 12:45:37 +03:00
}
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine calculates the value for sorting of the
* given square.
*/
1997-10-12 21:45:06 +04:00
static int
1993-03-21 12:45:37 +03:00
value(sqp)
1999-08-21 14:40:03 +04:00
SQUARE *sqp;
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
int sqr;
1993-03-21 12:45:37 +03:00
sqr = sqnum(sqp);
switch (sqp->type) {
case SAFE:
return 0;
default: /* Specials, etc */
return 1;
case UTIL:
if (sqr == 12)
return 2;
else
return 3;
case RR:
return 4 + sqr/10;
case PRPTY:
return 8 + (sqp->desc) - prop;
}
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine accepts bids for the current peice
* of property.
*/
1997-10-12 21:45:06 +04:00
void
bid()
{
1999-08-21 14:40:03 +04:00
static bool in[MAX_PL];
int i, num_in, cur_max;
char buf[80];
int cur_bid;
1993-03-21 12:45:37 +03:00
printf("\nSo it goes up for auction. Type your bid after your name\n");
for (i = 0; i < num_play; i++)
in[i] = TRUE;
i = -1;
cur_max = 0;
num_in = num_play;
while (num_in > 1 || (cur_max == 0 && num_in > 0)) {
i = (i + 1) % num_play;
1993-03-21 12:45:37 +03:00
if (in[i]) {
do {
(void)sprintf(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) {
1999-08-21 14:40:03 +04:00
printf("You must bid higher than %d "
"to stay in\n", cur_max);
1993-03-21 12:45:37 +03:00
printf("(bid of 0 drops you out)\n");
}
} while (cur_bid != 0 && cur_bid <= cur_max);
cur_max = (cur_bid ? cur_bid : cur_max);
}
}
if (cur_max != 0) {
while (!in[i])
i = (i + 1) % num_play;
1993-03-21 12:45:37 +03:00
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
1999-08-21 14:40:03 +04:00
printf("Nobody seems to want it, so we'll leave it for "
"later\n");
1993-03-21 12:45:37 +03:00
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine calculates the value of the property
* of given player.
*/
1997-10-12 21:45:06 +04:00
int
1993-03-21 12:45:37 +03:00
prop_worth(plp)
1999-08-21 14:40:03 +04:00
PLAY *plp;
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
OWN *op;
int worth;
1993-03-21 12:45:37 +03:00
worth = 0;
for (op = plp->own_list; op; op = op->next) {
if (op->sqr->type == PRPTY && op->sqr->desc->monop)
worth += op->sqr->desc->mon_desc->h_cost * 50 *
op->sqr->desc->houses;
worth += op->sqr->cost;
}
return worth;
}