(trad, set): Treat trade file slots with zero owner as unused, so that

freshly extended trade file makes sense.  When set() removes a lot,
simply zero the slot.

(set): Initialize trd_uid.

(trade_check_ok): Use check_land_ok() & friends instead of doing it by
hand, but wrong.  This fixes bying planes and land units loaded on
ships that moved after loading.

(check_trade_ok): New.
(trade_check_ok): Use it.  Remove unused argument lot.  Callers
changed.
This commit is contained in:
Markus Armbruster 2004-08-28 15:22:50 +00:00
parent 133c1754f9
commit e16e38dfab
6 changed files with 52 additions and 47 deletions

View file

@ -52,31 +52,25 @@
#include "optlist.h"
int
trade_check_ok(int lot, struct trdstr *tp, union trdgenstr *tgp)
trade_check_ok(struct trdstr *tp, union trdgenstr *tgp)
{
union trdgenstr check;
struct trdstr trade;
int result = 0;
if (!check_trade_ok(tp))
return 0;
trade_getitem(tp, &check);
if (tp->trd_type == EF_LAND)
result = memcmp(&(check.lnd), &(tgp->lnd), sizeof(struct lndstr));
else if (tp->trd_type == EF_PLANE)
result = memcmp(&(check.pln), &(tgp->pln), sizeof(struct plnstr));
else if (tp->trd_type == EF_SHIP)
result = memcmp(&(check.shp), &(tgp->shp), sizeof(struct shpstr));
else
result = memcmp(&(check.nuk), &(tgp->nuk), sizeof(struct nukstr));
if (result) {
pr("That item has changed!\n");
return 0;
}
gettrade(lot, &trade);
if (memcmp((s_char *)&trade, (s_char *)tp, sizeof(struct trdstr))) {
pr("That item has changed!\n");
return 0;
}
return 1;
return check_land_ok(&tgp->lnd);
if (tp->trd_type == EF_PLANE)
return check_plane_ok(&tgp->pln);
if (tp->trd_type == EF_SHIP)
return check_ship_ok(&tgp->shp);
if (tp->trd_type == EF_NUKE)
return check_nuke_ok(&tgp->nuk);
CANT_HAPPEN("Bad TRD_TYPE");
pr("Trade lot #%d went bad!\n", tp->trd_uid);
return 0;
}
s_char *