2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2005, 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:
48 static void scuttle_land(struct lndstr *);
57 scuttle_tradeship(struct shpstr *sp, int interactive)
68 mp = &mchr[(int)sp->shp_type];
69 getsect(sp->shp_x, sp->shp_y, §);
70 if (sect.sct_own && sect.sct_type == SCT_HARBR) {
71 dist = mapdist(sp->shp_x, sp->shp_y,
72 sp->shp_orig_x, sp->shp_orig_y);
73 /* Don't disclose distance to to pirates */
74 if (sp->shp_own == sp->shp_orig_own) {
76 pr("%s has gone %d sects\n", prship(sp), dist);
78 wu(0, sp->shp_own, "%s has gone %d sects\n",
81 if (dist < trade_1_dist)
83 else if (dist < trade_2_dist)
84 cash = (1.0 + trade_1 * ((float)dist));
85 else if (dist < trade_3_dist)
86 cash = (1.0 + trade_2 * ((float)dist));
88 cash = (1.0 + trade_3 * ((float)dist));
90 cash *= (((float)sp->shp_effic) / 100.0);
92 if (sect.sct_own != sp->shp_own) {
93 ally_cash = cash * trade_ally_cut;
94 cash *= (1.0 + trade_ally_bonus);
98 if (!interactive && cash) {
99 natp = getnatp(sp->shp_own);
100 natp->nat_money += cash;
102 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
103 } else if (!cash && !interactive) {
104 wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n");
105 } else if (cash && interactive) {
106 player->dolcost -= cash;
107 } else if (interactive && sp->shp_own == sp->shp_orig_own) {
108 pr("You won't get any money if you scuttle in %s!",
109 xyas(sp->shp_x, sp->shp_y, player->cnum));
110 sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp));
115 np = getnatp(sect.sct_own);
116 np->nat_money += ally_cash;
119 "Trade with %s nets you $%d at %s\n",
121 (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own));
122 if (sp->shp_own != sp->shp_orig_own)
123 nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1);
125 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
126 } else if (sp->shp_own != sp->shp_orig_own)
127 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);
143 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
156 pr("Ships, land units, or planes only! (s, l, p)\n");
159 sprintf(prompt, "%s(s)? ", ef_nameof(type));
160 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
162 if (!snxtitem(&ni, type, p))
164 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
166 s_char y_or_n[80], bbuf[80];
168 if (type == EF_SHIP) {
170 sprintf(bbuf, "all ships");
172 sprintf(bbuf, "all unassigned ships");
173 else if (issector(p))
174 sprintf(bbuf, "all ships in %s", p);
175 else if (isalpha(*p))
176 sprintf(bbuf, "fleet %c", *p);
178 sprintf(bbuf, "ships %s", p);
179 } else if (type == EF_LAND) {
181 sprintf(bbuf, "all land units");
183 sprintf(bbuf, "all unassigned land units");
184 else if (issector(p))
185 sprintf(bbuf, "all units in %s", p);
186 else if (isalpha(*p))
187 sprintf(bbuf, "army %c", *p);
189 sprintf(bbuf, "units %s", p);
192 sprintf(bbuf, "all planes");
194 sprintf(bbuf, "all unassigned planes");
195 else if (issector(p))
196 sprintf(bbuf, "all planes in %s", p);
197 else if (isalpha(*p))
198 sprintf(bbuf, "wing %c", *p);
200 sprintf(bbuf, "planes %s", p);
202 sprintf(y_or_n, "Really scuttle %s? ", bbuf);
203 if (!confirm(y_or_n))
206 while (nxtitem(&ni, &item)) {
210 if (ontradingblock(type, (int *)&item.ship)) {
211 pr("You cannot scuttle an item on the trading block!\n");
216 if (type == EF_SHIP) {
217 mp = &mchr[(int)item.ship.shp_type];
218 if (opt_TRADESHIPS) {
219 if (mp->m_flags & M_TRADE)
220 if (!scuttle_tradeship(&item.ship, 1))
223 pr("%s", prship(&item.ship));
224 scuttle_ship(&item.ship);
225 } else if (type == EF_LAND) {
226 if (item.land.lnd_ship >= 0) {
227 pr("%s is on a ship, and cannot be scuttled!\n",
231 pr("%s", prland(&item.land));
232 scuttle_land(&item.land);
234 pr("%s", prplane(&item.plane));
235 if (item.plane.pln_ship >= 0) {
238 getship(item.plane.pln_ship, &ship);
239 take_plane_off_ship(&item.plane, &ship);
241 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid,
242 item.plane.pln_x, item.plane.pln_y);
243 item.plane.pln_own = 0;
244 putplane(item.plane.pln_uid, &item.plane);
246 pr(" scuttled in %s\n",
247 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
254 scuttle_ship(struct shpstr *sp)
261 getsect(sp->shp_x, sp->shp_y, §);
262 snxtitem_all(&ni, EF_PLANE);
263 while (nxtitem(&ni, &plane)) {
264 if (plane.pln_own == 0)
266 if (plane.pln_ship == sp->shp_uid) {
268 if (sect.sct_own != sp->shp_own) {
269 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
271 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
272 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
273 plane.pln_x, plane.pln_y);
277 "Plane %d transferred off ship %d to %s\n",
278 plane.pln_uid, sp->shp_uid,
279 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
281 putplane(plane.pln_uid, &plane);
284 snxtitem_all(&ni, EF_LAND);
285 while (nxtitem(&ni, &land)) {
286 if (land.lnd_own == 0)
288 if (land.lnd_ship == sp->shp_uid) {
290 if (sect.sct_own == sp->shp_own) {
292 "Land unit %d transferred off ship %d to %s\n",
293 land.lnd_uid, sp->shp_uid,
294 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
295 putland(land.lnd_uid, &land);
300 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
302 putship(sp->shp_uid, sp);
306 scuttle_land(struct lndstr *lp)
313 getsect(lp->lnd_x, lp->lnd_y, §);
314 snxtitem_all(&ni, EF_PLANE);
315 while (nxtitem(&ni, &plane)) {
316 if (plane.pln_own == 0)
318 if (plane.pln_land == lp->lnd_uid) {
320 if (sect.sct_own != lp->lnd_own) {
321 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
323 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
324 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
325 plane.pln_x, plane.pln_y);
329 "Plane %d transferred off unit %d to %s\n",
330 plane.pln_uid, lp->lnd_uid,
331 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
333 putplane(plane.pln_uid, &plane);
336 snxtitem_all(&ni, EF_LAND);
337 while (nxtitem(&ni, &land)) {
338 if (land.lnd_own == 0)
340 if (land.lnd_land == lp->lnd_uid) {
342 if (sect.sct_own == lp->lnd_own) {
344 "Land unit %d transferred off unit %d to %s\n",
345 land.lnd_uid, lp->lnd_uid,
346 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
347 putland(land.lnd_uid, &land);
352 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
354 putland(lp->lnd_uid, lp);