2 * Empire - A multi-player, client/server Internet based war game.
3 * Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
4 * Ken Stevens, Steve McClure, Markus Armbruster
6 * Empire 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 3 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, see <http://www.gnu.org/licenses/>.
21 * See files README, COPYING and CREDITS in the root of the source
22 * tree for related information and legal notices. It is expected
23 * that future projects/authors will amend these files as needed.
27 * bridgefall.c: Knock a bridge down
29 * Known contributors to this file:
31 * Markus Armbruster, 2004-2014
45 #include "prototypes.h"
49 static void knockdown(struct sctstr *);
52 * Is there support for a bridge at @sp?
53 * Ignore support coming from direction @ignore_dir.
56 bridge_support_at(struct sctstr *sp, int ignore_dir)
61 for (i = 1; i <= 6; i++) {
64 nx = sp->sct_x + diroff[i][0];
65 ny = sp->sct_y + diroff[i][1];
66 getsect(nx, ny, §);
68 && sect.sct_type != SCT_WATER && sect.sct_type != SCT_BSPAN)
70 if (sect.sct_effic < SCT_MINEFF)
72 if (sect.sct_type == SCT_BHEAD && sect.sct_newtype == SCT_BHEAD)
74 if (sect.sct_type == SCT_BTOWER)
81 * Check bridges at and around @sp after damage to @sp.
82 * If @sp is an inefficent bridge, splash it.
83 * If @sp can't support a bridge, splash unsupported adjacent bridges.
84 * Write back splashed bridges, except for @sp; writing that one is
88 bridge_damaged(struct sctstr *sp)
92 if (sp->sct_effic >= SCT_MINEFF)
96 if (des == SCT_BSPAN || des == SCT_BTOWER)
98 if ((des == SCT_BHEAD && !opt_EASY_BRIDGES) || des == SCT_BTOWER)
103 bridgefall(struct sctstr *sp)
110 for (i = 1; i <= 6; i++) {
111 nx = sp->sct_x + diroff[i][0];
112 ny = sp->sct_y + diroff[i][1];
113 getsect(nx, ny, §);
114 if (sect.sct_type == SCT_BSPAN
115 && !bridge_support_at(§, DIR_BACK(i))) {
122 /* Knock down a bridge span. Note that this does NOT write the
123 * sector out to the database, it's up to the caller to do that. */
125 knockdown(struct sctstr *sp)
133 "Crumble... SCREEEECH! Splash! Bridge%s falls at %s!\n",
134 sp->sct_type == SCT_BTOWER ? " tower" : "",
135 xyas(sp->sct_x, sp->sct_y, sp->sct_own));
136 if (!SCT_MINES_ARE_SEAMINES(sp))
138 sp->sct_type = SCT_WATER;
139 sp->sct_newtype = SCT_WATER;
145 /* Sink all the units */
146 snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
147 while (nxtitem(&ni, &land)) {
148 if (land.lnd_own == 0)
150 if (land.lnd_ship >= 0)
152 mpr(land.lnd_own, " AARGH! %s tumbles to its doom!\n",
155 putland(land.lnd_uid, &land);
157 /* Sink all the planes */
158 snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
159 while (nxtitem(&ni, &plane)) {
160 if (plane.pln_own == 0)
162 if (plane.pln_flags & PLN_LAUNCHED)
164 if (plane.pln_ship >= 0)
166 mpr(plane.pln_own, " AARGH! %s tumbles to its doom!\n",
169 putplane(plane.pln_uid, &plane);
171 /* Sink all the nukes */
172 snxtitem_xy(&ni, EF_NUKE, sp->sct_x, sp->sct_y);
173 while (nxtitem(&ni, &nuke)) {
174 if (nuke.nuk_own == 0)
176 if (nuke.nuk_plane >= 0)
178 mpr(nuke.nuk_own, " %s sinks to the bottom of the sea!\n",
181 putnuke(nuke.nuk_uid, &nuke);
183 memset(sp->sct_item, 0, sizeof(sp->sct_item));
184 memset(sp->sct_del, 0, sizeof(sp->sct_del));
185 memset(sp->sct_dist, 0, sizeof(sp->sct_dist));
186 sp->sct_pstage = PLG_HEALTHY;
189 sp->sct_che_target = 0;