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_intercept(x, y, pp->pln_own, pcp->pl_def,
126 sublaunch, P_N, P_O)) {
130 if (pcp->pl_flags & P_MAR) {
131 if (shp_missile_defense(x, y, pp->pln_own, pcp->pl_def)) {
136 if (nuk_on_plane(pp) >= 0) {
137 mpr(pp->pln_own, "\tArming nuclear warheads...\n");
140 hitchance = pln_hitchance(pp, hardtarget, type);
141 hit = (roll(100) <= hitchance);
142 mpr(pp->pln_own, "\t%d%% hitchance...%s\n", hitchance,
143 hit ? "HIT!" : "miss");
146 if (pcp->pl_flags & P_T)
147 mpr(victim, "...Incoming %s missile %s\n",
148 sublaunch ? "" : cname(pp->pln_own),
149 hit ? "HIT!\n" : "missed\n");
150 if (hit && news_item) {
152 nreport(victim, snews_item, 0, 1);
154 nreport(pp->pln_own, news_item, victim, 1);
160 msl_sel(struct emp_qelem *list, coord x, coord y, natid victim,
161 int wantflags, int nowantflags, int mission)
163 struct plchrstr *pcp;
169 snxtitem_all(&ni, EF_PLANE);
170 while (nxtitem(&ni, &plane)) {
174 pcp = &plchr[(int)plane.pln_type];
175 if (!(pcp->pl_flags & P_M))
177 if (wantflags && (pcp->pl_flags & wantflags) != wantflags)
179 if (nowantflags && pcp->pl_flags & nowantflags)
181 if (mission && plane.pln_mission != mission)
184 plane.pln_radius < mapdist(x, y, plane.pln_opx, plane.pln_opy))
186 if (getrel(getnatp(plane.pln_own), victim) >= NEUTRAL)
188 /* missiles go one way, so we can use all the range */
189 if (plane.pln_range < mapdist(x, y, plane.pln_x, plane.pln_y))
191 if (plane.pln_mobil <= 0)
193 if (plane.pln_effic < 100)
195 if (!pln_airbase_ok(&plane, 1, 0))
197 /* got a valid interceptor */
198 irv = malloc(sizeof(*irv));
200 irv->pcp = &plchr[(int)plane.pln_type];
202 emp_insque(&irv->queue, list);
207 msl_intercept(coord x, coord y, natid bombown, int hardtarget,
208 int sublaunch, int wantflags, int nowantflags)
211 struct plchrstr *pcp;
213 struct emp_qelem *irvlist;
214 struct emp_qelem foo;
215 struct emp_qelem *intlist;
216 struct emp_qelem intfoo;
217 struct emp_qelem *qp;
218 struct emp_qelem *next;
225 char *who = sublaunch ? "" : cname(bombown);
227 getsect(x, y, §);
228 if (wantflags == P_O && !nowantflags) {
229 att_name = "satellite";
230 def_name = "a-sat missile";
231 news_item = N_SAT_KILL;
232 CANT_HAPPEN(sublaunch);
233 mpr(sect.sct_own, "%s has positioned a satellite over %s\n",
234 cname(bombown), xyas(x, y, sect.sct_own));
235 } else if (wantflags == P_N && nowantflags == P_O) {
236 att_name = "warhead";
238 news_item = sublaunch ? N_NUKE_SSTOP : N_NUKE_STOP;
240 att_name = "elephant";
241 def_name = "tomato"; /* heh -KHS */
242 news_item = N_NUKE_STOP;
246 /* get all hostile abms in range */
247 msl_sel(irvlist, x, y, bombown, wantflags, nowantflags, 0);
249 emp_initque(intlist);
250 /* First choose interceptors belonging to the target sector */
251 /* only allow two defense missiles per missile attack */
252 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
254 ip = (struct plist *)qp;
256 if (pp->pln_own != sect.sct_own)
259 if (mission_pln_equip(ip, NULL, 'i') < 0) {
264 /* got one interceptor, delete from irv_list and
268 emp_insque(qp, intlist);
269 putplane(pp->pln_uid, pp);
272 /* only allow two defense missiles per missile attack */
273 for (qp = irvlist->q_forw; qp != irvlist && icount < 2; qp = next) {
275 ip = (struct plist *)qp;
278 if (mission_pln_equip(ip, NULL, 'i') < 0) {
283 /* got one interceptor, delete from irv_list and
287 emp_insque(qp, intlist);
288 putplane(pp->pln_uid, pp);
291 /* Now, clean out the queue */
292 while (!QEMPTY(irvlist)) {
293 qp = irvlist->q_forw;
298 mpr(sect.sct_own, "No %ss launched to intercept.\n", def_name);
302 /* attempt to destroy incoming missile */
305 while (!destroyed && !QEMPTY(intlist)) {
306 qp = intlist->q_forw;
307 ip = (struct plist *)qp;
311 mpr(bombown, "%s %s launched in defense!\n",
312 cname(pp->pln_own), def_name);
313 if (sect.sct_own == pp->pln_own) {
314 mpr(sect.sct_own, "%s launched to intercept %s %s!\n",
315 def_name, who, att_name);
318 "%s launched an %s to intercept the %s %s!\n",
319 cname(pp->pln_own), def_name, who, att_name);
321 "%s launched to intercept %s %s arcing towards %s territory!\n",
322 def_name, who, att_name, cname(sect.sct_own));
325 if (msl_hit(pp, hardtarget, EF_PLANE, news_item, news_item,
326 att_name, x, y, bombown)) {
327 mpr(bombown, "%s destroyed by %s %s!\n",
328 att_name, cname(pp->pln_own), def_name);
329 mpr(sect.sct_own, "%s %s intercepted!\n", who, att_name);
330 if (sect.sct_own != pp->pln_own)
331 mpr(pp->pln_own, "%s %s intercepted!\n", who, att_name);
334 /* zap the missile */
336 putplane(pp->pln_uid, pp);
340 /* Clean out what is left in the list */
341 while (!QEMPTY(intlist)) {
342 qp = intlist->q_forw;
349 mpr(bombown, "%s made it through %s defenses!\n",
351 mpr(sect.sct_own, "%s made it through %s defenses!\n",