extern int check_plane_ok(struct plnstr *);
extern int check_comm_ok(struct comstr *);
extern int check_loan_ok(struct lonstr *);
+extern int check_trade_ok(struct trdstr *);
/* fsize.c */
extern int fsize(int);
extern int blksize(int);
struct shpstr shp;
};
-extern int trade_check_ok(int, struct trdstr *, union trdgenstr *);
+extern int trade_check_ok(struct trdstr *, union trdgenstr *);
extern s_char *trade_nameof(struct trdstr *, union trdgenstr *);
extern int trade_desc(struct trdstr *, union trdgenstr *);
extern int trade_getitem(struct trdstr *, union trdgenstr *);
freeslot = -1;
snxtitem_all(&ni_trade, EF_TRADE);
while (nxtitem(&ni_trade, (char *)&trade)) {
- if (trade.trd_unitid < 0)
+ if (trade.trd_owner == 0)
freeslot = ni_trade.cur;
if (trade.trd_unitid == ni.cur && trade.trd_type == type) {
foundslot = ni_trade.cur;
break;
}
}
- if (price == 0 && foundslot >= 0) {
- pr("%s #%d (lot #%d) removed from trading\n",
- trade_nameof(&trade, &item), ni.cur, foundslot);
- trade.trd_type = 0;
- trade.trd_owner = 0;
- trade.trd_unitid = -1;
- trade.trd_price = 0;
- (void)time(&now);
- trade.trd_markettime = now;
- trade.trd_maxbidder = player->cnum;
- puttrade(ni_trade.cur, &trade);
- } else if (price > 0) {
+ if (price <= 0) {
+ if (foundslot >= 0) {
+ pr("%s #%d (lot #%d) removed from trading\n",
+ trade_nameof(&trade, &item), ni.cur, foundslot);
+ memset(&trade, 0, sizeof(trade));
+ puttrade(ni_trade.cur, &trade);
+ }
+ } else {
+ if (foundslot >= 0)
+ id = foundslot;
+ else if (freeslot >= 0)
+ id = freeslot;
+ else {
+ ef_extend(EF_TRADE, 1);
+ id = ni_trade.cur;
+ }
trade.trd_x = item.gen.trg_x;
trade.trd_y = item.gen.trg_x;
trade.trd_type = type;
trade.trd_owner = player->cnum;
+ trade.trd_uid = id;
trade.trd_unitid = ni.cur;
trade.trd_price = price;
(void)time(&now);
trade.trd_markettime = now;
trade.trd_maxbidder = player->cnum;
- if (foundslot >= 0)
- id = foundslot;
- else if (freeslot >= 0)
- id = freeslot;
- else {
- ef_extend(EF_TRADE, 1);
- id = ni_trade.cur;
- }
puttrade(id, &trade);
pr("%s #%d (lot #%d) price %s to $%d\n",
trade_nameof(&trade, &item), ni.cur,
snxtitem_all(&ni, EF_TRADE);
while (nxtitem(&ni, (char *)&trade)) {
- if (trade.trd_unitid < 0)
+ if (trade.trd_owner == 0)
continue;
if (!trade_getitem(&trade, &tg)) {
continue;
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;
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;
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)
}
return 1;
}
+
+int
+check_trade_ok(struct trdstr *tp)
+{
+ struct trdstr chktrade;
+
+ gettrade(tp->trd_uid, &chktrade);
+ if (memcmp(tp, &chktrade, sizeof(struct trdstr))) {
+ pr("Trade lot #%d has changed!\n", tp->trd_uid);
+ return 0;
+ }
+ return 1;
+}
#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 *