2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future projects/authors will amend these files as needed.
28 * scut.c: Scuttle ships, planes or land units
30 * Known contributors to this file:
41 static void scuttle_land(struct lndstr *);
47 union empobj_storage item;
54 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
67 pr("Ships, land units, or planes only! (s, l, p)\n");
70 sprintf(prompt, "%s(s)? ", ef_nameof(type));
71 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
73 if (!snxtitem(&ni, type, p, NULL))
75 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
77 char y_or_n[80], bbuf[80];
79 if (type == EF_SHIP) {
81 sprintf(bbuf, "all ships");
83 sprintf(bbuf, "all unassigned ships");
85 sprintf(bbuf, "all ships in %s", p);
87 sprintf(bbuf, "fleet %c", *p);
89 sprintf(bbuf, "ships %s", p);
90 } else if (type == EF_LAND) {
92 sprintf(bbuf, "all land units");
94 sprintf(bbuf, "all unassigned land units");
96 sprintf(bbuf, "all units in %s", p);
98 sprintf(bbuf, "army %c", *p);
100 sprintf(bbuf, "units %s", p);
103 sprintf(bbuf, "all planes");
105 sprintf(bbuf, "all unassigned planes");
106 else if (issector(p))
107 sprintf(bbuf, "all planes in %s", p);
108 else if (isalpha(*p))
109 sprintf(bbuf, "wing %c", *p);
111 sprintf(bbuf, "planes %s", p);
113 sprintf(y_or_n, "Really scuttle %s? ", bbuf);
114 if (!confirm(y_or_n))
117 while (nxtitem(&ni, &item)) {
121 if (ontradingblock(type, &item.ship)) {
122 pr("You cannot scuttle an item on the trading block!\n");
127 if (type == EF_SHIP) {
128 mp = &mchr[(int)item.ship.shp_type];
129 if (opt_TRADESHIPS) {
130 if (mp->m_flags & M_TRADE)
131 if (!scuttle_tradeship(&item.ship, 1))
134 scuttle_ship(&item.ship);
135 } else if (type == EF_LAND) {
136 if (item.land.lnd_ship >= 0) {
137 pr("%s is on a ship, and cannot be scuttled!\n",
141 scuttle_land(&item.land);
143 item.plane.pln_effic = 0;
144 putplane(item.plane.pln_uid, &item.plane);
146 pr("%s scuttled in %s\n",
147 obj_nameof(&item.gen),
148 xyas(item.gen.x, item.gen.y, player->cnum));
155 scuttle_tradeship(struct shpstr *sp, int interactive)
166 mp = &mchr[(int)sp->shp_type];
167 getsect(sp->shp_x, sp->shp_y, §);
168 if (sect.sct_own && sect.sct_type == SCT_HARBR && sect.sct_effic >= 2
169 && getrel(getnatp(sect.sct_own), sp->shp_own) >= FRIENDLY) {
170 dist = mapdist(sp->shp_x, sp->shp_y,
171 sp->shp_orig_x, sp->shp_orig_y);
172 /* Don't disclose distance to to pirates */
173 if (sp->shp_own == sp->shp_orig_own)
174 mpr(sp->shp_own, "%s has gone %d sects\n", prship(sp), dist);
175 if (dist < trade_1_dist)
177 else if (dist < trade_2_dist)
178 cash = 1.0 + trade_1 * dist;
179 else if (dist < trade_3_dist)
180 cash = 1.0 + trade_2 * dist;
182 cash = 1.0 + trade_3 * dist;
184 cash *= sp->shp_effic / 100.0;
186 if (sect.sct_own != sp->shp_own) {
187 ally_cash = cash * trade_ally_cut;
188 cash *= (1.0 + trade_ally_bonus);
192 if (!cash && (dist < 0 || sp->shp_own == sp->shp_orig_own)) {
194 pr("You won't get any money if you scuttle in %s!",
195 xyas(sp->shp_x, sp->shp_y, player->cnum));
196 sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp));
203 player->dolcost -= cash;
205 natp = getnatp(sp->shp_own);
206 natp->nat_money += cash;
208 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
212 np = getnatp(sect.sct_own);
213 np->nat_money += ally_cash;
216 "Trade with %s nets you $%d at %s\n",
218 (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own));
219 if (sp->shp_own != sp->shp_orig_own)
220 nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1);
222 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
223 } else if (sp->shp_own != sp->shp_orig_own)
224 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);
230 scuttle_ship(struct shpstr *sp)
237 getsect(sp->shp_x, sp->shp_y, §);
238 snxtitem_cargo(&ni, EF_PLANE, EF_SHIP, sp->shp_uid);
239 while (nxtitem(&ni, &plane)) {
241 if (sect.sct_own != sp->shp_own) {
242 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
244 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
248 "Plane %d transferred off ship %d to %s\n",
249 plane.pln_uid, sp->shp_uid,
250 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
252 putplane(plane.pln_uid, &plane);
254 snxtitem_cargo(&ni, EF_LAND, EF_SHIP, sp->shp_uid);
255 while (nxtitem(&ni, &land)) {
257 if (sect.sct_own == sp->shp_own) {
259 "Land unit %d transferred off ship %d to %s\n",
260 land.lnd_uid, sp->shp_uid,
261 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
262 putland(land.lnd_uid, &land);
267 putship(sp->shp_uid, sp);
271 scuttle_land(struct lndstr *lp)
278 getsect(lp->lnd_x, lp->lnd_y, §);
279 snxtitem_cargo(&ni, EF_PLANE, EF_LAND, lp->lnd_uid);
280 while (nxtitem(&ni, &plane)) {
282 if (sect.sct_own != lp->lnd_own) {
283 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
285 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
289 "Plane %d transferred off unit %d to %s\n",
290 plane.pln_uid, lp->lnd_uid,
291 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
293 putplane(plane.pln_uid, &plane);
295 snxtitem_cargo(&ni, EF_LAND, EF_LAND, lp->lnd_uid);
296 while (nxtitem(&ni, &land)) {
298 if (sect.sct_own == lp->lnd_own) {
300 "Land unit %d transferred off unit %d to %s\n",
301 land.lnd_uid, lp->lnd_uid,
302 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
303 putland(land.lnd_uid, &land);
308 putland(lp->lnd_uid, lp);