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 * scut.c: Scuttle ships, planes or land units
30 * Known contributors to this file:
57 scuttle_tradeship(struct shpstr *sp, int interactive)
59 extern int trade_1_dist; /* less than this gets no money */
60 extern int trade_2_dist; /* less than this gets trade_1 money */
61 extern int trade_3_dist; /* less than this gets trade_2 money */
62 extern float trade_1; /* return on trade_1 distance */
63 extern float trade_2; /* return on trade_2 distance */
64 extern float trade_3; /* return on trade_3 distance */
65 extern float trade_ally_bonus; /* 20% bonus for trading with allies */
66 extern float trade_ally_cut; /* 10% bonus for ally you trade with */
76 mp = &mchr[(int)sp->shp_type];
77 getsect(sp->shp_x,sp->shp_y,§);
78 if (sect.sct_own && sect.sct_type == SCT_HARBR) {
79 dist = mapdist(sp->shp_x, sp->shp_y,
83 pr("%s has gone %d sects\n", prship(sp), dist);
85 wu(0, sp->shp_own, "%s has gone %d sects\n", prship(sp),
87 if (dist < trade_1_dist)
89 else if (dist < trade_2_dist)
90 cash = (1.0 + trade_1*((float)dist));
91 else if (dist < trade_3_dist)
92 cash = (1.0 + trade_2*((float)dist));
94 cash = (1.0 + trade_3*((float)dist));
96 cash *= (((float)sp->shp_effic) / 100.0);
98 if (sect.sct_own != sp->shp_own) {
99 cash *= (1.0 + trade_ally_bonus);
100 ally_cash = cash * trade_ally_cut;
104 if (!interactive && cash) {
105 natp = getnatp(sp->shp_own);
106 natp->nat_money += cash;
108 wu(0, sp->shp_own, "You just made $%d.\n", (int)cash);
109 } else if (!cash && !interactive) {
110 wu(0, sp->shp_own, "Unfortunately, you make $0 on this trade.\n");
111 } else if (cash && interactive) {
112 player->dolcost -= cash;
113 } else if (interactive) {
114 pr("You won't get any money if you scuttle in %s!",
115 xyas(sp->shp_x, sp->shp_y, player->cnum));
116 sprintf(buf, "Are you sure you want to scuttle %s? ",
122 np = getnatp(sect.sct_own);
123 np->nat_money += ally_cash;
126 "Trade with %s nets you $%d at %s\n",
129 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
130 if (sp->shp_own != sp->shp_orig_own)
132 N_PIRATE_TRADE, sp->shp_orig_own, 1);
134 nreport(sp->shp_own, N_TRADE, sect.sct_own, 1);
135 } else if (sp->shp_own != sp->shp_orig_own)
136 nreport(sp->shp_own, N_PIRATE_KEEP, sp->shp_orig_own, 1);
154 if (!(p = getstarg(player->argp[1], "Ship, land, or plane? ", buf)))
158 type = EF_SHIP; break;
160 type = EF_PLANE; break;
162 type = EF_LAND; break;
164 pr("Ships, land units, or planes only! (s, l, p)\n");
167 sprintf(prompt, "%s(s)? ", ef_nameof(type));
168 if ((p = getstarg(player->argp[2], prompt, buf)) == 0)
170 if (!snxtitem(&ni, type, p))
172 if (p && (isalpha(*p) || (*p == '*') || (*p == '~') || issector(p)
174 s_char y_or_n[80], bbuf[80];
176 if (type == EF_SHIP) {
178 sprintf(bbuf,"all ships");
180 sprintf(bbuf,"all unassigned ships");
181 else if (issector(p))
182 sprintf(bbuf,"all ships in %s",p);
183 else if (isalpha(*p))
184 sprintf(bbuf,"fleet %c",*p);
186 sprintf(bbuf,"ships %s",p);
187 } else if (type == EF_LAND) {
189 sprintf(bbuf,"all land units");
191 sprintf(bbuf,"all unassigned land units");
192 else if (issector(p))
193 sprintf(bbuf,"all units in %s",p);
194 else if (isalpha(*p))
195 sprintf(bbuf,"army %c",*p);
197 sprintf(bbuf,"units %s",p);
200 sprintf(bbuf,"all planes");
202 sprintf(bbuf,"all unassigned planes");
203 else if (issector(p))
204 sprintf(bbuf,"all planes in %s",p);
205 else if (isalpha(*p))
206 sprintf(bbuf,"wing %c",*p);
208 sprintf(bbuf,"planes %s",p);
210 sprintf(y_or_n,"Really scuttle %s? ", bbuf);
211 if (!confirm(y_or_n))
214 while (nxtitem(&ni, (s_char *)&item)) {
218 if (ontradingblock(type, (int *)&item.ship)) {
219 pr("You cannot scuttle an item on the trading block!\n");
224 if (type == EF_SHIP) {
225 mp = &mchr[(int)item.ship.shp_type];
226 if (opt_TRADESHIPS) {
227 if (mp->m_flags & M_TRADE)
228 if (!scuttle_tradeship(&item.ship, 1))
231 pr("%s", prship(&item.ship));
232 scuttle_ship(&item.ship);
233 } else if (type == EF_LAND) {
234 if (item.land.lnd_ship >= 0) {
235 pr("%s is on a ship, and cannot be scuttled!\n",
239 lp = &lchr[(int)item.land.lnd_type];
240 pr("%s", prland(&item.land));
241 scuttle_land(&item.land);
243 pp = &plchr[(int)item.plane.pln_type];
244 pr("%s", prplane(&item.plane));
245 if (item.plane.pln_ship >= 0){
248 getship(item.plane.pln_ship,&ship);
249 take_plane_off_ship(&item.plane,&ship);
251 makelost(EF_PLANE, item.plane.pln_own, item.plane.pln_uid, item.plane.pln_x, item.plane.pln_y);
252 item.plane.pln_own = 0;
253 putplane(item.plane.pln_uid, (s_char *)&item.plane);
255 pr(" scuttled in %s\n",
256 xyas(item.ship.shp_x, item.ship.shp_y , player->cnum));
263 scuttle_ship(struct shpstr *sp)
270 getsect(sp->shp_x, sp->shp_y, §);
271 snxtitem_all(&ni, EF_PLANE);
272 while (nxtitem(&ni, (s_char *)&plane)) {
273 if (plane.pln_own == 0)
275 if (plane.pln_ship == sp->shp_uid) {
277 if (sect.sct_own != sp->shp_own) {
278 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
280 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
281 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y);
285 "Plane %d transferred off ship %d to %s\n",
286 plane.pln_uid, sp->shp_uid,
287 xyas(plane.pln_x, plane.pln_y,plane.pln_own));
289 putplane(plane.pln_uid, (s_char *)&plane);
292 snxtitem_all(&ni, EF_LAND);
293 while (nxtitem(&ni, (s_char *)&land)) {
294 if (land.lnd_own == 0)
296 if (land.lnd_ship == sp->shp_uid) {
298 if (sect.sct_own == sp->shp_own) {
300 "Land unit %d transferred off ship %d to %s\n",
301 land.lnd_uid, sp->shp_uid,
302 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
303 putland(land.lnd_uid, (s_char *)&land);
308 makelost(EF_SHIP, sp->shp_own, sp->shp_uid, sp->shp_x, sp->shp_y);
310 putship(sp->shp_uid, sp);
314 scuttle_land(struct lndstr *lp)
321 getsect(lp->lnd_x, lp->lnd_y, §);
322 snxtitem_all(&ni, EF_PLANE);
323 while (nxtitem(&ni, (s_char *)&plane)) {
324 if (plane.pln_own == 0)
326 if (plane.pln_land == lp->lnd_uid) {
328 if (sect.sct_own != lp->lnd_own) {
329 wu(0, plane.pln_own, "Plane %d scuttled in %s\n",
331 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
332 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x, plane.pln_y);
336 "Plane %d transferred off unit %d to %s\n",
337 plane.pln_uid, lp->lnd_uid,
338 xyas(plane.pln_x, plane.pln_y,plane.pln_own));
340 putplane(plane.pln_uid, (s_char *)&plane);
343 snxtitem_all(&ni, EF_LAND);
344 while (nxtitem(&ni, (s_char *)&land)) {
345 if (land.lnd_own == 0)
347 if (land.lnd_land == lp->lnd_uid) {
349 if (sect.sct_own == lp->lnd_own) {
351 "Land unit %d transferred off unit %d to %s\n",
352 land.lnd_uid, lp->lnd_uid,
353 xyas(land.lnd_x, land.lnd_y, land.lnd_own));
354 putland(land.lnd_uid, (s_char *)&land);
359 makelost(EF_LAND, lp->lnd_own, lp->lnd_uid, lp->lnd_x, lp->lnd_y);
361 putland(lp->lnd_uid, lp);