2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2006, 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
49 #include "prototypes.h"
51 static void kaboom(int x, int y, int rad, natid cn);
54 detonate(struct nukstr *np, coord x, coord y, int airburst)
56 int nuketype = np->nuk_type;
57 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));
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, 0);
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 if ((type == SCT_CAPIT || type == SCT_MOUNT) && damage >= 100)
139 caploss(§, own, "\n%s lost its capital!\n\n");
140 (void)putsect(§);
141 if (type != SCT_WATER)
142 nreport(bombown, N_NUKE, own, 1);
143 mpr(bombown, bp, xyas(ns.x, ns.y, bombown));
144 if (own != bombown && own != 0) {
145 (void)sprintf(buf2, bp, xyas(ns.x, ns.y, own));
146 mpr(own, "%s nuclear device %s\n", cname(bombown), buf2);
150 snxtitem_dist(&ni, EF_PLANE, x, y, rad);
151 while (nxtitem(&ni, &plane)) {
152 /* Nukes falling on water affect only 1 sector */
153 if ((plane.pln_x != x) && issea)
155 if ((plane.pln_y != y) && issea)
157 if ((own = plane.pln_own) == 0)
159 if ((plane.pln_flags & PLN_LAUNCHED) && (airburst != 2))
161 damage = nukedamage(ncp, ni.curdist, airburst) - plane.pln_harden;
164 if (plane.pln_ship >= 0) {
165 /* Are we on a sub? */
166 getship(plane.pln_ship, &ship);
168 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
171 /* Should we damage this sub? */
172 getsect(ship.shp_x, ship.shp_y, §1);
174 if (sect1.sct_type == SCT_BSPAN ||
175 sect1.sct_type == SCT_BTOWER ||
176 sect1.sct_type == SCT_WATER) {
177 /* Ok, we're not in a harbor or trapped
178 inland. Now, did we get pasted
180 if (ship.shp_x != x || ship.shp_y != y) {
181 /* Nope, so don't mess with it */
187 planedamage(&plane, damage);
188 if (own == bombown) {
189 mpr(bombown, "%s at %s reports %d%% damage\n",
191 xyas(plane.pln_x, plane.pln_y, own), damage);
194 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
195 cname(bombown), damage,
196 prplane(&plane), xyas(plane.pln_x, plane.pln_y, own));
198 putplane(ni.cur, &plane);
201 snxtitem_dist(&ni, EF_LAND, x, y, rad);
202 while (nxtitem(&ni, &land)) {
203 /* Nukes falling on water affect only 1 sector */
204 if ((land.lnd_x != x) && issea)
206 if ((land.lnd_y != y) && issea)
208 if ((own = land.lnd_own) == 0)
210 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
213 if (land.lnd_ship >= 0) {
214 /* Are we on a sub? */
215 getship(land.lnd_ship, &ship);
217 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
220 /* Should we damage this sub? */
221 getsect(ship.shp_x, ship.shp_y, §1);
223 if (sect1.sct_type == SCT_BSPAN ||
224 sect1.sct_type == SCT_BTOWER ||
225 sect1.sct_type == SCT_WATER) {
226 /* Ok, we're not in a harbor or trapped
227 inland. Now, did we get pasted
229 if (ship.shp_x != x || ship.shp_y != y) {
230 /* Nope, so don't mess with it */
236 land_damage(&land, damage);
237 if (own == bombown) {
238 mpr(bombown, "%s at %s reports %d%% damage\n",
239 prland(&land), xyas(land.lnd_x, land.lnd_y, own), damage);
242 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
243 cname(bombown), damage,
244 prland(&land), xyas(land.lnd_x, land.lnd_y, own));
246 putland(land.lnd_uid, &land);
249 snxtitem_dist(&ni, EF_SHIP, x, y, rad);
250 while (nxtitem(&ni, &ship)) {
251 /* Nukes falling on water affect only 1 sector */
252 if ((ship.shp_x != x) && issea)
254 if ((ship.shp_y != y) && issea)
256 if ((own = ship.shp_own) == 0)
258 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
260 if (mchr[(int)ship.shp_type].m_flags & M_SUB) {
263 /* Should we damage this sub? */
264 getsect(ship.shp_x, ship.shp_y, §1);
266 if (sect1.sct_type == SCT_BSPAN ||
267 sect1.sct_type == SCT_BTOWER ||
268 sect1.sct_type == SCT_WATER) {
269 /* Ok, we're not in a harbor or trapped
270 inland. Now, did we get pasted
272 if (ship.shp_x != x || ship.shp_y != y) {
273 /* Nope, so don't mess with it */
278 ship_damage(&ship, damage);
279 if (own == bombown) {
280 mpr(bombown, "%s at %s reports %d%% damage\n",
281 prship(&ship), xyas(ship.shp_x, ship.shp_y, own), damage);
284 mpr(own, "%s nuclear device did %d%% damage to %s at %s\n",
285 cname(bombown), damage, prship(&ship),
286 xyas(ship.shp_x, ship.shp_y, own));
288 putship(ship.shp_uid, &ship);
291 snxtitem_dist(&ni, EF_NUKE, x, y, rad);
292 while (nxtitem(&ni, &nuke)) {
293 /* Nukes falling on water affect only 1 sector */
294 if ((nuke.nuk_x != x) && issea)
296 if ((nuke.nuk_y != y) && issea)
298 if ((own = nuke.nuk_own) == 0)
300 if ((damage = nukedamage(ncp, ni.curdist, airburst)) <= 0)
302 if (roll(100) >= damage)
305 if (own == bombown) {
306 mpr(bombown, "%s at %s destroyed\n",
307 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
310 mpr(own, "%s at %s destroyed\n",
311 prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
313 putnuke(ni.cur, &nuke);
324 kaboom(int x, int y, int rad, natid cn)
326 mpr(cn, "\n\nK A B ");
329 mpr(cn, "M ! in %s\n\n", xyas(x, y, cn));