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 * detonate.c: Detonate a nuclear device in a sector.
30 * Known contributors to this file:
31 * Steve McClure, 1998-2000
47 #include "prototypes.h"
52 static void kaboom(int x, int y, int rad, natid cn);
55 detonate(struct nukstr *np, coord x, coord y, int airburst)
57 int nuketype = np->nuk_type;
58 natid bombown = np->nuk_own;
78 issea = sect.sct_type == SCT_WATER;
79 ncp = &nchr[nuketype];
80 kaboom(x, y, ncp->n_blast, bombown);
85 putnuke(np->nuk_uid, np);
87 snxtsct_dist(&ns, x, y, rad);
88 while (nxtsct(&ns, §)) {
89 /* Nukes falling on water affect only 1 sector */
90 if ((sect.sct_x != x) && issea)
92 if ((sect.sct_y != y) && issea)
96 if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
98 if (type == SCT_SANCT) {
99 mpr(bombown, "bounced off %s\n", xyas(ns.x, ns.y, bombown));
100 mpr(own, "%s nuclear device bounced off %s\n",
101 cname(bombown), xyas(ns.x, ns.y, bombown));
102 nreport(bombown, N_NUKE, own, 1);
106 fallout = sect.sct_fallout;
107 sect_damage(§, damage);
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";
131 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
134 (void)putsect(§);
135 if (type != SCT_WATER)
136 nreport(bombown, N_NUKE, own, 1);
137 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
138 if (own != bombown && own != 0) {
139 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
140 mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
144 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
145 while (nxtitem(&ni, &plane)) {
146 /* Nukes falling on water affect only 1 sector */
147 if ((plane.pln_x != x) && issea)
149 if ((plane.pln_y != y) && issea)
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 /* Nukes falling on water affect only 1 sector */
197 if ((land.lnd_x != x) && issea)
199 if ((land.lnd_y != y) && issea)
201 if ((own = land.lnd_own) == 0)
203 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
206 if (land.lnd_ship >= 0) {
207 /* Are we on a sub? */
208 getship(land.lnd_ship, &ship);
210 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
213 /* Should we damage this sub? */
214 getsect(ship.shp_x, ship.shp_y, §1);
216 if (sect1.sct_type == SCT_BSPAN ||
217 sect1.sct_type == SCT_BTOWER ||
218 sect1.sct_type == SCT_WATER) {
219 /* Ok, we're not in a harbor or trapped
220 inland. Now, did we get pasted
222 if (ship.shp_x != x || ship.shp_y != y) {
223 /* Nope, so don't mess with it */
229 land_damage(&land, damage);
230 if (own == bombown) {
231 mpr(bombown, "%s at %s reports %d%% damage\n",
232 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
234 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
235 cname(bombown), damage,
236 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
238 putland(land.lnd_uid, &land);
241 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
242 while (nxtitem(&ni, &ship)) {
243 /* Nukes falling on water affect only 1 sector */
244 if ((ship.shp_x != x) && issea)
246 if ((ship.shp_y != y) && issea)
248 if ((own = ship.shp_own) == 0)
250 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
252 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
255 /* Should we damage this sub? */
256 getsect(ship.shp_x, ship.shp_y, §1);
258 if (sect1.sct_type == SCT_BSPAN ||
259 sect1.sct_type == SCT_BTOWER ||
260 sect1.sct_type == SCT_WATER) {
261 /* Ok, we're not in a harbor or trapped
262 inland. Now, did we get pasted
264 if (ship.shp_x != x || ship.shp_y != y) {
265 /* Nope, so don't mess with it */
270 ship_damage(&ship, damage);
271 if (own == bombown) {
272 mpr(bombown, "%s at %s reports %d%% damage\n",
273 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
275 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
276 cname(bombown), damage, prship(&ship),
277 xyas(ship.shp_x, ship.shp_y, own));
279 putship(ship.shp_uid, &ship);
282 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
283 while (nxtitem(&ni, &nuke)) {
284 /* Nukes falling on water affect only 1 sector */
285 if ((nuke.nuk_x != x) && issea)
287 if ((nuke.nuk_y != y) && issea)
289 if ((own = nuke.nuk_own) == 0)
291 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
293 if (roll(100) >= damage)
296 if (own == bombown) {
297 mpr(bombown, "%s at %s destroyed\n",
298 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
300 mpr(own, "%s at %s destroyed\n",
301 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
303 putnuke(ni.cur, &nuke);
306 return nukedamage(ncp, 0, airburst);
314 kaboom(int x, int y, int rad, natid cn)
316 mpr(cn, "\n\nK A B O O ");
319 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));