2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * sell.c: Sell commodities to other nations.
30 * Known contributors to this file:
40 #include "commodity.h"
48 * format: sell <COMMODITY> <SECTS> <NUMBER> <PRICE>
49 * where NUMBER represents either the number to reach
50 * or, if negative, the abs number to try and get from
72 pr("The market is disabled.\n");
77 if (!(ip = whatitem(player->argp[1], "Commodity you want to sell: ")))
79 if (ip->i_sell == 0) {
80 pr("You can't sell %s\n", ip->i_name);
83 if (!(p = getstarg(player->argp[2], "Sector to sell from: ", buf)))
85 if (!sarg_xy(p, &x, &y))
87 if (!getsect(x, y, §))
88 pr("Could not access that sector.\n");
89 if ((sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) ||
91 pr("That sector cannot sell goods.\n");
94 if (sect.sct_effic < 60) {
95 pr("Sectors need to be >= 60%% efficient to sell goods.\n");
98 if (sect.sct_mobil <= 0) {
99 pr("Sectors need at least 1 mobility to sell goods.\n");
103 p = getstarg(player->argp[3], "Quantity: ", buf);
106 if (!check_sect_ok(§))
108 number_set = atoi(p);
109 p = getstarg(player->argp[4], "Price per unit: ", buf);
112 if (!check_sect_ok(§))
119 if (price > 1000.0) /* Inf can cause overflow */
120 price = 1000.0; /* bailey@math-cs.kent.edu */
122 if (!military_control(§)) {
123 pr("Military control required to sell goods.\n");
126 if ((amt = sect.sct_item[ip->i_uid]) == 0) {
127 pr("You don't have any %s to sell there.\n", ip->i_name);
131 com = MIN(number_set, amt);
133 com = amt + number_set;
138 pr("Sold %d %s at %s (%d left)\n", com, ip->i_name,
139 xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
140 sect.sct_item[ip->i_uid] = amt;
143 for (ii = 0; getcomm(ii, &comm); ii++) {
144 if (comm.com_owner == 0)
148 ef_blank(EF_COMM, ii, &comm);
149 comm.com_type = ip->i_uid;
150 comm.com_owner = player->cnum;
151 comm.com_price = price;
152 comm.com_maxbidder = player->cnum;
153 comm.com_markettime = now;
154 comm.com_amount = totalcom;
157 comm.sell_x = sect.sct_x;
158 comm.sell_y = sect.sct_y;
159 if (!putcomm(ii, &comm)) {
160 pr("Problems with the commodities file, call the Deity\n");
164 pr("No eligible %s for sale\n", ip->i_name);