]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/buy.c
Update copyright notice
[empserver] / src / lib / commands / buy.c
index c77d20c6f99d6595baff5cd9e63fb63582726d6c..1bea19cb26327b028b37c2d6aaac12c6aa7cb7d2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -26,7 +26,7 @@
  *  ---
  *
  *  buy.c: Buy commodities from other nations
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Pat Loney, 1992
@@ -61,7 +61,7 @@ buy(void)
     struct trdstr tmpt;
     struct ichrstr *ip;
     int qty;
-    int o, n, q;
+    int o, n;
     coord x, y;
     char *p;
     float bid;
@@ -81,7 +81,7 @@ buy(void)
     display_mark(ip->i_uid, 0);
     pr("\n");
     p = getstarg(player->argp[2], "Which lot are you bidding on: ", buf);
-    if (p == 0)
+    if (!p)
        return RET_SYN;
     if (*p == 0)
        return RET_SYN;
@@ -100,7 +100,7 @@ buy(void)
        pr("You can't bid on your own lot.\n");
        return RET_OK;
     }
-    if ((p = getstarg(player->argp[3], "How much per unit: ", buf)) == 0)
+    if (!(p = getstarg(player->argp[3], "How much per unit: ", buf)))
        return RET_SYN;
     bid = atof(p);
     if (bid <= 0)
@@ -115,13 +115,13 @@ buy(void)
     would make him go broke.  Ken, I ought to skin you alive for making me code
     this part up.*/
     tally = 0.0;
-    for (q = 0; gettrade(q, &tmpt); q++) {
+    for (n = 0; gettrade(n, &tmpt); n++) {
        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 (n = 0; getcomm(n, &comt); n++) {
        if (comt.com_maxbidder == player->cnum &&
            comt.com_owner != 0 && comt.com_owner != player->cnum) {
            tally += comt.com_price * comt.com_amount * buytax;
@@ -204,14 +204,10 @@ check_market(void)
     int m;
     int n;
     time_t now;
-    double tmoney;
     double tleft;
-    double subleft;
-    double monleft;
     double gain;
     double price;
 
-/*    logerror("Checking the market.\n");*/
     for (n = 0; getcomm(n, &comm); n++) {
        if (comm.com_maxbidder == comm.com_owner || comm.com_owner == 0)
            continue;
@@ -226,31 +222,14 @@ check_market(void)
        sect = getsectp(comm.com_x, comm.com_y);
        m = sect->sct_item[comm.com_type];
 
-       monleft = 0;
-
        price = comm.com_price * comm.com_amount * buytax;
        gain = comm.com_price * comm.com_amount;
 
        natp = getnatp(comm.com_maxbidder);
-       tmoney = natp->nat_money;
-       if (tmoney <= 0)
-           monleft = price;
-       if (tmoney < price && tmoney > 0) {
-           monleft = price - (tmoney - 1);
-           tmoney = 1;
-           price = price - monleft;
-       } else if (tmoney > 0) {
-           monleft = 0;
-           tmoney = tmoney - price;
-       }
-
-       /* Subtract the amount of money that needs to come out in a loan. */
-       subleft = monleft;
-
-       if (monleft > 0) {
+       if (natp->nat_money < price) {
            nreport(comm.com_maxbidder, N_WELCH_DEAL, comm.com_owner, 1);
            wu(0, comm.com_maxbidder,
-              "You didn't have enough cash/credit to cover the cost.\n");
+              "You didn't have enough cash to cover the cost.\n");
            wu(0, comm.com_owner,
               "Sale #%d fell through.  Goods remain on the market.\n", n);
            comm.com_maxbidder = comm.com_owner;
@@ -277,17 +256,16 @@ check_market(void)
            wu(0, comm.com_maxbidder,
               "You just bought %d %s from %s for $%.2f\n",
               comm.com_amount, ichr[comm.com_type].i_name,
-              cname(comm.com_owner), gain * buytax);
+              cname(comm.com_owner), price);
+           natp->nat_money -= roundavg(price);
+           putnat(natp);
            natp = getnatp(comm.com_owner);
-           /* Make sure we subtract the amount that came out in a loan */
-           natp->nat_money += (gain - subleft);
-           natp = getnatp(comm.com_maxbidder);
-           natp->nat_money = tmoney;
+           natp->nat_money += roundavg(gain);
+           putnat(natp);
            comm.com_owner = 0;
        }
        comm.com_owner = 0;
        putcomm(n, &comm);
     }
-/*    logerror("Done checking the market.\n");*/
     return RET_OK;
 }