2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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:
50 static void scuttle_land(struct lndstr *);
69 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
82 pr("Ships, land units, or planes only! (s, l, p)\n");
85 sprintf(prompt, "%s(s)? ", ef_nameof(type));
86 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
88 if (!snxtitem(&ni, type, p))
90 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
92 char y_or_n[80], bbuf[80];
94 if (type == EF_SHIP) {
96 sprintf(bbuf, "all ships");
98 sprintf(bbuf, "all unassigned ships");
100 sprintf(bbuf, "all ships in %s", p);
101 else if (isalpha(*p))
102 sprintf(bbuf, "fleet %c", *p);
104 sprintf(bbuf, "ships %s", p);
105 } else if (type == EF_LAND) {
107 sprintf(bbuf, "all land units");
109 sprintf(bbuf, "all unassigned land units");
110 else if (issector(p))
111 sprintf(bbuf, "all units in %s", p);
112 else if (isalpha(*p))
113 sprintf(bbuf, "army %c", *p);
115 sprintf(bbuf, "units %s", p);
118 sprintf(bbuf, "all planes");
120 sprintf(bbuf, "all unassigned planes");
121 else if (issector(p))
122 sprintf(bbuf, "all planes in %s", p);
123 else if (isalpha(*p))
124 sprintf(bbuf, "wing %c", *p);
126 sprintf(bbuf, "planes %s", p);
128 sprintf(y_or_n, "Really scuttle %s? ", bbuf);
129 if (!confirm(y_or_n))
132 while (nxtitem(&ni, &item)) {
136 if (ontradingblock(type, &item.ship)) {
137 pr("You cannot scuttle an item on the trading block!\n");
142 if (type == EF_SHIP) {
143 mp = &mchr[(int)item.ship.shp_type];
144 if (opt_TRADESHIPS) {
145 if (mp->m_flags & M_TRADE)
146 if (!scuttle_tradeship(&item.ship, 1))
149 pr("%s", prship(&item.ship));
150 scuttle_ship(&item.ship);
151 } else if (type == EF_LAND) {
152 if (item.land.lnd_ship >= 0) {
153 pr("%s is on a ship, and cannot be scuttled!\n",
157 pr("%s", prland(&item.land));
158 scuttle_land(&item.land);
160 pr("%s", prplane(&item.plane));
161 if (item.plane.pln_ship >= 0) {
164 getship(item.plane.pln_ship, &ship);
165 take_plane_off_ship(&item.plane, &ship);
167 item.plane.pln_effic = 0;
168 putplane(item.plane.pln_uid, &item.plane);
170 pr(" scuttled in %s\n",
171 xyas(item.ship.shp_x, item.ship.shp_y, player->cnum));
178 scuttle_tradeship(struct shpstr *sp, int interactive)
189 mp = &mchr[(int)sp->shp_type];
190 getsect(sp->shp_x, sp->shp_y, §);
191 if (sect.sct_own && sect.sct_type == SCT_HARBR) {
192 dist = mapdist(sp->shp_x, sp->shp_y,
193 sp->shp_orig_x, sp->shp_orig_y);
194 /* Don't disclose distance to to pirates */
195 if (sp->shp_own == sp->shp_orig_own) {
197 pr("%s has gone %d sects\n", prship(sp), dist);
199 wu(0, sp->shp_own, "%s has gone %d sects\n",
202 if (dist < trade_1_dist)
204 else if (dist < trade_2_dist)
205 cash = 1.0 + trade_1 * dist;
206 else if (dist < trade_3_dist)
207 cash = 1.0 + trade_2 * dist;
209 cash = 1.0 + trade_3 * dist;
211 cash *= sp->shp_effic / 100.0;
213 if (sect.sct_own != sp->shp_own) {
214 ally_cash = cash * trade_ally_cut;
215 cash *= (1.0 + trade_ally_bonus);
219 if (!interactive && cash) {
220 natp = getnatp(sp->shp_own);
221 natp->nat_money += cash;
223 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
224 } else if (!cash && !interactive) {
225 wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n");
226 } else if (cash && interactive) {
227 player->dolcost -= cash;
228 } else if (interactive && sp->shp_own == sp->shp_orig_own) {
229 pr("You won't get any money if you scuttle in %s!",
230 xyas(sp->shp_x, sp->shp_y, player->cnum));
231 sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp));
236 np = getnatp(sect.sct_own);
237 np->nat_money += ally_cash;
240 "Trade with %s nets you $%d at %s\n",
242 (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own));
243 if (sp->shp_own != sp->shp_orig_own)
244 nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1);
246 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
247 } else if (sp->shp_own != sp->shp_orig_own)
248 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);
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));
275 "Plane %d transferred off ship %d to %s\n",
276 plane.pln_uid, sp->shp_uid,
277 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
279 putplane(plane.pln_uid, &plane);
282 snxtitem_all(&ni, EF_LAND);
283 while (nxtitem(&ni, &land)) {
284 if (land.lnd_own == 0)
286 if (land.lnd_ship == sp->shp_uid) {
288 if (sect.sct_own == sp->shp_own) {
290 "Land unit %d transferred off ship %d to %s\n",
291 land.lnd_uid, sp->shp_uid,
292 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
293 putland(land.lnd_uid, &land);
299 putship(sp->shp_uid, sp);
303 scuttle_land(struct lndstr *lp)
310 getsect(lp->lnd_x, lp->lnd_y, §);
311 snxtitem_all(&ni, EF_PLANE);
312 while (nxtitem(&ni, &plane)) {
313 if (plane.pln_own == 0)
315 if (plane.pln_land == lp->lnd_uid) {
317 if (sect.sct_own != lp->lnd_own) {
318 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
320 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
324 "Plane %d transferred off unit %d to %s\n",
325 plane.pln_uid, lp->lnd_uid,
326 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
328 putplane(plane.pln_uid, &plane);
331 snxtitem_all(&ni, EF_LAND);
332 while (nxtitem(&ni, &land)) {
333 if (land.lnd_own == 0)
335 if (land.lnd_land == lp->lnd_uid) {
337 if (sect.sct_own == lp->lnd_own) {
339 "Land unit %d transferred off unit %d to %s\n",
340 land.lnd_uid, lp->lnd_uid,
341 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
342 putland(land.lnd_uid, &land);
348 putland(lp->lnd_uid, lp);