2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2015, 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-2014
47 union empobj_storage item;
59 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
72 pr("Ships, land units, or planes only! (s, l, p)\n");
76 if (!snxtitem(&ni, type, player->argp[2], NULL))
79 while (nxtitem(&ni, &item)) {
84 snprintf(prompt, sizeof(prompt), "Really scrap %d %s%s [n]? ",
85 n, ef_nameof(type), splur(n));
90 while (nxtitem(&ni, &item)) {
95 if (ontradingblock(type, &item.ship)) {
96 pr("You cannot scrap an item on the trading block!\n");
101 getsect(item.gen.x, item.gen.y, §);
102 if (type == EF_SHIP) {
104 && relations_with(sect.sct_own, player->cnum) < FRIENDLY) {
105 pr("%s is not in a friendly harbor!\n",
109 if (sect.sct_type != SCT_HARBR || sect.sct_effic < 60) {
110 pr("%s is not in a 60%% efficient harbor!\n",
114 if (mchr[item.ship.shp_type].m_flags & M_TRADE) {
115 pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n");
117 "Are you really sure that you want to scrap %s (n)? ",
119 if (!confirm(prompt)) {
120 pr("%s not scrapped\n", prship(&item.ship));
126 && relations_with(sect.sct_own, player->cnum) != ALLIED) {
127 pr("%s is not in an allied sector!\n",
128 unit_nameof(&item.gen));
132 && (sect.sct_type != SCT_AIRPT || sect.sct_effic < 60)) {
133 pr("%s is not in a 60%% efficient airfield!\n",
134 prplane(&item.plane));
139 pr("%s scrapped in %s\n",
140 unit_nameof(&item.gen),
141 xyas(item.gen.x, item.gen.y, player->cnum));
142 unit_drop_cargo(&item.gen, sect.sct_own);
143 if (type == EF_SHIP) {
144 eff = item.ship.shp_effic / 100.0;
145 mp = &mchr[(int)item.ship.shp_type];
146 for (i = I_NONE + 1; i <= I_MAX; i++) {
147 if (load_comm_ok(§, item.ship.shp_own, i,
148 -item.ship.shp_item[i]))
149 sect.sct_item[i] += item.ship.shp_item[i];
151 sect.sct_item[I_LCM] += mp->m_lcm * 2 / 3 * eff;
152 sect.sct_item[I_HCM] += mp->m_hcm * 2 / 3 * eff;
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];
164 sect.sct_item[I_LCM] += lp->l_lcm * 2 / 3 * eff;
165 sect.sct_item[I_HCM] += lp->l_hcm * 2 / 3 * eff;
166 if (item.land.lnd_pstage == PLG_INFECT
167 && sect.sct_pstage == PLG_HEALTHY)
168 sect.sct_pstage = PLG_EXPOSED;
170 eff = item.land.lnd_effic / 100.0;
171 pp = &plchr[(int)item.plane.pln_type];
172 sect.sct_item[I_LCM] += pp->pl_lcm * 2 / 3 * eff;
173 sect.sct_item[I_HCM] += pp->pl_hcm * 2 / 3 * eff;
174 sect.sct_item[I_MILIT] += roundavg(pp->pl_crew * eff);
177 put_empobj(type, item.gen.uid, &item.gen);
178 for (i = I_NONE + 1; i <= I_MAX; i++) {
179 if (sect.sct_item[i] > ITEM_MAX)
180 sect.sct_item[i] = ITEM_MAX;