00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <config.h>
00038
00039 #include "commands.h"
00040 #include "commodity.h"
00041 #include "item.h"
00042 #include "land.h"
00043 #include "optlist.h"
00044 #include "plane.h"
00045 #include "ship.h"
00046
00047
00048
00049
00050
00051
00052
00053 int
00054 sell(void)
00055 {
00056 struct sctstr sect;
00057 struct ichrstr *ip;
00058 struct comstr comm;
00059 int number_set;
00060 int number_sub;
00061 int totalcom;
00062 int amt;
00063 int com;
00064 char *p;
00065 float price;
00066 time_t now;
00067 int ii = 0;
00068 coord x, y;
00069 char buf[1024];
00070
00071 if (!opt_MARKET) {
00072 pr("The market is disabled.\n");
00073 return RET_FAIL;
00074 }
00075 check_market();
00076 check_trade();
00077 if (!(ip = whatitem(player->argp[1], "Commodity you want to sell: ")))
00078 return RET_SYN;
00079 if (ip->i_sell == 0) {
00080 pr("You can't sell %s\n", ip->i_name);
00081 return RET_FAIL;
00082 }
00083 if (!(p = getstarg(player->argp[2], "Sector to sell from: ", buf)))
00084 return RET_SYN;
00085 if (!sarg_xy(p, &x, &y))
00086 return RET_SYN;
00087 if (!getsect(x, y, §))
00088 pr("Could not access that sector.\n");
00089 if ((sect.sct_type != SCT_HARBR && sect.sct_type != SCT_WAREH) ||
00090 !player->owner) {
00091 pr("That sector cannot sell goods.\n");
00092 return RET_FAIL;
00093 }
00094 if (sect.sct_effic < 60) {
00095 pr("Sectors need to be >= 60%% efficient to sell goods.\n");
00096 return RET_FAIL;
00097 }
00098 if (sect.sct_mobil <= 0) {
00099 pr("Sectors need at least 1 mobility to sell goods.\n");
00100 return RET_FAIL;
00101 }
00102 number_sub = 0;
00103 if ((p = getstarg(player->argp[3], "Quantity: ", buf)) == 0 || *p == 0)
00104 return RET_SYN;
00105 if (!check_sect_ok(§))
00106 return RET_FAIL;
00107 number_set = atoi(p);
00108 if ((p = getstarg(player->argp[4], "Price per unit: ", buf)) == 0 ||
00109 *p == 0)
00110 return RET_SYN;
00111 if (!check_sect_ok(§))
00112 return RET_FAIL;
00113 price = atof(p);
00114 if (price <= 0.0) {
00115 pr("No sale.\n");
00116 return RET_FAIL;
00117 }
00118 if (price > 1000.0)
00119 price = 1000.0;
00120 totalcom = 0;
00121 if (!military_control(§)) {
00122 pr("Military control required to sell goods.\n");
00123 return RET_FAIL;
00124 }
00125 if ((amt = sect.sct_item[ip->i_uid]) == 0) {
00126 pr("You don't have any %s to sell there.\n", ip->i_name);
00127 return RET_FAIL;
00128 }
00129 if (number_set >= 0)
00130 com = MIN(number_set, amt);
00131 else
00132 com = amt + number_set;
00133 if (com <= 0)
00134 return RET_SYN;
00135 totalcom += com;
00136 amt -= com;
00137 pr("Sold %d %s at %s (%d left)\n", com, ip->i_name,
00138 xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
00139 sect.sct_item[ip->i_uid] = amt;
00140 putsect(§);
00141 if (totalcom > 0) {
00142 for (ii = 0; getcomm(ii, &comm); ii++) {
00143 if (comm.com_owner == 0)
00144 break;
00145 }
00146 if (getcomm(ii, &comm) == 0)
00147 ef_extend(EF_COMM, 1);
00148 (void)time(&now);
00149 comm.com_type = ip->i_uid;
00150 comm.com_owner = player->cnum;
00151 comm.com_price = price;
00152 comm.com_maxbidder = player->cnum;
00153 comm.com_markettime = now;
00154 comm.com_amount = totalcom;
00155 comm.com_x = 0;
00156 comm.com_y = 0;
00157 comm.sell_x = sect.sct_x;
00158 comm.sell_y = sect.sct_y;
00159 comm.com_uid = ii;
00160 if (!putcomm(ii, &comm)) {
00161 pr("Problems with the commodities file, call the Deity\n");
00162 return RET_FAIL;
00163 }
00164 } else {
00165 pr("No eligible %s for sale\n", ip->i_name);
00166 return RET_FAIL;
00167 }
00168 return RET_OK;
00169 }