2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2014, 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 * sell.c: Sell commodities to other nations.
29 * Known contributors to this file:
39 #include "commodity.h"
44 * format: sell <COMMODITY> <SECTS> <NUMBER> <PRICE>
45 * where NUMBER represents either the number to reach
46 * or, if negative, the abs number to try and get from
67 pr("The market is disabled.\n");
72 if (!(ip = whatitem(player->argp[1], "Commodity you want to sell: ")))
74 if (ip->i_sell == 0) {
75 pr("You can't sell %s\n", ip->i_name);
78 if (!(p = getstarg(player->argp[2], "Sector to sell from: ", buf)))
80 if (!sarg_xy(p, &x, &y))
82 if (!getsect(x, y, §))
83 pr("Could not access that sector.\n");
84 if ((sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) ||
86 pr("That sector cannot sell goods.\n");
89 if (sect.sct_effic < 60) {
90 pr("Sectors need to be >= 60%% efficient to sell goods.\n");
93 if (sect.sct_mobil <= 0) {
94 pr("Sectors need at least 1 mobility to sell goods.\n");
97 if (ip->i_uid == I_CIVIL && sect.sct_oldown != sect.sct_own) {
98 pr("You can't sell conquered populace!\n");
101 p = getstarg(player->argp[3], "Quantity: ", buf);
104 if (!check_sect_ok(§))
106 number_set = atoi(p);
107 p = getstarg(player->argp[4], "Price per unit: ", buf);
110 if (!check_sect_ok(§))
117 if (price > 1000.0) /* Inf can cause overflow */
118 price = 1000.0; /* bailey@math-cs.kent.edu */
120 if (!military_control(§)) {
121 pr("Military control required to sell goods.\n");
124 if ((amt = sect.sct_item[ip->i_uid]) == 0) {
125 pr("You don't have any %s to sell there.\n", ip->i_name);
129 com = MIN(number_set, amt);
131 com = amt + number_set;
136 pr("Sold %d %s at %s (%d left)\n", com, ip->i_name,
137 xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
138 sect.sct_item[ip->i_uid] = amt;
141 for (ii = 0; getcomm(ii, &comm); ii++) {
142 if (comm.com_owner == 0)
146 ef_blank(EF_COMM, ii, &comm);
147 comm.com_type = ip->i_uid;
148 comm.com_owner = player->cnum;
149 comm.com_price = price;
150 comm.com_maxbidder = player->cnum;
151 comm.com_markettime = now;
152 comm.com_amount = totalcom;
155 comm.sell_x = sect.sct_x;
156 comm.sell_y = sect.sct_y;
157 if (!putcomm(ii, &comm)) {
158 pr("Problems with the commodities file, call the Deity\n");