Forbid selling units with unsalable cargo, permit selling military

Deities can customize which commodities can be sold in table item.
Default is to allow anything but civilians and military.  However,
this applies only to the commodity market, not to the unit market:
cargo of ships and land units is not restricted.

Make the two markets consistent: permit selling military by default,
forbid selling units carrying unsalable commodities.  This outlaws
selling units carrying civilians by default.
This commit is contained in:
Markus Armbruster 2012-07-01 14:33:49 +02:00
parent 6c086a8110
commit 324109ae45
4 changed files with 38 additions and 2 deletions

View file

@ -60,6 +60,7 @@ struct trdstr {
extern int trade_check_ok(struct trdstr *, struct empobj *); extern int trade_check_ok(struct trdstr *, struct empobj *);
extern char *trade_nameof(struct trdstr *, struct empobj *); extern char *trade_nameof(struct trdstr *, struct empobj *);
extern int trade_desc(struct empobj *); extern int trade_desc(struct empobj *);
extern int trade_has_unsalable_cargo(struct empobj *, int);
extern int trade_getitem(struct trdstr *, union empobj_storage *); extern int trade_getitem(struct trdstr *, union empobj_storage *);
#define gettrade(n, p) ef_read(EF_TRADE, (n), (p)) #define gettrade(n, p) ef_read(EF_TRADE, (n), (p))

View file

@ -116,6 +116,8 @@ set(void)
puttrade(ni_trade.cur, &trade); puttrade(ni_trade.cur, &trade);
} }
} else { } else {
if (trade_has_unsalable_cargo(&item.gen, 1))
return RET_FAIL;
if (foundslot >= 0) if (foundslot >= 0)
id = foundslot; id = foundslot;
else if (freeslot >= 0) else if (freeslot >= 0)

View file

@ -27,7 +27,7 @@
# item.config: Item characteristics # item.config: Item characteristics
# #
# Known contributors to this file: # Known contributors to this file:
# Markus Armbruster, 2006-2011 # Markus Armbruster, 2006-2012
# #
# Derived from item.c; no known contributors. # Derived from item.c; no known contributors.
# #
@ -45,7 +45,7 @@
config item # ineff norm ware urban bank config item # ineff norm ware urban bank
uid mnem val sell lbs pkg(0) pkg(1) pkg(2) pkg(3) pkg(4) melt name uid mnem val sell lbs pkg(0) pkg(1) pkg(2) pkg(3) pkg(4) melt name
0 "c" 1 0 1 1 10 10 10 10 4 "civilians" 0 "c" 1 0 1 1 10 10 10 10 4 "civilians"
1 "m" 0 0 1 1 1 1 1 1 20 "military" 1 "m" 0 1 1 1 1 1 1 1 20 "military"
2 "s" 5 1 1 1 1 10 1 1 80 "shells" 2 "s" 5 1 1 1 1 10 1 1 80 "shells"
3 "g" 60 1 10 1 1 10 1 1 100 "guns" 3 "g" 60 1 10 1 1 10 1 1 100 "guns"
4 "p" 4 1 1 1 1 10 1 1 50 "petrol" 4 "p" 4 1 1 1 1 10 1 1 50 "petrol"

View file

@ -48,6 +48,7 @@
#include "sect.h" #include "sect.h"
#include "ship.h" #include "ship.h"
#include "trade.h" #include "trade.h"
#include "unit.h"
#include "xy.h" #include "xy.h"
int int
@ -171,6 +172,38 @@ trade_desc(struct empobj *tgp)
return 1; return 1;
} }
int
trade_has_unsalable_cargo(struct empobj *tgp, int noisy)
{
int ret, i, type;
short *item;
struct nstr_item ni;
union empobj_storage cargo;
ret = 0;
if (tgp->ef_type == EF_SHIP || tgp->ef_type == EF_LAND) {
item = tgp->ef_type == EF_SHIP
? ((struct shpstr *)tgp)->shp_item
: ((struct lndstr *)tgp)->lnd_item;
for (i = I_NONE + 1; i <= I_MAX; i++) {
if (item[i] && !ichr[i].i_sell) {
if (noisy)
pr("%s carries %s, which you can't sell.\n",
unit_nameof(tgp), ichr[i].i_name);
ret = 1;
}
}
}
for (type = EF_PLANE; type <= EF_NUKE; type++) {
snxtitem_cargo(&ni, type, tgp->ef_type, tgp->uid);
while (nxtitem(&ni, &cargo))
ret |= trade_has_unsalable_cargo(&cargo.gen, noisy);
}
return ret;
}
int int
trade_getitem(struct trdstr *tp, union empobj_storage *tgp) trade_getitem(struct trdstr *tp, union empobj_storage *tgp)
{ {