]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/trdsub.c
Update copyright notice.
[empserver] / src / lib / subs / trdsub.c
index eaf98a0ef1276ef5289a546370185d5fca2e924b..b687fa8a3765244a40e284326cd703f0cc8df610 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2005, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     Steve McClure, 1996
  */
 
-#include "misc.h"
-#include "player.h"
-#include "sect.h"
-#include "nat.h"
+#include <config.h>
+
+#include "empobj.h"
+#include "file.h"
 #include "item.h"
-#include "ship.h"
 #include "land.h"
+#include "loan.h"
+#include "misc.h"
+#include "nat.h"
+#include "nsc.h"
 #include "nuke.h"
+#include "optlist.h"
 #include "plane.h"
+#include "player.h"
+#include "prototypes.h"
+#include "sect.h"
+#include "ship.h"
 #include "trade.h"
 #include "xy.h"
-#include "nsc.h"
-#include "file.h"
-#include "loan.h"
-#include "prototypes.h"
-#include "optlist.h"
 
 int
-trade_check_ok(struct trdstr *tp, union trdgenstr *tgp)
+trade_check_ok(struct trdstr *tp, union empobj_storage *tgp)
 {
-    union trdgenstr check;
-
-    if (!check_trade_ok(tp))
-       return 0;
+    return check_trade_ok(tp) && trade_check_item_ok(tgp);
+}
 
-    trade_getitem(tp, &check);
-    if (tp->trd_type == EF_LAND)
-       return check_land_ok(&tgp->lnd);
-    if (tp->trd_type == EF_PLANE)
-       return check_plane_ok(&tgp->pln);
-    if (tp->trd_type == EF_SHIP)
-       return check_ship_ok(&tgp->shp);
-    if (tp->trd_type == EF_NUKE)
-       return check_nuke_ok(&tgp->nuk);
-    CANT_HAPPEN("Bad TRD_TYPE");
-    pr("Trade lot #%d went bad!\n", tp->trd_uid);
+int
+trade_check_item_ok(union empobj_storage *tgp)
+{
+    if (tgp->gen.ef_type == EF_LAND)
+       return check_land_ok(&tgp->land);
+    if (tgp->gen.ef_type == EF_PLANE)
+       return check_plane_ok(&tgp->plane);
+    if (tgp->gen.ef_type == EF_SHIP)
+       return check_ship_ok(&tgp->ship);
+    if (tgp->gen.ef_type == EF_NUKE)
+       return check_nuke_ok(&tgp->nuke);
+    CANT_REACH();
+    pr("Trade lot went bad!\n");
     return 0;
 }
 
-s_char *
-trade_nameof(struct trdstr *tp, union trdgenstr *tgp)
+char *
+trade_nameof(struct trdstr *tp, union empobj_storage *tgp)
 {
     switch (tp->trd_type) {
     case EF_NUKE:
-       return "nuclear stockpile";
+       return nchr[(int)tgp->nuke.nuk_type].n_name;
     case EF_PLANE:
-       return plchr[(int)tgp->pln.pln_type].pl_name;
+       return plchr[(int)tgp->plane.pln_type].pl_name;
     case EF_SHIP:
-       return mchr[(int)tgp->shp.shp_type].m_name;
+       return mchr[(int)tgp->ship.shp_type].m_name;
     case EF_LAND:
-       return lchr[(int)tgp->lnd.lnd_type].l_name;
+       return lchr[(int)tgp->land.lnd_type].l_name;
     }
     return "Bad trade type, get help";
 }
@@ -94,47 +97,35 @@ trade_nameof(struct trdstr *tp, union trdgenstr *tgp)
  * Return 1 on success, 0 on error
  */
 int
-trade_desc(struct trdstr *tp, union trdgenstr *tgp)
+trade_desc(struct trdstr *tp, union empobj_storage *tgp)
 {
-    int i;
+    i_type it;
     struct sctstr sect;
     struct nukstr *np;
     struct shpstr *sp;
     struct plnstr *pp;
     struct lndstr *lp;
-    struct natstr *natp;
-    int needcomma;
     struct nstr_item ni;
     struct plnstr plane;
     struct lndstr land;
 
     switch (tp->trd_type) {
     case EF_NUKE:
-       np = &tgp->nuk;
-       if (!getsect(np->nuk_x, np->nuk_y, &sect))
-           return 0;
-       tp->trd_owner = sect.sct_own;
-       natp = getnatp(tp->trd_owner);
-       pr("(%3d)  ", sect.sct_own);
-       needcomma = 0;
-       for (i = 0; i < N_MAXNUKE; i++) {
-           if (np->nuk_types[i]) {
-               if (needcomma)
-                   pr(",");
-               pr("%dx%s", np->nuk_types[i], nchr[i].n_name);
-               needcomma = 1;
-           }
-       }
+       np = &tgp->nuke;
+       tp->trd_owner = np->nuk_own;
+       pr("(%3d)  tech %d %d%% %s #%d",
+          tp->trd_owner, np->nuk_tech, np->nuk_effic,
+          nchr[(int)np->nuk_type].n_name, tp->trd_unitid);
        break;
     case EF_SHIP:
-       sp = &tgp->shp;
+       sp = &tgp->ship;
        tp->trd_owner = sp->shp_own;
        pr("(%3d)  tech %d %d%% %s [",
           tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
 
-       for (i = I_NONE + 1; i <= I_MAX; ++i) {
-           if (sp->shp_item[i])
-               pr("%c:%d ", ichr[i].i_mnem, sp->shp_item[i]);
+       for (it = I_NONE + 1; it <= I_MAX; ++it) {
+           if (sp->shp_item[it])
+               pr("%c:%d ", ichr[it].i_mnem, sp->shp_item[it]);
        }
        pr("] #%d", tp->trd_unitid);
        if (opt_SHOWPLANE) {
@@ -168,8 +159,7 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
                                   plane.pln_uid);
                                if (plane.pln_nuketype != -1) {
                                    pr("(%s)",
-                                      nchr[(int)plane.pln_nuketype].
-                                      n_name);
+                                      nchr[(int)plane.pln_nuketype].n_name);
                                }
                            }
                        }
@@ -179,20 +169,20 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
        }
        getsect(sp->shp_x, sp->shp_y, &sect);
        if (sect.sct_type != SCT_WATER)
-           pr(" in a %s %s", cname(sect.sct_own),
-              dchr[sect.sct_type].d_name);
+           pr(" in a %s %s",
+              cname(sect.sct_own), dchr[sect.sct_type].d_name);
        else
            pr(" at sea");
        break;
     case EF_LAND:
-       lp = &tgp->lnd;
+       lp = &tgp->land;
        tp->trd_owner = lp->lnd_own;
        pr("(%3d)  tech %d %d%% %s [",
           tp->trd_owner,
           lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
-       for (i = I_NONE + 1; i <= I_MAX; ++i) {
-           if (lp->lnd_item[i])
-               pr("%c:%d ", ichr[i].i_mnem, lp->lnd_item[i]);
+       for (it = I_NONE + 1; it <= I_MAX; ++it) {
+           if (lp->lnd_item[it])
+               pr("%c:%d ", ichr[it].i_mnem, lp->lnd_item[it]);
        }
        pr("] #%d", tp->trd_unitid);
        if (opt_SHOWPLANE) {
@@ -212,7 +202,7 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
        getsect(lp->lnd_x, lp->lnd_y, &sect);
        break;
     case EF_PLANE:
-       pp = &tgp->pln;
+       pp = &tgp->plane;
        tp->trd_owner = pp->pln_own;
        pr("(%3d)  tech %d %d%% %s #%d",
           tp->trd_owner,
@@ -231,51 +221,13 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp)
 }
 
 int
-trade_getitem(struct trdstr *tp, union trdgenstr *tgp)
+trade_getitem(struct trdstr *tp, union empobj_storage *tgp)
 {
     if (!ef_read(tp->trd_type, tp->trd_unitid, tgp))
        return 0;
     return 1;
 }
 
-long
-get_couval(int cnum)
-{
-    struct sctstr *sp;
-    int j, k, val;
-    long secttot = 0;
-
-    for (j = 0; NULL != (sp = getsectid(j)); j++) {
-       if (sp->sct_own != cnum)
-           continue;
-       secttot += (long)(dchr[sp->sct_type].d_value *
-                         ((float)sp->sct_effic + 100.0));
-       for (k = 0; ichr[k].i_name; k++) {
-           if (ichr[k].i_value == 0 || ichr[k].i_vtype == I_NONE)
-               continue;
-           val = sp->sct_item[ichr[k].i_vtype];
-           secttot += val * ichr[k].i_value;
-       }
-    }
-    return secttot;
-}
-
-long
-get_outstand(int cnum)
-{
-    struct lonstr loan;
-    int j;
-    long loantot = 0;
-
-    for (j = 0; getloan(j, &loan); j++) {
-       if (loan.l_status == LS_FREE)
-           continue;
-       if (loan.l_lonee == cnum)
-           loantot += loan.l_amtdue;
-    }
-    return loantot;
-}
-
 /*
  * Return amount due for LOAN at time PAYTIME.
  */