]> git.pond.sub.org Git - empserver/commitdiff
Intercept planes at their assembly point
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 25 Sep 2008 02:09:59 +0000 (22:09 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 1 Feb 2009 16:14:39 +0000 (17:14 +0100)
Change ac_encounter() to start intercepting and running air defense
missions at the assembly point instead of the first sector entered
from there.

This also fixes a coding bug: when the flight path was empty, evaded
was used uninitialized when checking whether to intercept over the
target.  The compiler even warned about that.  Since the uninitialized
evaded typically read non-zero, interception triggered by ships and
land units didn't work.  Abusable: if you managed to make your target
sector an assembly point, e.g. by placing an own or allied ship there,
you could bomb it without getting intercepted or taking flak.

src/lib/subs/aircombat.c

index 2c6c0f7611d5f52e0f38ac70ffd3b96ce0a90ab5..27e0fcfd472b644ae7c40047f09589f78fffbafb 100644 (file)
@@ -128,12 +128,7 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
        }
     }
 
-    while ((dir = *path++) && !QEMPTY(bomb_list)) {
-       if ((val = diridx(dir)) == DIR_STOP)
-           break;
-       /* XXX using xnorm is probably bad */
-       x = xnorm(x + diroff[val][0]);
-       y = ynorm(y + diroff[val][1]);
+    for (;;) {
        getsect(x, y, &sect);
 
        if (mission_flags & PM_R) {
@@ -192,44 +187,46 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
        }
 
        evaded = do_evade(bomb_list, esc_list);
-       if (evaded)
-           continue;
+       if (!evaded) {
+           if (sect.sct_own != 0 && sect.sct_own != plane_owner
+               && getrel(getnatp(sect.sct_own), plane_owner) != ALLIED) {
+               overfly[sect.sct_own]++;
+               PR(sect.sct_own, "%s planes spotted over %s\n",
+                  cname(plane_owner), xyas(x, y, sect.sct_own));
+               if (opt_HIDDEN)
+                   setcont(sect.sct_own, plane_owner, FOUND_FLY);
+           }
 
-       if (sect.sct_own != 0 && sect.sct_own != plane_owner
-           && getrel(getnatp(sect.sct_own), plane_owner) != ALLIED) {
-           overfly[sect.sct_own]++;
-           PR(sect.sct_own, "%s planes spotted over %s\n",
-              cname(plane_owner), xyas(x, y, sect.sct_own));
-           if (opt_HIDDEN)
-               setcont(sect.sct_own, plane_owner, FOUND_FLY);
+           /* Fire flak */
+           if (unfriendly[sect.sct_own])
+               ac_doflak(bomb_list, &sect);
+           /* If bombers left, fire flak from units and ships */
+           if (!QEMPTY(bomb_list))
+               ac_landflak(bomb_list, x, y);
+           if (!QEMPTY(bomb_list))
+               ac_shipflak(bomb_list, x, y);
+           /* mission planes aborted due to flak -- don't send escorts */
+           if (QEMPTY(bomb_list))
+               break;
+
+           if (!no_air_defense)
+               air_defense(x, y, plane_owner, bomb_list, esc_list);
+
+           if (unfriendly[sect.sct_own]) {
+               if (!gotilist[sect.sct_own]) {
+                   getilist(&ilist[sect.sct_own], sect.sct_own);
+                   gotilist[sect.sct_own]++;
+               }
+               ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
+                            sect.sct_own, x, y);
+           }
        }
 
-       /* Fire flak */
-       if (unfriendly[sect.sct_own])
-           ac_doflak(bomb_list, &sect);
-       /* If bombers left, fire flak from units and ships */
-       if (!QEMPTY(bomb_list))
-           ac_landflak(bomb_list, x, y);
-       if (!QEMPTY(bomb_list))
-           ac_shipflak(bomb_list, x, y);
-       /* mission planes aborted due to flak -- don't send escorts */
-       if (QEMPTY(bomb_list))
+       dir = *path++;
+       if (!dir || QEMPTY(bomb_list) || (val = diridx(dir)) == DIR_STOP)
            break;
-
-       if (!no_air_defense)
-           air_defense(x, y, plane_owner, bomb_list, esc_list);
-
-       if (sect.sct_own == 0 || sect.sct_own == plane_owner)
-           continue;
-
-       if (unfriendly[sect.sct_own]) {
-           if (!gotilist[sect.sct_own]) {
-               getilist(&ilist[sect.sct_own], sect.sct_own);
-               gotilist[sect.sct_own]++;
-           }
-           ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
-                        sect.sct_own, x, y);
-       }
+       x = xnorm(x + diroff[val][0]);
+       y = ynorm(y + diroff[val][1]);
     }
 
     /* Let's report all of the overflights even if aborted */