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 * buy.c: Buy commodities from other nations
30 * Known contributors to this file:
33 * Steve McClure, 1996-2000
47 #include "commodity.h"
58 * format: buy <COMMODITY>
82 pr("The market is disabled.\n");
85 natp = getnatp(player->cnum);
86 display_mark(player->argp[1]);
88 p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
96 if (!getcomm(o, &comm) || comm.com_owner == 0) {
97 pr("Invalid lot number.\n");
100 if (player->argp[1] && *(player->argp[1]) &&
101 comm.com_type != player->argp[1][0]) {
102 pr("That lot is not of the type you specified.\n");
105 if (comm.com_owner == player->cnum) {
106 pr("You can't bid on your own lot.\n");
109 pr("WARNING! This market issues credit. If you make more\n");
110 pr(" bids than your treasury can cover at the time of sale,\n");
111 pr(" you can potentially go into financial ruin, and see no\n");
112 pr(" gains. You have been warned.\n\n");
113 if ((p = getstarg(player->argp[3], "How much per unit: ", buf)) == 0)
118 if (natp->nat_money < (bid * comm.com_amount * buytax)) {
119 pr("This purchase would cost %.2f, %.2f more than you have.\n",
120 bid * comm.com_amount * buytax,
121 bid * comm.com_amount * buytax - natp->nat_money);
124 /* check to see if all of the bids that this player has out plus this new bid
125 would make him go broke. Ken, I ought to skin you alive for making me code
128 for (q = 0; gettrade(q, &tmpt); q++) {
129 if (tmpt.trd_maxbidder == player->cnum &&
130 tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
131 tally += tmpt.trd_maxprice * tradetax;
134 for (q = 0; getcomm(q, &comt); q++) {
135 if (comt.com_maxbidder == player->cnum &&
136 comt.com_owner != 0 && comt.com_owner != player->cnum) {
137 tally += (comt.com_maxprice * comt.com_amount) * buytax;
140 canspend = natp->nat_money - tally;
142 if ((bid * comm.com_amount * buytax) > canspend) {
143 pr("You have overextended yourself in the market\n");
144 pr("You can not bid on the current items at that price.\n");
147 if (!(p = getstarg(player->argp[4], "destination sector : ", buf)))
149 if (!sarg_xy(p, &x, &y))
151 if (!getsect(x, y, §)) {
152 pr("Could not access sector");
155 if ((sect.sct_type != SCT_WAREH && sect.sct_type != SCT_HARBR) ||
156 sect.sct_own != player->cnum) {
157 pr("The destination sector is not one of your warehouses.\n");
160 if (sect.sct_effic < 60) {
161 pr("That sector is under construction.\n");
164 ip = whichitem(comm.com_type);
165 n = getvar(ip->i_vtype, (char *)§, EF_SECTOR);
166 qty = comm.com_amount;
167 if (qty + n > 9990) {
168 pr("That sector cannot hold %d more %s. It currently holds %d.\n",
172 /* First we check for room, then we yank back. Probably not necessary. */
173 if (putvar(ip->i_vtype, n + qty, (char *)§, EF_SECTOR) <= 0) {
174 pr("No room to store %s in %s\n",
175 ip->i_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
178 if (putvar(ip->i_vtype, n, (char *)§, EF_SECTOR) <= 0) {
179 pr("Something weird just happened, tell the deity.\n");
180 logerror("buy.c: putvar failed.\n");
183 if ((bid * comm.com_amount) > natp->nat_money) {
184 pr("You don't have that much to spend!\n");
188 if (!ncomm.com_owner) {
189 pr("That lot has been taken off the market.\n");
192 if (bid > 0.04 + comm.com_maxprice) {
193 comm.com_maxprice = bid;
194 /* Add five minutes to the time if less than 5 minutes */
196 if (((MARK_DELAY - (now - comm.com_markettime)) < 300) &&
197 comm.com_maxbidder != player->cnum) {
198 comm.com_markettime += 300;
199 /* Special case - what if so much time has gone by? Well,
200 Just reset the markettime so that only 5 minutes are left */
201 if ((MARK_DELAY - (now - comm.com_markettime)) < 0)
202 comm.com_markettime = (now - (MARK_DELAY - 300));
204 comm.com_maxbidder = player->cnum;
208 pr("Your bid is being considered.\n");
210 pr("Your bid wasn't high enough (you need to bid at least $0.05 higher\n");
211 pr("than the last bid.\n");
237 long outstanding; /* Outstanding debt */
238 long couval; /* Value of country's goods */
242 /* logerror("Checking the market.\n");*/
243 for (n = 0; getcomm(n, &comm); n++) {
244 if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
247 tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.0;
252 ip = whichitem(comm.com_type);
253 sect = getsectp(comm.com_x, comm.com_y);
254 m = getvar(ip->i_vtype, (char *)sect, EF_SECTOR);
258 price = comm.com_maxprice * comm.com_amount * buytax;
259 gain = comm.com_maxprice * comm.com_amount;
261 natp = getnatp(comm.com_maxbidder);
262 tmoney = natp->nat_money;
265 if (tmoney < price && tmoney > 0) {
266 monleft = price - (tmoney - 1);
268 price = price - monleft;
269 } else if (tmoney > 0) {
271 tmoney = tmoney - price;
274 /* Subtract the amount of money that needs to come out in a loan. */
278 /* Try to make a loan for the rest from the owner. */
279 if (monleft > 0 && tmoney > 0) {
280 if ((float)((float)price / (float)(price + monleft)) < 0.1) {
281 wu(0, comm.com_maxbidder,
282 "You need at least 10 percent down to purchase something on credit.\n");
284 couval = get_couval(comm.com_maxbidder);
285 outstanding = get_outstand(comm.com_maxbidder);
286 couval = couval - outstanding;
287 if (couval > monleft) {
290 for (j = 0; getloan(j, &loan); j++) {
291 if (loan.l_status != LS_FREE)
297 ef_extend(EF_LOAN, 1);
298 loan.l_status = LS_SIGNED;
299 loan.l_loner = comm.com_owner;
300 loan.l_lonee = comm.com_maxbidder;
304 loan.l_amtdue = monleft;
305 time(&loan.l_lastpay);
307 (loan.l_ldur * SECS_PER_DAY) + loan.l_lastpay;
309 if (!putloan(j, &loan))
310 logerror("Error writing to the loan file.\n");
313 nreport(comm.com_maxbidder, N_FIN_TROUBLE,
315 wu(0, comm.com_maxbidder,
316 "You just took loan #%d for $%.2f to cover the cost of your purchase.\n",
318 wu(0, comm.com_owner,
319 "You just extended loan #%d to %s to help with the purchase cose.\n",
320 j, cname(comm.com_maxbidder));
322 nreport(comm.com_maxbidder, N_CREDIT_JUNK,
324 wu(0, comm.com_maxbidder,
325 "You don't have enough credit to get a loan.\n");
326 wu(0, comm.com_owner,
327 "You just turned down a loan to %s.\n",
328 cname(comm.com_maxbidder));
335 nreport(comm.com_maxbidder, N_WELCH_DEAL, comm.com_owner, 1);
336 wu(0, comm.com_maxbidder,
337 "You didn't have enough cash/credit to cover the cost.\n");
338 wu(0, comm.com_owner,
339 "Sale #%d fell through. Goods remain on the market.\n", n);
340 comm.com_maxbidder = comm.com_owner;
341 } else if (sect->sct_type != SCT_WAREH
342 && sect->sct_type != SCT_HARBR) {
343 wu(0, comm.com_maxbidder,
344 "Sector not a warehouse now, sale #%d fell though.\n", n);
345 wu(0, comm.com_owner,
346 "Sale #%d fell through. Goods remain on the market.\n", n);
347 comm.com_maxbidder = comm.com_owner;
348 } else if (putvar(ip->i_vtype, m + comm.com_amount,
349 (char *)sect, EF_SECTOR) <= 0) {
350 wu(0, comm.com_maxbidder,
351 "Warehouse full, sale #%d fell though.\n", n);
352 wu(0, comm.com_owner,
353 "Sale #%d fell through. Goods remain on the market.\n", n);
354 comm.com_maxbidder = comm.com_owner;
357 nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1);
358 wu(0, comm.com_owner, "%s bought %d %c's from you for $%.2f\n",
359 cname(comm.com_maxbidder), comm.com_amount,
360 comm.com_type, gain);
361 wu(0, comm.com_maxbidder,
362 "You just bought %d %c's from %s for $%.2f\n",
363 comm.com_amount, comm.com_type, cname(comm.com_owner),
365 natp = getnatp(comm.com_owner);
366 /* Make sure we subtract the amount that came out in a loan */
367 natp->nat_money += (gain - subleft);
368 natp = getnatp(comm.com_maxbidder);
369 natp->nat_money = tmoney;
375 /* logerror("Done checking the market.\n");*/