]> git.pond.sub.org Git - empserver/commitdiff
Fix confused and buggy bridge splashing code
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 11 Feb 2008 22:14:04 +0000 (23:14 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 16 Feb 2008 19:57:38 +0000 (20:57 +0100)
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.

include/prototypes.h
src/lib/commands/bomb.c
src/lib/subs/bridgefall.c
src/lib/subs/sect.c
src/lib/subs/sectdamage.c

index 6c170c174c4e229a91b8ce22e4862674b07591ac..5b8ea6959450cb112d2bf0725437c3052a71ffbb 100644 (file)
@@ -402,8 +402,8 @@ extern void stop_service(void);
 extern int confirm(char *);
 extern int askyn(char *);
 /* bridgefall.c */
 extern int confirm(char *);
 extern int askyn(char *);
 /* bridgefall.c */
+extern void bridge_damaged(struct sctstr *, struct emp_qelem *);
 extern void bridgefall(struct sctstr *, struct emp_qelem *);
 extern void bridgefall(struct sctstr *, struct emp_qelem *);
-extern void knockdown(struct sctstr *, struct emp_qelem *);
 /* bsanct.c */
 extern void bsanct(void);
 /* caploss.c */
 /* bsanct.c */
 extern void bsanct(void);
 /* caploss.c */
index 4afac17e1d215ad81faab3e6669cdbe90c3b11af..72e4f1f95d34fd3bb133a51899dabc021a7c6db5 100644 (file)
@@ -369,14 +369,7 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target)
           "%s bombing raid did %d%% damage in %s\n",
           cname(player->cnum), oldeff - target->sct_effic,
           xyas(target->sct_x, target->sct_y, target->sct_own));
           "%s bombing raid did %d%% damage in %s\n",
           cname(player->cnum), oldeff - target->sct_effic,
           xyas(target->sct_x, target->sct_y, target->sct_own));
-    if (target->sct_effic < SCT_MINEFF) {
-       if (target->sct_type == SCT_BSPAN)
-           knockdown(target, list);
-       else if (target->sct_type == SCT_BTOWER) {
-           knockdown(target, list);
-           bridgefall(target, list);
-       }
-    }
+    bridge_damaged(target, list);
     putsect(&sect);
     collateral_damage(target->sct_x, target->sct_y, dam, list);
 }
     putsect(&sect);
     collateral_damage(target->sct_x, target->sct_y, dam, list);
 }
index c11529d1e4424064e393876ae57c27c60146b2b4..160bd3167bc10b7fd4a4cfe3fb2ff5c83faebb79 100644 (file)
 #include "sect.h"
 #include "xy.h"
 
 #include "sect.h"
 #include "xy.h"
 
+static void knockdown(struct sctstr *, struct emp_qelem *);
+
+/*
+ * Check bridges at and around SP after damage to SP.
+ * If SP is an inefficent bridge, splash it.
+ * If SP can't support a bridge, splash unsupported adjacent bridges.
+ * Don't drown planes in LIST when splashing bridges.
+ * Write back splashed bridges, except for SP; writing that one is
+ * left to the caller.
+ */
+void
+bridge_damaged(struct sctstr *sp, struct emp_qelem *list)
+{
+    int des;
+
+    if (sp->sct_effic >= SCT_MINEFF)
+       return;
+
+    des = sp->sct_type;
+    if (des == SCT_BSPAN || des == SCT_BTOWER)
+       knockdown(sp, list);
+    if ((des == SCT_BHEAD || des == SCT_BTOWER) && !opt_EASY_BRIDGES)
+       bridgefall(sp, list);
+}
+
 void
 bridgefall(struct sctstr *sp, struct emp_qelem *list)
 {
 void
 bridgefall(struct sctstr *sp, struct emp_qelem *list)
 {
@@ -94,7 +119,7 @@ bridgefall(struct sctstr *sp, struct emp_qelem *list)
 
 /* Knock down a bridge span.  Note that this does NOT write the
  * sector out to the database, it's up to the caller to do that. */
 
 /* Knock down a bridge span.  Note that this does NOT write the
  * sector out to the database, it's up to the caller to do that. */
-void
+static void
 knockdown(struct sctstr *sp, struct emp_qelem *list)
 {
     struct lndstr land;
 knockdown(struct sctstr *sp, struct emp_qelem *list)
 {
     struct lndstr land;
index 52f22f1e3e96525651b7bc2a0d304684b695a778..febaaae1e8df65d484ccdcfa351c92f02070114a 100644 (file)
@@ -70,6 +70,7 @@ sct_prewrite(int id, void *ptr)
 
     time(&sp->sct_timestamp);
 
 
     time(&sp->sct_timestamp);
 
+    bridge_damaged(sp, NULL);
     checksect(sp);
     getsect(sp->sct_x, sp->sct_y, &sect);
     return 1;
     checksect(sp);
     getsect(sp->sct_x, sp->sct_y, &sect);
     return 1;
@@ -106,14 +107,6 @@ checksect(struct sctstr *sp)
     else
        loyalcivs = 0;
 
     else
        loyalcivs = 0;
 
-    if (sp->sct_effic < SCT_MINEFF) {
-       if (sp->sct_type == SCT_BSPAN)
-           knockdown(sp, 0);
-       else if (sp->sct_type == SCT_BTOWER) {
-           knockdown(sp, 0);
-           bridgefall(sp, 0);
-       }
-    }
     if (sp->sct_own != 0 && !civs) {
        sp->sct_work = 100;
        sp->sct_oldown = sp->sct_own;
     if (sp->sct_own != 0 && !civs) {
        sp->sct_work = 100;
        sp->sct_oldown = sp->sct_own;
index 6dcacbb7036f948a5a138866fd29b1deea622b9f..a14dad48b79c8f1e8d7683487243d07a6538cd6a 100644 (file)
@@ -69,13 +69,7 @@ sect_damage(struct sctstr *sp, int dam, struct emp_qelem *list)
     if (sp->sct_mobil > 0)
        sp->sct_mobil = damage(sp->sct_mobil, dam);
     item_damage(dam, sp->sct_item);
     if (sp->sct_mobil > 0)
        sp->sct_mobil = damage(sp->sct_mobil, dam);
     item_damage(dam, sp->sct_item);
-    if (opt_EASY_BRIDGES == 0) {
-       if (sp->sct_effic < SCT_MINEFF && sp->sct_type == SCT_BHEAD)
-           bridgefall(sp, list);
-    } else {
-       if (sp->sct_effic < SCT_MINEFF && sp->sct_type == SCT_BSPAN)
-           knockdown(sp, list);
-    }
+    bridge_damaged(sp, list);
     putsect(sp);
     return eff;
 }
     putsect(sp);
     return eff;
 }