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);
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";
130 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
133 (void)putsect(§);
134 if (type != SCT_WATER)
135 nreport(bombown, N_NUKE, own, 1);
136 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
137 if (own != bombown && own != 0) {
138 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
139 mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
143 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
144 while (nxtitem(&ni, &plane)) {
145 /* Nukes falling on water affect only 1 sector */
146 if ((plane.pln_x != x) && issea)
148 if ((plane.pln_y != y) && issea)
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 == bombown) {
182 mpr(bombown, "%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(bombown), 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 /* Nukes falling on water affect only 1 sector */
196 if ((land.lnd_x != x) && issea)
198 if ((land.lnd_y != y) && issea)
200 if ((own = land.lnd_own) == 0)
202 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
205 if (land.lnd_ship >= 0) {
206 /* Are we on a sub? */
207 getship(land.lnd_ship, &ship);
209 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
212 /* Should we damage this sub? */
213 getsect(ship.shp_x, ship.shp_y, §1);
215 if (sect1.sct_type == SCT_BSPAN ||
216 sect1.sct_type == SCT_BTOWER ||
217 sect1.sct_type == SCT_WATER) {
218 /* Ok, we're not in a harbor or trapped
219 inland. Now, did we get pasted
221 if (ship.shp_x != x || ship.shp_y != y) {
222 /* Nope, so don't mess with it */
228 land_damage(&land, damage);
229 if (own == bombown) {
230 mpr(bombown, "%s at %s reports %d%% damage\n",
231 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
233 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
234 cname(bombown), damage,
235 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
237 putland(land.lnd_uid, &land);
240 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
241 while (nxtitem(&ni, &ship)) {
242 /* Nukes falling on water affect only 1 sector */
243 if ((ship.shp_x != x) && issea)
245 if ((ship.shp_y != y) && issea)
247 if ((own = ship.shp_own) == 0)
249 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
251 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
254 /* Should we damage this sub? */
255 getsect(ship.shp_x, ship.shp_y, §1);
257 if (sect1.sct_type == SCT_BSPAN ||
258 sect1.sct_type == SCT_BTOWER ||
259 sect1.sct_type == SCT_WATER) {
260 /* Ok, we're not in a harbor or trapped
261 inland. Now, did we get pasted
263 if (ship.shp_x != x || ship.shp_y != y) {
264 /* Nope, so don't mess with it */
269 ship_damage(&ship, damage);
270 if (own == bombown) {
271 mpr(bombown, "%s at %s reports %d%% damage\n",
272 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
274 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
275 cname(bombown), damage, prship(&ship),
276 xyas(ship.shp_x, ship.shp_y, own));
278 putship(ship.shp_uid, &ship);
281 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
282 while (nxtitem(&ni, &nuke)) {
283 /* Nukes falling on water affect only 1 sector */
284 if ((nuke.nuk_x != x) && issea)
286 if ((nuke.nuk_y != y) && issea)
288 if ((own = nuke.nuk_own) == 0)
290 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
292 if (roll(100) >= damage)
295 if (own == bombown) {
296 mpr(bombown, "%s at %s destroyed\n",
297 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
299 mpr(own, "%s at %s destroyed\n",
300 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
302 putnuke(ni.cur, &nuke);
305 return nukedamage(ncp, 0, airburst);
313 kaboom(int x, int y, int rad, natid cn)
315 mpr(cn, "\n\nK A B O O ");
318 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));