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 * scut.c: Scuttle ships, planes or land units
30 * Known contributors to this file:
57 scuttle_tradeship(struct shpstr *sp, int interactive)
59 extern int trade_1_dist; /* less than this gets no money */
60 extern int trade_2_dist; /* less than this gets trade_1 money */
61 extern int trade_3_dist; /* less than this gets trade_2 money */
62 extern float trade_1; /* return on trade_1 distance */
63 extern float trade_2; /* return on trade_2 distance */
64 extern float trade_3; /* return on trade_3 distance */
65 extern float trade_ally_bonus; /* 20% bonus for trading with allies */
66 extern float trade_ally_cut; /* 10% bonus for ally you trade with */
76 mp = &mchr[(int)sp->shp_type];
77 getsect(sp->shp_x, sp->shp_y, §);
78 if (sect.sct_own && sect.sct_type == SCT_HARBR) {
79 dist = mapdist(sp->shp_x, sp->shp_y,
80 sp->shp_orig_x, sp->shp_orig_y);
82 pr("%s has gone %d sects\n", prship(sp), dist);
84 wu(0, sp->shp_own, "%s has gone %d sects\n", prship(sp), dist);
85 if (dist < trade_1_dist)
87 else if (dist < trade_2_dist)
88 cash = (1.0 + trade_1 * ((float)dist));
89 else if (dist < trade_3_dist)
90 cash = (1.0 + trade_2 * ((float)dist));
92 cash = (1.0 + trade_3 * ((float)dist));
94 cash *= (((float)sp->shp_effic) / 100.0);
96 if (sect.sct_own != sp->shp_own) {
97 cash *= (1.0 + trade_ally_bonus);
98 ally_cash = cash * trade_ally_cut;
102 if (!interactive && cash) {
103 natp = getnatp(sp->shp_own);
104 natp->nat_money += cash;
106 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
107 } else if (!cash && !interactive) {
108 wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n");
109 } else if (cash && interactive) {
110 player->dolcost -= cash;
111 } else if (interactive) {
112 pr("You won't get any money if you scuttle in %s!",
113 xyas(sp->shp_x, sp->shp_y, player->cnum));
114 sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp));
119 np = getnatp(sect.sct_own);
120 np->nat_money += ally_cash;
123 "Trade with %s nets you $%d at %s\n",
125 (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own));
126 if (sp->shp_own != sp->shp_orig_own)
127 nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1);
129 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
130 } else if (sp->shp_own != sp->shp_orig_own)
131 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);
149 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
162 pr("Ships, land units, or planes only! (s, l, p)\n");
165 sprintf(prompt, "%s(s)? ", ef_nameof(type));
166 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
168 if (!snxtitem(&ni, type, p))
170 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
172 s_char y_or_n[80], bbuf[80];
174 if (type == EF_SHIP) {
176 sprintf(bbuf, "all ships");
178 sprintf(bbuf, "all unassigned ships");
179 else if (issector(p))
180 sprintf(bbuf, "all ships in %s", p);
181 else if (isalpha(*p))
182 sprintf(bbuf, "fleet %c", *p);
184 sprintf(bbuf, "ships %s", p);
185 } else if (type == EF_LAND) {
187 sprintf(bbuf, "all land units");
189 sprintf(bbuf, "all unassigned land units");
190 else if (issector(p))
191 sprintf(bbuf, "all units in %s", p);
192 else if (isalpha(*p))
193 sprintf(bbuf, "army %c", *p);
195 sprintf(bbuf, "units %s", p);
198 sprintf(bbuf, "all planes");
200 sprintf(bbuf, "all unassigned planes");
201 else if (issector(p))
202 sprintf(bbuf, "all planes in %s", p);
203 else if (isalpha(*p))
204 sprintf(bbuf, "wing %c", *p);
206 sprintf(bbuf, "planes %s", p);
208 sprintf(y_or_n, "Really scuttle %s? ", bbuf);
209 if (!confirm(y_or_n))
212 while (nxtitem(&ni, (s_char *)&item)) {
216 if (ontradingblock(type, (int *)&item.ship)) {
217 pr("You cannot scuttle an item on the trading block!\n");
222 if (type == EF_SHIP) {
223 mp = &mchr[(int)item.ship.shp_type];
224 if (opt_TRADESHIPS) {
225 if (mp->m_flags & M_TRADE)
226 if (!scuttle_tradeship(&item.ship, 1))
229 pr("%s", prship(&item.ship));
230 scuttle_ship(&item.ship);
231 } else if (type == EF_LAND) {
232 if (item.land.lnd_ship >= 0) {
233 pr("%s is on a ship, and cannot be scuttled!\n",
237 lp = &lchr[(int)item.land.lnd_type];
238 pr("%s", prland(&item.land));
239 scuttle_land(&item.land);
241 pp = &plchr[(int)item.plane.pln_type];
242 pr("%s", prplane(&item.plane));
243 if (item.plane.pln_ship >= 0) {
246 getship(item.plane.pln_ship, &ship);
247 take_plane_off_ship(&item.plane, &ship);
249 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid,
250 item.plane.pln_x, item.plane.pln_y);
251 item.plane.pln_own = 0;
252 putplane(item.plane.pln_uid, (s_char *)&item.plane);
254 pr(" scuttled in %s\n",
255 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
262 scuttle_ship(struct shpstr *sp)
269 getsect(sp->shp_x, sp->shp_y, §);
270 snxtitem_all(&ni, EF_PLANE);
271 while (nxtitem(&ni, (s_char *)&plane)) {
272 if (plane.pln_own == 0)
274 if (plane.pln_ship == sp->shp_uid) {
276 if (sect.sct_own != sp->shp_own) {
277 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
279 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
280 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
281 plane.pln_x, plane.pln_y);
285 "Plane %d transferred off ship %d to %s\n",
286 plane.pln_uid, sp->shp_uid,
287 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
289 putplane(plane.pln_uid, (s_char *)&plane);
292 snxtitem_all(&ni, EF_LAND);
293 while (nxtitem(&ni, (s_char *)&land)) {
294 if (land.lnd_own == 0)
296 if (land.lnd_ship == sp->shp_uid) {
298 if (sect.sct_own == sp->shp_own) {
300 "Land unit %d transferred off ship %d to %s\n",
301 land.lnd_uid, sp->shp_uid,
302 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
303 putland(land.lnd_uid, (s_char *)&land);
308 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
310 putship(sp->shp_uid, sp);
314 scuttle_land(struct lndstr *lp)
321 getsect(lp->lnd_x, lp->lnd_y, §);
322 snxtitem_all(&ni, EF_PLANE);
323 while (nxtitem(&ni, (s_char *)&plane)) {
324 if (plane.pln_own == 0)
326 if (plane.pln_land == lp->lnd_uid) {
328 if (sect.sct_own != lp->lnd_own) {
329 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
331 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
332 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
333 plane.pln_x, plane.pln_y);
337 "Plane %d transferred off unit %d to %s\n",
338 plane.pln_uid, lp->lnd_uid,
339 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
341 putplane(plane.pln_uid, (s_char *)&plane);
344 snxtitem_all(&ni, EF_LAND);
345 while (nxtitem(&ni, (s_char *)&land)) {
346 if (land.lnd_own == 0)
348 if (land.lnd_land == lp->lnd_uid) {
350 if (sect.sct_own == lp->lnd_own) {
352 "Land unit %d transferred off unit %d to %s\n",
353 land.lnd_uid, lp->lnd_uid,
354 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
355 putland(land.lnd_uid, (s_char *)&land);
360 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
362 putland(lp->lnd_uid, lp);