A bridge (span or tower) must be splashed when it gets damaged below SCT_MINEFF. Likewise when its last supporting sector (bridge head or tower) gets damaged below SCT_MINEFF, unless EASY_BRIDGES is enabled. We need to check this whenever a bridge head, span or tower gets damaged. This is done in three places, and all of them screw up: * checksect() ignores damage to bridge heads. It also leaves writing back the sector it checks to the caller, which never happens when it's called from sct_postread(). Note that checksect() drowns all planes on bridges it splashes. Functions that need to exempt flying planes from such a fate have to splash bridges themselves. * sect_damage() ignores damage to bridge towers, and damage to bridge spans unless EASY_BRIDGES is enabled. It then runs checksect(), which compensates for these omissions, but happily drowns the planes sect_damage() attempts to protect. * eff_bomb() ignores damage to bridge heads. Collateral damage makes sect_damage() run, which compensates for the omission. This causes the following bugs: * Efficiency damage going through sect_damage() can drown planes it shouldn't. This affects pinpoint bombing when collateral damage splashes a bridge, and strategic bombing. The drowned planes then crash and burn when they attempt to land at their (just splashed) base. * Efficiency damage to bridge heads not going through sect_damage() fails to collapse unsupported bridges. This affects pin-bombing efficiency without collateral damage, and ground combat. Also deity commands edit, setsector and add, but that could be regarded as a feature. * If the sector file somehow ends up with an inefficient bridge span, it collapses on every read again and again, until it collapses on a write. Related problems exist with other actions of checksect(), and they're not addressed here. * If the sector file somehow ends up with adjacent inefficient bridge towers, checksect() on any of them recurses infinitely: - checksect() inefficient tower T1 - knockdown() T1, but don't write that back to the sector file - bridgefall() T1; this reads all adjacent sectors, including inefficient towert T2 - checksect() T2 - knockdown() T2, but don't write that back to the sector file - bridgefall() T1; this reads adjacent sectors including T1 - checksect() T1 ... This commit creates a new function bridge_damaged() to splash any bridges that became inefficient or unsupported after damage to a sector. To avoid the inifinite recursion, we call it in sct_prewrite() instead of checksect(). No uses knockdown() outside bridgefall.c remain, so give it internal linkage.
124 lines
3.3 KiB
C
124 lines
3.3 KiB
C
/*
|
|
* Empire - A multi-player, client/server Internet based war game.
|
|
* Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
|
|
* Ken Stevens, Steve McClure
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
*
|
|
* ---
|
|
*
|
|
* See files README, COPYING and CREDITS in the root of the source
|
|
* tree for related information and legal notices. It is expected
|
|
* that future projects/authors will amend these files as needed.
|
|
*
|
|
* ---
|
|
*
|
|
* sectdamage.c: Damage a sector
|
|
*
|
|
* Known contributors to this file:
|
|
* Dave Pare, 1989
|
|
* Steve McClure, 1996
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "combat.h"
|
|
#include "damage.h"
|
|
#include "file.h"
|
|
#include "land.h"
|
|
#include "misc.h"
|
|
#include "nat.h"
|
|
#include "nsc.h"
|
|
#include "optlist.h"
|
|
#include "plane.h"
|
|
#include "prototypes.h"
|
|
#include "sect.h"
|
|
#include "ship.h"
|
|
#include "xy.h"
|
|
|
|
int
|
|
sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list)
|
|
{
|
|
int eff;
|
|
|
|
if (dam <= 0)
|
|
return 0;
|
|
if (dam > 100)
|
|
dam = 100;
|
|
|
|
sp->sct_effic = damage(sp->sct_effic, dam);
|
|
sp->sct_avail = damage(sp->sct_avail, dam);
|
|
sp->sct_road = damage(sp->sct_road, dam);
|
|
sp->sct_rail = damage(sp->sct_rail, dam);
|
|
sp->sct_defense = damage(sp->sct_defense, dam);
|
|
|
|
eff = dam;
|
|
|
|
if (sp->sct_mobil > 0)
|
|
sp->sct_mobil = damage(sp->sct_mobil, dam);
|
|
item_damage(dam, sp->sct_item);
|
|
bridge_damaged(sp, list);
|
|
putsect(sp);
|
|
return eff;
|
|
}
|
|
|
|
int
|
|
sectdamage(struct sctstr *sp, int dam, struct emp_qelem *list)
|
|
{
|
|
struct nstr_item ni;
|
|
struct lndstr land;
|
|
struct plnstr plane;
|
|
int eff;
|
|
|
|
/* Some sectors are harder/easier to kill.. */
|
|
/* Average sector has a dstr of 1, so adjust */
|
|
/* the damage accordingly. Makes forts a pain */
|
|
dam = ldround(dam / sector_strength(sp), 1);
|
|
|
|
eff = sect_damage(sp, PERCENT_DAMAGE(dam), list);
|
|
|
|
/* Damage all the land units in the sector */
|
|
/* Units don't take full damage */
|
|
dam = ldround(DPERCENT_DAMAGE(dam * unit_damage), 1);
|
|
if (dam <= 0)
|
|
return eff;
|
|
|
|
snxtitem_xy(&ni, EF_LAND, sp->sct_x, sp->sct_y);
|
|
while (nxtitem(&ni, &land)) {
|
|
if (!land.lnd_own)
|
|
continue;
|
|
landdamage(&land, dam);
|
|
putland(land.lnd_uid, &land);
|
|
}
|
|
|
|
dam = dam / 7;
|
|
if (dam <= 0)
|
|
return eff;
|
|
snxtitem_xy(&ni, EF_PLANE, sp->sct_x, sp->sct_y);
|
|
while (nxtitem(&ni, &plane)) {
|
|
if (!plane.pln_own)
|
|
continue;
|
|
if (plane.pln_flags & PLN_LAUNCHED)
|
|
continue;
|
|
if (plane.pln_ship >= 0)
|
|
continue;
|
|
/* Is this plane flying in this list? */
|
|
if (ac_isflying(&plane, list))
|
|
continue;
|
|
planedamage(&plane, dam);
|
|
putplane(plane.pln_uid, &plane);
|
|
}
|
|
return eff;
|
|
}
|