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)
119 price = multread(tp->trd_owner, player->cnum) * tp->trd_price;
120 switch (tp->trd_type) {
123 if (!getsect(np->nuk_x, np->nuk_y, §))
125 tp->trd_owner = sect.sct_own;
126 natp = getnatp(tp->trd_owner);
127 pr("(%3d) ", sect.sct_own);
129 for (i = 0; i < N_MAXNUKE; i++) {
130 if (np->nuk_types[i]) {
133 pr("%dx%s", np->nuk_types[i], nchr[i].n_name);
140 tp->trd_owner = sp->shp_own;
141 pr("(%3d) tech %d %d%% %s [",
147 for (i = 0; i < sp->shp_nv; i++) {
149 ichr[sp->shp_vtype[i] & ~VT_TYPE].i_mnem,
152 pr("] #%d", tp->trd_unitid);
154 snxtitem_all(&ni, EF_PLANE);
155 while (nxtitem(&ni, (s_char *)&plane))
157 if (plane.pln_ship == sp->shp_uid &&
160 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
163 plchr[(int)plane.pln_type].pl_name,
165 if (plane.pln_nuketype != (s_char)-1)
167 pr("(%s)",nchr[(int)plane.pln_nuketype].n_name);
171 snxtitem_all(&ni, EF_LAND);
172 while (nxtitem(&ni, (s_char *)&land))
174 if (land.lnd_ship == sp->shp_uid &&
177 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
180 lchr[(int)land.lnd_type].l_name,
182 if (land.lnd_nxlight)
184 snxtitem_all(&ni, EF_PLANE);
185 while (nxtitem(&ni, (s_char *)&plane))
187 if (plane.pln_land == land.lnd_uid)
189 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
192 plchr[(int)plane.pln_type].pl_name,
194 if (plane.pln_nuketype != (s_char)-1)
197 nchr[(int)plane.pln_nuketype].n_name);
205 getsect(sp->shp_x, sp->shp_y, §);
206 if (sect.sct_type != SCT_WATER)
207 pr(" in a %s %s", cname(sect.sct_own),
208 dchr[sect.sct_type].d_name);
214 tp->trd_owner = lp->lnd_own;
215 pr("(%3d) tech %d %d%% %s [",
219 lchr[(int)lp->lnd_type].l_name);
220 for (i = 0; i < lp->lnd_nv; i++) {
222 ichr[lp->lnd_vtype[i] & ~VT_TYPE].i_mnem,
225 pr("] #%d", tp->trd_unitid);
227 snxtitem_all(&ni, EF_PLANE);
228 while (nxtitem(&ni, (s_char *)&plane))
230 if (plane.pln_land == lp->lnd_uid &&
233 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
236 plchr[(int)plane.pln_type].pl_name,
238 if (plane.pln_nuketype != (s_char)-1)
241 nchr[(int)plane.pln_nuketype].n_name);
246 getsect(lp->lnd_x, lp->lnd_y, §);
250 tp->trd_owner = pp->pln_own;
251 pr("(%3d) tech %d %d%% %s #%d",
255 plchr[(int)pp->pln_type].pl_name,
257 if (pp->pln_nuketype != (s_char)-1) {
258 pr("(%s)", nchr[(int)pp->pln_nuketype].n_name);
262 pr("flaky unit type %d", tp->trd_type);
269 trade_getitem(struct trdstr *tp, union trdgenstr *tgp)
271 if (!ef_read(tp->trd_type, tp->trd_unitid, (s_char *)tgp))
280 register int j, k, val;
283 for (j = 0; NULL != (sp = getsectid(j)); j++) {
284 if (sp->sct_own != cnum)
286 secttot += (long)(dchr[sp->sct_type].d_value *
287 ((float)sp->sct_effic+100.0));
288 for (k = 0; ichr[k].i_name; k++) {
289 if (ichr[k].i_value == 0 || ichr[k].i_vtype == 0)
291 val = getvar(ichr[k].i_vtype, (s_char *)sp, EF_SECTOR);
292 secttot += val * ichr[k].i_value;
299 get_outstand(int cnum)
305 for (j = 0; getloan(j, &loan); j++) {
306 if (loan.l_status == LS_FREE)
308 if (loan.l_lonee == cnum)
309 loantot += loan.l_amtdue;
321 for (i = 1; ichr[i].i_mnem != 0; i++)
322 if (p == ichr[i].i_mnem)
323 return (struct ichrstr *)(&ichr[i]);
324 pr("Unrecognized item \"%c\"\n", p);