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:
78 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
82 type = EF_SHIP; break;
84 type = EF_PLANE; break;
86 type = EF_LAND; break;
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];
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, (s_char *)&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", prland(&item.land));
162 getsect(item.land.lnd_x, item.land.lnd_y, §);
164 getsect(item.plane.pln_x, item.plane.pln_y, §);
165 if (sect.sct_type != SCT_AIRPT)
167 if (sect.sct_effic < 60 ||
168 (sect.sct_own != player->cnum &&
169 getrel(getnatp(sect.sct_own),player->cnum) < FRIENDLY))
172 getvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);
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");
179 sprintf(prompt, "Are you really sure that you want to scrap %s (n)? ", prship(&item.ship));
180 if (!confirm(prompt)) {
181 pr("%s not scrapped\n", prship(&item.ship));
186 pr("%s", prship(&item.ship));
187 getvec(VT_ITEM, itemvec, (s_char *)&item.ship, EF_SHIP);
188 for (i = 1; i <= I_MAX; i++) {
189 vec[i] += itemvec[i];
191 vec[I_LCM] += mp->m_lcm * 2 / 3 * eff;
192 vec[I_HCM] += mp->m_hcm * 2 / 3 * eff;
193 getsect(item.ship.shp_x,item.ship.shp_y,§2);
194 snxtitem_all(&ni2, EF_PLANE);
195 while (nxtitem(&ni2, (s_char *)&plane)){
196 if (plane.pln_own == 0)
198 if (plane.pln_ship == item.ship.shp_uid){
200 "Plane %d transferred off ship %d to %s\n",
201 ni2.cur, item.ship.shp_uid,
202 xyas(plane.pln_x, plane.pln_y,player->cnum));
204 if(sect2.sct_own != plane.pln_own) {
206 "%s given to %s\n", prplane(&plane),
207 cname(sect2.sct_own));
209 "%s given to you by %s\n", prplane(&plane),
210 cname(player->cnum));
212 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
213 plane.pln_x, plane.pln_y);
214 plane.pln_own = sect2.sct_own;
215 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
216 plane.pln_x, plane.pln_y);
217 putplane(plane.pln_uid, (s_char *)&plane);
220 snxtitem_all(&ni2, EF_LAND);
221 while (nxtitem(&ni2, (s_char *)&land)){
222 if (land.lnd_own == 0)
224 if (land.lnd_ship == item.ship.shp_uid){
226 "Land unit %d transferred off ship %d to %s\n",
227 ni2.cur, item.ship.shp_uid,
228 xyas(land.lnd_x, land.lnd_y,player->cnum));
230 if(sect2.sct_own != land.lnd_own){
232 "%s given to %s\n", prland(&land),
233 cname(sect2.sct_own));
235 "%s given to you by %s\n", prland(&land),
236 cname(player->cnum));
238 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
239 land.lnd_x, land.lnd_y);
240 land.lnd_own = sect2.sct_own;
241 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
242 land.lnd_x, land.lnd_y);
243 putland(land.lnd_uid, (s_char *)&land);
246 makelost(EF_SHIP, item.ship.shp_own, item.ship.shp_uid,
247 item.ship.shp_x, item.ship.shp_y);
248 item.ship.shp_own = 0;
249 putship(item.ship.shp_uid, (s_char *)&item.ship);
250 } else if (type == EF_LAND) {
251 eff = ((float)item.land.lnd_effic/100.0);
252 lp = &lchr[(int)item.land.lnd_type];
253 pr("%s", prland(&item.land));
254 getvec(VT_ITEM, itemvec, (s_char *)&item.land, EF_LAND);
255 for (i = 1; i <= I_MAX; i++) {
256 vec[i] += itemvec[i];
258 /* Military, guns and shells are not required to build land units */
259 /* vec[I_MILIT] += total_mil(&item.land);*/
260 /* vec[I_GUN] += lp->l_gun * 2 / 3 * eff;*/
261 /* vec[I_SHELL] += lp->l_shell * 2 / 3 * eff;*/
262 vec[I_LCM] += lp->l_lcm * 2 / 3 * eff;
263 vec[I_HCM] += lp->l_hcm * 2 / 3 * eff;
264 getsect(item.land.lnd_x,item.land.lnd_y,§2);
266 snxtitem_all(&ni2, EF_LAND);
267 while (nxtitem(&ni2, (s_char *)&land)){
268 if (land.lnd_own == 0)
270 if (land.lnd_land == item.land.lnd_uid){
272 "Land unit %d transferred off land unit %d to %s\n",
273 land.lnd_uid, item.land.lnd_uid,
274 xyas(land.lnd_x, land.lnd_y,player->cnum));
276 if (sect2.sct_own != land.lnd_own) {
278 "%s given to %s\n", prland(&land),
279 cname(sect2.sct_own));
281 "%s given to you by %s\n", prland(&land),
282 cname(player->cnum));
284 makelost(EF_LAND, land.lnd_own, land.lnd_uid,
285 land.lnd_x, land.lnd_y);
286 land.lnd_own = sect2.sct_own;
287 makenotlost(EF_LAND, land.lnd_own, land.lnd_uid,
288 land.lnd_x, land.lnd_y);
289 putland(land.lnd_uid, (s_char *)&land);
293 snxtitem_all(&ni2, EF_PLANE);
294 while (nxtitem(&ni2, (s_char *)&plane)) {
295 if (plane.pln_own == 0)
297 if (plane.pln_land == item.land.lnd_uid){
299 "Plane %d transferred off land unit %d to %s\n",
300 ni2.cur, item.land.lnd_uid,
301 xyas(plane.pln_x, plane.pln_y,player->cnum));
303 if(sect2.sct_own != plane.pln_own) {
305 "%s given to %s\n", prplane(&plane),
306 cname(sect2.sct_own));
308 "%s given to you by %s\n", prplane(&plane),
309 cname(player->cnum));
311 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
312 plane.pln_x, plane.pln_y);
313 plane.pln_own = sect2.sct_own;
314 makenotlost(EF_PLANE, plane.pln_own, plane.pln_uid,
315 plane.pln_x, plane.pln_y);
316 putplane(plane.pln_uid, (s_char *)&plane);
319 makelost(EF_LAND, item.land.lnd_own, item.land.lnd_uid,
320 item.land.lnd_x, item.land.lnd_y);
321 item.land.lnd_own = 0;
322 putland(item.land.lnd_uid, (s_char *)&item.land);
324 eff = ((float)item.land.lnd_effic/100.0);
325 pp = &plchr[(int)item.plane.pln_type];
326 pr("%s", prplane(&item.plane));
327 vec[I_LCM] += pp->pl_lcm * 2 / 3 * eff;
328 vec[I_HCM] += pp->pl_hcm * 2 / 3 * eff;
329 vec[I_MILIT] += pp->pl_crew;
330 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid,
331 item.plane.pln_x, item.plane.pln_y);
332 item.plane.pln_own = 0;
333 putplane(item.plane.pln_uid, (s_char *)&item.plane);
335 pr(" scrapped in %s\n",
336 xyas(sect.sct_x, sect.sct_y, player->cnum));
337 putvec(VT_ITEM, vec, (s_char *)§, EF_SECTOR);