/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure, Markus Armbruster
*
* Empire is free software: you can redistribute it and/or modify
#include "sect.h"
#include "ship.h"
#include "trade.h"
+#include "unit.h"
#include "xy.h"
int
-trade_check_ok(struct trdstr *tp, union empobj_storage *tgp)
+trade_check_ok(struct trdstr *tp, struct empobj *tgp)
{
- return check_trade_ok(tp) && trade_check_item_ok(tgp);
-}
-
-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;
+ return check_trade_ok(tp) && check_obj_ok(tgp);
}
char *
-trade_nameof(struct trdstr *tp, union empobj_storage *tgp)
+trade_nameof(struct trdstr *tp, struct empobj *tgp)
{
switch (tp->trd_type) {
case EF_NUKE:
- return nchr[(int)tgp->nuke.nuk_type].n_name;
+ return nchr[tgp->type].n_name;
case EF_PLANE:
- return plchr[(int)tgp->plane.pln_type].pl_name;
+ return plchr[tgp->type].pl_name;
case EF_SHIP:
- return mchr[(int)tgp->ship.shp_type].m_name;
+ return mchr[tgp->type].m_name;
case EF_LAND:
- return lchr[(int)tgp->land.lnd_type].l_name;
+ return lchr[tgp->type].l_name;
}
return "Bad trade type, get help";
}
* Return 1 on success, 0 on error
*/
int
-trade_desc(struct trdstr *tp, union empobj_storage *tgp)
+trade_desc(struct empobj *tgp)
{
i_type it;
struct sctstr sect;
struct lndstr land;
struct nukstr nuke;
- switch (tp->trd_type) {
+ switch (tgp->ef_type) {
case EF_NUKE:
- np = &tgp->nuke;
- tp->trd_owner = np->nuk_own;
+ np = (struct nukstr *)tgp;
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);
+ np->nuk_own, np->nuk_tech, np->nuk_effic,
+ nchr[(int)np->nuk_type].n_name, np->nuk_uid);
break;
case EF_SHIP:
- sp = &tgp->ship;
- tp->trd_owner = sp->shp_own;
+ sp = (struct shpstr *)tgp;
pr("(%3d) tech %d %d%% %s [",
- tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
+ sp->shp_own, sp->shp_tech, sp->shp_effic, prship(sp));
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);
+ 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",
pr(" at sea");
break;
case EF_LAND:
- lp = &tgp->land;
- tp->trd_owner = lp->lnd_own;
+ lp = (struct lndstr *)tgp;
pr("(%3d) tech %d %d%% %s [",
- tp->trd_owner,
+ lp->lnd_own,
lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
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);
+ pr("] #%d", lp->lnd_uid);
break;
case EF_PLANE:
- pp = &tgp->plane;
- tp->trd_owner = pp->pln_own;
+ pp = (struct plnstr *)tgp;
pr("(%3d) tech %d %d%% %s #%d",
- tp->trd_owner,
+ 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)
{