]> git.pond.sub.org Git - empserver/commitdiff
Forbid selling units with unsalable cargo, permit selling military
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 1 Jul 2012 12:33:49 +0000 (14:33 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 13 Jul 2012 18:15:34 +0000 (20:15 +0200)
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
src/lib/commands/set.c
src/lib/global/item.config
src/lib/subs/trdsub.c

index f12fc97be6544448e911a87abbdb649490b81464..6fe7da4246b55d6867e2d9dc549f6cff8ede8968 100644 (file)
@@ -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))
index b00eabfc063b145fec1c404d28fc808af62f7cea..374fd5dd7c729997400d4c1c14af1b52d7d860a1 100644 (file)
@@ -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)
index a1ac560ee741655b66b9a59465ab0b8194b4973f..91903390a89f2a8a9dc3449ebbd1918d2079a6a5 100644 (file)
@@ -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"
index 93391497c9b0f30a8fcb0cd85af01465d41cc428..2d43f6121a63ae41c1d020b2b9211ab5eb069213 100644 (file)
@@ -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)
 {