]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/aircombat.c
Intercept planes at their assembly point
[empserver] / src / lib / subs / aircombat.c
index 6832712798f7f3407a2e24185348373df5050bd9..27e0fcfd472b644ae7c40047f09589f78fffbafb 100644 (file)
@@ -82,8 +82,6 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     int overfly[MAXNOC];
     int flags;
     struct emp_qelem ilist[MAXNOC];
-    char mypath[1024];
-    int myp;
     int civ, mil;
     natid plane_owner;
     struct sctstr sect;
@@ -91,7 +89,7 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     struct lndstr land;
     struct nstr_item ni;
     natid cn;
-    struct natstr *over, *mynatp;
+    struct natstr *mynatp;
     struct plist *plp;
     int evaded;
     struct shiplist *head = NULL;
@@ -103,9 +101,6 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     plp = (struct plist *)bomb_list->q_forw;
     plane_owner = plp->plane.pln_own;
 
-    strncpy(mypath, path, sizeof(mypath));
-    myp = 0;
-
     memset(overfly, 0, sizeof(overfly));
     memset(gotilist, 0, sizeof(gotilist));
     memset(unfriendly, 0, sizeof(unfriendly));
@@ -133,14 +128,8 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
        }
     }
 
-    while ((dir = mypath[myp++]) && !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);
-       over = getnatp(sect.sct_own);
 
        if (mission_flags & PM_R) {
            flags = plane_caps(bomb_list);
@@ -196,47 +185,48 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
            changed += map_set(plane_owner, sect.sct_x, sect.sct_y,
                               dchr[sect.sct_type].d_mnem, 0);
        }
-       if ((rel = getrel(over, plane_owner)) == ALLIED)
-           continue;
 
        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) {
-           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] && !gotilist[sect.sct_own]) {
-           getilist(&ilist[sect.sct_own], sect.sct_own);
-           gotilist[sect.sct_own]++;
-       }
-       if (rel > HOSTILE)
-           continue;
-       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 */
@@ -350,11 +340,8 @@ sam_intercept(struct emp_qelem *att_list, struct emp_qelem *def_list,
                continue;
 
            if (dplp->plane.pln_range <
-               mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y)) {
-               emp_remque(dqp);
-               free(dqp);
+               mapdist(x, y, dplp->plane.pln_x, dplp->plane.pln_y))
                continue;
-           }
            if (CANT_HAPPEN(dplp->plane.pln_flags & PLN_LAUNCHED)
                || mission_pln_equip(dplp, 0, P_F, 0) < 0) {
                emp_remque(dqp);
@@ -410,7 +397,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list,
     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, 1);
+    sam_intercept(esc_list, def_list, def_own, plane_owner, x, y, 0);
 
     att_count = 0;
     for (qp = bomb_list->q_forw; qp != bomb_list; qp = qp->q_forw)