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
46 #include "commodity.h"
57 * format: buy <COMMODITY>
81 pr("The market is disabled.\n");
84 natp = getnatp(player->cnum);
85 display_mark(player->argp[1]);
87 p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
95 if (!getcomm(o, &comm) || comm.com_owner == 0) {
96 pr("Invalid lot number.\n");
99 if (player->argp[1] && *(player->argp[1]) &&
100 comm.com_type != player->argp[1][0]) {
101 pr("That lot is not of the type you specified.\n");
104 if (comm.com_owner == player->cnum) {
105 pr("You can't bid on your own lot.\n");
108 pr("WARNING! This market issues credit. If you make more\n");
109 pr(" bids than your treasury can cover at the time of sale,\n");
110 pr(" you can potentially go into financial ruin, and see no\n");
111 pr(" gains. You have been warned.\n\n");
112 if ((p = getstarg(player->argp[3], "How much per unit: ", buf)) == 0)
117 if (natp->nat_money < (bid * comm.com_amount * buytax)) {
118 pr("This purchase would cost %.2f, %.2f more than you have.\n",
119 bid * comm.com_amount * buytax,
120 bid * comm.com_amount * buytax - natp->nat_money);
123 /* check to see if all of the bids that this player has out plus this new bid
124 would make him go broke. Ken, I ought to skin you alive for making me code
127 for (q = 0; gettrade(q, &tmpt); q++) {
128 if (tmpt.trd_maxbidder == player->cnum &&
129 tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
130 tally += tmpt.trd_price * tradetax;
133 for (q = 0; getcomm(q, &comt); q++) {
134 if (comt.com_maxbidder == player->cnum &&
135 comt.com_owner != 0 && comt.com_owner != player->cnum) {
136 tally += (comt.com_price * comt.com_amount) * buytax;
139 canspend = natp->nat_money - tally;
141 if ((bid * comm.com_amount * buytax) > canspend) {
142 pr("You have overextended yourself in the market\n");
143 pr("You can not bid on the current items at that price.\n");
146 if (!(p = getstarg(player->argp[4], "destination sector : ", buf)))
148 if (!sarg_xy(p, &x, &y))
150 if (!getsect(x, y, §)) {
151 pr("Could not access sector");
154 if ((sect.sct_type != SCT_WAREH && sect.sct_type != SCT_HARBR) ||
155 sect.sct_own != player->cnum) {
156 pr("The destination sector is not one of your warehouses.\n");
159 if (sect.sct_effic < 60) {
160 pr("That sector is under construction.\n");
163 ip = whichitem(comm.com_type);
164 n = sect.sct_item[ip->i_vtype];
165 qty = comm.com_amount;
166 if (qty + n > 9990) {
167 pr("That sector cannot hold %d more %s. It currently holds %d.\n",
171 if ((bid * comm.com_amount) > natp->nat_money) {
172 pr("You don't have that much to spend!\n");
176 if (!ncomm.com_owner) {
177 pr("That lot has been taken off the market.\n");
180 if (bid > 0.04 + comm.com_price) {
181 comm.com_price = bid;
182 /* Add five minutes to the time if less than 5 minutes */
184 if (((MARK_DELAY - (now - comm.com_markettime)) < 300) &&
185 comm.com_maxbidder != player->cnum) {
186 comm.com_markettime += 300;
187 /* Special case - what if so much time has gone by? Well,
188 Just reset the markettime so that only 5 minutes are left */
189 if ((MARK_DELAY - (now - comm.com_markettime)) < 0)
190 comm.com_markettime = (now - (MARK_DELAY - 300));
192 comm.com_maxbidder = player->cnum;
196 pr("Your bid is being considered.\n");
198 pr("Your bid wasn't high enough (you need to bid at least $0.05 higher\n");
199 pr("than the last bid.\n");
225 long outstanding; /* Outstanding debt */
226 long couval; /* Value of country's goods */
230 /* logerror("Checking the market.\n");*/
231 for (n = 0; getcomm(n, &comm); n++) {
232 if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
235 tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.0;
240 ip = whichitem(comm.com_type);
241 sect = getsectp(comm.com_x, comm.com_y);
242 m = sect->sct_item[ip->i_vtype];
246 price = comm.com_price * comm.com_amount * buytax;
247 gain = comm.com_price * comm.com_amount;
249 natp = getnatp(comm.com_maxbidder);
250 tmoney = natp->nat_money;
253 if (tmoney < price && tmoney > 0) {
254 monleft = price - (tmoney - 1);
256 price = price - monleft;
257 } else if (tmoney > 0) {
259 tmoney = tmoney - price;
262 /* Subtract the amount of money that needs to come out in a loan. */
266 /* Try to make a loan for the rest from the owner. */
267 if (monleft > 0 && tmoney > 0) {
268 if ((float)((float)price / (float)(price + monleft)) < 0.1) {
269 wu(0, comm.com_maxbidder,
270 "You need at least 10 percent down to purchase something on credit.\n");
272 couval = get_couval(comm.com_maxbidder);
273 outstanding = get_outstand(comm.com_maxbidder);
274 couval = couval - outstanding;
275 if (couval > monleft) {
278 for (j = 0; getloan(j, &loan); j++) {
279 if (loan.l_status != LS_FREE)
285 ef_extend(EF_LOAN, 1);
286 loan.l_status = LS_SIGNED;
287 loan.l_loner = comm.com_owner;
288 loan.l_lonee = comm.com_maxbidder;
292 loan.l_amtdue = monleft;
293 time(&loan.l_lastpay);
295 (loan.l_ldur * SECS_PER_DAY) + loan.l_lastpay;
297 if (!putloan(j, &loan))
298 logerror("Error writing to the loan file.\n");
301 nreport(comm.com_maxbidder, N_FIN_TROUBLE,
303 wu(0, comm.com_maxbidder,
304 "You just took loan #%d for $%.2f to cover the cost of your purchase.\n",
306 wu(0, comm.com_owner,
307 "You just extended loan #%d to %s to help with the purchase cose.\n",
308 j, cname(comm.com_maxbidder));
310 nreport(comm.com_maxbidder, N_CREDIT_JUNK,
312 wu(0, comm.com_maxbidder,
313 "You don't have enough credit to get a loan.\n");
314 wu(0, comm.com_owner,
315 "You just turned down a loan to %s.\n",
316 cname(comm.com_maxbidder));
323 nreport(comm.com_maxbidder, N_WELCH_DEAL, comm.com_owner, 1);
324 wu(0, comm.com_maxbidder,
325 "You didn't have enough cash/credit to cover the cost.\n");
326 wu(0, comm.com_owner,
327 "Sale #%d fell through. Goods remain on the market.\n", n);
328 comm.com_maxbidder = comm.com_owner;
329 } else if (sect->sct_type != SCT_WAREH
330 && sect->sct_type != SCT_HARBR) {
331 wu(0, comm.com_maxbidder,
332 "Sector not a warehouse now, sale #%d fell though.\n", n);
333 wu(0, comm.com_owner,
334 "Sale #%d fell through. Goods remain on the market.\n", n);
335 comm.com_maxbidder = comm.com_owner;
336 } else if (m + comm.com_amount > ITEM_MAX) {
337 wu(0, comm.com_maxbidder,
338 "Warehouse full, sale #%d fell though.\n", n);
339 wu(0, comm.com_owner,
340 "Sale #%d fell through. Goods remain on the market.\n", n);
341 comm.com_maxbidder = comm.com_owner;
343 sect->sct_item[ip->i_vtype] = m + comm.com_amount;
345 nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1);
346 wu(0, comm.com_owner, "%s bought %d %c's from you for $%.2f\n",
347 cname(comm.com_maxbidder), comm.com_amount,
348 comm.com_type, gain);
349 wu(0, comm.com_maxbidder,
350 "You just bought %d %c's from %s for $%.2f\n",
351 comm.com_amount, comm.com_type, cname(comm.com_owner),
353 natp = getnatp(comm.com_owner);
354 /* Make sure we subtract the amount that came out in a loan */
355 natp->nat_money += (gain - subleft);
356 natp = getnatp(comm.com_maxbidder);
357 natp->nat_money = tmoney;
363 /* logerror("Done checking the market.\n");*/