]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/sell.c
commands: Rename the command functions
[empserver] / src / lib / commands / sell.c
index 572e76faa3cb53ebf1423e85ffa890f11dfe19bc..e53ce8462d5f83372b4a277c9df1471c200b3aad 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *  sell.c: Sell commodities to other nations.
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Jeff Bailey
  *     Steve McClure, 1996
  */
 
-#include "misc.h"
-#include "xy.h"
-#include "file.h"
-#include "var.h"
-#include "sect.h"
-#include "item.h"
-#include "nsc.h"
-#include "nat.h"
-#include "nuke.h"
-#include "plane.h"
-#include "ship.h"
-#include <math.h>              /* bailey@math-cs.kent.edu */
-#include "commodity.h"
-#include "land.h"
-#include "trade.h"
-#include "player.h"
+#include <config.h>
+
 #include "commands.h"
+#include "commodity.h"
+#include "item.h"
 #include "optlist.h"
-/*#define EF_COMM 10*/
 
 /*
  * format: sell <COMMODITY> <SECTS> <NUMBER> <PRICE>
  *   each sector.
  */
 int
-sell(void)
+c_sell(void)
 {
     struct sctstr sect;
     struct ichrstr *ip;
     struct comstr comm;
     int number_set;
-    int number_sub;
     int totalcom;
     int amt;
     int com;
@@ -76,7 +61,7 @@ sell(void)
     time_t now;
     int ii = 0;
     coord x, y;
-    s_char buf[1024];
+    char buf[1024];
 
     if (!opt_MARKET) {
        pr("The market is disabled.\n");
@@ -109,14 +94,18 @@ sell(void)
        pr("Sectors need at least 1 mobility to sell goods.\n");
        return RET_FAIL;
     }
-    number_sub = 0;
-    if ((p = getstarg(player->argp[3], "Amount:  ", buf)) == 0 || *p == 0)
+    if (ip->i_uid == I_CIVIL && sect.sct_oldown != sect.sct_own) {
+       pr("You can't sell conquered populace!\n");
+       return RET_FAIL;
+    }
+    p = getstarg(player->argp[3], "Quantity: ", buf);
+    if (!p || !*p)
        return RET_SYN;
     if (!check_sect_ok(&sect))
        return RET_FAIL;
     number_set = atoi(p);
-    if ((p = getstarg(player->argp[4], "Price per unit: ", buf)) == 0 ||
-       *p == 0)
+    p = getstarg(player->argp[4], "Price per unit: ", buf);
+    if (!p || !*p)
        return RET_SYN;
     if (!check_sect_ok(&sect))
        return RET_FAIL;
@@ -128,32 +117,16 @@ sell(void)
     if (price > 1000.0)                /* Inf can cause overflow */
        price = 1000.0;         /* bailey@math-cs.kent.edu */
     totalcom = 0;
-    /*
-     * military control necessary to sell
-     * goodies in occupied territory.
-     */
-    if (sect.sct_oldown != player->cnum) {
-       int tot_mil = 0;
-       struct nstr_item ni;
-       struct lndstr land;
-
-       snxtitem_xy(&ni, EF_LAND, sect.sct_x, sect.sct_y);
-       while (nxtitem(&ni, (s_char *)&land)) {
-           if (land.lnd_own == player->cnum)
-               tot_mil += total_mil(&land);
-       }
-       if (((tot_mil + sect.sct_item[I_MILIT]) * 10)
-           < sect.sct_item[I_CIVIL]) {
-           pr("Military control required to sell goods.\n");
-           return RET_FAIL;
-       }
+    if (!military_control(&sect)) {
+       pr("Military control required to sell goods.\n");
+       return RET_FAIL;
     }
-    if ((amt = sect.sct_item[ip->i_vtype]) == 0) {
+    if ((amt = sect.sct_item[ip->i_uid]) == 0) {
        pr("You don't have any %s to sell there.\n", ip->i_name);
        return RET_FAIL;
     }
     if (number_set >= 0)
-       com = min(number_set, amt);
+       com = MIN(number_set, amt);
     else
        com = amt + number_set;
     if (com <= 0)
@@ -162,33 +135,27 @@ sell(void)
     amt -= com;
     pr("Sold %d %s at %s (%d left)\n", com, ip->i_name,
        xyas(sect.sct_x, sect.sct_y, player->cnum), amt);
-    sect.sct_item[ip->i_vtype] = amt;
+    sect.sct_item[ip->i_uid] = amt;
     putsect(&sect);
-    if (totalcom > 0) {
-       for (ii = 0; getcomm(ii, &comm); ii++) {
-           if (comm.com_owner == 0)
-               break;
-       }
-       if (getcomm(ii, &comm) == 0)
-           ef_extend(EF_COMM, 1);
-       (void)time(&now);
-       comm.com_type = ip->i_vtype;
-       comm.com_owner = player->cnum;
-       comm.com_price = price;
-       comm.com_maxbidder = player->cnum;
-       comm.com_markettime = now;
-       comm.com_amount = totalcom;
-       comm.com_x = 0;
-       comm.com_y = 0;
-       comm.sell_x = sect.sct_x;
-       comm.sell_y = sect.sct_y;
-       comm.com_uid = ii;
-       if (!putcomm(ii, &comm)) {
-           pr("Problems with the commodities file, call the Deity\n");
-           return RET_FAIL;
-       }
-    } else {
-       pr("No eligible %s for sale\n", ip->i_name);
+
+    for (ii = 0; getcomm(ii, &comm); ii++) {
+       if (comm.com_owner == 0)
+           break;
+    }
+    (void)time(&now);
+    ef_blank(EF_COMM, ii, &comm);
+    comm.com_type = ip->i_uid;
+    comm.com_owner = player->cnum;
+    comm.com_price = price;
+    comm.com_maxbidder = player->cnum;
+    comm.com_markettime = now;
+    comm.com_amount = totalcom;
+    comm.com_x = 0;
+    comm.com_y = 0;
+    comm.sell_x = sect.sct_x;
+    comm.sell_y = sect.sct_y;
+    if (!putcomm(ii, &comm)) {
+       pr("Problems with the commodities file, call the Deity\n");
        return RET_FAIL;
     }
     return RET_OK;