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
52 #include "prototypes.h"
55 msl_equip(struct plnstr *pp)
59 memset(&pl, 0, sizeof(struct plist));
60 pl.pcp = plchr + pp->pln_type;
62 return mission_pln_equip(&pl, 0, 0, 'p');
66 msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
67 int snews_item, s_char *what, coord x, coord y, int victim)
73 struct plchrstr *pcp = plchr + pp->pln_type;
74 int hitchance = pln_hitchance(pp, hardtarget, type);
78 mpr(pp->pln_own, "Preparing to launch %s at %s %s %s%s\n",
82 (type == EF_SHIP || type == EF_PLANE) ? "in " : "",
83 xyas(x, y, pp->pln_own));
84 mpr(pp->pln_own, "\tLaunching from ");
85 if (pp->pln_ship >= 0) {
86 getship(pp->pln_ship, &ship);
87 mpr(pp->pln_own, "%s in ", prship(&ship));
88 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
93 mpr(pp->pln_own, "%s\n",
94 xyas(ship.shp_x, ship.shp_y, pp->pln_own));
96 if (pp->pln_harden > 0) {
97 mpr(pp->pln_own, "missile silo at ");
100 from = "on launch pad";
101 mpr(pp->pln_own, "%s\n", xyas(pp->pln_x, pp->pln_y, pp->pln_own));
104 if (chance((0.05 + (100 - pp->pln_effic) / 100.0)
105 * (1 - techfact(pp->pln_tech, 1.0)))) {
106 mpr(pp->pln_own, "KABOOOOM! Missile explodes %s!\n", from);
108 if (pp->pln_nuketype != (s_char)-1 && opt_NUKEFAILDETONATE) {
109 pp->pln_flags &= ~PLN_AIRBURST;
110 detonate(pp, pp->pln_x, pp->pln_y);
112 dam = pln_damage(pp, pp->pln_x, pp->pln_y,
113 'p', &dummyi, 1) / 2;
115 if (pp->pln_ship >= 0) {
116 shipdamage(&ship, dam);
117 putship(ship.shp_uid, &ship);
119 pr("Explosion damages %s %d%%",
120 xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam);
121 getsect(pp->pln_x, pp->pln_y, §);
122 sectdamage(§, dam, 0);
131 mpr(pp->pln_own, "\tSHWOOOOOSH! Missile launched!\n");
133 if (pp->pln_nuketype != (s_char)-1)
134 mpr(pp->pln_own, "\tArming nuclear warheads...\n");
136 if (pcp->pl_flags & P_T)
137 mpr(victim, "Incoming %s missile sighted at %s...\n",
138 sublaunch ? "sub-launched" : cname(pp->pln_own),
141 if (opt_PINPOINTMISSILE == 0 ||
142 (pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) {
143 if (msl_intercept(x, y, pp->pln_own, pcp->pl_def,
144 sublaunch, P_N, P_O)) {
148 if (pcp->pl_flags & P_MAR) {
149 if (shp_missile_defense(x, y, pp->pln_own, pcp->pl_def)) {
154 if (pp->pln_nuketype != (s_char)-1)
157 mpr(pp->pln_own, "\t%d%% hitchance...", hitchance);
158 hit = (roll(100) <= hitchance);
160 mpr(pp->pln_own, hit ? "HIT!\n" : "miss\n");
161 if (pcp->pl_flags & P_T)
162 mpr(victim, "...Incoming %s missile %s\n",
163 sublaunch ? (s_char *)"" : cname(pp->pln_own),
164 hit ? "HIT!\n" : "missed\n");
165 if (hit && news_item) {
167 nreport(victim, snews_item, 0, 1);
169 nreport(pp->pln_own, news_item, victim, 1);
175 msl_sel(struct emp_qelem *list, coord x, coord y, natid victim,
176 int wantflags, int nowantflags, int mission)
178 struct plchrstr *pcp;
184 snxtitem_all(&ni, EF_PLANE);
185 while (nxtitem(&ni, (s_char *)&plane)) {
189 pcp = &plchr[(int)plane.pln_type];
190 if (!(pcp->pl_flags & P_M))
192 if (wantflags && (pcp->pl_flags & wantflags) != wantflags)
194 if (nowantflags && pcp->pl_flags & nowantflags)
196 if (mission && plane.pln_mission != mission)
198 if (getrel(getnatp(plane.pln_own), victim) >= NEUTRAL)
200 /* missiles go one way, so we can use all the range */
201 if (plane.pln_range < mapdist(x, y, plane.pln_x, plane.pln_y))
203 if (plane.pln_mobil <= (s_char)0)
205 if (plane.pln_effic < 100)
207 /* got a valid interceptor */
208 irv = (struct plist *)malloc(sizeof(*irv));
212 irv->pcp = &plchr[(int)plane.pln_type];
214 emp_insque(&irv->queue, list);
219 msl_intercept(coord x, coord y, natid bombown, int hardtarget,
220 int sublaunch, int wantflags, int nowantflags)
223 struct plchrstr *pcp;
225 struct emp_qelem *irvlist;
226 struct emp_qelem foo;
227 struct emp_qelem *intlist;
228 struct emp_qelem intfoo;
229 struct emp_qelem *qp;
230 struct emp_qelem *next;
237 s_char *who = sublaunch ? (s_char *)"" : cname(bombown);
239 getsect(x, y, §);
240 if (wantflags == P_O && !nowantflags) {
241 att_name = "satellite";
242 def_name = "a-sat missile";
243 news_item = N_SAT_KILL;
245 mpr(sect.sct_own, "%s has positioned a satellite over %s\n",
246 sublaunch ? (s_char *)"someone" : cname(bombown), xyas(x,
251 } else if (wantflags == P_N && nowantflags == P_O) {
252 att_name = "warhead";
254 news_item = sublaunch ? N_NUKE_SSTOP : N_NUKE_STOP;
256 att_name = "elephant";
257 def_name = "tomato"; /* heh -KHS */
258 news_item = N_NUKE_STOP;
262 /* get all hostile abms in range */
263 msl_sel(irvlist, x, y, bombown, wantflags, nowantflags, 0);
265 emp_initque(intlist);
266 /* First choose interceptors belonging to the target sector */
267 /* only allow two defense missiles per missile attack */
268 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
270 ip = (struct plist *)qp;
272 if (pp->pln_own != sect.sct_own)
275 if (mission_pln_equip(ip, 0, 0, 'i') < 0) {
280 /* got one interceptor, delete from irv_list and
284 emp_insque(qp, intlist);
285 putplane(pp->pln_uid, pp);
288 /* only allow two defense missiles per missile attack */
289 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
291 ip = (struct plist *)qp;
294 if (mission_pln_equip(ip, 0, 0, 'i') < 0) {
299 /* got one interceptor, delete from irv_list and
303 emp_insque(qp, intlist);
304 putplane(pp->pln_uid, pp);
307 /* Now, clean out the queue */
308 while (!QEMPTY(irvlist)) {
309 qp = irvlist->q_forw;
314 if (sect.sct_own != 0)
315 mpr(sect.sct_own, "No %ss launched to intercept.\n", def_name);
319 /* attempt to destroy incoming missile */
321 while (!QEMPTY(intlist)) {
322 qp = intlist->q_forw;
323 ip = (struct plist *)qp;
327 mpr(bombown, "%s %s launched in defense!\n",
328 cname(pp->pln_own), def_name);
329 if (sect.sct_own == pp->pln_own) {
330 mpr(sect.sct_own, "%s launched to intercept %s %s!\n",
331 def_name, who, att_name);
335 "%s launched an %s to intercept the %s %s!\n",
336 cname(pp->pln_own), def_name, who, att_name);
338 "%s launched to intercept %s %s arcing towards %s territory!\n",
339 def_name, who, att_name, cname(sect.sct_own));
343 msl_hit(pp, hardtarget, EF_PLANE, news_item, news_item,
344 att_name, x, y, bombown)) {
345 mpr(bombown, "%s destroyed by %s %s!\n", att_name,
346 cname(pp->pln_own), def_name);
348 mpr(sect.sct_own, "%s %s intercepted!\n", who, att_name);
349 if (sect.sct_own != pp->pln_own)
350 mpr(pp->pln_own, "%s %s intercepted!\n", who, att_name);
353 /* zap the missile */
354 makelost(EF_PLANE, pp->pln_own, pp->pln_uid, pp->pln_x, pp->pln_y);
356 putplane(pp->pln_uid, pp);
362 /* Clean out what is left in the list */
363 while (!QEMPTY(intlist)) {
364 qp = intlist->q_forw;
371 mpr(bombown, "%s made it through %s defenses!\n", att_name,
374 mpr(sect.sct_own, "%s made it through %s defenses!\n",
380 /* Keep launching missiles on list until mindam damage has been done */
382 msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget,
383 int type, int mindam, s_char *whatp, int victim,
386 struct emp_qelem *qp;
387 struct emp_qelem *next;
394 if (type == EF_SHIP) {
395 news_item = N_SHP_MISS;
396 snews_item = N_SHP_SMISS;
397 } else if (type == EF_LAND) {
398 news_item = N_LND_MISS;
399 snews_item = N_LND_SMISS;
401 news_item = N_SCT_MISS;
402 snews_item = N_SCT_SMISS;
405 for (qp = list->q_back; qp != list && dam < mindam && !nukedam;
408 plp = (struct plist *)qp;
410 if (mission_pln_equip(plp, 0, 0, 'p') >= 0) {
411 if (msl_hit(&plp->plane,
412 hardtarget, type, news_item, snews_item,
413 whatp, x, y, victim)) {
414 newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 1);
416 if (mission == MI_INTERDICT && type == EF_SECTOR)
421 /* Missiles that miss have to hit somewhere! */
422 newdam = pln_damage(&plp->plane, x, y, 'p', &nukedam, 0);
423 collateral_damage(x, y, newdam, 0);
425 makelost(EF_PLANE, plp->plane.pln_own, plp->plane.pln_uid,
426 plp->plane.pln_x, plp->plane.pln_y);
427 plp->plane.pln_own = 0;
428 putplane(plp->plane.pln_uid, &plp->plane);