(trade_check_item_ok): New.

(trade_check_ok): Use it and simplify.

(set): Use new trade_check_item_ok().  The code replaced by it didn't
work (abusable bug).
This commit is contained in:
Markus Armbruster 2006-03-25 15:26:29 +00:00
parent 79714720cc
commit 38f3f7ea49
3 changed files with 13 additions and 16 deletions

View file

@ -65,6 +65,7 @@ union trdgenstr {
}; };
extern int trade_check_ok(struct trdstr *, union trdgenstr *); extern int trade_check_ok(struct trdstr *, union trdgenstr *);
extern int trade_check_item_ok(union trdgenstr *);
extern s_char *trade_nameof(struct trdstr *, union trdgenstr *); extern s_char *trade_nameof(struct trdstr *, union trdgenstr *);
extern int trade_desc(struct trdstr *, union trdgenstr *); extern int trade_desc(struct trdstr *, union trdgenstr *);
extern int trade_getitem(struct trdstr *, union trdgenstr *); extern int trade_getitem(struct trdstr *, union trdgenstr *);

View file

@ -64,7 +64,6 @@ set(void)
struct nstr_item ni; struct nstr_item ni;
struct nstr_item ni_trade; struct nstr_item ni_trade;
union trdgenstr item; union trdgenstr item;
union trdgenstr check;
struct sctstr sect; struct sctstr sect;
int freeslot; int freeslot;
int foundslot; int foundslot;
@ -98,13 +97,10 @@ set(void)
trade.trd_type = type; trade.trd_type = type;
sprintf(prompt, "%s #%d; Price? ", sprintf(prompt, "%s #%d; Price? ",
trade_nameof(&trade, &item), ni.cur); trade_nameof(&trade, &item), ni.cur);
memcpy(&check, &item, sizeof(union trdgenstr));
if ((p = getstarg(player->argp[3], prompt, buf)) == 0) if ((p = getstarg(player->argp[3], prompt, buf)) == 0)
break; break;
if (memcmp(&check, &item, sizeof(union trdgenstr))) { if (!trade_check_item_ok(&item))
pr("That item has changed!\n");
return RET_FAIL; return RET_FAIL;
}
if ((price = atoi(p)) < 0) if ((price = atoi(p)) < 0)
continue; continue;
foundslot = -1; foundslot = -1;

View file

@ -55,22 +55,22 @@
int int
trade_check_ok(struct trdstr *tp, union trdgenstr *tgp) trade_check_ok(struct trdstr *tp, union trdgenstr *tgp)
{ {
union trdgenstr check; return check_trade_ok(tp) && trade_check_item_ok(tgp);
}
if (!check_trade_ok(tp)) int
return 0; trade_check_item_ok(union trdgenstr *tgp)
{
trade_getitem(tp, &check); if (tgp->gen.ef_type == EF_LAND)
if (tp->trd_type == EF_LAND)
return check_land_ok(&tgp->lnd); return check_land_ok(&tgp->lnd);
if (tp->trd_type == EF_PLANE) if (tgp->gen.ef_type == EF_PLANE)
return check_plane_ok(&tgp->pln); return check_plane_ok(&tgp->pln);
if (tp->trd_type == EF_SHIP) if (tgp->gen.ef_type == EF_SHIP)
return check_ship_ok(&tgp->shp); return check_ship_ok(&tgp->shp);
if (tp->trd_type == EF_NUKE) if (tgp->gen.ef_type == EF_NUKE)
return check_nuke_ok(&tgp->nuk); return check_nuke_ok(&tgp->nuk);
CANT_HAPPEN("Bad TRD_TYPE"); CANT_HAPPEN("Bad EF_TYPE");
pr("Trade lot #%d went bad!\n", tp->trd_uid); pr("Trade lot went bad!\n");
return 0; return 0;
} }