]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/trad.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / trad.c
index e4ef961f136cf70396a068964a938b77c3c9bcaf..70c9dbd0e7b3e176c31444d13c05119e4d40abdd 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-2006, 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-2000
  */
 
+#include <config.h>
+
 #include <ctype.h>
 #include "misc.h"
-#include "var.h"
 #include "sect.h"
 #include "nat.h"
 #include "news.h"
-#include "item.h"
 #include "ship.h"
 #include "nuke.h"
 #include "land.h"
@@ -97,8 +97,8 @@ trad(void)
     pr(" --- --------  -- --------- -----  -------------------------\n");
 
     snxtitem_all(&ni, EF_TRADE);
-    while (nxtitem(&ni, (char *)&trade)) {
-       if (trade.trd_unitid < 0)
+    while (nxtitem(&ni, &trade)) {
+       if (trade.trd_owner == 0)
            continue;
        if (!trade_getitem(&trade, &tg)) {
            continue;
@@ -115,7 +115,7 @@ trad(void)
            TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0;
        if (tleft < 0.0)
            tleft = 0.0;
-       pr("$%7d  %2d %5.2f hrs ", trade.trd_maxprice,
+       pr("$%7ld  %2d %5.2f hrs ", trade.trd_price,
           trade.trd_maxbidder, tleft);
        (void)trade_desc(&trade, &tg);  /* XXX */
        pr("\n");
@@ -174,7 +174,7 @@ trad(void)
        pr("You can't buy from yourself!\n");
        return RET_OK;
     }
-    price = trade.trd_maxprice;
+    price = trade.trd_price;
     natp = getnatp(player->cnum);
     if (natp->nat_money < price) {
        pr("You don't have %.2f to spend!\n", price);
@@ -184,13 +184,13 @@ trad(void)
     for (q = 0; gettrade(q, &tmpt); q++) {
        if (tmpt.trd_maxbidder == player->cnum &&
            tmpt.trd_unitid >= 0 && tmpt.trd_owner != player->cnum) {
-           tally += tmpt.trd_maxprice * tradetax;
+           tally += tmpt.trd_price * tradetax;
        }
     }
     for (q = 0; getcomm(q, &comt); q++) {
        if (comt.com_maxbidder == player->cnum &&
            comt.com_owner != 0 && comt.com_owner != player->cnum) {
-           tally += (comt.com_maxprice * comt.com_amount) * buytax;
+           tally += (comt.com_price * comt.com_amount) * buytax;
        }
     }
     canspend = natp->nat_money - tally;
@@ -205,7 +205,7 @@ trad(void)
        plflags = plchr[(int)tg.pln.pln_type].pl_flags;
        while (1) {
            p = getstring("Destination sector: ", buf);
-           if (!trade_check_ok(lotno, &trade, &tg))
+           if (!trade_check_ok(&trade, &tg))
                return RET_FAIL;
            if (p == 0) {
                return RET_FAIL;
@@ -234,7 +234,7 @@ trad(void)
     if (trade.trd_type == EF_LAND) {
        while (1) {
            p = getstring("Destination sector: ", buf);
-           if (!trade_check_ok(lotno, &trade, &tg))
+           if (!trade_check_ok(&trade, &tg))
                return RET_FAIL;
            if (p == 0) {
                return RET_FAIL;
@@ -259,14 +259,9 @@ trad(void)
        }
     }
 
-    pr("WARNING!  This market issues credit.  If you make more\n");
-    pr("  bids than your treasury can cover at the time of sale,\n");
-    pr("  you can potentially go into financial ruin, and see no\n");
-    pr("  gains.  You have been warned.\n\n");
-
     if ((p = getstring("How much do you bid: ", buf)) == 0 || *p == 0)
        return RET_OK;
-    if (!trade_check_ok(lotno, &trade, &tg))
+    if (!trade_check_ok(&trade, &tg))
        return RET_FAIL;
     bid = atoi(p);
     if (bid < price)
@@ -275,13 +270,13 @@ trad(void)
        pr("You don't have %.2f to spend!\n", price);
        return RET_OK;
     }
-    if (bid > trade.trd_maxprice) {
+    if (bid > trade.trd_price) {
        /* Add five minutes to the time if less than 5 minutes left. */
        time(&now);
        if (((TRADE_DELAY - (now - trade.trd_markettime)) < 300) &&
            trade.trd_maxbidder != player->cnum)
            trade.trd_markettime += 300;
-       trade.trd_maxprice = bid;
+       trade.trd_price = bid;
        trade.trd_maxbidder = player->cnum;
        trade.trd_x = sx;
        trade.trd_y = sy;
@@ -300,7 +295,6 @@ int
 check_trade(void)
 {
     int n;
-    int j;
     struct nstr_item ni;
     struct plnstr plane;
     struct lndstr land;
@@ -313,10 +307,6 @@ check_trade(void)
     double tleft;
     float price;
     int saveid;
-    struct lonstr loan;
-    long outstanding;          /* Outstanding debt */
-    long couval;               /* Value of country's goods */
-    int foundloan;
 
 /*    logerror("Checking the trades.\n");*/
     for (n = 0; gettrade(n, &trade); n++) {
@@ -355,7 +345,7 @@ check_trade(void)
        }
 
        monleft = 0;
-       price = trade.trd_maxprice;
+       price = trade.trd_price;
        natp = getnatp(trade.trd_maxbidder);
        if (natp->nat_money <= 0)
            monleft = price;
@@ -370,62 +360,6 @@ check_trade(void)
 
        subleft = monleft;
 
-       if (opt_LOANS) {
-           /* Try to make a loan for the rest from the owner. */
-           if (monleft > 0 && natp->nat_money > 0) {
-               if ((float)((float)price / (float)(price + monleft)) < 0.1) {
-                   wu(0, trade.trd_maxbidder,
-                      "You need at least 10 percent down to purchase something on credit.\n");
-               } else {
-                   couval = get_couval(trade.trd_maxbidder);
-                   outstanding = get_outstand(trade.trd_maxbidder);
-                   couval = couval - outstanding;
-                   if (couval > monleft) {
-                       /*  Make the loan */
-                       foundloan = 0;
-                       for (j = 0; getloan(j, &loan); j++) {
-                           if (loan.l_status != LS_FREE)
-                               continue;
-                           foundloan = 1;
-                           break;
-                       }
-                       if (!foundloan)
-                           ef_extend(EF_LOAN, 1);
-                       loan.l_status = LS_SIGNED;
-                       loan.l_loner = trade.trd_owner;
-                       loan.l_lonee = trade.trd_maxbidder;
-                       loan.l_irate = 25;
-                       loan.l_ldur = 4;
-                       loan.l_amtpaid = 0;
-                       loan.l_amtdue = monleft;
-                       time(&loan.l_lastpay);
-                       loan.l_duedate =
-                           (loan.l_ldur * SECS_PER_DAY) + loan.l_lastpay;
-                       loan.l_uid = j;
-                       if (!putloan(j, &loan))
-                           logerror("Error writing to the loan file.\n");
-                       else
-                           monleft = 0;
-                       nreport(trade.trd_maxbidder, N_FIN_TROUBLE,
-                               trade.trd_owner, 1);
-                       wu(0, trade.trd_maxbidder,
-                          "You just took loan #%d for $%.2f to cover the cost of your purchase.\n",
-                          j, (float)loan.l_amtdue);
-                       wu(0, trade.trd_owner,
-                          "You just extended loan #%d to %s to help with the purchase cost.\n",
-                          j, cname(trade.trd_maxbidder));
-                   } else {
-                       nreport(trade.trd_maxbidder, N_CREDIT_JUNK,
-                               trade.trd_owner, 1);
-                       wu(0, trade.trd_maxbidder,
-                          "You don't have enough credit to get a loan.\n");
-                       wu(0, trade.trd_owner,
-                          "You just turned down a loan to %s.\n",
-                          cname(trade.trd_maxbidder));
-                   }
-               }
-           }
-       }
        if (monleft > 0) {
            nreport(trade.trd_maxbidder, N_WELCH_DEAL, trade.trd_owner, 1);
            wu(0, trade.trd_owner,
@@ -514,7 +448,7 @@ check_trade(void)
            tg.lnd.lnd_mission = 0;
            /* Drop any land units this unit was carrying */
            snxtitem_xy(&ni, EF_LAND, tg.lnd.lnd_x, tg.lnd.lnd_y);
-           while (nxtitem(&ni, (s_char *)&land)) {
+           while (nxtitem(&ni, &land)) {
                if (land.lnd_land != tg.lnd.lnd_uid)
                    continue;
                land.lnd_land = -1;
@@ -525,7 +459,7 @@ check_trade(void)
            }
            /* Drop any planes this unit was carrying */
            snxtitem_xy(&ni, EF_PLANE, tg.lnd.lnd_x, tg.lnd.lnd_y);
-           while (nxtitem(&ni, (s_char *)&plane)) {
+           while (nxtitem(&ni, &plane)) {
                if (plane.pln_flags & PLN_LAUNCHED)
                    continue;
                if (plane.pln_land != land.lnd_uid)
@@ -543,7 +477,7 @@ check_trade(void)
            logerror("Bad trade type %d in trade\n", trade.trd_type);
            break;
        }
-       if (!ef_write(trade.trd_type, saveid, (char *)&tg)) {
+       if (!ef_write(trade.trd_type, saveid, &tg)) {
            logerror("Couldn't write unit to disk; seek help.\n");
            continue;
        }