2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * buy.c: Buy commodities from other nations
30 * Known contributors to this file:
33 * Steve McClure, 1996-2000
47 #include "commodity.h"
57 * format: buy <COMMODITY>
81 pr("The market is disabled.\n");
84 natp = getnatp(player->cnum);
85 ip = whatitem(player->argp[1], "Commodity you want to buy: ");
88 display_mark(ip->i_vtype, 0);
90 p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
98 if (!getcomm(o, &comm) || comm.com_owner == 0) {
99 pr("Invalid lot number.\n");
102 if (comm.com_type != ip->i_vtype) {
103 pr("That lot is not of the type you specified.\n");
106 if (comm.com_owner == player->cnum) {
107 pr("You can't bid on your own lot.\n");
110 if ((p = getstarg(player->argp[3], "How much per unit: ", buf)) == 0)
115 if (natp->nat_money < (bid * comm.com_amount * buytax)) {
116 pr("This purchase would cost %.2f, %.2f more than you have.\n",
117 bid * comm.com_amount * buytax,
118 bid * comm.com_amount * buytax - natp->nat_money);
121 /* check to see if all of the bids that this player has out plus this new bid
122 would make him go broke. Ken, I ought to skin you alive for making me code
125 for (q = 0; gettrade(q, &tmpt); q++) {
126 if (tmpt.trd_maxbidder == player->cnum &&
127 tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
128 tally += tmpt.trd_price * tradetax;
131 for (q = 0; getcomm(q, &comt); q++) {
132 if (comt.com_maxbidder == player->cnum &&
133 comt.com_owner != 0 && comt.com_owner != player->cnum) {
134 tally += (comt.com_price * comt.com_amount) * buytax;
137 canspend = natp->nat_money - tally;
139 if ((bid * comm.com_amount * buytax) > canspend) {
140 pr("You have overextended yourself in the market\n");
141 pr("You can not bid on the current items at that price.\n");
144 if (!(p = getstarg(player->argp[4], "destination sector : ", buf)))
146 if (!sarg_xy(p, &x, &y))
148 if (!getsect(x, y, §)) {
149 pr("Could not access sector");
152 if ((sect.sct_type != SCT_WAREH && sect.sct_type != SCT_HARBR) ||
153 sect.sct_own != player->cnum) {
154 pr("The destination sector is not one of your warehouses.\n");
157 if (sect.sct_effic < 60) {
158 pr("That sector is under construction.\n");
161 n = sect.sct_item[ip->i_vtype];
162 qty = comm.com_amount;
163 if (qty + n > ITEM_MAX) {
164 pr("That sector cannot hold %d more %s. It currently holds %d.\n",
168 if ((bid * comm.com_amount) > natp->nat_money) {
169 pr("You don't have that much to spend!\n");
173 if (!ncomm.com_owner) {
174 pr("That lot has been taken off the market.\n");
177 if (bid > 0.04 + comm.com_price) {
178 comm.com_price = bid;
179 /* Add five minutes to the time if less than 5 minutes */
181 if (((MARK_DELAY - (now - comm.com_markettime)) < 300) &&
182 comm.com_maxbidder != player->cnum) {
183 comm.com_markettime += 300;
184 /* Special case - what if so much time has gone by? Well,
185 Just reset the markettime so that only 5 minutes are left */
186 if ((MARK_DELAY - (now - comm.com_markettime)) < 0)
187 comm.com_markettime = (now - (MARK_DELAY - 300));
189 comm.com_maxbidder = player->cnum;
193 pr("Your bid is being considered.\n");
195 pr("Your bid wasn't high enough (you need to bid at least $0.05 higher\n");
196 pr("than the last bid.\n");
221 /* logerror("Checking the market.\n");*/
222 for (n = 0; getcomm(n, &comm); n++) {
223 if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
226 tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.0;
231 if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX))
233 sect = getsectp(comm.com_x, comm.com_y);
234 m = sect->sct_item[comm.com_type];
238 price = comm.com_price * comm.com_amount * buytax;
239 gain = comm.com_price * comm.com_amount;
241 natp = getnatp(comm.com_maxbidder);
242 tmoney = natp->nat_money;
245 if (tmoney < price && tmoney > 0) {
246 monleft = price - (tmoney - 1);
248 price = price - monleft;
249 } else if (tmoney > 0) {
251 tmoney = tmoney - price;
254 /* Subtract the amount of money that needs to come out in a loan. */
258 nreport(comm.com_maxbidder, N_WELCH_DEAL, comm.com_owner, 1);
259 wu(0, comm.com_maxbidder,
260 "You didn't have enough cash/credit to cover the cost.\n");
261 wu(0, comm.com_owner,
262 "Sale #%d fell through. Goods remain on the market.\n", n);
263 comm.com_maxbidder = comm.com_owner;
264 } else if (sect->sct_type != SCT_WAREH
265 && sect->sct_type != SCT_HARBR) {
266 wu(0, comm.com_maxbidder,
267 "Sector not a warehouse now, sale #%d fell though.\n", n);
268 wu(0, comm.com_owner,
269 "Sale #%d fell through. Goods remain on the market.\n", n);
270 comm.com_maxbidder = comm.com_owner;
271 } else if (m + comm.com_amount > ITEM_MAX) {
272 wu(0, comm.com_maxbidder,
273 "Warehouse full, sale #%d fell though.\n", n);
274 wu(0, comm.com_owner,
275 "Sale #%d fell through. Goods remain on the market.\n", n);
276 comm.com_maxbidder = comm.com_owner;
278 sect->sct_item[comm.com_type] = m + comm.com_amount;
280 nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1);
281 wu(0, comm.com_owner, "%s bought %d %s from you for $%.2f\n",
282 cname(comm.com_maxbidder), comm.com_amount,
283 ichr[comm.com_type].i_name, gain);
284 wu(0, comm.com_maxbidder,
285 "You just bought %d %s from %s for $%.2f\n",
286 comm.com_amount, ichr[comm.com_type].i_name,
287 cname(comm.com_owner), gain * buytax);
288 natp = getnatp(comm.com_owner);
289 /* Make sure we subtract the amount that came out in a loan */
290 natp->nat_money += (gain - subleft);
291 natp = getnatp(comm.com_maxbidder);
292 natp->nat_money = tmoney;
298 /* logerror("Done checking the market.\n");*/