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
49 #include "prototypes.h"
54 static void kaboom(int x, int y, int rad, natid cn);
57 detonate(struct nukstr *np, coord x, coord y, int airburst)
59 int nuketype = np->nuk_type;
60 natid bombown = np->nuk_own;
79 mpr(bombown, "Releasing RV's for %s detonation...\n",
80 airburst ? "airburst" : "groundburst");
83 ncp = &nchr[nuketype];
84 kaboom(x, y, ncp->n_blast, bombown);
88 if (sect.sct_type == SCT_WATER)
89 rad = 0; /* Nukes falling on water affect only 1 sector */
91 putnuke(np->nuk_uid, np);
93 snxtsct_dist(&ns, x, y, rad);
94 while (nxtsct(&ns, §)) {
97 if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
99 if (type == SCT_SANCT) {
100 mpr(bombown, "bounced off %s\n", xyas(ns.x, ns.y, bombown));
101 mpr(own, "%s nuclear device bounced off %s\n",
102 cname(bombown), xyas(ns.x, ns.y, bombown));
103 nreport(bombown, N_NUKE, own, 1);
106 sect_damage(§, damage);
108 fallout = sect.sct_fallout;
109 if (ncp->n_flags & N_NEUT)
110 fallout += damage * 30;
112 fallout += damage * 3;
113 sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
118 if (type == SCT_WATER || type == SCT_BSPAN ||
119 type == SCT_BTOWER) {
120 bp = "left nothing but water in %s\n";
121 if (type != SCT_WATER) {
122 sect.sct_newtype = SCT_WATER;
123 sect.sct_type = SCT_WATER;
126 sect.sct_newtype = SCT_WASTE;
127 sect.sct_type = SCT_WASTE;
128 bp = "turned %s into a radioactive wasteland\n";
130 changed |= map_set(player->cnum, sect.sct_x, sect.sct_y,
131 dchr[sect.sct_type].d_mnem, 0);
133 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
136 (void)putsect(§);
137 if (type != SCT_WATER)
138 nreport(bombown, N_NUKE, own, 1);
139 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
140 if (own != bombown && own != 0) {
141 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
142 mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
147 writebmap(player->cnum);
149 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
150 while (nxtitem(&ni, &plane)) {
151 if ((own = plane.pln_own) == 0)
153 if (plane.pln_flags & PLN_LAUNCHED)
155 damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
158 if (plane.pln_ship >= 0) {
159 /* Are we on a sub? */
160 getship(plane.pln_ship, &ship);
162 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
165 /* Should we damage this sub? */
166 getsect(ship.shp_x, ship.shp_y, §1);
168 if (sect1.sct_type == SCT_BSPAN ||
169 sect1.sct_type == SCT_BTOWER ||
170 sect1.sct_type == SCT_WATER) {
171 /* Ok, we're not in a harbor or trapped
172 inland. Now, did we get pasted
174 if (ship.shp_x != x || ship.shp_y != y) {
175 /* Nope, so don't mess with it */
181 planedamage(&plane, damage);
182 if (own == bombown) {
183 mpr(bombown, "%s at %s reports %d%% damage\n",
185 xyas(plane.pln_x, plane.pln_y, own), damage);
187 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
188 cname(bombown), damage,
189 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
191 putplane(ni.cur, &plane);
194 snxtitem_dist(&ni, EF_LAND, x, y, rad);
195 while (nxtitem(&ni, &land)) {
196 if ((own = land.lnd_own) == 0)
198 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
201 if (land.lnd_ship >= 0) {
202 /* Are we on a sub? */
203 getship(land.lnd_ship, &ship);
205 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
208 /* Should we damage this sub? */
209 getsect(ship.shp_x, ship.shp_y, §1);
211 if (sect1.sct_type == SCT_BSPAN ||
212 sect1.sct_type == SCT_BTOWER ||
213 sect1.sct_type == SCT_WATER) {
214 /* Ok, we're not in a harbor or trapped
215 inland. Now, did we get pasted
217 if (ship.shp_x != x || ship.shp_y != y) {
218 /* Nope, so don't mess with it */
224 land_damage(&land, damage);
225 if (own == bombown) {
226 mpr(bombown, "%s at %s reports %d%% damage\n",
227 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
229 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
230 cname(bombown), damage,
231 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
233 putland(land.lnd_uid, &land);
236 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
237 while (nxtitem(&ni, &ship)) {
238 if ((own = ship.shp_own) == 0)
240 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
242 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
245 /* Should we damage this sub? */
246 getsect(ship.shp_x, ship.shp_y, §1);
248 if (sect1.sct_type == SCT_BSPAN ||
249 sect1.sct_type == SCT_BTOWER ||
250 sect1.sct_type == SCT_WATER) {
251 /* Ok, we're not in a harbor or trapped
252 inland. Now, did we get pasted
254 if (ship.shp_x != x || ship.shp_y != y) {
255 /* Nope, so don't mess with it */
260 ship_damage(&ship, damage);
261 if (own == bombown) {
262 mpr(bombown, "%s at %s reports %d%% damage\n",
263 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
265 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
266 cname(bombown), damage, prship(&ship),
267 xyas(ship.shp_x, ship.shp_y, own));
269 putship(ship.shp_uid, &ship);
272 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
273 while (nxtitem(&ni, &nuke)) {
274 if ((own = nuke.nuk_own) == 0)
276 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
278 if (roll(100) >= damage)
281 if (own == bombown) {
282 mpr(bombown, "%s at %s destroyed\n",
283 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
285 mpr(own, "%s at %s destroyed\n",
286 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
288 putnuke(ni.cur, &nuke);
291 return nukedamage(ncp, 0, airburst);
299 kaboom(int x, int y, int rad, natid cn)
301 mpr(cn, "\n\nK A B O O ");
304 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));