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 * scra.c: Scrap ships, planes or land units
30 * Known contributors to this file:
45 union empobj_storage item;
61 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
74 pr("Ships, land units, or planes only! (s, l, p)\n");
77 sprintf(prompt, "%s(s)? ", ef_nameof(type));
78 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
80 if (!snxtitem(&ni, type, p, NULL))
82 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
84 char y_or_n[80], bbuf[80];
86 memset(y_or_n, 0, sizeof(y_or_n));
87 if (type == EF_SHIP) {
89 sprintf(bbuf, "all ships");
91 sprintf(bbuf, "all unassigned ships");
93 sprintf(bbuf, "all ships in %s", p);
95 sprintf(bbuf, "fleet %c", *p);
97 sprintf(bbuf, "ships %s", p);
98 } else if (type == EF_LAND) {
100 sprintf(bbuf, "all land units");
102 sprintf(bbuf, "all unassigned land units");
103 else if (issector(p))
104 sprintf(bbuf, "all units in %s", p);
105 else if (isalpha(*p))
106 sprintf(bbuf, "army %c", *p);
108 sprintf(bbuf, "units %s", p);
111 sprintf(bbuf, "all planes");
113 sprintf(bbuf, "all unassigned planes");
114 else if (issector(p))
115 sprintf(bbuf, "all planes in %s", p);
116 else if (isalpha(*p))
117 sprintf(bbuf, "wing %c", *p);
119 sprintf(bbuf, "planes %s", p);
122 sprintf(y_or_n, "Really scrap %s [n]? ", bbuf);
123 if (!confirm(y_or_n))
126 while (nxtitem(&ni, &item)) {
131 if (ontradingblock(type, &item.ship)) {
132 pr("You cannot scrap an item on the trading block!\n");
137 if (type == EF_SHIP) {
138 getsect(item.ship.shp_x, item.ship.shp_y, §);
139 if (sect.sct_type != SCT_HARBR)
141 if (sect.sct_effic < 60 || sect.sct_own != player->cnum)
143 } else if (type == EF_LAND) {
144 if (item.land.lnd_ship >= 0) {
145 pr("%s is on a ship, and cannot be scrapped!\n",
149 getsect(item.land.lnd_x, item.land.lnd_y, §);
151 getsect(item.plane.pln_x, item.plane.pln_y, §);
152 if (sect.sct_type != SCT_AIRPT)
154 if (sect.sct_effic < 60 ||
155 (sect.sct_own != player->cnum &&
156 getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY))
159 if (type == EF_SHIP) {
160 eff = item.ship.shp_effic / 100.0;
161 mp = &mchr[(int)item.ship.shp_type];
162 if (opt_TRADESHIPS) {
163 if (mp->m_flags & M_TRADE) {
164 pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n");
166 "Are you really sure that you want to scrap %s (n)? ",
168 if (!confirm(prompt)) {
169 pr("%s not scrapped\n", prship(&item.ship));
174 pr("%s", prship(&item.ship));
175 for (i = I_NONE + 1; i <= I_MAX; i++) {
176 sect.sct_item[i] += item.ship.shp_item[i];
178 sect.sct_item[I_LCM] += mp->m_lcm * 2 / 3 * eff;
179 sect.sct_item[I_HCM] += mp->m_hcm * 2 / 3 * eff;
180 getsect(item.ship.shp_x, item.ship.shp_y, §2);
181 snxtitem_all(&ni2, EF_PLANE);
182 while (nxtitem(&ni2, &plane)) {
183 if (plane.pln_own == 0)
185 if (plane.pln_ship == item.ship.shp_uid) {
187 "Plane %d transferred off ship %d to %s\n",
188 ni2.cur, item.ship.shp_uid,
189 xyas(plane.pln_x, plane.pln_y, player->cnum));
191 if (sect2.sct_own != plane.pln_own) {
193 "%s given to %s\n", prplane(&plane),
194 cname(sect2.sct_own));
196 "%s given to you by %s\n", prplane(&plane),
197 cname(player->cnum));
199 plane.pln_own = sect2.sct_own;
200 putplane(plane.pln_uid, &plane);
203 snxtitem_all(&ni2, EF_LAND);
204 while (nxtitem(&ni2, &land)) {
205 if (land.lnd_own == 0)
207 if (land.lnd_ship == item.ship.shp_uid) {
209 "Land unit %d transferred off ship %d to %s\n",
210 ni2.cur, item.ship.shp_uid,
211 xyas(land.lnd_x, land.lnd_y, player->cnum));
213 if (sect2.sct_own != land.lnd_own) {
215 "%s given to %s\n", prland(&land),
216 cname(sect2.sct_own));
218 "%s given to you by %s\n", prland(&land),
219 cname(player->cnum));
221 land.lnd_own = sect2.sct_own;
222 putland(land.lnd_uid, &land);
225 item.ship.shp_effic = 0;
226 putship(item.ship.shp_uid, &item.ship);
227 } else if (type == EF_LAND) {
228 eff = item.land.lnd_effic / 100.0;
229 lp = &lchr[(int)item.land.lnd_type];
230 pr("%s", prland(&item.land));
231 for (i = I_NONE + 1; i <= I_MAX; i++) {
232 sect.sct_item[i] += item.land.lnd_item[i];
234 sect.sct_item[I_LCM] += lp->l_lcm * 2 / 3 * eff;
235 sect.sct_item[I_HCM] += lp->l_hcm * 2 / 3 * eff;
236 getsect(item.land.lnd_x, item.land.lnd_y, §2);
238 snxtitem_all(&ni2, EF_LAND);
239 while (nxtitem(&ni2, &land)) {
240 if (land.lnd_own == 0)
242 if (land.lnd_land == item.land.lnd_uid) {
244 "Land unit %d transferred off land unit %d to %s\n",
245 land.lnd_uid, item.land.lnd_uid,
246 xyas(land.lnd_x, land.lnd_y, player->cnum));
248 if (sect2.sct_own != land.lnd_own) {
250 "%s given to %s\n", prland(&land),
251 cname(sect2.sct_own));
253 "%s given to you by %s\n", prland(&land),
254 cname(player->cnum));
256 land.lnd_own = sect2.sct_own;
257 putland(land.lnd_uid, &land);
261 snxtitem_all(&ni2, EF_PLANE);
262 while (nxtitem(&ni2, &plane)) {
263 if (plane.pln_own == 0)
265 if (plane.pln_land == item.land.lnd_uid) {
267 "Plane %d transferred off land unit %d to %s\n",
268 ni2.cur, item.land.lnd_uid,
269 xyas(plane.pln_x, plane.pln_y, player->cnum));
271 if (sect2.sct_own != plane.pln_own) {
273 "%s given to %s\n", prplane(&plane),
274 cname(sect2.sct_own));
276 "%s given to you by %s\n", prplane(&plane),
277 cname(player->cnum));
279 plane.pln_own = sect2.sct_own;
280 putplane(plane.pln_uid, &plane);
283 item.land.lnd_effic = 0;
284 putland(item.land.lnd_uid, &item.land);
286 eff = item.land.lnd_effic / 100.0;
287 pp = &plchr[(int)item.plane.pln_type];
288 pr("%s", prplane(&item.plane));
289 sect.sct_item[I_LCM] += pp->pl_lcm * 2 / 3 * eff;
290 sect.sct_item[I_HCM] += pp->pl_hcm * 2 / 3 * eff;
291 sect.sct_item[I_MILIT] += pp->pl_crew;
292 item.plane.pln_effic = 0;
293 putplane(item.plane.pln_uid, &item.plane);
295 pr(" scrapped in %s\n",
296 xyas(sect.sct_x, sect.sct_y, player->cnum));
297 for (i = I_NONE + 1; i <= I_MAX; i++) {
298 if (sect.sct_item[i] > ITEM_MAX)
299 sect.sct_item[i] = ITEM_MAX;