]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/trad.c
Fix extension of market bidding time when high bidder changes
[empserver] / src / lib / commands / trad.c
index ef46398d9e407d42e66f99bf5c4cdb68c730c1b6..6a850568a76796dd151c2613100bb0804e4f891a 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2004, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2013, 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.
  *
  *  ---
  *
  *  trad.c: Buy units/ships/planes/nukes from other nations.
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Pat Loney, 1992
  *     Steve McClure, 1996-2000
+ *     Markus Armbruster, 2004-2013
  */
 
+#include <config.h>
+
 #include <ctype.h>
-#include "misc.h"
-#include "sect.h"
-#include "nat.h"
+#include "chance.h"
+#include "commands.h"
+#include "commodity.h"
+#include "empobj.h"
+#include "land.h"
+#include "loan.h"
 #include "news.h"
-#include "item.h"
-#include "ship.h"
 #include "nuke.h"
-#include "land.h"
+#include "optlist.h"
 #include "plane.h"
+#include "ship.h"
 #include "trade.h"
-#include "xy.h"
-#include "nsc.h"
-#include "file.h"
-#include "player.h"
-#include "commodity.h"
-#include "loan.h"
-#include "commands.h"
-#include "optlist.h"
+#include "unit.h"
 
 /*
  * format: trade
@@ -70,16 +67,14 @@ trad(void)
     struct nstr_item ni;
     struct trdstr trade;
     struct trdstr tmpt;
-    union trdgenstr tg;
-    int plflags;
+    union empobj_storage tg;
     double canspend;
     time_t now;
     int bid;
     double tleft;
     double tally;
-    int q;
-    s_char buf[1024];
-
+    int i;
+    char buf[1024];
 
     if (!opt_MARKET) {
        pr("The market is disabled.\n");
@@ -96,27 +91,21 @@ trad(void)
     pr(" --- --------  -- --------- -----  -------------------------\n");
 
     snxtitem_all(&ni, EF_TRADE);
-    while (nxtitem(&ni, (char *)&trade)) {
+    while (nxtitem(&ni, &trade)) {
        if (trade.trd_owner == 0)
            continue;
        if (!trade_getitem(&trade, &tg)) {
            continue;
        };
-       /* fix up database if things get weird */
-       /*if (trade.trd_owner != tg.gen.trg_own) {
-          trade.trd_unitid = -1;
-          (void) puttrade(ni.cur, &trade);
-          continue;
-          } */
        pr(" %3d ", ni.cur);
        (void)time(&now);
        tleft =
            TRADE_DELAY / 3600.0 - (now - trade.trd_markettime) / 3600.0;
        if (tleft < 0.0)
            tleft = 0.0;
-       pr("$%7ld  %2d %5.2f hrs ", trade.trd_price,
-          trade.trd_maxbidder, tleft);
-       (void)trade_desc(&trade, &tg);  /* XXX */
+       pr("$%7d  %2d %5.2f hrs ",
+          trade.trd_price, trade.trd_maxbidder, tleft);
+       trade_desc(&tg.gen);    /* XXX */
        pr("\n");
        if (trade.trd_owner == player->cnum && !player->god)
            pr(" (your own lot)\n");
@@ -126,7 +115,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;
@@ -145,22 +135,17 @@ trad(void)
     }
     if (!trade_getitem(&trade, &tg)) {
        pr("Can't find trade #%d!\n", trade.trd_unitid);
+       trade.trd_owner = 0;
        trade.trd_unitid = -1;
        if (!puttrade(lotno, &trade)) {
+           logerror("trad: can't write trade");
            pr("Couldn't save after getitem failed; get help!\n");
-           return RET_SYS;
+           return RET_FAIL;
        }
        return RET_OK;
     }
     switch (trade.trd_type) {
     case EF_NUKE:
-       /*
-          if (!getsect(tg.gen.trg_x, tg.gen.trg_y, &sect)) {
-          return RET_FAIL;
-          }
-          trade.trd_owner = sect.sct_own;
-          break;
-        */
     case EF_PLANE:
     case EF_SHIP:
     case EF_LAND:
@@ -180,44 +165,39 @@ 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. Must be owned (except for satellites) and
-     * must be a 60% airfield (except for VTOL planes).
-     */
-    if (((trade.trd_type == EF_PLANE) || (trade.trd_type == EF_NUKE))
-       && ((trade.trd_type == EF_NUKE) ||
-           !(tg.pln.pln_flags & PLN_LAUNCHED))) {
-       plflags = plchr[(int)tg.pln.pln_type].pl_flags;
+
+    /* 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))
+           if (!trade_check_ok(&trade, &tg.gen))
                return RET_FAIL;
-           if (p == 0) {
+           if (!p) {
                return RET_FAIL;
            }
            if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, &sect)) {
                pr("Bad sector designation; try again!\n");
                continue;
            }
-           if (!player->owner && !(plflags & P_O)) {
+           if (!player->owner) {
                pr("You don't own that sector; try again!\n");
                continue;
            }
-           if (!(plflags & (P_V | P_O))) {
+           if (!(plchr[tg.plane.pln_type].pl_flags & P_V)) {
                if (!player->god && (sect.sct_type != SCT_AIRPT)) {
                    pr("Destination sector is not an airfield!\n");
                    continue;
@@ -229,13 +209,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))
+           if (!trade_check_ok(&trade, &tg.gen))
                return RET_FAIL;
-           if (p == 0) {
+           if (!p) {
                return RET_FAIL;
            }
            if (!sarg_xy(p, &sx, &sy) || !getsect(sx, sy, &sect)) {
@@ -256,16 +235,16 @@ trad(void)
            }
            break;
        }
+    } else {
+       /* This trade doesn't teleport; make destination invalid */
+       sx = 1;
+       sy = 0;
     }
 
-    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)
+    p = getstring("How much do you bid: ", buf);
+    if (!p || !*p)
        return RET_OK;
-    if (!trade_check_ok(&trade, &tg))
+    if (!trade_check_ok(&trade, &tg.gen))
        return RET_FAIL;
     bid = atoi(p);
     if (bid < price)
@@ -275,11 +254,10 @@ trad(void)
        return RET_OK;
     }
     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) &&
+       if (trade.trd_markettime  + TRADE_DELAY - now < minutes(5) &&
            trade.trd_maxbidder != player->cnum)
-           trade.trd_markettime += 300;
+           trade.trd_markettime = now + minutes(5) - TRADE_DELAY;
        trade.trd_price = bid;
        trade.trd_maxbidder = player->cnum;
        trade.trd_x = sx;
@@ -299,37 +277,29 @@ int
 check_trade(void)
 {
     int n;
-    int j;
-    struct nstr_item ni;
-    struct plnstr plane;
-    struct lndstr land;
     struct natstr *natp;
     struct trdstr trade;
-    union trdgenstr tg;
+    union empobj_storage tg;
     time_t now;
-    double subleft;
-    double monleft;
     double tleft;
-    float price;
+    int price;
     int saveid;
-    struct lonstr loan;
-    long outstanding;          /* Outstanding debt */
-    long couval;               /* Value of country's goods */
-    int foundloan;
+    natid seller;
 
-/*    logerror("Checking the trades.\n");*/
     for (n = 0; gettrade(n, &trade); n++) {
        if (trade.trd_unitid < 0)
            continue;
        if (!trade_getitem(&trade, &tg))
            continue;
-       if (tg.gen.trg_own == 0) {
+       if (tg.gen.own == 0) {
+           trade.trd_owner = 0;
            trade.trd_unitid = -1;
            puttrade(n, &trade);
            continue;
        }
-       if (tg.gen.trg_own != trade.trd_owner) {
-           logerror("Something weird, tg.gen.trg_own != trade.trd_owner!\n");
+       if (tg.gen.own != trade.trd_owner) {
+           logerror("Something weird, tg.gen.own != trade.trd_owner!\n");
+           trade.trd_owner = 0;
            trade.trd_unitid = -1;
            puttrade(n, &trade);
            continue;
@@ -347,224 +317,103 @@ check_trade(void)
            continue;
 
        saveid = trade.trd_unitid;
+       seller = trade.trd_owner;
+       trade.trd_owner = 0;
        trade.trd_unitid = -1;
        if (!puttrade(n, &trade)) {
            logerror("Couldn't save trade after purchase; get help!\n");
            continue;
        }
 
-       monleft = 0;
        price = trade.trd_price;
        natp = getnatp(trade.trd_maxbidder);
-       if (natp->nat_money <= 0)
-           monleft = price;
-       if (natp->nat_money < price && natp->nat_money > 0) {
-           monleft = price - (natp->nat_money - 1);
-           natp->nat_money = 1;
-           price = price - monleft;
-       } else if (natp->nat_money > 0) {
-           monleft = 0;
-           natp->nat_money -= price;
-       }
-
-       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,
+       if (natp->nat_money < price) {
+           nreport(trade.trd_maxbidder, N_WELCH_DEAL, seller, 1);
+           wu(0, seller,
               "%s tried to buy a %s #%d from you for $%.2f\n",
-              cname(trade.trd_maxbidder), trade_nameof(&trade, &tg),
-              saveid, (float)(price * tradetax));
-           wu(0, trade.trd_owner, "   but couldn't afford it.\n");
-           wu(0, trade.trd_owner,
+              cname(trade.trd_maxbidder), trade_nameof(&trade, &tg.gen),
+              saveid, price * tradetax);
+           wu(0, seller, "   but couldn't afford it.\n");
+           wu(0, seller,
               "   Your item was taken off the market.\n");
            wu(0, trade.trd_maxbidder,
-              "You tried to buy %s #%d from %s for $%.2f\n",
-              trade_nameof(&trade, &tg), saveid, cname(trade.trd_owner),
-              (float)(price * tradetax));
+              "You tried to buy %s #%d from %s for $%d\n",
+              trade_nameof(&trade, &tg.gen), saveid, cname(seller),
+              price);
            wu(0, trade.trd_maxbidder, "but couldn't afford it.\n");
            continue;
        }
 
 /* If we get this far, the sale will go through. */
-/* Only pay tax on the part you actually get cash for.  As a break,
-   we don't tax the part you have to give a loan on. */
 
+       natp->nat_money -= price;
        putnat(natp);
-       natp = getnatp(trade.trd_owner);
-       /* Make sure we subtract the extra amount */
-       natp->nat_money += (roundavg(price * tradetax) - subleft);
+
+       natp = getnatp(seller);
+       natp->nat_money += roundavg(price * tradetax);
        putnat(natp);
+
        switch (trade.trd_type) {
        case EF_NUKE:
-           tg.nuk.nuk_x = trade.trd_x;
-           tg.nuk.nuk_y = trade.trd_y;
-           makelost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid, tg.nuk.nuk_x,
-                    tg.nuk.nuk_y);
-           tg.nuk.nuk_own = trade.trd_maxbidder;
-           makenotlost(EF_NUKE, tg.nuk.nuk_own, tg.nuk.nuk_uid,
-                       tg.nuk.nuk_x, tg.nuk.nuk_y);
+           tg.nuke.nuk_x = trade.trd_x;
+           tg.nuke.nuk_y = trade.trd_y;
+           tg.nuke.nuk_plane = -1;
            break;
        case EF_PLANE:
-           if ((tg.pln.pln_flags & PLN_LAUNCHED) == 0) {
-               tg.pln.pln_x = trade.trd_x;
-               tg.pln.pln_y = trade.trd_y;
+           if (!pln_is_in_orbit(&tg.plane)) {
+               tg.plane.pln_x = trade.trd_x;
+               tg.plane.pln_y = trade.trd_y;
            }
-           makelost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid,
-                    tg.pln.pln_x, tg.pln.pln_y);
-           tg.pln.pln_own = trade.trd_maxbidder;
-           makenotlost(EF_PLANE, tg.pln.pln_own, tg.pln.pln_uid,
-                       tg.pln.pln_x, tg.pln.pln_y);
-           tg.pln.pln_wing = ' ';
-           /* no cheap version of fly */
            if (opt_MOB_ACCESS) {
-               tg.pln.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
+               tg.plane.pln_mobil = -(etu_per_update / sect_mob_neg_factor);
+               game_tick_to_now(&tg.plane.pln_access);
            } else {
-               tg.pln.pln_mobil = 0;
+               tg.plane.pln_mobil = 0;
            }
-           tg.pln.pln_mission = 0;
-           tg.pln.pln_harden = 0;
-           time(&tg.pln.pln_access);
-           tg.pln.pln_ship = -1;
-           tg.pln.pln_land = -1;
+           tg.plane.pln_harden = 0;
+           tg.plane.pln_ship = -1;
+           tg.plane.pln_land = -1;
            break;
        case EF_SHIP:
-           takeover_ship(&tg.shp, trade.trd_maxbidder, 0);
            break;
        case EF_LAND:
-           tg.lnd.lnd_x = trade.trd_x;
-           tg.lnd.lnd_y = trade.trd_y;
-           if (tg.lnd.lnd_ship >= 0) {
-               struct shpstr ship;
-               getship(tg.lnd.lnd_ship, &ship);
-               ship.shp_nland--;
-               putship(ship.shp_uid, &ship);
-           }
-           makelost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid, tg.lnd.lnd_x,
-                    tg.lnd.lnd_y);
-           tg.lnd.lnd_own = trade.trd_maxbidder;
-           makenotlost(EF_LAND, tg.lnd.lnd_own, tg.lnd.lnd_uid,
-                       tg.lnd.lnd_x, tg.lnd.lnd_y);
-           tg.lnd.lnd_army = ' ';
-           /* no cheap version of fly */
+           tg.land.lnd_x = trade.trd_x;
+           tg.land.lnd_y = trade.trd_y;
            if (opt_MOB_ACCESS) {
-               tg.lnd.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
+               tg.land.lnd_mobil = -(etu_per_update / sect_mob_neg_factor);
+               game_tick_to_now(&tg.land.lnd_access);
            } else {
-               tg.lnd.lnd_mobil = 0;
-           }
-           tg.lnd.lnd_harden = 0;
-           time(&tg.lnd.lnd_access);
-           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)) {
-               if (land.lnd_land != tg.lnd.lnd_uid)
-                   continue;
-               land.lnd_land = -1;
-               wu(0, land.lnd_own, "unit #%d dropped in %s\n",
-                  land.lnd_uid,
-                  xyas(land.lnd_x, land.lnd_y, land.lnd_own));
-               putland(land.lnd_uid, &land);
+               tg.land.lnd_mobil = 0;
            }
-           /* 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)) {
-               if (plane.pln_flags & PLN_LAUNCHED)
-                   continue;
-               if (plane.pln_land != land.lnd_uid)
-                   continue;
-               plane.pln_land = -1;
-               wu(0, plane.pln_own, "plane #%d dropped in %s\n",
-                  plane.pln_uid,
-                  xyas(plane.pln_x, plane.pln_y, plane.pln_own));
-               putplane(plane.pln_uid, &plane);
-           }
-           tg.lnd.lnd_ship = -1;
-           tg.lnd.lnd_land = -1;
+           tg.land.lnd_harden = 0;
+           unit_drop_cargo(&tg.gen, 0);
+           tg.land.lnd_ship = -1;
+           tg.land.lnd_land = -1;
            break;
        default:
            logerror("Bad trade type %d in trade\n", trade.trd_type);
            break;
        }
-       if (!ef_write(trade.trd_type, saveid, (char *)&tg)) {
-           logerror("Couldn't write unit to disk; seek help.\n");
-           continue;
-       }
-       nreport(trade.trd_owner, N_MAKE_SALE, trade.trd_maxbidder, 1);
-       wu(0, trade.trd_owner, "%s bought a %s #%d from you for $%.2f\n",
-          cname(trade.trd_maxbidder), trade_nameof(&trade, &tg),
-          saveid, (float)(price * tradetax));
+       unit_give_away(&tg.gen, trade.trd_maxbidder, 0);
+       put_empobj(trade.trd_type, saveid, &tg.gen);
+
+       nreport(seller, N_MAKE_SALE, trade.trd_maxbidder, 1);
+       wu(0, seller, "%s bought %s #%d from you for $%.2f\n",
+          cname(trade.trd_maxbidder), trade_nameof(&trade, &tg.gen),
+          saveid, price * tradetax);
        wu(0, trade.trd_maxbidder,
-          "The bidding is over & you bought %s #%d from %s for $%.2f\n",
-          trade_nameof(&trade, &tg), saveid, cname(trade.trd_owner),
-          (float)price);
+          "The bidding is over & you bought %s #%d from %s for $%d\n",
+          trade_nameof(&trade, &tg.gen), saveid, cname(seller),
+          price);
     }
-/*    logerror("Done checking the trades.\n");*/
     return RET_OK;
 }
 
 int
-ontradingblock(int type, int *ptr)
-         /* Generic pointer */
+ontradingblock(int type, void *ptr)
 {
     struct trdstr trade;
-    union trdgenstr tg;
+    union empobj_storage tg;
     int n;
 
     for (n = 0; gettrade(n, &trade); n++) {
@@ -574,18 +423,17 @@ ontradingblock(int type, int *ptr)
            continue;
        if (trade.trd_type != type)
            continue;
-       if (tg.gen.trg_uid == ((struct genstr *)ptr)->trg_uid)
+       if (tg.gen.uid == ((struct empobj *)ptr)->uid)
            return 1;
     }
     return 0;
 }
 
 void
-trdswitchown(int type, int *ptr, int newown)
-         /* Generic pointer */
+trdswitchown(int type, void *ptr, int newown)
 {
     struct trdstr trade;
-    union trdgenstr tg;
+    union empobj_storage tg;
     int n;
 
     for (n = 0; gettrade(n, &trade); n++) {
@@ -595,7 +443,7 @@ trdswitchown(int type, int *ptr, int newown)
            continue;
        if (trade.trd_type != type)
            continue;
-       if (tg.gen.trg_uid != ((struct genstr *)ptr)->trg_uid)
+       if (tg.gen.uid != ((struct empobj *)ptr)->uid)
            continue;
        if (trade.trd_owner == trade.trd_maxbidder)
            trade.trd_maxbidder = newown;