2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * comsub.c: Commodity read/write stuff
30 * Known contributors to this file:
39 #include "prototypes.h"
47 int c_comm[MAXNOC][I_MAX+1];
48 float c_price[MAXNOC][I_MAX+1];
49 float c_mult[MAXNOC][MAXNOC];
52 static struct iovec commvec[3] = {
53 { (caddr_t)c_comm, sizeof(c_comm) },
54 { (caddr_t)c_price, sizeof(c_price) },
55 { (caddr_t)c_mult, sizeof(c_mult) }
57 static int nvec = sizeof(commvec)/sizeof(struct iovec);
61 * comm file is the list of "deity commodities"
62 * lying around. Perhaps a better way of doing this
63 * might be at each update seeing what is on sale,
64 * then buying it, then distributing things amongst the
65 * people wanting the items.
67 * Of course that would be a gigantic pain...
75 (void) lseek(commf, (off_t) 0, 0);
77 if ((n = readv(commf, commvec, nvec)) !=
78 sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) {
79 logerror("commread: readv returns %d", n);
83 if ((n = read(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) {
84 logerror("commread: read returns %d, not %d", n, sizeof(c_comm));
87 if ((n = read(commf, c_price, sizeof(c_price))) != sizeof(c_price)) {
88 logerror("commread: read returns %d, not %d", n, sizeof(c_price));
91 if ((n = read(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) {
92 logerror("commread: read returns %d, not %d", n, sizeof(c_mult));
105 (void) lseek(commf, (off_t) 0, 0);
107 if (writev(commf, commvec, nvec) !=
108 sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) {
109 logerror("commwrite: writev failed");
113 if ((n = write(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) {
114 logerror("commwrite: write returns %d, not %d", n, sizeof(c_comm));
117 if ((n = write(commf, c_price, sizeof(c_price))) != sizeof(c_price)) {
118 logerror("commwrite: write returns %d, not %d", n, sizeof(c_price));
121 if ((n = write(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) {
122 logerror("commwrite: write returns %d, not %d", n, sizeof(c_mult));
132 return file_lock(commf);
138 return file_unlock(commf);
142 * returns amount of commodity, and price to the user
145 commamt(natid trader, int product, float *priceval)
147 *priceval = c_price[trader][product] * c_mult[trader][player->cnum];
148 return c_comm[trader][product];
152 commset(natid trader, int product, int amt)
154 c_comm[trader][product] += amt;
158 multread(natid trader, natid tradee)
160 return c_mult[trader][tradee];
164 multset(natid tradee, float newmult)
166 c_mult[player->cnum][tradee] = newmult;
170 commprice(int product, float *newprice)
172 c_price[player->cnum][product] = *newprice;