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 * laun.c: Launch missiles from land or sea
30 * Known contributors to this file:
33 * Steve McClure, 1998-2000
56 static int launch_as(struct plnstr *pp);
57 static int launch_missile(struct plnstr *pp, int sublaunch);
58 static int launch_sat(struct plnstr *pp, int sublaunch);
66 struct nstr_item nstr;
75 if (!snxtitem(&nstr, EF_PLANE, player->argp[1]))
77 while (nxtitem(&nstr, (s_char *)&plane)) {
78 if (plane.pln_own != player->cnum)
80 pcp = &plchr[(int)plane.pln_type];
81 if ((pcp->pl_flags & (P_M | P_O)) == 0) {
82 pr("%s isn't a missile!\n", prplane(&plane));
85 if (pcp->pl_flags & P_F) {
86 pr("%s is a surface-to-air missile!\n", prplane(&plane));
89 if (pcp->pl_flags & P_N) {
90 pr("%s is an anti-ballistic-missile missile!\n",
94 if ((plane.pln_flags & PLN_LAUNCHED) && (pcp->pl_flags & P_O)) {
95 pr("%s already in orbit!\n", prplane(&plane));
99 if (ontradingblock(EF_PLANE, (int *)&plane)) {
100 pr("plane #%d inelligible - it's for sale.\n",
107 if (plane.pln_ship >= 0) {
108 getship(plane.pln_ship, &ship);
110 pr("%s: ship #%d was sunk!\n",
111 prplane(&plane), ship.shp_uid);
112 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
113 plane.pln_x, plane.pln_y);
115 putplane(plane.pln_uid, &plane);
118 natp = getnatp(ship.shp_own);
119 rel = getrel(natp, player->cnum);
120 if (ship.shp_own != player->cnum && rel != ALLIED) {
121 pr("%s: you or an ally do not own ship #%d\n",
122 prplane(&plane), ship.shp_uid);
123 makelost(EF_PLANE, plane.pln_own, plane.pln_uid,
124 plane.pln_x, plane.pln_y);
126 putplane(plane.pln_uid, &plane);
129 if (mchr[(int)ship.shp_type].m_flags & M_SUB)
133 getsect(plane.pln_x, plane.pln_y, §);
134 natp = getnatp(sect.sct_own);
135 rel = getrel(natp, player->cnum);
136 if (sect.sct_own && sect.sct_own != player->cnum
138 pr("%s: you or an ally do not own sector %s!\n",
139 prplane(&plane), xyas(plane.pln_x, plane.pln_y,
144 if (plane.pln_effic < 60) {
145 pr("%s is damaged (%d%%)\n", prplane(&plane), plane.pln_effic);
148 pr("%s at %s; range %d, eff %d%%\n", prplane(&plane),
149 xyas(plane.pln_x, plane.pln_y, player->cnum),
150 plane.pln_range, plane.pln_effic);
151 if (!(pcp->pl_flags & P_O)) {
152 if (launch_missile(&plane, sublaunch) < 0)
154 } else if ((pcp->pl_flags & (P_M | P_O)) == (P_M | P_O)) {
155 if (launch_as(&plane) < 0) /* anti-sat */
157 } else { /* satellites */
158 if (launch_sat(&plane, sublaunch) < 0)
161 makelost(EF_PLANE, plane.pln_own, plane.pln_uid, plane.pln_x,
164 putplane(plane.pln_uid, &plane);
170 * Launch an anti-sat weapon.
171 * Return -1 on failure, 0 on success (even if missile explodes).
175 launch_as(struct plnstr *pp)
178 s_char *cp, buf[1024];
185 if (msl_equip(pp) < 0) {
186 pr("%s not enough petrol or shells!\n", prplane(pp));
190 cp = getstarg(player->argp[2], "Target sector? ", buf);
191 if (!check_plane_ok(pp))
196 if (!sarg_xy(cp, &sx, &sy)) {
197 pr("Bad sector designation; try again!\n");
200 if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > pp->pln_range) {
201 pr("Range too great; try again!\n");
207 snxtitem_dist(&ni, EF_PLANE, sx, sy, 0);
208 while (!goodtarget && nxtitem(&ni, (caddr_t)&plane)) {
211 if (!(plane.pln_flags & PLN_LAUNCHED))
217 pr("No satellites there!\n");
221 (pp, plane.pln_def, EF_PLANE, N_SAT_KILL, N_SAT_KILL,
222 prplane(&plane), sx, sy, plane.pln_own)) {
223 dam = pln_damage(pp, sx, sy, 'p', &nukedam, 1);
224 oldown = plane.pln_own;
225 planedamage(&plane, dam);
226 pr("Hit satellite for %d%% damage!\n", dam);
228 "%s anti-sat did %d%% damage to %s over %s\n",
229 cname(player->cnum), dam, prplane(&plane),
230 xyas(plane.pln_x, plane.pln_y, plane.pln_own));
231 putplane(plane.pln_uid, &plane);
233 mpr(oldown, "Satellite shot down\n");
240 * Return -1 on failure, 0 on success (even if missile explodes).
243 launch_missile(struct plnstr *pp, int sublaunch)
245 struct plchrstr *pcp = plchr + pp->pln_type;
250 struct shpstr target_ship;
258 if (pcp->pl_flags & P_MAR)
259 cp = getstarg(player->argp[2], "Target ship? ", buf);
261 cp = getstarg(player->argp[2], "Target sector? ", buf);
265 if (!check_plane_ok(pp))
267 if (opt_PINPOINTMISSILE && sarg_type(cp) == NS_LIST) {
268 if (!(pcp->pl_flags & P_MAR)) {
269 pr("Missile not designed to attack ships!\n");
273 if ((n < 0) || !getship(n, &target_ship) ||
274 !target_ship.shp_own) {
275 pr("Bad ship number; try again!\n");
278 sx = target_ship.shp_x;
279 sy = target_ship.shp_y;
280 mcp = &mchr[(int)target_ship.shp_type];
281 if (mcp->m_flags & M_SUB) {
282 pr("Bad ship number; try again!\n");
285 } /* not PINPOINTMISSILE for ships */
286 else if (!sarg_xy(cp, &sx, &sy)) {
287 pr("That's no good! try again!\n");
289 } else if (opt_PINPOINTMISSILE) {
290 if (pcp->pl_flags & P_MAR) {
291 pr("Missile designed to attack ships!\n");
295 /* end PINPOINTMISSILE */
296 if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > pp->pln_range) {
297 pr("Range too great; try again!\n");
302 if (msl_equip(pp) < 0) {
303 pr("%s not enough shells!\n", prplane(pp));
306 if (opt_PINPOINTMISSILE == 0 || !(pcp->pl_flags & P_MAR)) {
307 getsect(sx, sy, §);
309 natp = getnatp(player->cnum);
310 rel = getrel(natp, sect.sct_own);
311 if ((rel != AT_WAR) && (sect.sct_own != player->cnum) &&
312 (sect.sct_own) && (sect.sct_oldown != player->cnum)) {
313 pr("You are not at war with the player->owner of the target sector!\n");
316 pr("Missile monitoring officer destroys RV before detonation.\n");
320 if (!msl_hit(pp, SECT_HARDTARGET, EF_SECTOR, N_SCT_MISS,
321 N_SCT_SMISS, "sector", sx, sy, sect.sct_own)) {
323 dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 0);
324 collateral_damage(sect.sct_x, sect.sct_y, dam, 0);
328 dam = pln_damage(pp, sect.sct_x, sect.sct_y, 's', &nukedam, 1);
330 pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
331 xyas(sx, sy, player->cnum));
332 if (sect.sct_own != 0) {
335 "Sub missile attack did %d damage in %s\n",
336 dam, xyas(sx, sy, sect.sct_own));
339 "%s missile attack did %d damage in %s\n",
340 cname(player->cnum), dam,
341 xyas(sx, sy, sect.sct_own));
343 sectdamage(§, dam, 0);
346 } /* end PINPOINTMISSILE conditional */
347 else if (opt_PINPOINTMISSILE) { /* else */
348 if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP,
349 N_SHP_MISS, N_SHP_SMISS, prship(&target_ship),
350 target_ship.shp_x, target_ship.shp_y,
351 target_ship.shp_own)) {
354 dam = pln_damage(pp,target_ship.shp_x,target_ship.shp_y,'p',&nukedam, 0);
355 collateral_damage(target_ship.shp_x, target_ship.shp_y, dam, 0);
360 pln_damage(pp, target_ship.shp_x, target_ship.shp_y, 'p',
363 check_retreat_and_do_shipdamage(&target_ship, dam);
364 if (target_ship.shp_effic < SHIP_MINEFF)
365 pr("\t%s sunk!\n", prship(&target_ship));
366 putship(target_ship.shp_uid, &target_ship);
368 getship(n, &target_ship);
369 if (!target_ship.shp_own)
370 pr("%s sunk!\n", prship(&target_ship));
372 /* end PINPOINTMISSILE */
377 * Launch a satellite.
378 * Return -1 on error, 0 on success (even if the satellite fails).
381 launch_sat(struct plnstr *pp, int sublaunch)
383 struct plchrstr *pcp = plchr + pp->pln_type;
394 cp = getstarg(player->argp[2], "Target sector? ", buf);
395 if (!check_plane_ok(pp))
400 if (!sarg_xy(cp, &sx, &sy)) {
401 pr("Bad sector designation; try again!\n");
404 if ((dist = mapdist(pp->pln_x, pp->pln_y, sx, sy)) > pp->pln_range) {
405 pr("Range too great; try again!\n");
411 p = getstring("Geostationary orbit? ", buf);
414 if (!check_plane_ok(pp))
417 pp->pln_flags |= PLN_SYNCHRONOUS;
418 if (*p == 0 || *p == 'n')
419 pp->pln_flags &= ~(PLN_SYNCHRONOUS);
422 pr("3... 2... 1... Blastoff!!!\n");
423 if (chance(0.07 + (100 - pp->pln_effic) / 100.0)) {
424 pr("KABOOOOM! Range safety officer detonates booster!\n");
425 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
429 i = pp->pln_tech + pp->pln_effic;
430 if (chance(1.0 - (i / (i + 50.0)))) {
431 dir = (random() % 6) + 1;
432 sx += diroff[dir][0];
433 sy += diroff[dir][1];
434 pr("Your trajectory was a little off.\n");
436 nreport(player->cnum, N_LAUNCH, 0, 1);
437 pr("%s positioned over %s", prplane(pp), xyas(sx, sy, player->cnum));
438 if (msl_intercept(sx, sy, pp->pln_own, pcp->pl_def, sublaunch, P_O, 0)) {
443 pp->pln_flags |= PLN_LAUNCHED;
444 pp->pln_mobil = (pp->pln_mobil > dist) ? (pp->pln_mobil - dist) : 0;
445 putplane(pp->pln_uid, pp);
446 pr(", will be ready for use in %d time units\n", 127 - pp->pln_mobil);