2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * trdsub.c: Trade helper functions
30 * Known contributors to this file:
50 #include "prototypes.h"
54 trade_check_ok(struct trdstr *tp, union trdgenstr *tgp)
56 union trdgenstr check;
58 if (!check_trade_ok(tp))
61 trade_getitem(tp, &check);
62 if (tp->trd_type == EF_LAND)
63 return check_land_ok(&tgp->lnd);
64 if (tp->trd_type == EF_PLANE)
65 return check_plane_ok(&tgp->pln);
66 if (tp->trd_type == EF_SHIP)
67 return check_ship_ok(&tgp->shp);
68 if (tp->trd_type == EF_NUKE)
69 return check_nuke_ok(&tgp->nuk);
70 CANT_HAPPEN("Bad TRD_TYPE");
71 pr("Trade lot #%d went bad!\n", tp->trd_uid);
76 trade_nameof(struct trdstr *tp, union trdgenstr *tgp)
78 switch (tp->trd_type) {
80 return "nuclear stockpile";
82 return plchr[(int)tgp->pln.pln_type].pl_name;
84 return mchr[(int)tgp->shp.shp_type].m_name;
86 return lchr[(int)tgp->lnd.lnd_type].l_name;
88 return "Bad trade type, get help";
92 * Describe an item up for sale. "tgp" is a union containing
93 * the details of the generic item.
94 * Return 1 on success, 0 on error
97 trade_desc(struct trdstr *tp, union trdgenstr *tgp)
111 switch (tp->trd_type) {
114 if (!getsect(np->nuk_x, np->nuk_y, §))
116 tp->trd_owner = sect.sct_own;
117 natp = getnatp(tp->trd_owner);
118 pr("(%3d) ", sect.sct_own);
120 for (i = 0; i < N_MAXNUKE; i++) {
121 if (np->nuk_types[i]) {
124 pr("%dx%s", np->nuk_types[i], nchr[i].n_name);
131 tp->trd_owner = sp->shp_own;
132 pr("(%3d) tech %d %d%% %s [",
133 tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
135 for (i = I_NONE + 1; i <= I_MAX; ++i) {
137 pr("%c:%d ", ichr[i].i_mnem, sp->shp_item[i]);
139 pr("] #%d", tp->trd_unitid);
141 snxtitem_all(&ni, EF_PLANE);
142 while (nxtitem(&ni, (s_char *)&plane)) {
143 if (plane.pln_ship == sp->shp_uid && plane.pln_own != 0) {
144 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
147 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
148 if (plane.pln_nuketype != (s_char)-1) {
149 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
153 snxtitem_all(&ni, EF_LAND);
154 while (nxtitem(&ni, (s_char *)&land)) {
155 if (land.lnd_ship == sp->shp_uid && land.lnd_own != 0) {
156 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
159 lchr[(int)land.lnd_type].l_name, land.lnd_uid);
160 if (land.lnd_nxlight) {
161 snxtitem_all(&ni, EF_PLANE);
162 while (nxtitem(&ni, (s_char *)&plane)) {
163 if (plane.pln_land == land.lnd_uid) {
164 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
167 plchr[(int)plane.pln_type].pl_name,
169 if (plane.pln_nuketype != (s_char)-1) {
171 nchr[(int)plane.pln_nuketype].
180 getsect(sp->shp_x, sp->shp_y, §);
181 if (sect.sct_type != SCT_WATER)
182 pr(" in a %s %s", cname(sect.sct_own),
183 dchr[sect.sct_type].d_name);
189 tp->trd_owner = lp->lnd_own;
190 pr("(%3d) tech %d %d%% %s [",
192 lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
193 for (i = I_NONE + 1; i <= I_MAX; ++i) {
195 pr("%c:%d ", ichr[i].i_mnem, lp->lnd_item[i]);
197 pr("] #%d", tp->trd_unitid);
199 snxtitem_all(&ni, EF_PLANE);
200 while (nxtitem(&ni, (s_char *)&plane)) {
201 if (plane.pln_land == lp->lnd_uid && plane.pln_own != 0) {
202 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
205 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
206 if (plane.pln_nuketype != (s_char)-1) {
207 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
212 getsect(lp->lnd_x, lp->lnd_y, §);
216 tp->trd_owner = pp->pln_own;
217 pr("(%3d) tech %d %d%% %s #%d",
221 plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
222 if (pp->pln_nuketype != (s_char)-1) {
223 pr("(%s)", nchr[(int)pp->pln_nuketype].n_name);
227 pr("flaky unit type %d", tp->trd_type);
234 trade_getitem(struct trdstr *tp, union trdgenstr *tgp)
236 if (!ef_read(tp->trd_type, tp->trd_unitid, (s_char *)tgp))
248 for (j = 0; NULL != (sp = getsectid(j)); j++) {
249 if (sp->sct_own != cnum)
251 secttot += (long)(dchr[sp->sct_type].d_value *
252 ((float)sp->sct_effic + 100.0));
253 for (k = 0; ichr[k].i_name; k++) {
254 if (ichr[k].i_value == 0 || ichr[k].i_vtype == I_NONE)
256 val = sp->sct_item[ichr[k].i_vtype];
257 secttot += val * ichr[k].i_value;
264 get_outstand(int cnum)
270 for (j = 0; getloan(j, &loan); j++) {
271 if (loan.l_status == LS_FREE)
273 if (loan.l_lonee == cnum)
274 loantot += loan.l_amtdue;
280 * Return amount due for LOAN at time PAYTIME.
283 loan_owed(struct lonstr *loan, time_t paytime)
285 time_t rtime; /* regular interest time */
286 time_t xtime; /* double interest time */
291 * Split interval paytime - l_lastpay into regular (up to
292 * l_duedate) and extended (beyond l_duedate) time.
294 rtime = loan->l_duedate - loan->l_lastpay;
295 xtime = paytime - loan->l_duedate;
304 if (CANT_HAPPEN(rtime < 0))
308 if (CANT_HAPPEN(dur <= 0))
310 rate = loan->l_irate / 100.0 / (dur * SECS_PER_DAY);
312 return loan->l_amtdue * (1.0 + (rtime + xtime * 2) * rate);