2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2004, 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 * mslsub.c: Missile subroutine stuff
30 * Known contributors to this file:
32 * Steve McClure, 1996-2000
53 #include "prototypes.h"
56 msl_equip(struct plnstr *pp)
60 memset(&pl, 0, sizeof(struct plist));
61 pl.pcp = plchr + pp->pln_type;
63 return mission_pln_equip(&pl, 0, 0, 'p');
67 msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
68 int snews_item, s_char *what, coord x, coord y, int victim)
74 struct plchrstr *pcp = plchr + pp->pln_type;
75 int hitchance = pln_hitchance(pp, hardtarget, type);
79 mpr(pp->pln_own, "Preparing to launch %s at %s %s %s%s\n",
83 (type == EF_SHIP || type == EF_PLANE) ? "in " : "",
84 xyas(x, y, pp->pln_own));
85 mpr(pp->pln_own, "\tLaunching from ");
86 if (pp->pln_ship >= 0) {
87 getship(pp->pln_ship, &ship);
88 mpr(pp->pln_own, "%s in ", prship(&ship));
89 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
94 mpr(pp->pln_own, "%s\n",
95 xyas(ship.shp_x, ship.shp_y, pp->pln_own));
97 if (pp->pln_harden > 0) {
98 mpr(pp->pln_own, "missile silo at ");
101 from = "on launch pad";
102 mpr(pp->pln_own, "%s\n", xyas(pp->pln_x, pp->pln_y, pp->pln_own));
105 if (chance((0.05 + (100 - pp->pln_effic) / 100.0)
106 * (1 - techfact(pp->pln_tech, 1.0)))) {
107 mpr(pp->pln_own, "KABOOOOM! Missile explodes %s!\n", from);
109 if (pp->pln_nuketype != (s_char)-1 && opt_NUKEFAILDETONATE) {
110 pp->pln_flags &= ~PLN_AIRBURST;
111 detonate(pp, pp->pln_x, pp->pln_y);
113 dam = pln_damage(pp, pp->pln_x, pp->pln_y,
114 'p', &dummyi, 1) / 2;
116 if (pp->pln_ship >= 0) {
117 shipdamage(&ship, dam);
118 putship(ship.shp_uid, &ship);
120 pr("Explosion damages %s %d%%",
121 xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam);
122 getsect(pp->pln_x, pp->pln_y, §);
123 sectdamage(§, dam, 0);
132 mpr(pp->pln_own, "\tSHWOOOOOSH! Missile launched!\n");
134 if (pp->pln_nuketype != (s_char)-1)
135 mpr(pp->pln_own, "\tArming nuclear warheads...\n");
137 if (pcp->pl_flags & P_T)
138 mpr(victim, "Incoming %s missile sighted at %s...\n",
139 sublaunch ? "sub-launched" : cname(pp->pln_own),
142 if (opt_PINPOINTMISSILE == 0 ||
143 (pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) {
144 if (msl_intercept(x, y, pp->pln_own, pcp->pl_def,
145 sublaunch, P_N, P_O)) {
149 if (pcp->pl_flags & P_MAR) {
150 if (shp_missile_defense(x, y, pp->pln_own, pcp->pl_def)) {
155 if (pp->pln_nuketype != (s_char)-1)
158 mpr(pp->pln_own, "\t%d%% hitchance...", hitchance);
159 hit = (roll(100) <= hitchance);
161 mpr(pp->pln_own, hit ? "HIT!\n" : "miss\n");
162 if (pcp->pl_flags & P_T)
163 mpr(victim, "...Incoming %s missile %s\n",
164 sublaunch ? (s_char *)"" : cname(pp->pln_own),
165 hit ? "HIT!\n" : "missed\n");
166 if (hit && news_item) {
168 nreport(victim, snews_item, 0, 1);
170 nreport(pp->pln_own, news_item, victim, 1);
176 msl_sel(struct emp_qelem *list, coord x, coord y, natid victim,
177 int wantflags, int nowantflags, int mission)
179 register struct plchrstr *pcp;
185 snxtitem_all(&ni, EF_PLANE);
186 while (nxtitem(&ni, (s_char *)&plane)) {
190 pcp = &plchr[(int)plane.pln_type];
191 if (!(pcp->pl_flags & P_M))
193 if (wantflags && (pcp->pl_flags & wantflags) != wantflags)
195 if (nowantflags && pcp->pl_flags & nowantflags)
197 if (mission && plane.pln_mission != mission)
199 if (getrel(getnatp(plane.pln_own), victim) >= NEUTRAL)
201 /* missiles go one way, so we can use all the range */
202 if (plane.pln_range < mapdist(x, y, plane.pln_x, plane.pln_y))
204 if (plane.pln_mobil <= (s_char)0)
206 if (plane.pln_effic < 100)
208 /* got a valid interceptor */
209 irv = (struct plist *)malloc(sizeof(*irv));
213 irv->pcp = &plchr[(int)plane.pln_type];
215 emp_insque(&irv->queue, list);
220 msl_intercept(coord x, coord y, natid bombown, int hardtarget,
221 int sublaunch, int wantflags, int nowantflags)
223 register struct plnstr *pp;
224 register struct plchrstr *pcp;
226 struct emp_qelem *irvlist;
227 struct emp_qelem foo;
228 struct emp_qelem *intlist;
229 struct emp_qelem intfoo;
230 struct emp_qelem *qp;
231 struct emp_qelem *next;
238 s_char *who = sublaunch ? (s_char *)"" : cname(bombown);
240 getsect(x, y, §);
241 if (wantflags == P_O && !nowantflags) {
242 att_name = "satellite";
243 def_name = "a-sat missile";
244 news_item = N_SAT_KILL;
246 mpr(sect.sct_own, "%s has positioned a satellite over %s\n",
247 sublaunch ? (s_char *)"someone" : cname(bombown), xyas(x,
252 } else if (wantflags == P_N && nowantflags == P_O) {
253 att_name = "warhead";
255 news_item = sublaunch ? N_NUKE_SSTOP : N_NUKE_STOP;
257 att_name = "elephant";
258 def_name = "tomato"; /* heh -KHS */
259 news_item = N_NUKE_STOP;
263 /* get all hostile abms in range */
264 msl_sel(irvlist, x, y, bombown, wantflags, nowantflags, 0);
266 emp_initque(intlist);
267 /* First choose interceptors belonging to the target sector */
268 /* only allow two defense missiles per missile attack */
269 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
271 ip = (struct plist *)qp;
273 if (pp->pln_own != sect.sct_own)
276 if (mission_pln_equip(ip, 0, 0, 'i') < 0) {
281 /* got one interceptor, delete from irv_list and
285 emp_insque(qp, intlist);
286 putplane(pp->pln_uid, pp);
289 /* only allow two defense missiles per missile attack */
290 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
292 ip = (struct plist *)qp;
295 if (mission_pln_equip(ip, 0, 0, 'i') < 0) {
300 /* got one interceptor, delete from irv_list and
304 emp_insque(qp, intlist);
305 putplane(pp->pln_uid, pp);
308 /* Now, clean out the queue */
309 while (!QEMPTY(irvlist)) {
310 qp = irvlist->q_forw;
315 if (sect.sct_own != 0)
316 mpr(sect.sct_own, "No %ss launched to intercept.\n", def_name);
320 /* attempt to destroy incoming missile */
322 while (!QEMPTY(intlist)) {
323 qp = intlist->q_forw;
324 ip = (struct plist *)qp;
328 mpr(bombown, "%s %s launched in defense!\n",
329 cname(pp->pln_own), def_name);
330 if (sect.sct_own == pp->pln_own) {
331 mpr(sect.sct_own, "%s launched to intercept %s %s!\n",
332 def_name, who, att_name);
336 "%s launched an %s to intercept the %s %s!\n",
337 cname(pp->pln_own), def_name, who, att_name);
339 "%s launched to intercept %s %s arcing towards %s territory!\n",
340 def_name, who, att_name, cname(sect.sct_own));
344 msl_hit(pp, hardtarget, EF_PLANE, news_item, news_item,
345 att_name, x, y, bombown)) {
346 mpr(bombown, "%s destroyed by %s %s!\n", att_name,
347 cname(pp->pln_own), def_name);
349 mpr(sect.sct_own, "%s %s intercepted!\n", who, att_name);
350 if (sect.sct_own != pp->pln_own)
351 mpr(pp->pln_own, "%s %s intercepted!\n", who, att_name);
354 /* zap the missile */
355 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
357 putplane(pp->pln_uid, pp);
363 /* Clean out what is left in the list */
364 while (!QEMPTY(intlist)) {
365 qp = intlist->q_forw;
372 mpr(bombown, "%s made it through %s defenses!\n", att_name,
375 mpr(sect.sct_own, "%s made it through %s defenses!\n",
381 /* Keep launching missiles on list until mindam damage has been done */
383 msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget,
384 int type, int mindam, s_char *whatp, int victim,
387 struct emp_qelem *qp;
388 struct emp_qelem *next;
395 if (type == EF_SHIP) {
396 news_item = N_SHP_MISS;
397 snews_item = N_SHP_SMISS;
398 } else if (type == EF_LAND) {
399 news_item = N_LND_MISS;
400 snews_item = N_LND_SMISS;
402 news_item = N_SCT_MISS;
403 snews_item = N_SCT_SMISS;
406 for (qp = list->q_back; qp != list && dam < mindam && !nukedam;
409 plp = (struct plist *)qp;
411 if (mission_pln_equip(plp, 0, 0, 'p') >= 0) {
412 if (msl_hit(&plp->plane,
413 hardtarget, type, news_item, snews_item,
414 whatp, x, y, victim)) {
415 newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1);
417 if (mission == MI_INTERDICT && type == EF_SECTOR)
422 /* Missiles that miss have to hit somewhere! */
423 newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0);
424 collateral_damage(x, y, newdam, 0);
426 makelost(EF_PLANE, plp->plane.pln_own, plp->plane.pln_uid,
427 plp->plane.pln_x, plp->plane.pln_y);
428 plp->plane.pln_own = 0;
429 putplane(plp->plane.pln_uid, &plp->plane);