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 * scra.c: Scrap ships, planes or land units
30 * Known contributors to this file:
75 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
88 pr("Ships, land units, or planes only! (s, l, p)\n");
91 sprintf(prompt, "%s(s)? ", ef_nameof(type));
92 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
94 if (!snxtitem(&ni, type, p))
96 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
98 s_char y_or_n[80], bbuf[80];
100 memset(y_or_n, 0, sizeof(y_or_n));
101 if (type == EF_SHIP) {
103 sprintf(bbuf, "all ships");
105 sprintf(bbuf, "all unassigned ships");
106 else if (issector(p))
107 sprintf(bbuf, "all ships in %s", p);
108 else if (isalpha(*p))
109 sprintf(bbuf, "fleet %c", *p);
111 sprintf(bbuf, "ships %s", p);
112 } else if (type == EF_LAND) {
114 sprintf(bbuf, "all land units");
116 sprintf(bbuf, "all unassigned land units");
117 else if (issector(p))
118 sprintf(bbuf, "all units in %s", p);
119 else if (isalpha(*p))
120 sprintf(bbuf, "army %c", *p);
122 sprintf(bbuf, "units %s", p);
125 sprintf(bbuf, "all planes");
127 sprintf(bbuf, "all unassigned planes");
128 else if (issector(p))
129 sprintf(bbuf, "all planes in %s", p);
130 else if (isalpha(*p))
131 sprintf(bbuf, "wing %c", *p);
133 sprintf(bbuf, "planes %s", p);
136 sprintf(y_or_n, "Really scrap %s [n]? ", bbuf);
137 if (!confirm(y_or_n))
140 while (nxtitem(&ni, &item)) {
145 if (ontradingblock(type, (int *)&item.ship)) {
146 pr("You cannot scrap an item on the trading block!\n");
151 if (type == EF_SHIP) {
152 getsect(item.ship.shp_x, item.ship.shp_y, §);
153 if (sect.sct_type != SCT_HARBR)
155 if (sect.sct_effic < 60 || sect.sct_own != player->cnum)
157 } else if (type == EF_LAND) {
158 if (item.land.lnd_ship >= 0) {
159 pr("%s is on a ship, and cannot be scrapped!\n",
163 getsect(item.land.lnd_x, item.land.lnd_y, §);
165 getsect(item.plane.pln_x, item.plane.pln_y, §);
166 if (sect.sct_type != SCT_AIRPT)
168 if (sect.sct_effic < 60 ||
169 (sect.sct_own != player->cnum &&
170 getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY))
173 if (type == EF_SHIP) {
174 eff = ((float)item.ship.shp_effic / 100.0);
175 mp = &mchr[(int)item.ship.shp_type];
176 if (opt_TRADESHIPS) {
177 if (mp->m_flags & M_TRADE) {
178 pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n");
180 "Are you really sure that you want to scrap %s (n)? ",
182 if (!confirm(prompt)) {
183 pr("%s not scrapped\n", prship(&item.ship));
188 pr("%s", prship(&item.ship));
189 for (i = I_NONE + 1; i <= I_MAX; i++) {
190 sect.sct_item[i] += item.ship.shp_item[i];
192 sect.sct_item[I_LCM] += mp->m_lcm * 2 / 3 * eff;
193 sect.sct_item[I_HCM] += mp->m_hcm * 2 / 3 * eff;
194 getsect(item.ship.shp_x, item.ship.shp_y, §2);
195 snxtitem_all(&ni2, EF_PLANE);
196 while (nxtitem(&ni2, &plane)) {
197 if (plane.pln_own == 0)
199 if (plane.pln_ship == item.ship.shp_uid) {
201 "Plane %d transferred off ship %d to %s\n",
202 ni2.cur, item.ship.shp_uid,
203 xyas(plane.pln_x, plane.pln_y, player->cnum));
205 if (sect2.sct_own != plane.pln_own) {
207 "%s given to %s\n", prplane(&plane),
208 cname(sect2.sct_own));
210 "%s given to you by %s\n", prplane(&plane),
211 cname(player->cnum));
213 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
214 plane.pln_x, plane.pln_y);
215 plane.pln_own = sect2.sct_own;
216 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
217 plane.pln_x, plane.pln_y);
218 putplane(plane.pln_uid, &plane);
221 snxtitem_all(&ni2, EF_LAND);
222 while (nxtitem(&ni2, &land)) {
223 if (land.lnd_own == 0)
225 if (land.lnd_ship == item.ship.shp_uid) {
227 "Land unit %d transferred off ship %d to %s\n",
228 ni2.cur, item.ship.shp_uid,
229 xyas(land.lnd_x, land.lnd_y, player->cnum));
231 if (sect2.sct_own != land.lnd_own) {
233 "%s given to %s\n", prland(&land),
234 cname(sect2.sct_own));
236 "%s given to you by %s\n", prland(&land),
237 cname(player->cnum));
239 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
240 land.lnd_x, land.lnd_y);
241 land.lnd_own = sect2.sct_own;
242 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
243 land.lnd_x, land.lnd_y);
244 putland(land.lnd_uid, &land);
247 makelost(EF_SHIP, item.ship.shp_own, item.ship.shp_uid,
248 item.ship.shp_x, item.ship.shp_y);
249 item.ship.shp_own = 0;
250 putship(item.ship.shp_uid, &item.ship);
251 } else if (type == EF_LAND) {
252 eff = ((float)item.land.lnd_effic / 100.0);
253 lp = &lchr[(int)item.land.lnd_type];
254 pr("%s", prland(&item.land));
255 for (i = I_NONE + 1; i <= I_MAX; i++) {
256 sect.sct_item[i] += item.land.lnd_item[i];
258 sect.sct_item[I_LCM] += lp->l_lcm * 2 / 3 * eff;
259 sect.sct_item[I_HCM] += lp->l_hcm * 2 / 3 * eff;
260 getsect(item.land.lnd_x, item.land.lnd_y, §2);
262 snxtitem_all(&ni2, EF_LAND);
263 while (nxtitem(&ni2, &land)) {
264 if (land.lnd_own == 0)
266 if (land.lnd_land == item.land.lnd_uid) {
268 "Land unit %d transferred off land unit %d to %s\n",
269 land.lnd_uid, item.land.lnd_uid,
270 xyas(land.lnd_x, land.lnd_y, player->cnum));
272 if (sect2.sct_own != land.lnd_own) {
274 "%s given to %s\n", prland(&land),
275 cname(sect2.sct_own));
277 "%s given to you by %s\n", prland(&land),
278 cname(player->cnum));
280 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
281 land.lnd_x, land.lnd_y);
282 land.lnd_own = sect2.sct_own;
283 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
284 land.lnd_x, land.lnd_y);
285 putland(land.lnd_uid, &land);
289 snxtitem_all(&ni2, EF_PLANE);
290 while (nxtitem(&ni2, &plane)) {
291 if (plane.pln_own == 0)
293 if (plane.pln_land == item.land.lnd_uid) {
295 "Plane %d transferred off land unit %d to %s\n",
296 ni2.cur, item.land.lnd_uid,
297 xyas(plane.pln_x, plane.pln_y, player->cnum));
299 if (sect2.sct_own != plane.pln_own) {
301 "%s given to %s\n", prplane(&plane),
302 cname(sect2.sct_own));
304 "%s given to you by %s\n", prplane(&plane),
305 cname(player->cnum));
307 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
308 plane.pln_x, plane.pln_y);
309 plane.pln_own = sect2.sct_own;
310 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
311 plane.pln_x, plane.pln_y);
312 putplane(plane.pln_uid, &plane);
315 makelost(EF_LAND, item.land.lnd_own, item.land.lnd_uid,
316 item.land.lnd_x, item.land.lnd_y);
317 item.land.lnd_own = 0;
318 putland(item.land.lnd_uid, &item.land);
320 eff = ((float)item.land.lnd_effic / 100.0);
321 pp = &plchr[(int)item.plane.pln_type];
322 pr("%s", prplane(&item.plane));
323 sect.sct_item[I_LCM] += pp->pl_lcm * 2 / 3 * eff;
324 sect.sct_item[I_HCM] += pp->pl_hcm * 2 / 3 * eff;
325 sect.sct_item[I_MILIT] += pp->pl_crew;
326 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid,
327 item.plane.pln_x, item.plane.pln_y);
328 item.plane.pln_own = 0;
329 putplane(item.plane.pln_uid, &item.plane);
331 pr(" scrapped in %s\n",
332 xyas(sect.sct_x, sect.sct_y, player->cnum));
333 for (i = I_NONE + 1; i <= I_MAX; i++) {
334 if (sect.sct_item[i] > ITEM_MAX)
335 sect.sct_item[i] = ITEM_MAX;