2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2009, 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 files README, COPYING and CREDITS in the root of the source
23 * tree for related information and legal notices. It is expected
24 * that future 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
50 #include "prototypes.h"
57 msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
58 int snews_item, char *what, coord x, coord y, int victim)
64 struct plchrstr *pcp = plchr + pp->pln_type;
69 mpr(pp->pln_own, "Preparing to launch %s at %s %s %s%s\n",
73 (type == EF_SHIP || type == EF_PLANE) ? "in " : "",
74 xyas(x, y, pp->pln_own));
75 mpr(pp->pln_own, "\tLaunching from ");
76 if (pp->pln_ship >= 0) {
77 getship(pp->pln_ship, &ship);
78 mpr(pp->pln_own, "%s in ", prship(&ship));
79 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
84 mpr(pp->pln_own, "%s\n",
85 xyas(ship.shp_x, ship.shp_y, pp->pln_own));
87 if (pp->pln_harden > 0) {
88 mpr(pp->pln_own, "missile silo at ");
91 from = "on launch pad";
92 mpr(pp->pln_own, "%s\n", xyas(pp->pln_x, pp->pln_y, pp->pln_own));
95 if (chance((0.05 + (100 - pp->pln_effic) / 100.0)
96 * (1 - techfact(pp->pln_tech, 1.0)))) {
97 mpr(pp->pln_own, "KABOOOOM! Missile explodes %s!\n", from);
99 dam = pln_damage(pp, 'p', 1) / 2;
100 if (pp->pln_ship >= 0) {
101 shipdamage(&ship, dam);
102 putship(ship.shp_uid, &ship);
104 pr("Explosion damages %s %d%%",
105 xyas(pp->pln_x, pp->pln_y, pp->pln_own), dam);
106 getsect(pp->pln_x, pp->pln_y, §);
107 sectdamage(§, dam);
114 CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED);
115 pp->pln_flags |= PLN_LAUNCHED;
116 putplane(pp->pln_uid, pp);
117 mpr(pp->pln_own, "\tSHWOOOOOSH! Missile launched!\n");
119 if (pcp->pl_flags & P_T)
120 mpr(victim, "Incoming %s missile sighted at %s...\n",
121 sublaunch ? "sub-launched" : cname(pp->pln_own),
124 if ((pcp->pl_flags & P_T && !(pcp->pl_flags & P_MAR))) {
125 if (msl_abm_intercept(pp, x, y, sublaunch))
128 if (pcp->pl_flags & P_MAR) {
129 if (shp_missile_defense(x, y, pp->pln_own, pln_def(pp))) {
134 if (nuk_on_plane(pp) >= 0) {
135 mpr(pp->pln_own, "\tArming nuclear warheads...\n");
138 hitchance = pln_hitchance(pp, hardtarget, type);
139 hit = (roll(100) <= hitchance);
140 mpr(pp->pln_own, "\t%d%% hitchance...%s\n", hitchance,
141 hit ? "HIT!" : "miss");
144 if (pcp->pl_flags & P_T)
145 mpr(victim, "...Incoming %s missile %s\n",
146 sublaunch ? "" : cname(pp->pln_own),
147 hit ? "HIT!\n" : "missed\n");
148 if (hit && news_item) {
150 nreport(victim, snews_item, 0, 1);
152 nreport(pp->pln_own, news_item, victim, 1);
158 msl_sel(struct emp_qelem *list, coord x, coord y, natid victim,
159 int wantflags, int nowantflags, int mission)
161 struct plchrstr *pcp;
167 snxtitem_all(&ni, EF_PLANE);
168 while (nxtitem(&ni, &plane)) {
172 pcp = &plchr[(int)plane.pln_type];
173 if (!(pcp->pl_flags & P_M))
175 if (wantflags && (pcp->pl_flags & wantflags) != wantflags)
177 if (nowantflags && pcp->pl_flags & nowantflags)
179 if (mission && plane.pln_mission != mission)
182 plane.pln_radius < mapdist(x, y, plane.pln_opx, plane.pln_opy))
184 if (getrel(getnatp(plane.pln_own), victim) >= NEUTRAL)
186 /* missiles go one way, so we can use all the range */
187 if (plane.pln_range < mapdist(x, y, plane.pln_x, plane.pln_y))
189 if (plane.pln_mobil <= 0)
191 if (plane.pln_effic < 100)
193 if (!pln_airbase_ok(&plane, 1, 0))
195 /* got a valid interceptor */
196 irv = malloc(sizeof(*irv));
198 irv->pcp = &plchr[(int)plane.pln_type];
200 emp_insque(&irv->queue, list);
205 msl_intercept(struct plnstr *msl, struct sctstr *sp, int sublaunch,
206 struct emp_qelem *irvlist, char *att_name, char *def_name,
210 struct plchrstr *pcp;
211 struct emp_qelem *intlist;
212 struct emp_qelem intfoo;
213 struct emp_qelem *qp;
214 struct emp_qelem *next;
218 char *who = sublaunch ? "" : cname(msl->pln_own);
221 emp_initque(intlist);
222 /* First choose interceptors belonging to the target sector */
223 /* only allow two defense missiles per missile attack */
224 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
226 ip = (struct plist *)qp;
228 if (pp->pln_own != sp->sct_own)
231 if (mission_pln_equip(ip, NULL, 'i') < 0) {
236 /* got one interceptor, delete from irv_list and
240 emp_insque(qp, intlist);
241 putplane(pp->pln_uid, pp);
244 /* only allow two defense missiles per missile attack */
245 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
247 ip = (struct plist *)qp;
250 if (mission_pln_equip(ip, NULL, 'i') < 0) {
255 /* got one interceptor, delete from irv_list and
259 emp_insque(qp, intlist);
260 putplane(pp->pln_uid, pp);
263 /* Now, clean out the queue */
264 while (!QEMPTY(irvlist)) {
265 qp = irvlist->q_forw;
270 mpr(sp->sct_own, "No %ss launched to intercept.\n", def_name);
274 /* attempt to destroy incoming missile */
277 while (!destroyed && !QEMPTY(intlist)) {
278 qp = intlist->q_forw;
279 ip = (struct plist *)qp;
283 mpr(msl->pln_own, "%s %s launched in defense!\n",
284 cname(pp->pln_own), def_name);
285 if (sp->sct_own == pp->pln_own) {
286 mpr(sp->sct_own, "%s launched to intercept %s %s!\n",
287 def_name, who, att_name);
290 "%s launched an %s to intercept the %s %s!\n",
291 cname(pp->pln_own), def_name, who, att_name);
293 "%s launched to intercept %s %s arcing towards %s territory!\n",
294 def_name, who, att_name, cname(sp->sct_own));
297 if (msl_hit(pp, pln_def(msl), EF_PLANE, 0, 0,
298 att_name, sp->sct_x, sp->sct_y, msl->pln_own)) {
299 mpr(msl->pln_own, "%s destroyed by %s %s!\n",
300 att_name, cname(pp->pln_own), def_name);
301 mpr(sp->sct_own, "%s %s intercepted!\n", who, att_name);
302 if (sp->sct_own != pp->pln_own)
303 mpr(pp->pln_own, "%s %s intercepted!\n", who, att_name);
305 nreport(pp->pln_own, news_item, 0, 1);
307 nreport(pp->pln_own, news_item, msl->pln_own, 1);
310 /* zap the missile */
312 putplane(pp->pln_uid, pp);
316 /* Clean out what is left in the list */
317 while (!QEMPTY(intlist)) {
318 qp = intlist->q_forw;
325 mpr(msl->pln_own, "%s made it through %s defenses!\n",
327 mpr(sp->sct_own, "%s made it through %s defenses!\n",
334 msl_abm_intercept(struct plnstr *msl, coord x, coord y, int sublaunch)
337 struct emp_qelem irvlist;
339 getsect(x, y, §);
340 msl_sel(&irvlist, x, y, msl->pln_own, P_N, P_O, 0);
341 return msl_intercept(msl, §, sublaunch,
342 &irvlist, "warhead", "abm",
343 sublaunch ? N_NUKE_SSTOP : N_NUKE_STOP);
347 msl_asat_intercept(struct plnstr *msl, coord x, coord y)
350 struct emp_qelem irvlist;
352 getsect(x, y, §);
353 mpr(sect.sct_own, "%s has positioned a satellite over %s\n",
354 cname(msl->pln_own), xyas(x, y, sect.sct_own));
355 msl_sel(&irvlist, x, y, msl->pln_own, P_O, 0, 0);
356 return msl_intercept(msl, §, 0,
357 &irvlist, "satellite", "a-sat missile",