2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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:
49 static void scuttle_land(struct lndstr *);
58 scuttle_tradeship(struct shpstr *sp, int interactive)
69 mp = &mchr[(int)sp->shp_type];
70 getsect(sp->shp_x, sp->shp_y, §);
71 if (sect.sct_own && sect.sct_type == SCT_HARBR) {
72 dist = mapdist(sp->shp_x, sp->shp_y,
73 sp->shp_orig_x, sp->shp_orig_y);
74 /* Don't disclose distance to to pirates */
75 if (sp->shp_own == sp->shp_orig_own) {
77 pr("%s has gone %d sects\n", prship(sp), dist);
79 wu(0, sp->shp_own, "%s has gone %d sects\n",
82 if (dist < trade_1_dist)
84 else if (dist < trade_2_dist)
85 cash = (1.0 + trade_1 * ((float)dist));
86 else if (dist < trade_3_dist)
87 cash = (1.0 + trade_2 * ((float)dist));
89 cash = (1.0 + trade_3 * ((float)dist));
91 cash *= (((float)sp->shp_effic) / 100.0);
93 if (sect.sct_own != sp->shp_own) {
94 cash *= (1.0 + trade_ally_bonus);
95 ally_cash = cash * trade_ally_cut;
99 if (!interactive && cash) {
100 natp = getnatp(sp->shp_own);
101 natp->nat_money += cash;
103 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
104 } else if (!cash && !interactive) {
105 wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n");
106 } else if (cash && interactive) {
107 player->dolcost -= cash;
108 } else if (interactive && sp->shp_own == sp->shp_orig_own) {
109 pr("You won't get any money if you scuttle in %s!",
110 xyas(sp->shp_x, sp->shp_y, player->cnum));
111 sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp));
116 np = getnatp(sect.sct_own);
117 np->nat_money += ally_cash;
120 "Trade with %s nets you $%d at %s\n",
122 (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own));
123 if (sp->shp_own != sp->shp_orig_own)
124 nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1);
126 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
127 } else if (sp->shp_own != sp->shp_orig_own)
128 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);
146 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
159 pr("Ships, land units, or planes only! (s, l, p)\n");
162 sprintf(prompt, "%s(s)? ", ef_nameof(type));
163 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
165 if (!snxtitem(&ni, type, p))
167 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
169 s_char y_or_n[80], bbuf[80];
171 if (type == EF_SHIP) {
173 sprintf(bbuf, "all ships");
175 sprintf(bbuf, "all unassigned ships");
176 else if (issector(p))
177 sprintf(bbuf, "all ships in %s", p);
178 else if (isalpha(*p))
179 sprintf(bbuf, "fleet %c", *p);
181 sprintf(bbuf, "ships %s", p);
182 } else if (type == EF_LAND) {
184 sprintf(bbuf, "all land units");
186 sprintf(bbuf, "all unassigned land units");
187 else if (issector(p))
188 sprintf(bbuf, "all units in %s", p);
189 else if (isalpha(*p))
190 sprintf(bbuf, "army %c", *p);
192 sprintf(bbuf, "units %s", p);
195 sprintf(bbuf, "all planes");
197 sprintf(bbuf, "all unassigned planes");
198 else if (issector(p))
199 sprintf(bbuf, "all planes in %s", p);
200 else if (isalpha(*p))
201 sprintf(bbuf, "wing %c", *p);
203 sprintf(bbuf, "planes %s", p);
205 sprintf(y_or_n, "Really scuttle %s? ", bbuf);
206 if (!confirm(y_or_n))
209 while (nxtitem(&ni, (s_char *)&item)) {
213 if (ontradingblock(type, (int *)&item.ship)) {
214 pr("You cannot scuttle an item on the trading block!\n");
219 if (type == EF_SHIP) {
220 mp = &mchr[(int)item.ship.shp_type];
221 if (opt_TRADESHIPS) {
222 if (mp->m_flags & M_TRADE)
223 if (!scuttle_tradeship(&item.ship, 1))
226 pr("%s", prship(&item.ship));
227 scuttle_ship(&item.ship);
228 } else if (type == EF_LAND) {
229 if (item.land.lnd_ship >= 0) {
230 pr("%s is on a ship, and cannot be scuttled!\n",
234 lp = &lchr[(int)item.land.lnd_type];
235 pr("%s", prland(&item.land));
236 scuttle_land(&item.land);
238 pp = &plchr[(int)item.plane.pln_type];
239 pr("%s", prplane(&item.plane));
240 if (item.plane.pln_ship >= 0) {
243 getship(item.plane.pln_ship, &ship);
244 take_plane_off_ship(&item.plane, &ship);
246 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid,
247 item.plane.pln_x, item.plane.pln_y);
248 item.plane.pln_own = 0;
249 putplane(item.plane.pln_uid, (s_char *)&item.plane);
251 pr(" scuttled in %s\n",
252 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
259 scuttle_ship(struct shpstr *sp)
266 getsect(sp->shp_x, sp->shp_y, §);
267 snxtitem_all(&ni, EF_PLANE);
268 while (nxtitem(&ni, (s_char *)&plane)) {
269 if (plane.pln_own == 0)
271 if (plane.pln_ship == sp->shp_uid) {
273 if (sect.sct_own != sp->shp_own) {
274 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
276 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
277 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
278 plane.pln_x, plane.pln_y);
282 "Plane %d transferred off ship %d to %s\n",
283 plane.pln_uid, sp->shp_uid,
284 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
286 putplane(plane.pln_uid, (s_char *)&plane);
289 snxtitem_all(&ni, EF_LAND);
290 while (nxtitem(&ni, (s_char *)&land)) {
291 if (land.lnd_own == 0)
293 if (land.lnd_ship == sp->shp_uid) {
295 if (sect.sct_own == sp->shp_own) {
297 "Land unit %d transferred off ship %d to %s\n",
298 land.lnd_uid, sp->shp_uid,
299 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
300 putland(land.lnd_uid, (s_char *)&land);
305 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
307 putship(sp->shp_uid, sp);
311 scuttle_land(struct lndstr *lp)
318 getsect(lp->lnd_x, lp->lnd_y, §);
319 snxtitem_all(&ni, EF_PLANE);
320 while (nxtitem(&ni, (s_char *)&plane)) {
321 if (plane.pln_own == 0)
323 if (plane.pln_land == lp->lnd_uid) {
325 if (sect.sct_own != lp->lnd_own) {
326 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
328 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
329 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
330 plane.pln_x, plane.pln_y);
334 "Plane %d transferred off unit %d to %s\n",
335 plane.pln_uid, lp->lnd_uid,
336 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
338 putplane(plane.pln_uid, (s_char *)&plane);
341 snxtitem_all(&ni, EF_LAND);
342 while (nxtitem(&ni, (s_char *)&land)) {
343 if (land.lnd_own == 0)
345 if (land.lnd_land == lp->lnd_uid) {
347 if (sect.sct_own == lp->lnd_own) {
349 "Land unit %d transferred off unit %d to %s\n",
350 land.lnd_uid, lp->lnd_uid,
351 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
352 putland(land.lnd_uid, (s_char *)&land);
357 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
359 putland(lp->lnd_uid, lp);