2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * buy.c: Buy commodities from other nations
29 * Known contributors to this file:
32 * Steve McClure, 1996-2000
38 #include "commodity.h"
49 * format: buy <COMMODITY>
73 pr("The market is disabled.\n");
76 natp = getnatp(player->cnum);
77 ip = whatitem(player->argp[1], "Commodity you want to buy: ");
80 display_mark(ip->i_uid, 0);
82 p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
90 if (!getcomm(o, &comm) || comm.com_owner == 0) {
91 pr("Invalid lot number.\n");
94 if (comm.com_type != ip->i_uid) {
95 pr("That lot is not of the type you specified.\n");
98 if (comm.com_owner == player->cnum) {
99 pr("You can't bid on your own lot.\n");
102 if (!(p = getstarg(player->argp[3], "How much per unit: ", buf)))
107 if (natp->nat_money < bid * comm.com_amount * buytax) {
108 pr("This purchase would cost %.2f, %.2f more than you have.\n",
109 bid * comm.com_amount * buytax,
110 bid * comm.com_amount * buytax - natp->nat_money);
113 /* check to see if all of the bids that this player has out plus this new bid
114 would make him go broke. Ken, I ought to skin you alive for making me code
117 for (n = 0; gettrade(n, &tmpt); n++) {
118 if (tmpt.trd_maxbidder == player->cnum &&
119 tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
120 tally += tmpt.trd_price * tradetax;
123 for (n = 0; getcomm(n, &comt); n++) {
124 if (comt.com_maxbidder == player->cnum &&
125 comt.com_owner != 0 && comt.com_owner != player->cnum) {
126 tally += comt.com_price * comt.com_amount * buytax;
129 canspend = natp->nat_money - tally;
131 if (bid * comm.com_amount * buytax > canspend) {
132 pr("You have overextended yourself in the market\n");
133 pr("You can not bid on the current items at that price.\n");
136 if (!(p = getstarg(player->argp[4], "destination sector : ", buf)))
138 if (!sarg_xy(p, &x, &y))
140 if (!getsect(x, y, §)) {
141 pr("Could not access sector");
144 if ((sect.sct_type != SCT_WAREH && sect.sct_type != SCT_HARBR) ||
145 sect.sct_own != player->cnum) {
146 pr("The destination sector is not one of your warehouses.\n");
149 if (sect.sct_effic < 60) {
150 pr("That sector is under construction.\n");
153 n = sect.sct_item[ip->i_uid];
154 qty = comm.com_amount;
155 if (qty + n > ITEM_MAX) {
156 pr("That sector cannot hold %d more %s. It currently holds %d.\n",
160 if (bid * comm.com_amount > natp->nat_money) {
161 pr("You don't have that much to spend!\n");
165 if (!ncomm.com_owner) {
166 pr("That lot has been taken off the market.\n");
169 if (bid > 0.04 + comm.com_price) {
170 comm.com_price = bid;
171 /* Add five minutes to the time if less than 5 minutes */
173 if (((MARK_DELAY - (now - comm.com_markettime)) < 300) &&
174 comm.com_maxbidder != player->cnum) {
175 comm.com_markettime += 300;
176 /* Special case - what if so much time has gone by? Well,
177 Just reset the markettime so that only 5 minutes are left */
178 if ((MARK_DELAY - (now - comm.com_markettime)) < 0)
179 comm.com_markettime = (now - (MARK_DELAY - 300));
181 comm.com_maxbidder = player->cnum;
185 pr("Your bid is being considered.\n");
187 pr("Your bid wasn't high enough (you need to bid at least $0.05 higher\n");
188 pr("than the last bid.\n");
210 for (n = 0; getcomm(n, &comm); n++) {
211 if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
214 tleft = MARK_DELAY / 3600.0 - (now - comm.com_markettime) / 3600.0;
219 if (CANT_HAPPEN(comm.com_type <= I_NONE || comm.com_type > I_MAX))
221 sect = getsectp(comm.com_x, comm.com_y);
222 m = sect->sct_item[comm.com_type];
224 price = comm.com_price * comm.com_amount * buytax;
225 gain = comm.com_price * comm.com_amount;
227 natp = getnatp(comm.com_maxbidder);
228 if (natp->nat_money < price) {
229 nreport(comm.com_maxbidder, N_WELCH_DEAL, comm.com_owner, 1);
230 wu(0, comm.com_maxbidder,
231 "You didn't have enough cash to cover the cost.\n");
232 wu(0, comm.com_owner,
233 "Sale #%d fell through. Goods remain on the market.\n", n);
234 comm.com_maxbidder = comm.com_owner;
235 } else if (sect->sct_type != SCT_WAREH
236 && sect->sct_type != SCT_HARBR) {
237 wu(0, comm.com_maxbidder,
238 "Sector not a warehouse now, sale #%d fell though.\n", n);
239 wu(0, comm.com_owner,
240 "Sale #%d fell through. Goods remain on the market.\n", n);
241 comm.com_maxbidder = comm.com_owner;
242 } else if (m + comm.com_amount > ITEM_MAX) {
243 wu(0, comm.com_maxbidder,
244 "Warehouse full, sale #%d fell though.\n", n);
245 wu(0, comm.com_owner,
246 "Sale #%d fell through. Goods remain on the market.\n", n);
247 comm.com_maxbidder = comm.com_owner;
249 sect->sct_item[comm.com_type] = m + comm.com_amount;
251 nreport(comm.com_owner, N_MAKE_SALE, comm.com_maxbidder, 1);
252 wu(0, comm.com_owner, "%s bought %d %s from you for $%.2f\n",
253 cname(comm.com_maxbidder), comm.com_amount,
254 ichr[comm.com_type].i_name, gain);
255 wu(0, comm.com_maxbidder,
256 "You just bought %d %s from %s for $%.2f\n",
257 comm.com_amount, ichr[comm.com_type].i_name,
258 cname(comm.com_owner), price);
259 natp->nat_money -= roundavg(price);
261 natp = getnatp(comm.com_owner);
262 natp->nat_money += roundavg(gain);