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)}
55 {(caddr_t)c_price, sizeof(c_price)}
57 {(caddr_t)c_mult, sizeof(c_mult)}
59 static int nvec = sizeof(commvec) / sizeof(struct iovec);
63 * comm file is the list of "deity commodities"
64 * lying around. Perhaps a better way of doing this
65 * might be at each update seeing what is on sale,
66 * then buying it, then distributing things amongst the
67 * people wanting the items.
69 * Of course that would be a gigantic pain...
77 (void)lseek(commf, (off_t) 0, 0);
79 if ((n = readv(commf, commvec, nvec)) !=
80 sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) {
81 logerror("commread: readv returns %d", n);
85 if ((n = read(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) {
86 logerror("commread: read returns %d, not %d", n, sizeof(c_comm));
89 if ((n = read(commf, c_price, sizeof(c_price))) != sizeof(c_price)) {
90 logerror("commread: read returns %d, not %d", n, sizeof(c_price));
93 if ((n = read(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) {
94 logerror("commread: read returns %d, not %d", n, sizeof(c_mult));
107 (void)lseek(commf, (off_t) 0, 0);
109 if (writev(commf, commvec, nvec) !=
110 sizeof(c_comm) + sizeof(c_price) + sizeof(c_mult)) {
111 logerror("commwrite: writev failed");
115 if ((n = write(commf, c_comm, sizeof(c_comm))) != sizeof(c_comm)) {
116 logerror("commwrite: write returns %d, not %d", n, sizeof(c_comm));
119 if ((n = write(commf, c_price, sizeof(c_price))) != sizeof(c_price)) {
120 logerror("commwrite: write returns %d, not %d", n,
124 if ((n = write(commf, c_mult, sizeof(c_mult))) != sizeof(c_mult)) {
125 logerror("commwrite: write returns %d, not %d", n, sizeof(c_mult));
135 return file_lock(commf);
141 return file_unlock(commf);
145 * returns amount of commodity, and price to the user
148 commamt(natid trader, int product, float *priceval)
150 *priceval = c_price[trader][product] * c_mult[trader][player->cnum];
151 return c_comm[trader][product];
155 commset(natid trader, int product, int amt)
157 c_comm[trader][product] += amt;
161 multread(natid trader, natid tradee)
163 return c_mult[trader][tradee];
167 multset(natid tradee, float newmult)
169 c_mult[player->cnum][tradee] = newmult;
173 commprice(int product, float *newprice)
175 c_price[player->cnum][product] = *newprice;