]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/aircombat.c
Clean up dead stores
[empserver] / src / lib / subs / aircombat.c
index 2c6c0f7611d5f52e0f38ac70ffd3b96ce0a90ab5..d23265fb9e852c0e9d61fb06726e2ee3bbc97102 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -31,7 +31,7 @@
  *     Dave Pare, 1986
  *     Thomas Ruschak, 1992
  *     Steve McClure, 1996
- *     Markus Armbruster, 2006-2008
+ *     Markus Armbruster, 2006-2009
  */
 
 #include <config.h>
@@ -40,6 +40,7 @@
 #include "land.h"
 #include "map.h"
 #include "misc.h"
+#include "mission.h"
 #include "nat.h"
 #include "news.h"
 #include "nsc.h"
 
 #define FLAK_GUN_MAX 14
 
-static int plane_caps(struct emp_qelem *);
+static void sam_intercept(struct emp_qelem *, struct emp_qelem *,
+                         natid, natid, coord, coord, int);
 static void ac_intercept(struct emp_qelem *, struct emp_qelem *,
-                        struct emp_qelem *, natid, coord, coord);
+                        struct emp_qelem *, natid, coord, coord, int);
+static void ac_combat_headers(natid, natid);
+static void ac_airtoair(struct emp_qelem *, struct emp_qelem *);
 static void ac_dog(struct plist *, struct plist *);
 static void ac_planedamage(struct plist *, natid, int, natid, int,
                           int, char *);
@@ -64,21 +68,18 @@ static void ac_doflak(struct emp_qelem *, struct sctstr *);
 static void ac_landflak(struct emp_qelem *, coord, coord);
 static void ac_shipflak(struct emp_qelem *, coord, coord);
 static void ac_fireflak(struct emp_qelem *, natid, int);
-static void getilist(struct emp_qelem *, natid);
+static void getilists(struct emp_qelem *, unsigned char *, natid);
 static int do_evade(struct emp_qelem *, struct emp_qelem *);
 
 void
 ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
-            coord x, coord y, char *path, int mission_flags,
-            int no_air_defense)
+            coord x, coord y, char *path, int mission_flags)
 {
     int val;
-    int rel;
     int dir;
-    int nats[MAXNOC];
-    int lnats[MAXNOC];
-    int gotilist[MAXNOC];
-    int unfriendly[MAXNOC];
+    unsigned char gotships[MAXNOC];
+    unsigned char gotlands[MAXNOC];
+    unsigned char rel[MAXNOC];
     int overfly[MAXNOC];
     int flags;
     struct emp_qelem ilist[MAXNOC];
@@ -89,7 +90,6 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     struct lndstr land;
     struct nstr_item ni;
     natid cn;
-    struct natstr *mynatp;
     struct plist *plp;
     int evaded;
     struct shiplist *head = NULL;
@@ -102,20 +102,10 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     plane_owner = plp->plane.pln_own;
 
     memset(overfly, 0, sizeof(overfly));
-    memset(gotilist, 0, sizeof(gotilist));
-    memset(unfriendly, 0, sizeof(unfriendly));
-    for (cn = 1; cn < MAXNOC; cn++) {
-       if ((mynatp = getnatp(cn)) == 0)
-           continue;
-       rel = getrel(mynatp, plane_owner);
-       if (rel > HOSTILE)
-           continue;
-       if (plane_owner == cn)
-           continue;
-       unfriendly[cn]++;
-    }
+    getilists(ilist, rel, plane_owner);
+
     if (mission_flags & PM_R) {
-       flags = plane_caps(bomb_list);
+       flags = pln_caps(bomb_list);
        if (flags & P_S) {
            PR(plane_owner, "\nSPY Plane report\n");
            PRdate(plane_owner);
@@ -128,16 +118,25 @@ 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);
+       memset(gotships, 0, sizeof(gotships));
+       snxtitem_xy(&ni, EF_SHIP, x, y);
+       while (nxtitem(&ni, &ship)) {
+           if (mchr[(int)ship.shp_type].m_flags & M_SUB)
+               continue;
+           gotships[ship.shp_own] = 1;
+       }
+       memset(gotlands, 0, sizeof(gotlands));
+       snxtitem_xy(&ni, EF_LAND, x, y);
+       while (nxtitem(&ni, &land)) {
+           if (land.lnd_ship >= 0 || land.lnd_land >= 0)
+               continue;
+           gotlands[land.lnd_own] = 1;
+       }
 
        if (mission_flags & PM_R) {
-           flags = plane_caps(bomb_list);
+           flags = pln_caps(bomb_list);
            if (opt_HIDDEN)
                setcont(plane_owner, sect.sct_own, FOUND_FLY);
            if (sect.sct_type == SCT_WATER) {
@@ -184,6 +183,18 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
            }
            if (flags & P_S)
                satdisp_units(sect.sct_x, sect.sct_y);
+           else {
+               for (cn = 1; cn < MAXNOC; cn++) {
+                   if (cn == plane_owner)
+                       continue;
+                   if (gotships[cn])
+                       PR(plane_owner, "Flying over %s ships in %s\n",
+                          cname(cn), xyas(x, y, plane_owner));
+                   if (gotlands[cn])
+                       PR(plane_owner, "Flying over %s land units in %s\n",
+                          cname(cn), xyas(x, y, plane_owner));
+               }
+           }
        } else {
            PR(plane_owner, "flying over %s at %s\n",
               dchr[sect.sct_type].d_name, xyas(x, y, plane_owner));
@@ -192,134 +203,67 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
        }
 
        evaded = do_evade(bomb_list, esc_list);
-       if (evaded)
-           continue;
-
-       if (sect.sct_own != 0 && sect.sct_own != plane_owner
-           && getrel(getnatp(sect.sct_own), plane_owner) != ALLIED) {
+       if (!evaded) {
            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 (sect.sct_own == 0 || sect.sct_own == plane_owner)
-           continue;
+           for (cn = 1; cn < MAXNOC; cn++) {
+               if (cn == plane_owner || rel[cn] == ALLIED)
+                   continue;
+               if (cn != sect.sct_own && !gotships[cn] && !gotlands[cn])
+                   continue;
+               PR(cn, "%s planes spotted over %s\n",
+                  cname(plane_owner), xyas(x, y, cn));
+               if (opt_HIDDEN)
+                   setcont(cn, plane_owner, FOUND_FLY);
+           }
 
-       if (unfriendly[sect.sct_own]) {
-           if (!gotilist[sect.sct_own]) {
-               getilist(&ilist[sect.sct_own], sect.sct_own);
-               gotilist[sect.sct_own]++;
+           /* Fire flak */
+           if (rel[sect.sct_own] <= HOSTILE)
+               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;
+
+           for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
+               if (rel[cn] > HOSTILE)
+                   continue;
+               ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x, y,
+                            !(cn == sect.sct_own
+                              || gotships[cn] || gotlands[cn]));
            }
-           ac_intercept(bomb_list, esc_list, &ilist[sect.sct_own],
-                        sect.sct_own, x, y);
        }
+
+       dir = *path++;
+       if (!dir || QEMPTY(bomb_list) || (val = diridx(dir)) == DIR_STOP)
+           break;
+       x = xnorm(x + diroff[val][0]);
+       y = ynorm(y + diroff[val][1]);
     }
 
     /* Let's report all of the overflights even if aborted */
     for (cn = 1; cn < MAXNOC; cn++) {
        if (plane_owner == cn)
            continue;
-       if (overfly[cn] > 0)
+       if (overfly[cn] > 0 && rel[cn] != ALLIED)
            nreport(plane_owner, N_OVFLY_SECT, cn, overfly[cn]);
     }
     /* If the map changed, update it */
     if (changed)
        writemap(player->cnum);
-    /* Now, if the bomber and escort lists are empty, we are done */
-    if (QEMPTY(bomb_list) && QEMPTY(esc_list))
-       goto out;
 
-    /* Something made it through */
-    /* Go figure out if there are ships in this sector, and who's they are */
-    memset(nats, 0, sizeof(nats));
-    snxtitem_xy(&ni, EF_SHIP, x, y);
-    while (nxtitem(&ni, &ship)) {
-       if (mchr[(int)ship.shp_type].m_flags & M_SUB)
-           continue;
-       nats[ship.shp_own]++;
-    }
-    /* Go figure out if there are units in this sector, and who's they are */
-    memset(lnats, 0, sizeof(lnats));
-    snxtitem_xy(&ni, EF_LAND, x, y);
-    while (nxtitem(&ni, &land)) {
-       if (land.lnd_ship >= 0 || land.lnd_land >= 0)
-           continue;
-       lnats[land.lnd_own]++;
-    }
-
-    /* Now, let's make life a little rougher. */
-    for (cn = 1; cn < MAXNOC && !QEMPTY(bomb_list); cn++) {
-       if (plane_owner == cn)
-           continue;
-       if (nats[cn] != 0) {
-           PR(plane_owner, "Flying over %s ships in %s\n",
-              cname(cn), xyas(x, y, plane_owner));
-           PR(cn, "%s planes spotted over ships in %s\n",
-              cname(plane_owner), xyas(x, y, cn));
-       }
-       if (lnats[cn] != 0) {
-           PR(plane_owner, "Flying over %s land units in %s\n",
-              cname(cn), xyas(x, y, plane_owner));
-           PR(cn, "%s planes spotted over land units in %s\n",
-              cname(plane_owner), xyas(x, y, cn));
-       }
-       if (nats[cn] || lnats[cn]) {
-           if (opt_HIDDEN)
-               setcont(cn, plane_owner, FOUND_FLY);
-           if (unfriendly[cn] && !evaded) {
-               if (!gotilist[cn]) {
-                   getilist(&ilist[cn], cn);
-                   gotilist[cn]++;
-               }
-               ac_intercept(bomb_list, esc_list, &ilist[cn], cn, x, y);
-           }
-       }
-    }
-out:
     free_shiplist(&head);
-    for (cn = 1; cn < MAXNOC; cn++) {
-       if (gotilist[cn])
-           pln_put(&ilist[cn]);
-    }
-}
-
-static int
-plane_caps(struct emp_qelem *list)
-{
-    struct emp_qelem *qp;
-    struct plist *plp;
-    int fl;
-
-    fl = 0;
-    for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
-       plp = (struct plist *)qp;
-       fl |= plp->pcp->pl_flags;
-    }
-
-    return fl;
+    for (cn = 1; cn < MAXNOC; cn++)
+       pln_put(&ilist[cn]);
 }
 
-void
+static void
 sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
              natid def_own, natid plane_owner, coord x, coord y,
-             int delete_missiles)
+             int only_mission)
 {
     struct emp_qelem *aqp;
     struct emp_qelem *anext;
@@ -327,6 +271,7 @@ sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
     struct emp_qelem *dnext;
     struct plist *aplp;
     struct plist *dplp;
+    struct plnstr *pp;
     int first = 1;
 
     for (aqp = att_list->q_forw,
@@ -339,20 +284,24 @@ sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
        for (; dqp != def_list; dqp = dnext) {
            dnext = dqp->q_forw;
            dplp = (struct plist *)dqp;
+           pp = &dplp->plane;
            if (!(dplp->pcp->pl_flags & P_M))
                continue;
-
-           if (dplp->plane.pln_range <
-               mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y))
+           if (only_mission && !pp->pln_mission)
                continue;
-           if (CANT_HAPPEN(dplp->plane.pln_flags & PLN_LAUNCHED)
-               || mission_pln_equip(dplp, 0, P_F, 0) < 0) {
+           if (pp->pln_range < mapdist(x, y, pp->pln_x, pp->pln_y))
+               continue;
+           if (pp->pln_mission
+               && pp->pln_radius < mapdist(x, y, pp->pln_opx, pp->pln_opy))
+               continue;
+           if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED)
+               || mission_pln_equip(dplp, NULL, 0) < 0) {
                emp_remque(dqp);
                free(dqp);
                continue;
            }
-           dplp->plane.pln_flags |= PLN_LAUNCHED;
-           putplane(dplp->plane.pln_uid, &dplp->plane);
+           pp->pln_flags |= PLN_LAUNCHED;
+           putplane(pp->pln_uid, pp);
            if (first) {
                first = 0;
                PR(plane_owner, "%s launches SAMs!\n", cname(def_own));
@@ -369,22 +318,12 @@ sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
        PR(plane_owner, "\n");
        PR(def_own, "\n");
     }
-    if (delete_missiles) {
-       for (; dqp != def_list; dqp = dnext) {
-           dnext = dqp->q_forw;
-           dplp = (struct plist *)dqp;
-           if (!(dplp->pcp->pl_flags & P_M))
-               continue;
-           emp_remque(dqp);
-           free(dqp);
-           continue;
-       }
-    }
 }
 
 static void
 ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
-            struct emp_qelem *def_list, natid def_own, coord x, coord y)
+            struct emp_qelem *def_list, natid def_own, coord x, coord y,
+            int only_mission)
 {
     struct plnstr *pp;
     struct plist *plp;
@@ -399,8 +338,10 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     plp = (struct plist *)bomb_list->q_forw;
     plane_owner = plp->plane.pln_own;
 
-    sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y, 0);
-    sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 0);
+    sam_intercept(bomb_list, def_list, def_own, plane_owner, x, y,
+                 only_mission);
+    sam_intercept(esc_list, def_list, def_own, plane_owner, x, y,
+                 only_mission);
 
     att_count = 0;
     for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw)
@@ -419,11 +360,16 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
        /* SAMs interdict separately */
        if (plp->pcp->pl_flags & P_M)
            continue;
+       if (only_mission && !pp->pln_mission)
+           continue;
        dist = mapdist(x, y, pp->pln_x, pp->pln_y) * 2;
        if (pp->pln_range < dist)
            continue;
+       if (pp->pln_mission
+           && pp->pln_radius < mapdist(x, y, pp->pln_opx, pp->pln_opy))
+           continue;
        if (CANT_HAPPEN(pp->pln_flags & PLN_LAUNCHED)
-           || mission_pln_equip(plp, 0, P_F, 0) < 0) {
+           || mission_pln_equip(plp, NULL, 0) < 0) {
            emp_remque(qp);
            free(qp);
            continue;
@@ -432,7 +378,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
        emp_remque(qp);
        emp_insque(qp, &int_list);
        pp->pln_flags |= PLN_LAUNCHED;
-       pp->pln_mobil -= pln_mobcost(dist, pp, P_F);
+       pp->pln_mobil -= pln_mobcost(dist, pp, 0);
        putplane(pp->pln_uid, pp);
        icount++;
        if (icount > att_count)
@@ -453,7 +399,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     pln_put(&int_list);
 }
 
-void
+static void
 ac_combat_headers(natid plane_owner, natid def_own)
 {
     PR(plane_owner,
@@ -467,14 +413,13 @@ ac_combat_headers(natid plane_owner, natid def_own)
 /*
  * air-to-air combat.
  */
-void
+static void
 ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list)
 {
     struct plist *attacker;
     struct plist *interceptor;
     struct emp_qelem *att;
     struct emp_qelem *in;
-    int nplanes;
     int more_att;
     int more_int;
     struct emp_qelem *att_next;
@@ -493,9 +438,6 @@ ac_airtoair(struct emp_qelem *att_list, struct emp_qelem *int_list)
        att_next = att->q_forw;
        attacker = (struct plist *)att;
        interceptor = (struct plist *)in;
-       nplanes = attacker->plane.pln_effic;
-       if (nplanes > interceptor->plane.pln_effic)
-           nplanes = interceptor->plane.pln_effic;
        ac_dog(attacker, interceptor);
        in = in_next;
        att = att_next;
@@ -546,9 +488,9 @@ ac_dog(struct plist *ap, struct plist *dp)
     def = pln_def(&dp->plane) * dp->plane.pln_effic / 100;
     def = MAX(def, dp->pcp->pl_def / 2);
 
-    if ((ap->pcp->pl_flags & P_F) && ap->bombs != 0)
+    if ((ap->pcp->pl_flags & P_F) && ap->load != 0)
        att -= 2;
-    if ((dp->pcp->pl_flags & P_F) && dp->bombs != 0)
+    if ((dp->pcp->pl_flags & P_F) && dp->load != 0)
        def -= 2;
     att += ap->pcp->pl_stealth / 25.0;
     def += dp->pcp->pl_stealth / 25.0;
@@ -674,7 +616,6 @@ ac_planedamage(struct plist *plp, natid from, int dam, natid other,
 static void
 ac_doflak(struct emp_qelem *list, struct sctstr *from)
 {
-    int shell;
     int gun;
     natid plane_owner;
     struct plist *plp;
@@ -683,16 +624,6 @@ ac_doflak(struct emp_qelem *list, struct sctstr *from)
     plane_owner = plp->plane.pln_own;
 
     gun = MIN(FLAK_GUN_MAX, from->sct_item[I_GUN]);
-    shell = from->sct_item[I_SHELL];
-    if (gun > shell * 2) {
-       shell += supply_commod(from->sct_own, from->sct_x, from->sct_y,
-                              I_SHELL, (gun + 1) / 2 - shell);
-       from->sct_item[I_SHELL] = shell;
-       putsect(from);
-    }
-    if (gun > shell * 2)
-       gun = shell * 2;
-
     gun = roundavg(tfact(from->sct_own, 2.0 * gun));
     if (gun > 0) {
        PR(plane_owner, "firing %d flak guns in %s...\n",
@@ -711,17 +642,15 @@ ac_shipflak(struct emp_qelem *list, coord x, coord y)
     struct shpstr ship;
     struct mchrstr *mcp;
     double flak, total, ngun;
-    int gun, shell;
+    int gun;
     int rel;
     struct plist *plp;
     natid plane_owner;
     natid from;
-    int nats[MAXNOC];
 
     plp = (struct plist *)list->q_forw;
     plane_owner = plp->plane.pln_own;
 
-    memset(nats, 0, sizeof(nats));
     total = ngun = 0;
     snxtitem_xy(&ni, EF_SHIP, x, y);
     while (!QEMPTY(list) && nxtitem(&ni, &ship)) {
@@ -733,31 +662,13 @@ ac_shipflak(struct emp_qelem *list, coord x, coord y)
        rel = getrel(getnatp(ship.shp_own), plane_owner);
        if (rel > HOSTILE)
            continue;
-       shell = 0;
        gun = shp_usable_guns(&ship);
-       if (gun) {
-           shell = ship.shp_item[I_SHELL];
-           if (shell <= 0) {
-               shell = supply_commod(ship.shp_own, ship.shp_x, ship.shp_y,
-                                     I_SHELL, 1);
-               ship.shp_item[I_SHELL] = shell;
-               putship(ship.shp_uid, &ship);
-           }
-       }
-       if (gun == 0 || shell == 0)
+       if (gun == 0)
            continue;
        flak = gun * (ship.shp_effic / 100.0);
        ngun += flak;
        total += techfact(ship.shp_tech, flak * 2.0);
 
-       if (!nats[ship.shp_own]) {
-           /* First time here, print the message */
-           PR(ship.shp_own, "%s planes spotted over ships in %s\n",
-              cname(plane_owner), xyas(x, y, ship.shp_own));
-           PR(plane_owner, "Flying over %s ships in %s\n",
-              cname(ship.shp_own), xyas(x, y, plane_owner));
-           nats[ship.shp_own] = 1;
-       }
        PR(ship.shp_own, "firing %.0f flak guns from %s...\n",
           flak, prship(&ship));
        from = ship.shp_own;
@@ -786,12 +697,10 @@ ac_landflak(struct emp_qelem *list, coord x, coord y)
     struct plist *plp;
     natid plane_owner;
     natid from;
-    int nats[MAXNOC];
 
     plp = (struct plist *)list->q_forw;
     plane_owner = plp->plane.pln_own;
 
-    memset(nats, 0, sizeof(nats));
     total = ngun = 0;
     snxtitem_xy(&ni, EF_LAND, x, y);
     while (!QEMPTY(list) && nxtitem(&ni, &land)) {
@@ -810,14 +719,6 @@ ac_landflak(struct emp_qelem *list, coord x, coord y)
        ngun += flak;
        total += techfact(land.lnd_tech, flak * 2.0);
 
-       if (!nats[land.lnd_own]) {
-           /* First time here, print the message */
-           PR(land.lnd_own, "%s planes spotted over land units in %s\n",
-              cname(plane_owner), xyas(x, y, land.lnd_own));
-           PR(plane_owner, "Flying over %s land units in %s\n",
-              cname(land.lnd_own), xyas(x, y, plane_owner));
-           nats[land.lnd_own] = 1;
-       }
        PR(land.lnd_own, "firing flak guns from unit %s (aa rating %d)\n",
           prland(&land), aaf);
        from = land.lnd_own;
@@ -846,8 +747,6 @@ ac_fireflak(struct emp_qelem *list, natid from, int guns)
     struct emp_qelem *next;
     char msg[255];
 
-    plp = (struct plist *)list->q_forw;
-
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
        plp = (struct plist *)qp;
@@ -875,10 +774,6 @@ ac_flak_dam(int guns, int def, int pl_flags)
     flak = guns - def;
     if ((pl_flags & P_T) == 0)
        flak--;
-    if (pl_flags & P_X)
-       flak -= 2;
-    if (pl_flags & P_H)
-       flak -= 1;
 
     if (flak > 8)
        mult = flaktable[FLAK_MAX];
@@ -896,27 +791,33 @@ ac_flak_dam(int guns, int def, int pl_flags)
 }
 
 /*
- * Get a list of planes available for interception duties.
+ * Get planes available for interception duties.
  */
 static void
-getilist(struct emp_qelem *list, natid own)
+getilists(struct emp_qelem *list, unsigned char *rel, natid intruder)
 {
+    natid cn;
     struct plchrstr *pcp;
     struct plnstr plane;
     struct nstr_item ni;
     struct plist *ip;
 
-    emp_initque(list);
+    rel[0] = NEUTRAL;
+    for (cn = 1; cn < MAXNOC; cn++) {
+       rel[cn] = getrel(getnatp(cn), intruder);
+       emp_initque(&list[cn]);
+    }
+
     snxtitem_all(&ni, EF_PLANE);
     while (nxtitem(&ni, &plane)) {
-       if (plane.pln_own != own)
+       if (rel[plane.pln_own] > HOSTILE)
            continue;
        pcp = &plchr[(int)plane.pln_type];
        if ((pcp->pl_flags & P_F) == 0)
            continue;
        if (plane.pln_flags & PLN_LAUNCHED)
            continue;
-       if (plane.pln_mission != 0)
+       if (plane.pln_mission && plane.pln_mission != MI_AIR_DEFENSE)
            continue;
        if (plane.pln_mobil <= 0)
            continue;
@@ -926,11 +827,10 @@ getilist(struct emp_qelem *list, natid own)
            continue;
        /* got one! */
        ip = malloc(sizeof(*ip));
-       ip->bombs = 0;
-       ip->misc = 0;
+       ip->load = 0;
        ip->pcp = &plchr[(int)plane.pln_type];
        ip->plane = plane;
-       emp_insque(&ip->queue, list);
+       emp_insque(&ip->queue, &list[plane.pln_own]);
     }
 }