2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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:
51 #include "prototypes.h"
55 trade_check_ok(int lot, struct trdstr *tp, union trdgenstr *tgp)
57 union trdgenstr check;
61 trade_getitem(tp, &check);
62 if (tp->trd_type == EF_LAND)
63 result = memcmp(&(check.lnd), &(tgp->lnd), sizeof(struct lndstr));
64 else if (tp->trd_type == EF_PLANE)
65 result = memcmp(&(check.pln), &(tgp->pln), sizeof(struct plnstr));
66 else if (tp->trd_type == EF_SHIP)
67 result = memcmp(&(check.shp), &(tgp->shp), sizeof(struct shpstr));
69 result = memcmp(&(check.nuk), &(tgp->nuk), sizeof(struct nukstr));
71 pr("That item has changed!\n");
74 gettrade(lot, &trade);
75 if (memcmp((s_char *)&trade, (s_char *)tp, sizeof(struct trdstr))) {
76 pr("That item has changed!\n");
83 trade_nameof(struct trdstr *tp, union trdgenstr *tgp)
85 switch (tp->trd_type) {
87 return "nuclear stockpile";
89 return plchr[(int)tgp->pln.pln_type].pl_name;
91 return mchr[(int)tgp->shp.shp_type].m_name;
93 return lchr[(int)tgp->lnd.lnd_type].l_name;
95 return "Bad trade type, get help";
99 * Describe an item up for sale. "tgp" is a union containing
100 * the details of the generic item.
101 * Return 1 on success, 0 on error
104 trade_desc(struct trdstr *tp, union trdgenstr *tgp)
118 switch (tp->trd_type) {
121 if (!getsect(np->nuk_x, np->nuk_y, §))
123 tp->trd_owner = sect.sct_own;
124 natp = getnatp(tp->trd_owner);
125 pr("(%3d) ", sect.sct_own);
127 for (i = 0; i < N_MAXNUKE; i++) {
128 if (np->nuk_types[i]) {
131 pr("%dx%s", np->nuk_types[i], nchr[i].n_name);
138 tp->trd_owner = sp->shp_own;
139 pr("(%3d) tech %d %d%% %s [",
140 tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
142 for (i = 1; i <= I_MAX; ++i) {
144 pr("%c:%d ", ichr[i].i_mnem, sp->shp_item[i]);
146 pr("] #%d", tp->trd_unitid);
148 snxtitem_all(&ni, EF_PLANE);
149 while (nxtitem(&ni, (s_char *)&plane)) {
150 if (plane.pln_ship == sp->shp_uid && plane.pln_own != 0) {
151 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
154 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
155 if (plane.pln_nuketype != (s_char)-1) {
156 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
160 snxtitem_all(&ni, EF_LAND);
161 while (nxtitem(&ni, (s_char *)&land)) {
162 if (land.lnd_ship == sp->shp_uid && land.lnd_own != 0) {
163 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
166 lchr[(int)land.lnd_type].l_name, land.lnd_uid);
167 if (land.lnd_nxlight) {
168 snxtitem_all(&ni, EF_PLANE);
169 while (nxtitem(&ni, (s_char *)&plane)) {
170 if (plane.pln_land == land.lnd_uid) {
171 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
174 plchr[(int)plane.pln_type].pl_name,
176 if (plane.pln_nuketype != (s_char)-1) {
178 nchr[(int)plane.pln_nuketype].
187 getsect(sp->shp_x, sp->shp_y, §);
188 if (sect.sct_type != SCT_WATER)
189 pr(" in a %s %s", cname(sect.sct_own),
190 dchr[sect.sct_type].d_name);
196 tp->trd_owner = lp->lnd_own;
197 pr("(%3d) tech %d %d%% %s [",
199 lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
200 for (i = 1; i <= I_MAX; ++i) {
202 pr("%c:%d ", ichr[i].i_mnem, lp->lnd_item[i]);
204 pr("] #%d", tp->trd_unitid);
206 snxtitem_all(&ni, EF_PLANE);
207 while (nxtitem(&ni, (s_char *)&plane)) {
208 if (plane.pln_land == lp->lnd_uid && plane.pln_own != 0) {
209 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
212 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
213 if (plane.pln_nuketype != (s_char)-1) {
214 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
219 getsect(lp->lnd_x, lp->lnd_y, §);
223 tp->trd_owner = pp->pln_own;
224 pr("(%3d) tech %d %d%% %s #%d",
228 plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
229 if (pp->pln_nuketype != (s_char)-1) {
230 pr("(%s)", nchr[(int)pp->pln_nuketype].n_name);
234 pr("flaky unit type %d", tp->trd_type);
241 trade_getitem(struct trdstr *tp, union trdgenstr *tgp)
243 if (!ef_read(tp->trd_type, tp->trd_unitid, (s_char *)tgp))
252 register int j, k, val;
255 for (j = 0; NULL != (sp = getsectid(j)); j++) {
256 if (sp->sct_own != cnum)
258 secttot += (long)(dchr[sp->sct_type].d_value *
259 ((float)sp->sct_effic + 100.0));
260 for (k = 0; ichr[k].i_name; k++) {
261 if (ichr[k].i_value == 0 || ichr[k].i_vtype == 0)
263 val = sp->sct_item[ichr[k].i_vtype];
264 secttot += val * ichr[k].i_value;
271 get_outstand(int cnum)
277 for (j = 0; getloan(j, &loan); j++) {
278 if (loan.l_status == LS_FREE)
280 if (loan.l_lonee == cnum)
281 loantot += loan.l_amtdue;
287 * Return amount due for LOAN at time PAYTIME.
290 loan_owed(struct lonstr *loan, time_t paytime)
292 time_t rtime; /* regular interest time */
293 time_t xtime; /* double interest time */
298 * Split interval paytime - l_lastpay into regular (up to
299 * l_duedate) and extended (beyond l_duedate) time.
301 rtime = loan->l_duedate - loan->l_lastpay;
302 xtime = paytime - loan->l_duedate;
311 if (CANT_HAPPEN(rtime < 0))
315 if (CANT_HAPPEN(dur <= 0))
317 rate = loan->l_irate / 100.0 / (dur * SECS_PER_DAY);
319 return loan->l_amtdue * (1.0 + (rtime + xtime * 2) * rate);