]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/trdsub.c
Update copyright notice
[empserver] / src / lib / subs / trdsub.c
index 7833a6e66d3717f1fa8aaa9bbe30517864a469e7..be46dc70a29bfb9517ea704f5f21a31d1aeb3f5b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2018, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -35,7 +35,6 @@
 #include <config.h>
 
 #include "empobj.h"
-#include "file.h"
 #include "item.h"
 #include "land.h"
 #include "loan.h"
@@ -48,6 +47,7 @@
 #include "sect.h"
 #include "ship.h"
 #include "trade.h"
+#include "unit.h"
 #include "xy.h"
 
 int
@@ -78,7 +78,7 @@ trade_nameof(struct trdstr *tp, struct empobj *tgp)
  * Return 1 on success, 0 on error
  */
 int
-trade_desc(struct trdstr *tp, struct empobj *tgp)
+trade_desc(struct empobj *tgp)
 {
     i_type it;
     struct sctstr sect;
@@ -91,12 +91,12 @@ trade_desc(struct trdstr *tp, struct empobj *tgp)
     struct lndstr land;
     struct nukstr nuke;
 
-    switch (tp->trd_type) {
+    switch (tgp->ef_type) {
     case EF_NUKE:
        np = (struct nukstr *)tgp;
        pr("(%3d)  tech %d %d%% %s #%d",
           np->nuk_own, np->nuk_tech, np->nuk_effic,
-          nchr[(int)np->nuk_type].n_name, tp->trd_unitid);
+          nchr[(int)np->nuk_type].n_name, np->nuk_uid);
        break;
     case EF_SHIP:
        sp = (struct shpstr *)tgp;
@@ -107,7 +107,7 @@ trade_desc(struct trdstr *tp, struct empobj *tgp)
            if (sp->shp_item[it])
                pr("%c:%d ", ichr[it].i_mnem, sp->shp_item[it]);
        }
-       pr("] #%d", tp->trd_unitid);
+       pr("] #%d", sp->shp_uid);
        snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
        while (nxtitem(&ni, &plane)) {
            pr("\n\t\t\t\t    tech %3d %3d%% %s #%d",
@@ -152,7 +152,7 @@ trade_desc(struct trdstr *tp, struct empobj *tgp)
            if (lp->lnd_item[it])
                pr("%c:%d ", ichr[it].i_mnem, lp->lnd_item[it]);
        }
-       pr("] #%d", tp->trd_unitid);
+       pr("] #%d", lp->lnd_uid);
        break;
     case EF_PLANE:
        pp = (struct plnstr *)tgp;
@@ -160,17 +160,49 @@ trade_desc(struct trdstr *tp, struct empobj *tgp)
           pp->pln_own,
           pp->pln_tech,
           pp->pln_effic,
-          plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
+          plchr[(int)pp->pln_type].pl_name, pp->pln_uid);
        if (getnuke(nuk_on_plane(pp), &nuke))
            pr("(%s)", nchr[nuke.nuk_type].n_name);
        break;
     default:
-       pr("flaky unit type %d", tp->trd_type);
+       pr("flaky unit type %d", tgp->uid);
        break;
     }
     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)
 {
@@ -180,7 +212,7 @@ trade_getitem(struct trdstr *tp, union empobj_storage *tgp)
 }
 
 /*
- * Return amount due for LOAN at time PAYTIME.
+ * Return amount due for @loan at time @paytime.
  */
 double
 loan_owed(struct lonstr *loan, time_t paytime)