]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/trad.c
License upgrade to GPL version 3 or later
[empserver] / src / lib / commands / trad.c
index d5aea2702e59b6900777a5a75cca32d90a0edfee..50c05b50c12e468ce4ecb4cef83a8c0778e2736c 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2011, 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,
@@ -14,8 +14,7 @@
  *  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/>.
  *
  *  ---
  *
@@ -26,7 +25,7 @@
  *  ---
  *
  *  trad.c: Buy units/ships/planes/nukes from other nations.
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Pat Loney, 1992
@@ -72,7 +71,7 @@ trad(void)
     int bid;
     double tleft;
     double tally;
-    int q;
+    int i;
     char buf[1024];
 
     if (!opt_MARKET) {
@@ -114,7 +113,8 @@ trad(void)
        pr("Nothing to buy at the moment...\n");
        return RET_OK;
     }
-    if ((p = getstring("Which lot to buy: ", buf)) == 0 || *p == 0)
+    p = getstring("Which lot to buy: ", buf);
+    if (!p || !*p)
        return RET_OK;
     if (isdigit(*p) == 0)
        return RET_OK;
@@ -163,31 +163,28 @@ trad(void)
        return RET_OK;
     }
     tally = 0.0;
-    for (q = 0; gettrade(q, &tmpt); q++) {
+    for (i = 0; gettrade(i, &tmpt); i++) {
        if (tmpt.trd_maxbidder == player->cnum &&
            tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
            tally += tmpt.trd_price * tradetax;
        }
     }
-    for (q = 0; getcomm(q, &comt); q++) {
+    for (i = 0; getcomm(i, &comt); i++) {
        if (comt.com_maxbidder == player->cnum &&
            comt.com_owner != 0 && comt.com_owner != player->cnum) {
            tally += (comt.com_price * comt.com_amount) * buytax;
        }
     }
     canspend = natp->nat_money - tally;
-    /*
-     * Find the destination sector for the plane before the trade is
-     * actually made, except for satellites in orbit.  Must be owned
-     * and must be a 60% airfield (except for VTOL planes).
-     */
+
+    /* Find the destination sector for the trade */
     if (((trade.trd_type == EF_PLANE) && !pln_is_in_orbit(&tg.plane))
        || (trade.trd_type == EF_NUKE)) {
        while (1) {
            p = getstring("Destination sector: ", buf);
            if (!trade_check_ok(&trade, &tg))
                return RET_FAIL;
-           if (p == 0) {
+           if (!p) {
                return RET_FAIL;
            }
            if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, &sect)) {
@@ -210,13 +207,12 @@ trad(void)
            }
            break;
        }
-    }
-    if (trade.trd_type == EF_LAND) {
+    } else if (trade.trd_type == EF_LAND) {
        while (1) {
            p = getstring("Destination sector: ", buf);
            if (!trade_check_ok(&trade, &tg))
                return RET_FAIL;
-           if (p == 0) {
+           if (!p) {
                return RET_FAIL;
            }
            if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, &sect)) {
@@ -237,9 +233,14 @@ trad(void)
            }
            break;
        }
+    } else {
+       /* This trade doesn't teleport; make destination invalid */
+       sx = 1;
+       sy = 0;
     }
 
-    if ((p = getstring("How much do you bid: ", buf)) == 0 || *p == 0)
+    p = getstring("How much do you bid: ", buf);
+    if (!p || !*p)
        return RET_OK;
     if (!trade_check_ok(&trade, &tg))
        return RET_FAIL;
@@ -283,7 +284,6 @@ check_trade(void)
     float price;
     int saveid;
 
-/*    logerror("Checking the trades.\n");*/
     for (n = 0; gettrade(n, &trade); n++) {
        if (trade.trd_unitid < 0)
            continue;
@@ -372,8 +372,6 @@ check_trade(void)
            tg.plane.pln_land = -1;
            break;
        case EF_SHIP:
-           tg.ship.shp_rflags = 0;
-           memset(tg.ship.shp_rpath, 0, sizeof(tg.ship.shp_rpath));
            break;
        case EF_LAND:
            tg.land.lnd_x = trade.trd_x;
@@ -405,7 +403,6 @@ check_trade(void)
           trade_nameof(&trade, &tg), saveid, cname(trade.trd_owner),
           price);
     }
-/*    logerror("Done checking the trades.\n");*/
     return RET_OK;
 }