From b60e5be22c8b5559f82ad6dcb90f3fd747c9bc49 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 23 Jun 2012 16:38:04 +0200 Subject: [PATCH] Don't let planes fly to a carrier without sufficient space 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index e7a51d25..c261ae1f 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -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