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);
57 detonate(struct nukstr *np, coord x, coord y, int airburst)
59 int nuketype = np->nuk_type;
78 pr("Releasing RV's for %s detonation...\n",
79 airburst ? "airburst" : "groundburst");
82 ncp = &nchr[nuketype];
83 kaboom(x, y, ncp->n_blast);
87 if (sect.sct_type == SCT_WATER)
88 rad = 0; /* Nukes falling on water affect only 1 sector */
90 putnuke(np->nuk_uid, np);
92 snxtsct_dist(&ns, x, y, rad);
93 while (nxtsct(&ns, §)) {
96 if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
98 if (type == SCT_SANCT) {
99 pr("bounced off %s\n", xyas(ns.x, ns.y, player->cnum));
100 mpr(own, "%s nuclear device bounced off %s\n",
101 cname(player->cnum), xyas(ns.x, ns.y, own));
102 nreport(player->cnum, N_NUKE, own, 1);
105 sect_damage(§, damage);
107 fallout = sect.sct_fallout;
108 if (ncp->n_flags & N_NEUT)
109 fallout += damage * 30;
111 fallout += damage * 3;
112 sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
117 if (type == SCT_WATER || type == SCT_BSPAN ||
118 type == SCT_BTOWER) {
119 bp = "left nothing but water in %s\n";
120 if (type != SCT_WATER) {
121 sect.sct_newtype = SCT_WATER;
122 sect.sct_type = SCT_WATER;
125 sect.sct_newtype = SCT_WASTE;
126 sect.sct_type = SCT_WASTE;
127 bp = "turned %s into a radioactive wasteland\n";
129 changed |= map_set(player->cnum, sect.sct_x, sect.sct_y,
130 dchr[sect.sct_type].d_mnem, 0);
132 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
135 (void)putsect(§);
136 if (type != SCT_WATER)
137 nreport(player->cnum, N_NUKE, own, 1);
138 pr(bp, xyas(ns.x, ns.y, player->cnum));
139 if (own != player->cnum && own != 0) {
140 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
141 mpr(own, "%s nuclear device %s", cname(player->cnum), buf2);
146 writebmap(player->cnum);
148 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
149 while (nxtitem(&ni, &plane)) {
150 if ((own = plane.pln_own) == 0)
152 if (plane.pln_flags & PLN_LAUNCHED)
154 damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
157 if (plane.pln_ship >= 0) {
158 /* Are we on a sub? */
159 getship(plane.pln_ship, &ship);
161 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
164 /* Should we damage this sub? */
165 getsect(ship.shp_x, ship.shp_y, §1);
167 if (sect1.sct_type == SCT_BSPAN ||
168 sect1.sct_type == SCT_BTOWER ||
169 sect1.sct_type == SCT_WATER) {
170 /* Ok, we're not in a harbor or trapped
171 inland. Now, did we get pasted
173 if (ship.shp_x != x || ship.shp_y != y) {
174 /* Nope, so don't mess with it */
180 planedamage(&plane, damage);
181 if (own == player->cnum) {
182 pr("%s at %s reports %d%% damage\n",
184 xyas(plane.pln_x, plane.pln_y, own), damage);
186 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
187 cname(player->cnum), damage,
188 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
190 putplane(ni.cur, &plane);
193 snxtitem_dist(&ni, EF_LAND, x, y, rad);
194 while (nxtitem(&ni, &land)) {
195 if ((own = land.lnd_own) == 0)
197 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
200 if (land.lnd_ship >= 0) {
201 /* Are we on a sub? */
202 getship(land.lnd_ship, &ship);
204 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
207 /* Should we damage this sub? */
208 getsect(ship.shp_x, ship.shp_y, §1);
210 if (sect1.sct_type == SCT_BSPAN ||
211 sect1.sct_type == SCT_BTOWER ||
212 sect1.sct_type == SCT_WATER) {
213 /* Ok, we're not in a harbor or trapped
214 inland. Now, did we get pasted
216 if (ship.shp_x != x || ship.shp_y != y) {
217 /* Nope, so don't mess with it */
223 land_damage(&land, damage);
224 if (own == player->cnum) {
225 pr("%s at %s reports %d%% damage\n",
226 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
228 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
229 cname(player->cnum), damage,
230 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
232 putland(land.lnd_uid, &land);
235 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
236 while (nxtitem(&ni, &ship)) {
237 if ((own = ship.shp_own) == 0)
239 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
241 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
244 /* Should we damage this sub? */
245 getsect(ship.shp_x, ship.shp_y, §1);
247 if (sect1.sct_type == SCT_BSPAN ||
248 sect1.sct_type == SCT_BTOWER ||
249 sect1.sct_type == SCT_WATER) {
250 /* Ok, we're not in a harbor or trapped
251 inland. Now, did we get pasted
253 if (ship.shp_x != x || ship.shp_y != y) {
254 /* Nope, so don't mess with it */
259 ship_damage(&ship, damage);
260 if (own == player->cnum) {
261 pr("%s at %s reports %d%% damage\n",
262 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
264 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
265 cname(player->cnum), damage, prship(&ship),
266 xyas(ship.shp_x, ship.shp_y, own));
268 putship(ship.shp_uid, &ship);
271 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
272 while (nxtitem(&ni, &nuke)) {
273 if ((own = nuke.nuk_own) == 0)
275 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
277 if (roll(100) >= damage)
280 if (own == player->cnum) {
281 pr("%s at %s destroyed\n",
282 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
284 mpr(own, "%s at %s destroyed\n",
285 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
287 putnuke(ni.cur, &nuke);
290 return nukedamage(ncp, 0, airburst);
298 kaboom(int x, int y, int rad)
300 pr("\n\nK A B O O ");
303 pr("M ! in %s\n\n", xyas(x, y, player->cnum));