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.
This commit is contained in:
Markus Armbruster 2012-06-23 16:38:04 +02:00
parent 81efebd367
commit b60e5be22c

View file

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