2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * See files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * trdsub.c: Trade helper functions
30 * Known contributors to this file:
50 #include "prototypes.h"
57 trade_check_ok(struct trdstr *tp, union empobj_storage *tgp)
59 return check_trade_ok(tp) && trade_check_item_ok(tgp);
63 trade_check_item_ok(union empobj_storage *tgp)
65 if (tgp->gen.ef_type == EF_LAND)
66 return check_land_ok(&tgp->land);
67 if (tgp->gen.ef_type == EF_PLANE)
68 return check_plane_ok(&tgp->plane);
69 if (tgp->gen.ef_type == EF_SHIP)
70 return check_ship_ok(&tgp->ship);
71 if (tgp->gen.ef_type == EF_NUKE)
72 return check_nuke_ok(&tgp->nuke);
74 pr("Trade lot went bad!\n");
79 trade_nameof(struct trdstr *tp, union empobj_storage *tgp)
81 switch (tp->trd_type) {
83 return nchr[(int)tgp->nuke.nuk_type].n_name;
85 return plchr[(int)tgp->plane.pln_type].pl_name;
87 return mchr[(int)tgp->ship.shp_type].m_name;
89 return lchr[(int)tgp->land.lnd_type].l_name;
91 return "Bad trade type, get help";
95 * Describe an item up for sale. "tgp" is a union containing
96 * the details of the generic item.
97 * Return 1 on success, 0 on error
100 trade_desc(struct trdstr *tp, union empobj_storage *tgp)
113 switch (tp->trd_type) {
116 tp->trd_owner = np->nuk_own;
117 pr("(%3d) tech %d %d%% %s #%d",
118 tp->trd_owner, np->nuk_tech, np->nuk_effic,
119 nchr[(int)np->nuk_type].n_name, tp->trd_unitid);
123 tp->trd_owner = sp->shp_own;
124 pr("(%3d) tech %d %d%% %s [",
125 tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
127 for (it = I_NONE + 1; it <= I_MAX; ++it) {
128 if (sp->shp_item[it])
129 pr("%c:%d ", ichr[it].i_mnem, sp->shp_item[it]);
131 pr("] #%d", tp->trd_unitid);
133 snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
134 while (nxtitem(&ni, &plane)) {
135 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
138 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
139 if (getnuke(nuk_on_plane(&plane), &nuke))
140 pr("(%s)", nchr[nuke.nuk_type].n_name);
142 snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
143 while (nxtitem(&ni, &land)) {
144 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
147 lchr[(int)land.lnd_type].l_name, land.lnd_uid);
148 if (pln_first_on_land(&land) >= 0) {
149 snxtitem_cargo(&ni, EF_PLANE, EF_LAND, land.lnd_uid);
150 while (nxtitem(&ni, &plane)) {
151 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
154 plchr[(int)plane.pln_type].pl_name,
156 if (getnuke(nuk_on_plane(&plane), &nuke))
157 pr("(%s)", nchr[nuke.nuk_type].n_name);
162 getsect(sp->shp_x, sp->shp_y, §);
163 if (sect.sct_type != SCT_WATER)
165 cname(sect.sct_own), dchr[sect.sct_type].d_name);
171 tp->trd_owner = lp->lnd_own;
172 pr("(%3d) tech %d %d%% %s [",
174 lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
175 for (it = I_NONE + 1; it <= I_MAX; ++it) {
176 if (lp->lnd_item[it])
177 pr("%c:%d ", ichr[it].i_mnem, lp->lnd_item[it]);
179 pr("] #%d", tp->trd_unitid);
181 snxtitem_cargo(&ni, EF_PLANE, EF_LAND, lp->lnd_uid);
182 while (nxtitem(&ni, &plane)) {
183 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
186 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
187 if (getnuke(nuk_on_plane(&plane), &nuke))
188 pr("(%s)", nchr[nuke.nuk_type].n_name);
191 getsect(lp->lnd_x, lp->lnd_y, §);
195 tp->trd_owner = pp->pln_own;
196 pr("(%3d) tech %d %d%% %s #%d",
200 plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
201 if (getnuke(nuk_on_plane(pp), &nuke))
202 pr("(%s)", nchr[nuke.nuk_type].n_name);
205 pr("flaky unit type %d", tp->trd_type);
212 trade_getitem(struct trdstr *tp, union empobj_storage *tgp)
214 if (!ef_read(tp->trd_type, tp->trd_unitid, tgp))
220 * Return amount due for LOAN at time PAYTIME.
223 loan_owed(struct lonstr *loan, time_t paytime)
225 time_t rtime; /* regular interest time */
226 time_t xtime; /* double interest time */
231 * Split interval paytime - l_lastpay into regular (up to
232 * l_duedate) and extended (beyond l_duedate) time.
234 rtime = loan->l_duedate - loan->l_lastpay;
235 xtime = paytime - loan->l_duedate;
244 if (CANT_HAPPEN(rtime < 0))
248 if (CANT_HAPPEN(dur <= 0))
250 rate = loan->l_irate / 100.0 / (dur * SECS_PER_DAY);
252 return loan->l_amtdue * (1.0 + (rtime + xtime * 2) * rate);