]> git.pond.sub.org Git - empserver/commitdiff
(pln_wanted): Rewrite. Old version was incomprehensible, slow and
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 1 Nov 2007 19:16:29 +0000 (19:16 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 1 Nov 2007 19:16:29 +0000 (19:16 +0000)
buggy: any P_E, P_L, P_K in wantflags were ignored when the plane
lacked P_ESC.  The bug bit only when non-escort interceptors escorted
a one-way mission to a carrier.  pln_oneway_to_carrier_ok() then could
not fit the plane on the carrier, and the command failed complaining
about lack of room on the carrier.  Broken since Chainsaw added
escorts, abusable before 4.2.17 catched it.  Also change behavior when
only one of P_F and P_ESC is in wantflags: new version requires that
flag, while old version treats it as if both flags were in wantflags:
a plane having either is okay.  Current code never passes such
wantflags.

src/lib/subs/plnsub.c

index a77107b59fbeab4a692261311fd2c67a66ef2d2e..e358708b61107c4e3f67f9fa7ef7971301d5b3fb 100644 (file)
@@ -351,64 +351,37 @@ pln_mine(struct emp_qelem *list, struct sctstr *sectp)
     }
 }
 
+/*
+ * Is a plane of PP's type wanted?
+ * A plane type is wanted unless
+ * - it lacks all of the P_F, P_ESC in wantflags, or
+ * - it lacks all of the P_E, P_L, P_K in wantflags, or
+ * - it lacks any of the other flags in wantflags, or
+ * - it has any of the flags in nowantflags.
+ */
 static int
 pln_wanted(struct plnstr *pp, int wantflags, int nowantflags)
 {
-    int y, bad, bad1;
-    unsigned x;
-    struct plchrstr *pcp = plchr + pp->pln_type;
+    int flags = plchr[(int)pp->pln_type].pl_flags;
 
-    bad = 0;
-    bad1 = 0;
-    if (wantflags) {
-       for (x = 0; x < sizeof(wantflags) * 8; x++) {
-           y = (1 << x);
-           if ((wantflags & y) == y)
-               if ((pcp->pl_flags & y) != y) {
-                   switch (y) {
-                   case P_F:
-                   case P_ESC:
-                       bad1 = 2;
-                       break;
-                   case P_E:
-                   case P_L:
-                   case P_K:
-                       bad1 = 1;
-                       break;
-                   default:
-                       bad = 1;
-                   }
-               }
-       }
-       if (bad)
-           return 0;
-       if (bad1 == 2) {
-           if ((pcp->pl_flags & P_ESC) || (pcp->pl_flags & P_F))
-               bad1 = 0;
-       }
-       if (bad1 == 1) {
-           if ((wantflags & P_L) && (pcp->pl_flags & P_L))
-               bad1 = 0;
-           if ((wantflags & P_K) && (pcp->pl_flags & P_K))
-               bad1 = 0;
-           if ((wantflags & P_E) && (pcp->pl_flags & P_E))
-               bad1 = 0;
-       }
-       if (bad1)
+    if (wantflags & (P_F | P_ESC)) {
+       if ((flags & wantflags & (P_F | P_ESC)) == 0)
            return 0;
+       wantflags &= ~(P_F | P_ESC);
     }
-    bad = 0;
-    bad1 = 0;
-    if (nowantflags) {
-       for (x = 0; x < sizeof(nowantflags) * 8; x++) {
-           y = (1 << x);
-           if ((nowantflags & y) == y)
-               if ((pcp->pl_flags & y) == y)
-                   bad = 1;
-       }
-       if (bad)
+
+    if (wantflags & (P_E | P_L | P_K)) {
+       if ((flags & wantflags & (P_E | P_L | P_K)) == 0)
            return 0;
+       wantflags &= ~(P_E | P_L | P_K);
     }
+
+    if ((flags & wantflags) != wantflags)
+       return 0;
+
+    if (flags & nowantflags)
+       return 0;
+
     return 1;
 }