From 324109ae4545b9188026369ee4b8bacb4faa7646 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sun, 1 Jul 2012 14:33:49 +0200 Subject: [PATCH] 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. --- include/trade.h | 1 + src/lib/commands/set.c | 2 ++ src/lib/global/item.config | 4 ++-- src/lib/subs/trdsub.c | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/trade.h b/include/trade.h index f12fc97b..6fe7da42 100644 --- a/include/trade.h +++ b/include/trade.h @@ -60,6 +60,7 @@ struct trdstr { extern int trade_check_ok(struct trdstr *, struct empobj *); extern char *trade_nameof(struct trdstr *, 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 *); #define gettrade(n, p) ef_read(EF_TRADE, (n), (p)) diff --git a/src/lib/commands/set.c b/src/lib/commands/set.c index b00eabfc..374fd5dd 100644 --- a/src/lib/commands/set.c +++ b/src/lib/commands/set.c @@ -116,6 +116,8 @@ set(void) puttrade(ni_trade.cur, &trade); } } else { + if (trade_has_unsalable_cargo(&item.gen, 1)) + return RET_FAIL; if (foundslot >= 0) id = foundslot; else if (freeslot >= 0) diff --git a/src/lib/global/item.config b/src/lib/global/item.config index a1ac560e..91903390 100644 --- a/src/lib/global/item.config +++ b/src/lib/global/item.config @@ -27,7 +27,7 @@ # item.config: Item characteristics # # Known contributors to this file: -# Markus Armbruster, 2006-2011 +# Markus Armbruster, 2006-2012 # # Derived from item.c; no known contributors. # @@ -45,7 +45,7 @@ config item # ineff norm ware urban bank 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" - 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" 3 "g" 60 1 10 1 1 10 1 1 100 "guns" 4 "p" 4 1 1 1 1 10 1 1 50 "petrol" diff --git a/src/lib/subs/trdsub.c b/src/lib/subs/trdsub.c index 93391497..2d43f612 100644 --- a/src/lib/subs/trdsub.c +++ b/src/lib/subs/trdsub.c @@ -48,6 +48,7 @@ #include "sect.h" #include "ship.h" #include "trade.h" +#include "unit.h" #include "xy.h" int @@ -171,6 +172,38 @@ trade_desc(struct empobj *tgp) 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 trade_getitem(struct trdstr *tp, union empobj_storage *tgp) {