]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/sell.c
Update copyright notice.
[empserver] / src / lib / commands / sell.c
index 59601c13a2f7fead8c779d0e0dea6964829a8c28..02725736ad9a5e27dde33a2a8f457a3a331dcf43 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  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.
  *
  *  ---
  *
  *     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 <config.h>
+
+#include "commands.h"
 #include "commodity.h"
+#include "item.h"
 #include "land.h"
-#include "trade.h"
-#include "player.h"
-#include "commands.h"
 #include "optlist.h"
-/*#define EF_COMM 10*/
+#include "plane.h"
+#include "ship.h"
 
 /*
  * format: sell <COMMODITY> <SECTS> <NUMBER> <PRICE>
@@ -73,11 +63,10 @@ sell(void)
     int com;
     char *p;
     float price;
-    char cc;
     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");
@@ -85,8 +74,7 @@ sell(void)
     }
     check_market();
     check_trade();
-    if ((ip =
-        whatitem(player->argp[1], "Commodity you want to sell: ")) == 0)
+    if (!(ip = whatitem(player->argp[1], "Commodity you want to sell: ")))
        return RET_SYN;
     if (ip->i_sell == 0) {
        pr("You can't sell %s\n", ip->i_name);
@@ -111,9 +99,8 @@ sell(void)
        pr("Sectors need at least 1 mobility to sell goods.\n");
        return RET_FAIL;
     }
-    number_set = 0;
     number_sub = 0;
-    if ((p = getstarg(player->argp[3], "Amount:  ", buf)) == 0 || *p == 0)
+    if ((p = getstarg(player->argp[3], "Quantity: ", buf)) == 0 || *p == 0)
        return RET_SYN;
     if (!check_sect_ok(&sect))
        return RET_FAIL;
@@ -131,44 +118,25 @@ 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);
-    else if (number_set < 0)
-       com = amt + number_set;
+    if (number_set >= 0)
+       com = MIN(number_set, amt);
     else
-       com = 0;
+       com = amt + number_set;
     if (com <= 0)
        return RET_SYN;
     totalcom += com;
     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;
-    cc = ip->i_mnem;
+    sect.sct_item[ip->i_uid] = amt;
     putsect(&sect);
     if (totalcom > 0) {
        for (ii = 0; getcomm(ii, &comm); ii++) {
@@ -178,7 +146,7 @@ sell(void)
        if (getcomm(ii, &comm) == 0)
            ef_extend(EF_COMM, 1);
        (void)time(&now);
-       comm.com_type = ip->i_mnem;
+       comm.com_type = ip->i_uid;
        comm.com_owner = player->cnum;
        comm.com_price = price;
        comm.com_maxbidder = player->cnum;