]> git.pond.sub.org Git - empserver/commitdiff
Replace pln_oneway_to_carrier_ok() by pln_can_land_on_carrier()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 23 Jun 2012 18:49:48 +0000 (20:49 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 13 Jul 2012 18:15:33 +0000 (20:15 +0200)
Avoids reading the target ship again.

include/prototypes.h
src/lib/commands/fly.c
src/lib/commands/reco.c
src/lib/subs/plnsub.c

index 554f6b411ffd198e64b5b5cf3234de92a7a1f1bb..e7be088e5d2a5d801a0bf4642de287872cc889e3 100644 (file)
@@ -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 *);
                      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 *);
 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 *);
index 57d298a6d56bb06f376573db275a301d5892a03d..f3d723b059fb9c0d4176ecaca67931fc2da638c9 100644 (file)
@@ -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);
            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;
     }
        pr("Not enough room on ship #%d!\n", cno);
        return RET_FAIL;
     }
index e27031cfe929cfed366565e531618220d7583ba3..381bbf54223a8bad10f4784570d8741c68eed885 100644 (file)
@@ -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);
            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;
     }
        pr("Not enough room on ship #%d!\n", cno);
        return RET_FAIL;
     }
index 7c6f49cb49b3b94a09104bffd40e0aab2afc56de..24aa56fdafe563b6bee80273ec9c68a9f87e0804 100644 (file)
@@ -184,17 +184,16 @@ pln_where_to_land(coord x, coord y,
 }
 
 int
 }
 
 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;
 {
     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;
 
     /* 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;
         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;
        }
     }
                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
 }
 
 void