2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2000, 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 the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23 * related information and legal notices. It is expected that any future
24 * 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
48 #include "prototypes.h"
50 static void kaboom(int x, int y, int rad, natid cn);
53 detonate(struct plnstr *pp, int x, int y)
55 int nuketype = pp->pln_nuketype;
56 natid bombown = pp->pln_own;
57 int airburst = (pp->pln_flags & PLN_AIRBURST);
77 pp->pln_nuketype = -1;
79 if (sect.sct_type == SCT_WATER)
81 ncp = &nchr[nuketype];
82 kaboom(x, y, ncp->n_blast, bombown);
86 snxtsct_dist(&ns, x, y, rad);
87 while (nxtsct(&ns, §)) {
88 /* Nukes falling on water affect only 1 sector */
89 if ((sect.sct_x != x) && issea)
91 if ((sect.sct_y != y) && issea)
95 if ((damage = nukedamage(ncp, ns.curdist, airburst)) <= 0)
97 if (type == SCT_SANCT) {
98 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, 0);
108 if (sect.sct_x == x && sect.sct_y == y)
111 if (opt_NEUTRON && (ncp->n_flags & N_NEUT))
112 fallout += damage * 30;
114 fallout += damage * 3;
115 sect.sct_fallout = min(fallout, FALLOUT_MAX);
118 makelost(EF_SECTOR, sect.sct_own, 0, sect.sct_x, sect.sct_y);
121 if (type == SCT_WATER || type == SCT_BSPAN ||
122 type == SCT_BTOWER) {
123 bp = "left nothing but water in %s\n";
124 if (type != SCT_WATER) {
125 sect.sct_newtype = SCT_WATER;
126 sect.sct_type = SCT_WATER;
129 sect.sct_newtype = SCT_WASTE;
130 sect.sct_type = SCT_WASTE;
131 bp = "turned %s into a radioactive wasteland\n";
134 sprintf(buf, "did %d%%%% damage in %%s\n", damage);
137 if ((type == SCT_CAPIT || type == SCT_MOUNT) && damage >= 100)
138 caploss(§, own, "\n%s lost its capital!\n\n");
139 (void)putsect(§);
140 if (type != SCT_WATER)
141 nreport(bombown, N_NUKE, own, 1);
142 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
143 if (own != bombown && own != 0) {
144 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
145 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) && (airburst != 2))
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);
193 "%s nuclear device did %d%% damage to %s at %s\n",
194 cname(bombown), damage,
195 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
197 putplane(ni.cur, &plane);
199 snxtitem_dist(&ni, EF_LAND, x, y, rad);
200 while (nxtitem(&ni, &land)) {
201 /* Nukes falling on water affect only 1 sector */
202 if ((land.lnd_x != x) && issea)
204 if ((land.lnd_y != y) && issea)
206 if ((own = land.lnd_own) == 0)
208 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
211 if (land.lnd_ship >= 0) {
212 /* Are we on a sub? */
213 getship(land.lnd_ship, &ship);
215 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
218 /* Should we damage this sub? */
219 getsect(ship.shp_x, ship.shp_y, §1);
221 if (sect1.sct_type == SCT_BSPAN ||
222 sect1.sct_type == SCT_BTOWER ||
223 sect1.sct_type == SCT_WATER) {
224 /* Ok, we're not in a harbor or trapped
225 inland. Now, did we get pasted
227 if (ship.shp_x != x || ship.shp_y != y) {
228 /* Nope, so don't mess with it */
234 land_damage(&land, damage);
235 if (own == bombown) {
236 mpr(bombown, "%s at %s reports %d%% damage\n",
237 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
240 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
241 cname(bombown), damage,
242 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
244 putland(land.lnd_uid, &land);
246 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
247 while (nxtitem(&ni, &ship)) {
248 /* Nukes falling on water affect only 1 sector */
249 if ((ship.shp_x != x) && issea)
251 if ((ship.shp_y != y) && issea)
253 if ((own = ship.shp_own) == 0)
255 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
257 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
260 /* Should we damage this sub? */
261 getsect(ship.shp_x, ship.shp_y, §1);
263 if (sect1.sct_type == SCT_BSPAN ||
264 sect1.sct_type == SCT_BTOWER ||
265 sect1.sct_type == SCT_WATER) {
266 /* Ok, we're not in a harbor or trapped
267 inland. Now, did we get pasted
269 if (ship.shp_x != x || ship.shp_y != y) {
270 /* Nope, so don't mess with it */
275 ship_damage(&ship, damage);
276 if (own == bombown) {
277 mpr(bombown, "%s at %s reports %d%% damage\n",
278 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
281 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
282 cname(bombown), damage, prship(&ship),
283 xyas(ship.shp_x, ship.shp_y, own));
285 putship(ship.shp_uid, &ship);
287 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
288 while (nxtitem(&ni, &nuke)) {
289 /* Nukes falling on water affect only 1 sector */
290 if ((nuke.nuk_x != x) && issea)
292 if ((nuke.nuk_y != y) && issea)
294 if ((own = nuke.nuk_own) == 0)
296 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
298 if (roll(100) >= damage)
300 makelost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid, nuke.nuk_x,
303 if (own == bombown) {
304 mpr(bombown, "nuclear stockpile #%d at %s destroyed\n",
305 ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own));
308 mpr(own, "nuclear stockpile #%d at %s destroyed\n",
309 ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own));
311 putnuke(ni.cur, &nuke);
321 kaboom(int x, int y, int rad, natid cn)
323 mpr(cn, "\n\nK A B ");
326 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));