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 [",
142 tp->trd_owner, sp->shp_tech, sp->shp_effic, prship(sp));
144 for (i = 0; i < sp->shp_nv; i++) {
146 ichr[sp->shp_vtype[i] & ~VT_TYPE].i_mnem, sp->shp_vamt[i]);
148 pr("] #%d", tp->trd_unitid);
150 snxtitem_all(&ni, EF_PLANE);
151 while (nxtitem(&ni, (s_char *)&plane)) {
152 if (plane.pln_ship == sp->shp_uid && plane.pln_own != 0) {
153 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
156 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
157 if (plane.pln_nuketype != (s_char)-1) {
158 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
162 snxtitem_all(&ni, EF_LAND);
163 while (nxtitem(&ni, (s_char *)&land)) {
164 if (land.lnd_ship == sp->shp_uid && land.lnd_own != 0) {
165 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
168 lchr[(int)land.lnd_type].l_name, land.lnd_uid);
169 if (land.lnd_nxlight) {
170 snxtitem_all(&ni, EF_PLANE);
171 while (nxtitem(&ni, (s_char *)&plane)) {
172 if (plane.pln_land == land.lnd_uid) {
173 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
176 plchr[(int)plane.pln_type].pl_name,
178 if (plane.pln_nuketype != (s_char)-1) {
180 nchr[(int)plane.pln_nuketype].
189 getsect(sp->shp_x, sp->shp_y, §);
190 if (sect.sct_type != SCT_WATER)
191 pr(" in a %s %s", cname(sect.sct_own),
192 dchr[sect.sct_type].d_name);
198 tp->trd_owner = lp->lnd_own;
199 pr("(%3d) tech %d %d%% %s [",
201 lp->lnd_tech, lp->lnd_effic, lchr[(int)lp->lnd_type].l_name);
202 for (i = 0; i < lp->lnd_nv; i++) {
204 ichr[lp->lnd_vtype[i] & ~VT_TYPE].i_mnem, lp->lnd_vamt[i]);
206 pr("] #%d", tp->trd_unitid);
208 snxtitem_all(&ni, EF_PLANE);
209 while (nxtitem(&ni, (s_char *)&plane)) {
210 if (plane.pln_land == lp->lnd_uid && plane.pln_own != 0) {
211 pr("\n\t\t\t\t tech %3d %3d%% %s #%d",
214 plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
215 if (plane.pln_nuketype != (s_char)-1) {
216 pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
221 getsect(lp->lnd_x, lp->lnd_y, §);
225 tp->trd_owner = pp->pln_own;
226 pr("(%3d) tech %d %d%% %s #%d",
230 plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
231 if (pp->pln_nuketype != (s_char)-1) {
232 pr("(%s)", nchr[(int)pp->pln_nuketype].n_name);
236 pr("flaky unit type %d", tp->trd_type);
243 trade_getitem(struct trdstr *tp, union trdgenstr *tgp)
245 if (!ef_read(tp->trd_type, tp->trd_unitid, (s_char *)tgp))
254 register int j, k, val;
257 for (j = 0; NULL != (sp = getsectid(j)); j++) {
258 if (sp->sct_own != cnum)
260 secttot += (long)(dchr[sp->sct_type].d_value *
261 ((float)sp->sct_effic + 100.0));
262 for (k = 0; ichr[k].i_name; k++) {
263 if (ichr[k].i_value == 0 || ichr[k].i_vtype == 0)
265 val = getvar(ichr[k].i_vtype, (s_char *)sp, EF_SECTOR);
266 secttot += val * ichr[k].i_value;
273 get_outstand(int cnum)
279 for (j = 0; getloan(j, &loan); j++) {
280 if (loan.l_status == LS_FREE)
282 if (loan.l_lonee == cnum)
283 loantot += loan.l_amtdue;
295 for (i = 1; ichr[i].i_mnem != 0; i++)
296 if (p == ichr[i].i_mnem)
297 return (struct ichrstr *)(&ichr[i]);
298 pr("Unrecognized item \"%c\"\n", p);