2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * projects/authors will amend these files as needed.
28 * scra.c: Scrap ships, planes or land units
30 * Known contributors to this file:
62 int itemvec[I_MAX + 1];
78 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
91 pr("Ships, land units, or planes only! (s, l, p)\n");
94 sprintf(prompt, "%s(s)? ", ef_nameof(type));
95 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
97 if (!snxtitem(&ni, type, p))
99 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
101 s_char y_or_n[80], bbuf[80];
104 if (type == EF_SHIP) {
106 sprintf(bbuf, "all ships");
108 sprintf(bbuf, "all unassigned ships");
109 else if (issector(p))
110 sprintf(bbuf, "all ships in %s", p);
111 else if (isalpha(*p))
112 sprintf(bbuf, "fleet %c", *p);
114 sprintf(bbuf, "ships %s", p);
115 } else if (type == EF_LAND) {
117 sprintf(bbuf, "all land units");
119 sprintf(bbuf, "all unassigned land units");
120 else if (issector(p))
121 sprintf(bbuf, "all units in %s", p);
122 else if (isalpha(*p))
123 sprintf(bbuf, "army %c", *p);
125 sprintf(bbuf, "units %s", p);
128 sprintf(bbuf, "all planes");
130 sprintf(bbuf, "all unassigned planes");
131 else if (issector(p))
132 sprintf(bbuf, "all planes in %s", p);
133 else if (isalpha(*p))
134 sprintf(bbuf, "wing %c", *p);
136 sprintf(bbuf, "planes %s", p);
139 sprintf(y_or_n, "Really scrap %s [n]? ", bbuf);
140 if (!confirm(y_or_n))
143 while (nxtitem(&ni, (s_char *)&item)) {
148 if (ontradingblock(type, (int *)&item.ship)) {
149 pr("You cannot scrap an item on the trading block!\n");
154 if (type == EF_SHIP) {
155 getsect(item.ship.shp_x, item.ship.shp_y, §);
156 if (sect.sct_type != SCT_HARBR)
158 if (sect.sct_effic < 60 || sect.sct_own != player->cnum)
160 } else if (type == EF_LAND) {
161 if (item.land.lnd_ship >= 0) {
162 pr("%s is on a ship, and cannot be scrapped!\n",
166 getsect(item.land.lnd_x, item.land.lnd_y, §);
168 getsect(item.plane.pln_x, item.plane.pln_y, §);
169 if (sect.sct_type != SCT_AIRPT)
171 if (sect.sct_effic < 60 ||
172 (sect.sct_own != player->cnum &&
173 getrel(getnatp(sect.sct_own), player->cnum) < FRIENDLY))
176 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
177 if (type == EF_SHIP) {
178 eff = ((float)item.ship.shp_effic / 100.0);
179 mp = &mchr[(int)item.ship.shp_type];
180 if (opt_TRADESHIPS) {
181 if (mp->m_flags & M_TRADE) {
182 pr("WARNING: You only collect money from trade ships if you \"scuttle\" them!\n");
184 "Are you really sure that you want to scrap %s (n)? ",
186 if (!confirm(prompt)) {
187 pr("%s not scrapped\n", prship(&item.ship));
192 pr("%s", prship(&item.ship));
193 getvec(VT_ITEM, itemvec, (s_char *)&item.ship, EF_SHIP);
194 for (i = 1; i <= I_MAX; i++) {
195 vec[i] += itemvec[i];
197 vec[I_LCM] += mp->m_lcm * 2 / 3 * eff;
198 vec[I_HCM] += mp->m_hcm * 2 / 3 * eff;
199 getsect(item.ship.shp_x, item.ship.shp_y, §2);
200 snxtitem_all(&ni2, EF_PLANE);
201 while (nxtitem(&ni2, (s_char *)&plane)) {
202 if (plane.pln_own == 0)
204 if (plane.pln_ship == item.ship.shp_uid) {
206 "Plane %d transferred off ship %d to %s\n",
207 ni2.cur, item.ship.shp_uid,
208 xyas(plane.pln_x, plane.pln_y, player->cnum));
210 if (sect2.sct_own != plane.pln_own) {
212 "%s given to %s\n", prplane(&plane),
213 cname(sect2.sct_own));
215 "%s given to you by %s\n", prplane(&plane),
216 cname(player->cnum));
218 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
219 plane.pln_x, plane.pln_y);
220 plane.pln_own = sect2.sct_own;
221 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
222 plane.pln_x, plane.pln_y);
223 putplane(plane.pln_uid, (s_char *)&plane);
226 snxtitem_all(&ni2, EF_LAND);
227 while (nxtitem(&ni2, (s_char *)&land)) {
228 if (land.lnd_own == 0)
230 if (land.lnd_ship == item.ship.shp_uid) {
232 "Land unit %d transferred off ship %d to %s\n",
233 ni2.cur, item.ship.shp_uid,
234 xyas(land.lnd_x, land.lnd_y, player->cnum));
236 if (sect2.sct_own != land.lnd_own) {
238 "%s given to %s\n", prland(&land),
239 cname(sect2.sct_own));
241 "%s given to you by %s\n", prland(&land),
242 cname(player->cnum));
244 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
245 land.lnd_x, land.lnd_y);
246 land.lnd_own = sect2.sct_own;
247 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
248 land.lnd_x, land.lnd_y);
249 putland(land.lnd_uid, (s_char *)&land);
252 makelost(EF_SHIP, item.ship.shp_own, item.ship.shp_uid,
253 item.ship.shp_x, item.ship.shp_y);
254 item.ship.shp_own = 0;
255 putship(item.ship.shp_uid, (s_char *)&item.ship);
256 } else if (type == EF_LAND) {
257 eff = ((float)item.land.lnd_effic / 100.0);
258 lp = &lchr[(int)item.land.lnd_type];
259 pr("%s", prland(&item.land));
260 getvec(VT_ITEM, itemvec, (s_char *)&item.land, EF_LAND);
261 for (i = 1; i <= I_MAX; i++) {
262 vec[i] += itemvec[i];
264 /* Military, guns and shells are not required to build land units */
265 /* vec[I_MILIT] += total_mil(&item.land);*/
266 /* vec[I_GUN] += lp->l_gun * 2 / 3 * eff;*/
267 /* vec[I_SHELL] += lp->l_shell * 2 / 3 * eff;*/
268 vec[I_LCM] += lp->l_lcm * 2 / 3 * eff;
269 vec[I_HCM] += lp->l_hcm * 2 / 3 * eff;
270 getsect(item.land.lnd_x, item.land.lnd_y, §2);
272 snxtitem_all(&ni2, EF_LAND);
273 while (nxtitem(&ni2, (s_char *)&land)) {
274 if (land.lnd_own == 0)
276 if (land.lnd_land == item.land.lnd_uid) {
278 "Land unit %d transferred off land unit %d to %s\n",
279 land.lnd_uid, item.land.lnd_uid,
280 xyas(land.lnd_x, land.lnd_y, player->cnum));
282 if (sect2.sct_own != land.lnd_own) {
284 "%s given to %s\n", prland(&land),
285 cname(sect2.sct_own));
287 "%s given to you by %s\n", prland(&land),
288 cname(player->cnum));
290 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
291 land.lnd_x, land.lnd_y);
292 land.lnd_own = sect2.sct_own;
293 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
294 land.lnd_x, land.lnd_y);
295 putland(land.lnd_uid, (s_char *)&land);
299 snxtitem_all(&ni2, EF_PLANE);
300 while (nxtitem(&ni2, (s_char *)&plane)) {
301 if (plane.pln_own == 0)
303 if (plane.pln_land == item.land.lnd_uid) {
305 "Plane %d transferred off land unit %d to %s\n",
306 ni2.cur, item.land.lnd_uid,
307 xyas(plane.pln_x, plane.pln_y, player->cnum));
309 if (sect2.sct_own != plane.pln_own) {
311 "%s given to %s\n", prplane(&plane),
312 cname(sect2.sct_own));
314 "%s given to you by %s\n", prplane(&plane),
315 cname(player->cnum));
317 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
318 plane.pln_x, plane.pln_y);
319 plane.pln_own = sect2.sct_own;
320 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
321 plane.pln_x, plane.pln_y);
322 putplane(plane.pln_uid, (s_char *)&plane);
325 makelost(EF_LAND, item.land.lnd_own, item.land.lnd_uid,
326 item.land.lnd_x, item.land.lnd_y);
327 item.land.lnd_own = 0;
328 putland(item.land.lnd_uid, (s_char *)&item.land);
330 eff = ((float)item.land.lnd_effic / 100.0);
331 pp = &plchr[(int)item.plane.pln_type];
332 pr("%s", prplane(&item.plane));
333 vec[I_LCM] += pp->pl_lcm * 2 / 3 * eff;
334 vec[I_HCM] += pp->pl_hcm * 2 / 3 * eff;
335 vec[I_MILIT] += pp->pl_crew;
336 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid,
337 item.plane.pln_x, item.plane.pln_y);
338 item.plane.pln_own = 0;
339 putplane(item.plane.pln_uid, (s_char *)&item.plane);
341 pr(" scrapped in %s\n",
342 xyas(sect.sct_x, sect.sct_y, player->cnum));
343 putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);