]> git.pond.sub.org Git - empserver/commitdiff
Don't let planes fly to a carrier without sufficient space
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Jun 2012 14:38:04 +0000 (16:38 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 12 Jul 2012 17:51:57 +0000 (19:51 +0200)
We test whether the the carrier has space for each plane individually
instead of whether it has space for all of them.  The planes that fit
land, the others abort and get teleported home.  Abusable.

pln_oneway_to_carrier_ok() was created in commit 1127762c (v4.2.17) to
fix almost the same bug.  It worked fine then, because
fit_plane_on_ship() worked with load counters, and incremented them.

Broken in commit 3e370da5 (v4.3.17), which made fit_plane_on_ship()
count the loaded planes, to permit the removal of load counters.  But
unlike load counters, loaded planes don't change during
pln_oneway_to_carrier_ok().  Thus, each plane is checked individually.

Fix by tallying all the planes before checking for space.

src/lib/subs/plnsub.c

index e7a51d25164b345096fb9d8c3ad7923acf213dbf..c261ae1f39a57dfa7cd0bd3582b452f816a5bae8 100644 (file)
@@ -51,7 +51,8 @@
 #include "ship.h"
 #include "xy.h"
 
-static int fit_plane_on_ship(struct plnstr *, struct shpstr *);
+static int ship_can_carry(struct shpstr *, int, int, int, int);
+static int inc_shp_nplane(struct plnstr *, int *, int *, int *);
 
 /*
  * Get planes and escorts argument.
@@ -188,12 +189,14 @@ int
 pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
                         struct emp_qelem *esc_list, int cno)
 {
+    int n, nch, nxl, nmsl;
     struct emp_qelem *list, *qp;
     struct plist *plp;
     struct shpstr ship;
 
     if (cno < 0 || !getship(cno, &ship))
        return 0;
+    n = shp_nplane(&ship, &nch, &nxl, &nmsl);
 
     /* for both lists */
     for (list = bomb_list;
@@ -203,11 +206,12 @@ pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list,
            plp = (struct plist *)qp;
            if (plp->plane.pln_ship == ship.shp_uid)
                continue;
-           if (!fit_plane_on_ship(&plp->plane, &ship))
+           n++;
+           if (!inc_shp_nplane(&plp->plane, &nch, &nxl, &nmsl))
                return 0;
        }
     }
-    return 1;
+    return ship_can_carry(&ship, n, nch, nxl, nmsl);
 }
 
 void