(ef_byname_from): New.

(set, mission, multifire, fuel, cons_choose, cede): Use it instead of
ef_byname().  Remove the hacks to map unwanted results to wanted
results.  The hacks in set() were broken: bad input made the code cast
arbitrary items to union trdgenstr, with potentially disastrous
consequences.  Closes #906483 and #906486.

(set): Less cryptic prompt and diagnostics.
This commit is contained in:
Markus Armbruster 2005-10-27 21:33:17 +00:00
parent 2df98825e9
commit 2fc1e74a72
8 changed files with 54 additions and 30 deletions

View file

@ -53,6 +53,7 @@
int
set(void)
{
static int ef_saleable[] = { EF_SHIP, EF_PLANE, EF_LAND, EF_NUKE, EF_BAD };
char *p;
int type;
int price;
@ -76,18 +77,12 @@ set(void)
check_market();
check_trade();
if ((p = getstarg(player->argp[1], "Item type? ", buf)) == 0)
if ((p = getstarg(player->argp[1], "Ship, plane, land unit or nuke? ", buf)) == 0)
return RET_SYN;
if ((type = ef_byname(p)) < 0) {
pr("%s: not an item type\n", p);
if ((type = ef_byname_from(p, ef_saleable)) < 0) {
pr("You can sell only ships, planes, land units or nukes\n", p);
return RET_SYN;
}
if (type == EF_SECTOR)
type = EF_SHIP;
if (type == EF_NEWS)
type = EF_NUKE;
if (type == EF_LOAN)
type = EF_LAND;
if (!snxtitem(&ni, type, player->argp[2]))
return RET_SYN;
while (nxtitem(&ni, &item)) {