2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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 * sell.c: Sell commodities to other nations.
30 * Known contributors to this file:
48 #include <math.h> /* bailey@math-cs.kent.edu */
49 #include "commodity.h"
54 /*#define EF_COMM 10*/
57 * format: sell <COMMODITY> <SECTS> <NUMBER> <PRICE>
58 * where NUMBER represents either the number to reach
59 * or, if negative, the abs number to try and get from
81 pr("The market is disabled.\n");
86 if (!(ip = whatitem(player->argp[1], "Commodity you want to sell: ")))
88 if (ip->i_sell == 0) {
89 pr("You can't sell %s\n", ip->i_name);
92 if (!(p = getstarg(player->argp[2], "Sector to sell from: ", buf)))
94 if (!sarg_xy(p, &x, &y))
96 if (!getsect(x, y, §))
97 pr("Could not access that sector.\n");
98 if ((sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) ||
100 pr("That sector cannot sell goods.\n");
103 if (sect.sct_effic < 60) {
104 pr("Sectors need to be >= 60%% efficient to sell goods.\n");
107 if (sect.sct_mobil <= 0) {
108 pr("Sectors need at least 1 mobility to sell goods.\n");
112 if ((p = getstarg(player->argp[3], "Quantity: ", buf)) == 0 || *p == 0)
114 if (!check_sect_ok(§))
116 number_set = atoi(p);
117 if ((p = getstarg(player->argp[4], "Price per unit: ", buf)) == 0 ||
120 if (!check_sect_ok(§))
127 if (price > 1000.0) /* Inf can cause overflow */
128 price = 1000.0; /* bailey@math-cs.kent.edu */
130 if (!military_control(§)) {
131 pr("Military control required to sell goods.\n");
134 if ((amt = sect.sct_item[ip->i_vtype]) == 0) {
135 pr("You don't have any %s to sell there.\n", ip->i_name);
139 com = min(number_set, amt);
141 com = amt + number_set;
146 pr("Sold %d %s at %s (%d left)\n", com, ip->i_name,
147 xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
148 sect.sct_item[ip->i_vtype] = amt;
151 for (ii = 0; getcomm(ii, &comm); ii++) {
152 if (comm.com_owner == 0)
155 if (getcomm(ii, &comm) == 0)
156 ef_extend(EF_COMM, 1);
158 comm.com_type = ip->i_vtype;
159 comm.com_owner = player->cnum;
160 comm.com_price = price;
161 comm.com_maxbidder = player->cnum;
162 comm.com_markettime = now;
163 comm.com_amount = totalcom;
166 comm.sell_x = sect.sct_x;
167 comm.sell_y = sect.sct_y;
169 if (!putcomm(ii, &comm)) {
170 pr("Problems with the commodities file, call the Deity\n");
174 pr("No eligible %s for sale\n", ip->i_name);