2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2010, 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 * detonate.c: Detonate a nuclear device in a sector.
30 * Known contributors to this file:
31 * Steve McClure, 1998-2000
32 * Markus Armbruster, 2004-2009
48 #include "prototypes.h"
53 static void kaboom(int x, int y, int rad, natid cn);
56 detonate(struct nukstr *np, coord x, coord y, int airburst)
58 int nuketype = np->nuk_type;
59 natid bombown = np->nuk_own;
77 mpr(bombown, "Releasing RV's for %s detonation...\n",
78 airburst ? "airburst" : "groundburst");
81 ncp = &nchr[nuketype];
82 kaboom(x, y, ncp->n_blast, bombown);
86 if (sect.sct_type == SCT_WATER)
87 rad = 0; /* Nukes falling on water affect only 1 sector */
89 putnuke(np->nuk_uid, np);
91 snxtsct_dist(&ns, x, y, rad);
92 while (nxtsct(&ns, §)) {
95 if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
97 if (type == SCT_SANCT) {
98 mpr(bombown, "bounced off %s\n", xyas(ns.x, ns.y, bombown));
99 mpr(own, "%s nuclear device bounced off %s\n",
100 cname(bombown), xyas(ns.x, ns.y, bombown));
101 nreport(bombown, N_NUKE, own, 1);
104 sect_damage(§, damage);
106 fallout = sect.sct_fallout;
107 if (ncp->n_flags & N_NEUT)
108 fallout += damage * 30;
110 fallout += damage * 3;
111 sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
116 if (type == SCT_WATER || type == SCT_BSPAN ||
117 type == SCT_BTOWER) {
118 bp = "left nothing but water in %s\n";
119 if (type != SCT_WATER) {
120 sect.sct_newtype = SCT_WATER;
121 sect.sct_type = SCT_WATER;
124 sect.sct_newtype = SCT_WASTE;
125 sect.sct_type = SCT_WASTE;
126 bp = "turned %s into a radioactive wasteland\n";
129 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
132 (void)putsect(§);
133 if (type != SCT_WATER)
134 nreport(bombown, N_NUKE, own, 1);
135 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
136 if (own != bombown && own != 0) {
137 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
138 mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
142 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
143 while (nxtitem(&ni, &plane)) {
144 if ((own = plane.pln_own) == 0)
146 if (plane.pln_flags & PLN_LAUNCHED)
148 damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
151 if (plane.pln_ship >= 0) {
152 /* Are we on a sub? */
153 getship(plane.pln_ship, &ship);
155 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
158 /* Should we damage this sub? */
159 getsect(ship.shp_x, ship.shp_y, §1);
161 if (sect1.sct_type == SCT_BSPAN ||
162 sect1.sct_type == SCT_BTOWER ||
163 sect1.sct_type == SCT_WATER) {
164 /* Ok, we're not in a harbor or trapped
165 inland. Now, did we get pasted
167 if (ship.shp_x != x || ship.shp_y != y) {
168 /* Nope, so don't mess with it */
174 planedamage(&plane, damage);
175 if (own == bombown) {
176 mpr(bombown, "%s at %s reports %d%% damage\n",
178 xyas(plane.pln_x, plane.pln_y, own), damage);
180 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
181 cname(bombown), damage,
182 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
184 putplane(ni.cur, &plane);
187 snxtitem_dist(&ni, EF_LAND, x, y, rad);
188 while (nxtitem(&ni, &land)) {
189 if ((own = land.lnd_own) == 0)
191 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
194 if (land.lnd_ship >= 0) {
195 /* Are we on a sub? */
196 getship(land.lnd_ship, &ship);
198 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
201 /* Should we damage this sub? */
202 getsect(ship.shp_x, ship.shp_y, §1);
204 if (sect1.sct_type == SCT_BSPAN ||
205 sect1.sct_type == SCT_BTOWER ||
206 sect1.sct_type == SCT_WATER) {
207 /* Ok, we're not in a harbor or trapped
208 inland. Now, did we get pasted
210 if (ship.shp_x != x || ship.shp_y != y) {
211 /* Nope, so don't mess with it */
217 land_damage(&land, damage);
218 if (own == bombown) {
219 mpr(bombown, "%s at %s reports %d%% damage\n",
220 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
222 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
223 cname(bombown), damage,
224 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
226 putland(land.lnd_uid, &land);
229 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
230 while (nxtitem(&ni, &ship)) {
231 if ((own = ship.shp_own) == 0)
233 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
235 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
238 /* Should we damage this sub? */
239 getsect(ship.shp_x, ship.shp_y, §1);
241 if (sect1.sct_type == SCT_BSPAN ||
242 sect1.sct_type == SCT_BTOWER ||
243 sect1.sct_type == SCT_WATER) {
244 /* Ok, we're not in a harbor or trapped
245 inland. Now, did we get pasted
247 if (ship.shp_x != x || ship.shp_y != y) {
248 /* Nope, so don't mess with it */
253 ship_damage(&ship, damage);
254 if (own == bombown) {
255 mpr(bombown, "%s at %s reports %d%% damage\n",
256 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
258 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
259 cname(bombown), damage, prship(&ship),
260 xyas(ship.shp_x, ship.shp_y, own));
262 putship(ship.shp_uid, &ship);
265 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
266 while (nxtitem(&ni, &nuke)) {
267 if ((own = nuke.nuk_own) == 0)
269 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
271 if (roll(100) >= damage)
274 if (own == bombown) {
275 mpr(bombown, "%s at %s destroyed\n",
276 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
278 mpr(own, "%s at %s destroyed\n",
279 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
281 putnuke(ni.cur, &nuke);
284 return nukedamage(ncp, 0, airburst);
292 kaboom(int x, int y, int rad, natid cn)
294 mpr(cn, "\n\nK A B O O ");
297 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));