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 * bridgefall.c: Knock a bridge down
30 * Known contributors to this file:
32 * Markus Armbruster, 2004-2009
48 #include "prototypes.h"
52 static void knockdown(struct sctstr *);
55 * Check bridges at and around SP after damage to SP.
56 * If SP is an inefficent bridge, splash it.
57 * If SP can't support a bridge, splash unsupported adjacent bridges.
58 * Write back splashed bridges, except for SP; writing that one is
62 bridge_damaged(struct sctstr *sp)
66 if (sp->sct_effic >= SCT_MINEFF)
70 if (des == SCT_BSPAN || des == SCT_BTOWER)
72 if ((des == SCT_BHEAD || des == SCT_BTOWER) && !opt_EASY_BRIDGES)
77 bridgefall(struct sctstr *sp)
82 struct sctstr bh_sect;
88 if (CANT_HAPPEN(opt_EASY_BRIDGES))
91 for (i = 1; i <= 6; i++) {
92 nx = sp->sct_x + diroff[i][0];
93 ny = sp->sct_y + diroff[i][1];
94 getsect(nx, ny, §);
95 if (sect.sct_type != SCT_BSPAN)
97 for (j = 1; j <= 6; j++) {
98 nnx = nx + diroff[j][0];
99 nny = ny + diroff[j][1];
100 if (nnx == sp->sct_x && nny == sp->sct_y)
102 getsect(nnx, nny, &bh_sect);
103 if (bh_sect.sct_type == SCT_BHEAD &&
104 bh_sect.sct_newtype == SCT_BHEAD)
106 if (bh_sect.sct_type == SCT_BTOWER)
116 /* Knock down a bridge span. Note that this does NOT write the
117 * sector out to the database, it's up to the caller to do that. */
119 knockdown(struct sctstr *sp)
128 "Crumble... SCREEEECH! Splash! Bridge%s falls at %s!\n",
129 sp->sct_type == SCT_BTOWER ? " tower" : "",
130 xyas(sp->sct_x, sp->sct_y, sp->sct_own));
131 if (!SCT_MINES_ARE_SEAMINES(sp))
133 sp->sct_type = SCT_WATER;
134 sp->sct_newtype = SCT_WATER;
140 /* Sink all the units */
141 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
142 while (nxtitem(&ni, &land)) {
143 if (land.lnd_own == 0)
145 if (land.lnd_ship >= 0)
147 np = getnatp(land.lnd_own);
148 if (np->nat_flags & NF_BEEP)
149 mpr(land.lnd_own, "\07");
150 mpr(land.lnd_own, " AARGH! %s tumbles to its doom!\n",
153 putland(land.lnd_uid, &land);
155 /* Sink all the planes */
156 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
157 while (nxtitem(&ni, &plane)) {
158 if (plane.pln_own == 0)
160 if (plane.pln_flags & PLN_LAUNCHED)
162 if (plane.pln_ship >= 0)
164 np = getnatp(plane.pln_own);
165 if (np->nat_flags & NF_BEEP)
166 mpr(plane.pln_own, "\07");
167 mpr(plane.pln_own, " AARGH! %s tumbles to its doom!\n",
170 putplane(plane.pln_uid, &plane);
172 /* Sink all the nukes */
173 snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
174 while (nxtitem(&ni, &nuke)) {
175 if (nuke.nuk_own == 0)
177 if (nuke.nuk_plane >= 0)
179 np = getnatp(nuke.nuk_own);
180 if (np->nat_flags & NF_BEEP)
181 mpr(nuke.nuk_own, "\07");
182 mpr(nuke.nuk_own, " %s sinks to the bottom of the sea!\n",
185 putnuke(nuke.nuk_uid, &nuke);
187 memset(sp->sct_item, 0, sizeof(sp->sct_item));
188 memset(sp->sct_del, 0, sizeof(sp->sct_del));
189 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
190 sp->sct_pstage = PLG_HEALTHY;
193 sp->sct_che_target = 0;