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));
101 mpr(own, "%s nuclear device bounced off %s\n",
102 cname(bombown), xyas(ns.x, ns.y, bombown));
103 nreport(bombown, N_NUKE, own, 1);
107 fallout = sect.sct_fallout;
108 sect_damage(§, damage);
109 if (sect.sct_x == x && sect.sct_y == y)
112 if (ncp->n_flags & N_NEUT)
113 fallout += damage * 30;
115 fallout += damage * 3;
116 sect.sct_fallout = MIN(fallout, FALLOUT_MAX);
119 makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
122 if (type == SCT_WATER || type == SCT_BSPAN ||
123 type == SCT_BTOWER) {
124 bp = "left nothing but water in %s\n";
125 if (type != SCT_WATER) {
126 sect.sct_newtype = SCT_WATER;
127 sect.sct_type = SCT_WATER;
130 sect.sct_newtype = SCT_WASTE;
131 sect.sct_type = SCT_WASTE;
132 bp = "turned %s into a radioactive wasteland\n";
135 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
138 (void)putsect(§);
139 if (type != SCT_WATER)
140 nreport(bombown, N_NUKE, own, 1);
141 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
142 if (own != bombown && own != 0) {
143 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
144 mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
148 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
149 while (nxtitem(&ni, &plane)) {
150 /* Nukes falling on water affect only 1 sector */
151 if ((plane.pln_x != x) && issea)
153 if ((plane.pln_y != y) && issea)
155 if ((own = plane.pln_own) == 0)
157 if (plane.pln_flags & PLN_LAUNCHED)
159 damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
162 if (plane.pln_ship >= 0) {
163 /* Are we on a sub? */
164 getship(plane.pln_ship, &ship);
166 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
169 /* Should we damage this sub? */
170 getsect(ship.shp_x, ship.shp_y, §1);
172 if (sect1.sct_type == SCT_BSPAN ||
173 sect1.sct_type == SCT_BTOWER ||
174 sect1.sct_type == SCT_WATER) {
175 /* Ok, we're not in a harbor or trapped
176 inland. Now, did we get pasted
178 if (ship.shp_x != x || ship.shp_y != y) {
179 /* Nope, so don't mess with it */
185 planedamage(&plane, damage);
186 if (own == bombown) {
187 mpr(bombown, "%s at %s reports %d%% damage\n",
189 xyas(plane.pln_x, plane.pln_y, own), damage);
191 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
192 cname(bombown), damage,
193 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
195 putplane(ni.cur, &plane);
198 snxtitem_dist(&ni, EF_LAND, x, y, rad);
199 while (nxtitem(&ni, &land)) {
200 /* Nukes falling on water affect only 1 sector */
201 if ((land.lnd_x != x) && issea)
203 if ((land.lnd_y != y) && issea)
205 if ((own = land.lnd_own) == 0)
207 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
210 if (land.lnd_ship >= 0) {
211 /* Are we on a sub? */
212 getship(land.lnd_ship, &ship);
214 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
217 /* Should we damage this sub? */
218 getsect(ship.shp_x, ship.shp_y, §1);
220 if (sect1.sct_type == SCT_BSPAN ||
221 sect1.sct_type == SCT_BTOWER ||
222 sect1.sct_type == SCT_WATER) {
223 /* Ok, we're not in a harbor or trapped
224 inland. Now, did we get pasted
226 if (ship.shp_x != x || ship.shp_y != y) {
227 /* Nope, so don't mess with it */
233 land_damage(&land, damage);
234 if (own == bombown) {
235 mpr(bombown, "%s at %s reports %d%% damage\n",
236 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
238 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
239 cname(bombown), damage,
240 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
242 putland(land.lnd_uid, &land);
245 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
246 while (nxtitem(&ni, &ship)) {
247 /* Nukes falling on water affect only 1 sector */
248 if ((ship.shp_x != x) && issea)
250 if ((ship.shp_y != y) && issea)
252 if ((own = ship.shp_own) == 0)
254 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
256 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
259 /* Should we damage this sub? */
260 getsect(ship.shp_x, ship.shp_y, §1);
262 if (sect1.sct_type == SCT_BSPAN ||
263 sect1.sct_type == SCT_BTOWER ||
264 sect1.sct_type == SCT_WATER) {
265 /* Ok, we're not in a harbor or trapped
266 inland. Now, did we get pasted
268 if (ship.shp_x != x || ship.shp_y != y) {
269 /* Nope, so don't mess with it */
274 ship_damage(&ship, damage);
275 if (own == bombown) {
276 mpr(bombown, "%s at %s reports %d%% damage\n",
277 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
279 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
280 cname(bombown), damage, prship(&ship),
281 xyas(ship.shp_x, ship.shp_y, own));
283 putship(ship.shp_uid, &ship);
286 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
287 while (nxtitem(&ni, &nuke)) {
288 /* Nukes falling on water affect only 1 sector */
289 if ((nuke.nuk_x != x) && issea)
291 if ((nuke.nuk_y != y) && issea)
293 if ((own = nuke.nuk_own) == 0)
295 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
297 if (roll(100) >= damage)
300 if (own == bombown) {
301 mpr(bombown, "%s at %s destroyed\n",
302 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
304 mpr(own, "%s at %s destroyed\n",
305 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
307 putnuke(ni.cur, &nuke);
318 kaboom(int x, int y, int rad, natid cn)
320 mpr(cn, "\n\nK A B O O ");
323 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));