2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * trdsub.c: Trade helper functions
29 * Known contributors to this file:
47 #include "prototypes.h"
54 trade_check_ok(struct trdstr *tp, union empobj_storage *tgp)
56 return check_trade_ok(tp) && check_obj_ok(&tgp->gen);
60 trade_nameof(struct trdstr *tp, union empobj_storage *tgp)
62 switch (tp->trd_type) {
64 return nchr[(int)tgp->nuke.nuk_type].n_name;
66 return plchr[(int)tgp->plane.pln_type].pl_name;
68 return mchr[(int)tgp->ship.shp_type].m_name;
70 return lchr[(int)tgp->land.lnd_type].l_name;
72 return "Bad trade type, get help";
76 * Describe an item up for sale. "tgp" is a union containing
77 * the details of the generic item.
78 * Return 1 on success, 0 on error
81 trade_desc(struct trdstr *tp, union empobj_storage *tgp)
94 switch (tp->trd_type) {
97 tp->trd_owner = np->nuk_own;
98 pr("(%3d) tech %d %d%% %s #%d",
99 tp->trd_owner, np->nuk_tech, np->nuk_effic,
100 nchr[(int)np->nuk_type].n_name, tp->trd_unitid);
104 tp->trd_owner = sp->shp_own;
105 pr("(%3d) tech %d %d%% %s [",
106 tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
108 for (it = I_NONE + 1; it <= I_MAX; ++it) {
109 if (sp->shp_item[it])
110 pr("%c:%d ", ichr[it].i_mnem, sp->shp_item[it]);
112 pr("] #%d", tp->trd_unitid);
113 snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
114 while (nxtitem(&ni, &plane)) {
115 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
118 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
119 if (getnuke(nuk_on_plane(&plane), &nuke))
120 pr("(%s)", nchr[nuke.nuk_type].n_name);
122 snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
123 while (nxtitem(&ni, &land)) {
124 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
127 lchr[(int)land.lnd_type].l_name, land.lnd_uid);
128 if (pln_first_on_land(&land) >= 0) {
129 snxtitem_cargo(&ni, EF_PLANE, EF_LAND, land.lnd_uid);
130 while (nxtitem(&ni, &plane)) {
131 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
134 plchr[(int)plane.pln_type].pl_name,
136 if (getnuke(nuk_on_plane(&plane), &nuke))
137 pr("(%s)", nchr[nuke.nuk_type].n_name);
141 getsect(sp->shp_x, sp->shp_y, §);
142 if (sect.sct_type != SCT_WATER)
144 cname(sect.sct_own), dchr[sect.sct_type].d_name);
150 tp->trd_owner = lp->lnd_own;
151 pr("(%3d) tech %d %d%% %s [",
153 lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
154 for (it = I_NONE + 1; it <= I_MAX; ++it) {
155 if (lp->lnd_item[it])
156 pr("%c:%d ", ichr[it].i_mnem, lp->lnd_item[it]);
158 pr("] #%d", tp->trd_unitid);
162 tp->trd_owner = pp->pln_own;
163 pr("(%3d) tech %d %d%% %s #%d",
167 plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
168 if (getnuke(nuk_on_plane(pp), &nuke))
169 pr("(%s)", nchr[nuke.nuk_type].n_name);
172 pr("flaky unit type %d", tp->trd_type);
179 trade_getitem(struct trdstr *tp, union empobj_storage *tgp)
181 if (!ef_read(tp->trd_type, tp->trd_unitid, tgp))
187 * Return amount due for LOAN at time PAYTIME.
190 loan_owed(struct lonstr *loan, time_t paytime)
192 time_t rtime; /* regular interest time */
193 time_t xtime; /* double interest time */
198 * Split interval paytime - l_lastpay into regular (up to
199 * l_duedate) and extended (beyond l_duedate) time.
201 rtime = loan->l_duedate - loan->l_lastpay;
202 xtime = paytime - loan->l_duedate;
211 if (CANT_HAPPEN(rtime < 0))
215 if (CANT_HAPPEN(dur <= 0))
217 rate = loan->l_irate / 100.0 / (dur * SECS_PER_DAY);
219 return loan->l_amtdue * (1.0 + (rtime + xtime * 2) * rate);