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;
77 mpr(bombown, "Releasing RV's for %s detonation...\n",
78 airburst ? "airburst" : "groundburst");
81 issea = sect.sct_type == SCT_WATER;
82 ncp = &nchr[nuketype];
83 kaboom(x, y, ncp->n_blast, bombown);
88 putnuke(np->nuk_uid, np);
90 snxtsct_dist(&ns, x, y, rad);
91 while (nxtsct(&ns, §)) {
92 /* Nukes falling on water affect only 1 sector */
93 if ((sect.sct_x != x) && issea)
95 if ((sect.sct_y != y) && issea)
99 if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
101 if (type == SCT_SANCT) {
102 mpr(bombown, "bounced off %s\n", xyas(ns.x, ns.y, bombown));
103 mpr(own, "%s nuclear device bounced off %s\n",
104 cname(bombown), xyas(ns.x, ns.y, bombown));
105 nreport(bombown, N_NUKE, own, 1);
108 sect_damage(§, damage);
110 fallout = sect.sct_fallout;
111 if (ncp->n_flags & N_NEUT)
112 fallout += damage * 30;
114 fallout += damage * 3;
115 sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
120 if (type == SCT_WATER || type == SCT_BSPAN ||
121 type == SCT_BTOWER) {
122 bp = "left nothing but water in %s\n";
123 if (type != SCT_WATER) {
124 sect.sct_newtype = SCT_WATER;
125 sect.sct_type = SCT_WATER;
128 sect.sct_newtype = SCT_WASTE;
129 sect.sct_type = SCT_WASTE;
130 bp = "turned %s into a radioactive wasteland\n";
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);
146 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
147 while (nxtitem(&ni, &plane)) {
148 /* Nukes falling on water affect only 1 sector */
149 if ((plane.pln_x != x) && issea)
151 if ((plane.pln_y != y) && issea)
153 if ((own = plane.pln_own) == 0)
155 if (plane.pln_flags & PLN_LAUNCHED)
157 damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
160 if (plane.pln_ship >= 0) {
161 /* Are we on a sub? */
162 getship(plane.pln_ship, &ship);
164 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
167 /* Should we damage this sub? */
168 getsect(ship.shp_x, ship.shp_y, §1);
170 if (sect1.sct_type == SCT_BSPAN ||
171 sect1.sct_type == SCT_BTOWER ||
172 sect1.sct_type == SCT_WATER) {
173 /* Ok, we're not in a harbor or trapped
174 inland. Now, did we get pasted
176 if (ship.shp_x != x || ship.shp_y != y) {
177 /* Nope, so don't mess with it */
183 planedamage(&plane, damage);
184 if (own == bombown) {
185 mpr(bombown, "%s at %s reports %d%% damage\n",
187 xyas(plane.pln_x, plane.pln_y, own), damage);
189 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
190 cname(bombown), damage,
191 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
193 putplane(ni.cur, &plane);
196 snxtitem_dist(&ni, EF_LAND, x, y, rad);
197 while (nxtitem(&ni, &land)) {
198 /* Nukes falling on water affect only 1 sector */
199 if ((land.lnd_x != x) && issea)
201 if ((land.lnd_y != y) && issea)
203 if ((own = land.lnd_own) == 0)
205 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
208 if (land.lnd_ship >= 0) {
209 /* Are we on a sub? */
210 getship(land.lnd_ship, &ship);
212 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
215 /* Should we damage this sub? */
216 getsect(ship.shp_x, ship.shp_y, §1);
218 if (sect1.sct_type == SCT_BSPAN ||
219 sect1.sct_type == SCT_BTOWER ||
220 sect1.sct_type == SCT_WATER) {
221 /* Ok, we're not in a harbor or trapped
222 inland. Now, did we get pasted
224 if (ship.shp_x != x || ship.shp_y != y) {
225 /* Nope, so don't mess with it */
231 land_damage(&land, damage);
232 if (own == bombown) {
233 mpr(bombown, "%s at %s reports %d%% damage\n",
234 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
236 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
237 cname(bombown), damage,
238 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
240 putland(land.lnd_uid, &land);
243 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
244 while (nxtitem(&ni, &ship)) {
245 /* Nukes falling on water affect only 1 sector */
246 if ((ship.shp_x != x) && issea)
248 if ((ship.shp_y != y) && issea)
250 if ((own = ship.shp_own) == 0)
252 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
254 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
257 /* Should we damage this sub? */
258 getsect(ship.shp_x, ship.shp_y, §1);
260 if (sect1.sct_type == SCT_BSPAN ||
261 sect1.sct_type == SCT_BTOWER ||
262 sect1.sct_type == SCT_WATER) {
263 /* Ok, we're not in a harbor or trapped
264 inland. Now, did we get pasted
266 if (ship.shp_x != x || ship.shp_y != y) {
267 /* Nope, so don't mess with it */
272 ship_damage(&ship, damage);
273 if (own == bombown) {
274 mpr(bombown, "%s at %s reports %d%% damage\n",
275 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
277 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
278 cname(bombown), damage, prship(&ship),
279 xyas(ship.shp_x, ship.shp_y, own));
281 putship(ship.shp_uid, &ship);
284 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
285 while (nxtitem(&ni, &nuke)) {
286 /* Nukes falling on water affect only 1 sector */
287 if ((nuke.nuk_x != x) && issea)
289 if ((nuke.nuk_y != y) && issea)
291 if ((own = nuke.nuk_own) == 0)
293 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
295 if (roll(100) >= damage)
298 if (own == bombown) {
299 mpr(bombown, "%s at %s destroyed\n",
300 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
302 mpr(own, "%s at %s destroyed\n",
303 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
305 putnuke(ni.cur, &nuke);
308 return nukedamage(ncp, 0, airburst);
316 kaboom(int x, int y, int rad, natid cn)
318 mpr(cn, "\n\nK A B O O ");
321 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));