2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2008, 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;
79 issea = sect.sct_type == SCT_WATER;
80 ncp = &nchr[nuketype];
81 kaboom(x, y, ncp->n_blast, bombown);
86 putnuke(np->nuk_uid, np);
88 snxtsct_dist(&ns, x, y, rad);
89 while (nxtsct(&ns, §)) {
90 /* Nukes falling on water affect only 1 sector */
91 if ((sect.sct_x != x) && issea)
93 if ((sect.sct_y != y) && issea)
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));
102 mpr(own, "%s nuclear device bounced off %s\n",
103 cname(bombown), xyas(ns.x, ns.y, bombown));
104 nreport(bombown, N_NUKE, own, 1);
108 fallout = sect.sct_fallout;
109 sect_damage(§, damage, 0);
110 if (sect.sct_x == x && sect.sct_y == y)
113 if (ncp->n_flags & N_NEUT)
114 fallout += damage * 30;
116 fallout += damage * 3;
117 sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
120 makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
123 if (type == SCT_WATER || type == SCT_BSPAN ||
124 type == SCT_BTOWER) {
125 bp = "left nothing but water in %s\n";
126 if (type != SCT_WATER) {
127 sect.sct_newtype = SCT_WATER;
128 sect.sct_type = SCT_WATER;
131 sect.sct_newtype = SCT_WASTE;
132 sect.sct_type = SCT_WASTE;
133 bp = "turned %s into a radioactive wasteland\n";
136 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
139 if ((type == SCT_CAPIT || type == SCT_MOUNT) && damage >= 100)
140 caploss(§, own, "\n%s lost its capital!\n\n");
141 (void)putsect(§);
142 if (type != SCT_WATER)
143 nreport(bombown, N_NUKE, own, 1);
144 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
145 if (own != bombown && own != 0) {
146 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
147 mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
151 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
152 while (nxtitem(&ni, &plane)) {
153 /* Nukes falling on water affect only 1 sector */
154 if ((plane.pln_x != x) && issea)
156 if ((plane.pln_y != y) && issea)
158 if ((own = plane.pln_own) == 0)
160 if ((plane.pln_flags & PLN_LAUNCHED) && (airburst != 2))
162 damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
165 if (plane.pln_ship >= 0) {
166 /* Are we on a sub? */
167 getship(plane.pln_ship, &ship);
169 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
172 /* Should we damage this sub? */
173 getsect(ship.shp_x, ship.shp_y, §1);
175 if (sect1.sct_type == SCT_BSPAN ||
176 sect1.sct_type == SCT_BTOWER ||
177 sect1.sct_type == SCT_WATER) {
178 /* Ok, we're not in a harbor or trapped
179 inland. Now, did we get pasted
181 if (ship.shp_x != x || ship.shp_y != y) {
182 /* Nope, so don't mess with it */
188 planedamage(&plane, damage);
189 if (own == bombown) {
190 mpr(bombown, "%s at %s reports %d%% damage\n",
192 xyas(plane.pln_x, plane.pln_y, own), damage);
195 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
196 cname(bombown), damage,
197 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
199 putplane(ni.cur, &plane);
202 snxtitem_dist(&ni, EF_LAND, x, y, rad);
203 while (nxtitem(&ni, &land)) {
204 /* Nukes falling on water affect only 1 sector */
205 if ((land.lnd_x != x) && issea)
207 if ((land.lnd_y != y) && issea)
209 if ((own = land.lnd_own) == 0)
211 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
214 if (land.lnd_ship >= 0) {
215 /* Are we on a sub? */
216 getship(land.lnd_ship, &ship);
218 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
221 /* Should we damage this sub? */
222 getsect(ship.shp_x, ship.shp_y, §1);
224 if (sect1.sct_type == SCT_BSPAN ||
225 sect1.sct_type == SCT_BTOWER ||
226 sect1.sct_type == SCT_WATER) {
227 /* Ok, we're not in a harbor or trapped
228 inland. Now, did we get pasted
230 if (ship.shp_x != x || ship.shp_y != y) {
231 /* Nope, so don't mess with it */
237 land_damage(&land, damage);
238 if (own == bombown) {
239 mpr(bombown, "%s at %s reports %d%% damage\n",
240 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
243 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
244 cname(bombown), damage,
245 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
247 putland(land.lnd_uid, &land);
250 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
251 while (nxtitem(&ni, &ship)) {
252 /* Nukes falling on water affect only 1 sector */
253 if ((ship.shp_x != x) && issea)
255 if ((ship.shp_y != y) && issea)
257 if ((own = ship.shp_own) == 0)
259 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
261 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
264 /* Should we damage this sub? */
265 getsect(ship.shp_x, ship.shp_y, §1);
267 if (sect1.sct_type == SCT_BSPAN ||
268 sect1.sct_type == SCT_BTOWER ||
269 sect1.sct_type == SCT_WATER) {
270 /* Ok, we're not in a harbor or trapped
271 inland. Now, did we get pasted
273 if (ship.shp_x != x || ship.shp_y != y) {
274 /* Nope, so don't mess with it */
279 ship_damage(&ship, damage);
280 if (own == bombown) {
281 mpr(bombown, "%s at %s reports %d%% damage\n",
282 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
285 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
286 cname(bombown), damage, prship(&ship),
287 xyas(ship.shp_x, ship.shp_y, own));
289 putship(ship.shp_uid, &ship);
292 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
293 while (nxtitem(&ni, &nuke)) {
294 /* Nukes falling on water affect only 1 sector */
295 if ((nuke.nuk_x != x) && issea)
297 if ((nuke.nuk_y != y) && issea)
299 if ((own = nuke.nuk_own) == 0)
301 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
303 if (roll(100) >= damage)
306 if (own == bombown) {
307 mpr(bombown, "%s at %s destroyed\n",
308 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
311 mpr(own, "%s at %s destroyed\n",
312 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
314 putnuke(ni.cur, &nuke);
325 kaboom(int x, int y, int rad, natid cn)
327 mpr(cn, "\n\nK A B O O ");
330 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));