From b4acb73fd160a25cf7241e0954d1978318c1460b Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 23 Jun 2012 20:49:48 +0200 Subject: [PATCH] Replace pln_oneway_to_carrier_ok() by pln_can_land_on_carrier() Avoids reading the target ship again. --- include/prototypes.h | 4 ++-- src/lib/commands/fly.c | 3 ++- src/lib/commands/reco.c | 3 ++- src/lib/subs/plnsub.c | 15 +++++++-------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/prototypes.h b/include/prototypes.h index 554f6b411..e7be088e5 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -505,8 +505,8 @@ extern int get_planes(struct nstr_item *, struct nstr_item *, char *, char *); extern struct sctstr *get_assembly_point(char *, struct sctstr *, char *); extern int pln_where_to_land(coord, coord, union empobj_storage *, int *); -extern int pln_oneway_to_carrier_ok(struct emp_qelem *, - struct emp_qelem *, int); +extern int pln_can_land_on_carrier(struct emp_qelem *, struct emp_qelem *, + struct shpstr *); extern void pln_newlanding(struct emp_qelem *, coord, coord, int); extern int could_be_on_ship(struct plnstr *, struct shpstr *); extern int put_plane_on_ship(struct plnstr *, struct shpstr *); diff --git a/src/lib/commands/fly.c b/src/lib/commands/fly.c index 57d298a6d..f3d723b05 100644 --- a/src/lib/commands/fly.c +++ b/src/lib/commands/fly.c @@ -98,7 +98,8 @@ fly(void) wantflags, P_M | P_O); pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, 1, wantflags | P_ESC | P_F, P_M | P_O); - if (cno >= 0 && !pln_oneway_to_carrier_ok(&bomb_list, &esc_list, cno)) { + if (cno >= 0 + && !pln_can_land_on_carrier(&bomb_list, &esc_list, &target.ship)) { pr("Not enough room on ship #%d!\n", cno); return RET_FAIL; } diff --git a/src/lib/commands/reco.c b/src/lib/commands/reco.c index e27031cfe..381bbf542 100644 --- a/src/lib/commands/reco.c +++ b/src/lib/commands/reco.c @@ -87,7 +87,8 @@ reco(void) P_M | P_O); pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, 1, wantflags | P_ESC | P_F, P_M | P_O); - if (cno >= 0 && !pln_oneway_to_carrier_ok(&bomb_list, &esc_list, cno)) { + if (cno >= 0 + && !pln_can_land_on_carrier(&bomb_list, &esc_list, &target.ship)) { pr("Not enough room on ship #%d!\n", cno); return RET_FAIL; } diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index 7c6f49cb4..24aa56fda 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -184,17 +184,16 @@ pln_where_to_land(coord x, coord y, } int -pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list, - struct emp_qelem *esc_list, int cno) +pln_can_land_on_carrier(struct emp_qelem *bomb_list, + struct emp_qelem *esc_list, + struct shpstr *sp) + { 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); + n = shp_nplane(sp, &nch, &nxl, &nmsl); /* for both lists */ for (list = bomb_list; @@ -202,14 +201,14 @@ pln_oneway_to_carrier_ok(struct emp_qelem *bomb_list, list = list == bomb_list ? esc_list : NULL) { for (qp = list->q_forw; qp != list; qp = qp->q_forw) { plp = (struct plist *)qp; - if (plp->plane.pln_ship == ship.shp_uid) + if (plp->plane.pln_ship == sp->shp_uid) continue; n++; if (!inc_shp_nplane(&plp->plane, &nch, &nxl, &nmsl)) return 0; } } - return ship_can_carry(&ship, n, nch, nxl, nmsl); + return ship_can_carry(sp, n, nch, nxl, nmsl); } void -- 2.43.0