2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2021, 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 * scra.c: Scrap ships, planes or land units
29 * Known contributors to this file:
31 * Markus Armbruster, 2004-2016
46 union empobj_storage item;
60 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
73 pr("Ships, land units, or planes only! (s, l, p)\n");
77 if (!snxtitem(&ni, type, player->argp[2], NULL))
80 while (nxtitem(&ni, &item)) {
85 snprintf(prompt, sizeof(prompt), "Really scrap %d %s%s [n]? ",
86 n, ef_nameof(type), splur(n));
91 while (nxtitem(&ni, &item)) {
96 if (ontradingblock(type, &item.ship)) {
97 pr("You cannot scrap an item on the trading block!\n");
102 getsect(item.gen.x, item.gen.y, §);
103 if (type == EF_SHIP) {
105 && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
106 pr("%s is not in a friendly harbor!\n",
110 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60) {
111 pr("%s is not in a 60%% efficient harbor!\n",
115 if (mchr[item.ship.shp_type].m_flags & M_TRADE) {
116 pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n");
118 "Are you really sure that you want to scrap %s (n)? ",
120 if (!confirm(prompt)) {
121 pr("%s not scrapped\n", prship(&item.ship));
127 && relations_with(sect.sct_own, player->cnum) != ALLIED) {
128 pr("%s is not in an allied sector!\n",
129 unit_nameof(&item.gen));
133 && (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)) {
134 pr("%s is not in a 60%% efficient airfield!\n",
135 prplane(&item.plane));
140 pr("%s scrapped in %s\n",
141 unit_nameof(&item.gen),
142 xyas(item.gen.x, item.gen.y, player->cnum));
143 unit_drop_cargo(&item.gen, sect.sct_own);
144 if (type == EF_SHIP) {
145 eff = item.ship.shp_effic / 100.0;
146 mp = &mchr[(int)item.ship.shp_type];
147 for (i = I_NONE + 1; i <= I_MAX; i++) {
148 if (load_comm_ok(§, item.ship.shp_own, i,
149 -item.ship.shp_item[i]))
150 sect.sct_item[i] += item.ship.shp_item[i];
153 if (item.ship.shp_pstage == PLG_INFECT
154 && sect.sct_pstage == PLG_HEALTHY)
155 sect.sct_pstage = PLG_EXPOSED;
156 } else if (type == EF_LAND) {
157 eff = item.land.lnd_effic / 100.0;
158 lp = &lchr[(int)item.land.lnd_type];
159 for (i = I_NONE + 1; i <= I_MAX; i++) {
160 if (load_comm_ok(§, item.land.lnd_own, i,
161 -item.land.lnd_item[i]))
162 sect.sct_item[i] += item.land.lnd_item[i];
165 if (item.land.lnd_pstage == PLG_INFECT
166 && sect.sct_pstage == PLG_HEALTHY)
167 sect.sct_pstage = PLG_EXPOSED;
169 eff = item.land.lnd_effic / 100.0;
170 pp = &plchr[(int)item.plane.pln_type];
174 put_empobj(type, item.gen.uid, &item.gen);
175 for (i = I_NONE + 1; i <= I_MAX; i++) {
176 if (i == I_CIVIL || i == I_MILIT || i == I_UW)
177 amt = sect.sct_item[i] + mvec[i] * eff;
179 amt = sect.sct_item[i] + mvec[i] * 2 / 3 * eff;
182 sect.sct_item[i] = amt;