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:
50 static void scuttle_land(struct lndstr *);
59 scuttle_tradeship(struct shpstr *sp, int interactive)
61 extern int trade_1_dist; /* less than this gets no money */
62 extern int trade_2_dist; /* less than this gets trade_1 money */
63 extern int trade_3_dist; /* less than this gets trade_2 money */
64 extern float trade_1; /* return on trade_1 distance */
65 extern float trade_2; /* return on trade_2 distance */
66 extern float trade_3; /* return on trade_3 distance */
67 extern float trade_ally_bonus; /* 20% bonus for trading with allies */
68 extern float trade_ally_cut; /* 10% bonus for ally you trade with */
78 mp = &mchr[(int)sp->shp_type];
79 getsect(sp->shp_x, sp->shp_y, §);
80 if (sect.sct_own && sect.sct_type == SCT_HARBR) {
81 dist = mapdist(sp->shp_x, sp->shp_y,
82 sp->shp_orig_x, sp->shp_orig_y);
83 /* Don't disclose distance to to pirates */
84 if (sp->shp_own == sp->shp_orig_own) {
86 pr("%s has gone %d sects\n", prship(sp), dist);
88 wu(0, sp->shp_own, "%s has gone %d sects\n",
91 if (dist < trade_1_dist)
93 else if (dist < trade_2_dist)
94 cash = (1.0 + trade_1 * ((float)dist));
95 else if (dist < trade_3_dist)
96 cash = (1.0 + trade_2 * ((float)dist));
98 cash = (1.0 + trade_3 * ((float)dist));
100 cash *= (((float)sp->shp_effic) / 100.0);
102 if (sect.sct_own != sp->shp_own) {
103 cash *= (1.0 + trade_ally_bonus);
104 ally_cash = cash * trade_ally_cut;
108 if (!interactive && cash) {
109 natp = getnatp(sp->shp_own);
110 natp->nat_money += cash;
112 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
113 } else if (!cash && !interactive) {
114 wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n");
115 } else if (cash && interactive) {
116 player->dolcost -= cash;
117 } else if (interactive && sp->shp_own == sp->shp_orig_own) {
118 pr("You won't get any money if you scuttle in %s!",
119 xyas(sp->shp_x, sp->shp_y, player->cnum));
120 sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp));
125 np = getnatp(sect.sct_own);
126 np->nat_money += ally_cash;
129 "Trade with %s nets you $%d at %s\n",
131 (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own));
132 if (sp->shp_own != sp->shp_orig_own)
133 nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1);
135 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
136 } else if (sp->shp_own != sp->shp_orig_own)
137 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);
155 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
168 pr("Ships, land units, or planes only! (s, l, p)\n");
171 sprintf(prompt, "%s(s)? ", ef_nameof(type));
172 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
174 if (!snxtitem(&ni, type, p))
176 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
178 s_char y_or_n[80], bbuf[80];
180 if (type == EF_SHIP) {
182 sprintf(bbuf, "all ships");
184 sprintf(bbuf, "all unassigned ships");
185 else if (issector(p))
186 sprintf(bbuf, "all ships in %s", p);
187 else if (isalpha(*p))
188 sprintf(bbuf, "fleet %c", *p);
190 sprintf(bbuf, "ships %s", p);
191 } else if (type == EF_LAND) {
193 sprintf(bbuf, "all land units");
195 sprintf(bbuf, "all unassigned land units");
196 else if (issector(p))
197 sprintf(bbuf, "all units in %s", p);
198 else if (isalpha(*p))
199 sprintf(bbuf, "army %c", *p);
201 sprintf(bbuf, "units %s", p);
204 sprintf(bbuf, "all planes");
206 sprintf(bbuf, "all unassigned planes");
207 else if (issector(p))
208 sprintf(bbuf, "all planes in %s", p);
209 else if (isalpha(*p))
210 sprintf(bbuf, "wing %c", *p);
212 sprintf(bbuf, "planes %s", p);
214 sprintf(y_or_n, "Really scuttle %s? ", bbuf);
215 if (!confirm(y_or_n))
218 while (nxtitem(&ni, (s_char *)&item)) {
222 if (ontradingblock(type, (int *)&item.ship)) {
223 pr("You cannot scuttle an item on the trading block!\n");
228 if (type == EF_SHIP) {
229 mp = &mchr[(int)item.ship.shp_type];
230 if (opt_TRADESHIPS) {
231 if (mp->m_flags & M_TRADE)
232 if (!scuttle_tradeship(&item.ship, 1))
235 pr("%s", prship(&item.ship));
236 scuttle_ship(&item.ship);
237 } else if (type == EF_LAND) {
238 if (item.land.lnd_ship >= 0) {
239 pr("%s is on a ship, and cannot be scuttled!\n",
243 lp = &lchr[(int)item.land.lnd_type];
244 pr("%s", prland(&item.land));
245 scuttle_land(&item.land);
247 pp = &plchr[(int)item.plane.pln_type];
248 pr("%s", prplane(&item.plane));
249 if (item.plane.pln_ship >= 0) {
252 getship(item.plane.pln_ship, &ship);
253 take_plane_off_ship(&item.plane, &ship);
255 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid,
256 item.plane.pln_x, item.plane.pln_y);
257 item.plane.pln_own = 0;
258 putplane(item.plane.pln_uid, (s_char *)&item.plane);
260 pr(" scuttled in %s\n",
261 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
268 scuttle_ship(struct shpstr *sp)
275 getsect(sp->shp_x, sp->shp_y, §);
276 snxtitem_all(&ni, EF_PLANE);
277 while (nxtitem(&ni, (s_char *)&plane)) {
278 if (plane.pln_own == 0)
280 if (plane.pln_ship == sp->shp_uid) {
282 if (sect.sct_own != sp->shp_own) {
283 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
285 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
286 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
287 plane.pln_x, plane.pln_y);
291 "Plane %d transferred off ship %d to %s\n",
292 plane.pln_uid, sp->shp_uid,
293 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
295 putplane(plane.pln_uid, (s_char *)&plane);
298 snxtitem_all(&ni, EF_LAND);
299 while (nxtitem(&ni, (s_char *)&land)) {
300 if (land.lnd_own == 0)
302 if (land.lnd_ship == sp->shp_uid) {
304 if (sect.sct_own == sp->shp_own) {
306 "Land unit %d transferred off ship %d to %s\n",
307 land.lnd_uid, sp->shp_uid,
308 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
309 putland(land.lnd_uid, (s_char *)&land);
314 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
316 putship(sp->shp_uid, sp);
320 scuttle_land(struct lndstr *lp)
327 getsect(lp->lnd_x, lp->lnd_y, §);
328 snxtitem_all(&ni, EF_PLANE);
329 while (nxtitem(&ni, (s_char *)&plane)) {
330 if (plane.pln_own == 0)
332 if (plane.pln_land == lp->lnd_uid) {
334 if (sect.sct_own != lp->lnd_own) {
335 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
337 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
338 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
339 plane.pln_x, plane.pln_y);
343 "Plane %d transferred off unit %d to %s\n",
344 plane.pln_uid, lp->lnd_uid,
345 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
347 putplane(plane.pln_uid, (s_char *)&plane);
350 snxtitem_all(&ni, EF_LAND);
351 while (nxtitem(&ni, (s_char *)&land)) {
352 if (land.lnd_own == 0)
354 if (land.lnd_land == lp->lnd_uid) {
356 if (sect.sct_own == lp->lnd_own) {
358 "Land unit %d transferred off unit %d to %s\n",
359 land.lnd_uid, lp->lnd_uid,
360 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
361 putland(land.lnd_uid, (s_char *)&land);
366 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
368 putland(lp->lnd_uid, lp);