2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2014, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * scut.c: Scuttle ships, planes or land units
29 * Known contributors to this file:
30 * Markus Armbruster, 2004-2012
45 union empobj_storage item;
53 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
66 pr("Ships, land units, or planes only! (s, l, p)\n");
70 if (!snxtitem(&ni, type, player->argp[2], NULL))
73 while (nxtitem(&ni, &item)) {
78 snprintf(prompt, sizeof(prompt), "Really scuttle %d %s%s [n]? ",
79 n, ef_nameof(type), splur(n));
84 while (nxtitem(&ni, &item)) {
88 if (ontradingblock(type, &item.ship)) {
89 pr("You cannot scuttle an item on the trading block!\n");
94 if (type == EF_SHIP) {
95 mp = &mchr[(int)item.ship.shp_type];
96 if (mp->m_flags & M_TRADE) {
97 if (!scuttle_tradeship(&item.ship, 1))
100 } else if (type == EF_LAND) {
101 if (item.land.lnd_ship >= 0) {
102 pr("%s is on a ship, and cannot be scuttled!\n",
107 pr("%s scuttled in %s\n",
108 unit_nameof(&item.gen),
109 xyas(item.gen.x, item.gen.y, player->cnum));
110 getsect(item.gen.x, item.gen.y, §);
111 if (sect.sct_own == item.gen.own)
112 unit_drop_cargo(&item.gen, sect.sct_own);
114 put_empobj(type, item.gen.uid, &item.gen);
121 scuttle_tradeship(struct shpstr *sp, int interactive)
132 mp = &mchr[(int)sp->shp_type];
133 getsect(sp->shp_x, sp->shp_y, §);
134 if (sect.sct_own && sect.sct_type == SCT_HARBR && sect.sct_effic >= 2
135 && relations_with(sect.sct_own, sp->shp_own) >= FRIENDLY) {
136 dist = mapdist(sp->shp_x, sp->shp_y,
137 sp->shp_orig_x, sp->shp_orig_y);
138 /* Don't disclose distance to to pirates */
139 if (sp->shp_own == sp->shp_orig_own)
140 mpr(sp->shp_own, "%s has gone %d sects\n", prship(sp), dist);
141 if (dist < trade_1_dist)
143 else if (dist < trade_2_dist)
144 cash = 1.0 + trade_1 * dist;
145 else if (dist < trade_3_dist)
146 cash = 1.0 + trade_2 * dist;
148 cash = 1.0 + trade_3 * dist;
150 cash *= sp->shp_effic / 100.0;
152 if (sect.sct_own != sp->shp_own) {
153 ally_cash = cash * trade_ally_cut;
154 cash *= (1.0 + trade_ally_bonus);
158 if (!cash && (dist < 0 || sp->shp_own == sp->shp_orig_own)) {
160 pr("You won't get any money if you scuttle in %s!",
161 xyas(sp->shp_x, sp->shp_y, player->cnum));
162 sprintf(buf, "Are you sure you want to scuttle %s? ", prship(sp));
169 player->dolcost -= cash;
171 natp = getnatp(sp->shp_own);
172 natp->nat_money += cash;
174 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
178 np = getnatp(sect.sct_own);
179 np->nat_money += ally_cash;
182 "Trade with %s nets you $%d at %s\n",
184 (int)ally_cash, xyas(sect.sct_x, sect.sct_y, sect.sct_own));
185 if (sp->shp_own != sp->shp_orig_own)
186 nreport(sp->shp_own, N_PIRATE_TRADE, sp->shp_orig_own, 1);
188 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
189 } else if (sp->shp_own != sp->shp_orig_own)
190 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);