]> git.pond.sub.org Git - empserver/commitdiff
Inline BestShipPath(), BestAirPath() glue
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Mar 2011 07:03:19 +0000 (08:03 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 12 Apr 2011 19:51:32 +0000 (21:51 +0200)
Following commits will simplify the resulting code.

include/path.h
include/prototypes.h
src/lib/common/path.c [deleted file]
src/lib/subs/mission.c
src/lib/subs/paths.c
src/lib/subs/unitsub.c
src/lib/update/nav_ship.c

index b061426c3bdf891db5c79ca7b6a4c666dc77bffb..8efa85f7735ec07df147a25ebf44c80c9c81a845 100644 (file)
@@ -81,10 +81,6 @@ extern void path_find_print_stats(void);
 #define path_find_print_stats() ((void)0)
 #endif
 
-/* src/lib/common/path.c */
-extern char *BestShipPath(char *, int, int, int, int, int);
-extern char *BestAirPath(char *, int, int, int, int);
-
 /* src/lib/subs/paths.c */
 extern char *getpath(char *, char *, coord, coord, int, int, enum p_mode);
 extern double fcost(struct sctstr *, natid);
index 53a283983e419951fb6ec45c46a565a842736685..5ea60bfcb083df3acb5a58e8f5c5b99844741106 100644 (file)
@@ -281,8 +281,6 @@ extern int mapdist(int, int, int, int);
 /* in path.h */
 /* nstreval.c */
 /* in nsc.h */
-/* path.c */
-/* in path.h */
 /* rdsched.c */
 extern int read_schedule(char *, time_t[], int, time_t, time_t);
 /* res_pop.c */
diff --git a/src/lib/common/path.c b/src/lib/common/path.c
deleted file mode 100644 (file)
index 178d7ff..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                Ken Stevens, Steve McClure, Markus Armbruster
- *
- *  Empire is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- *  ---
- *
- *  See files README, COPYING and CREDITS in the root of the source
- *  tree for related information and legal notices.  It is expected
- *  that future projects/authors will amend these files as needed.
- *
- *  ---
- *
- *  path.c: Path finding interface code
- *
- *  Known contributors to this file:
- *     Phil Lapsley, 1991
- *     Dave Pare, 1991
- *     Thomas Ruschak, 1993
- *     Steve McClure, 1997
- *     Markus Armbruster, 2011
- */
-
-#include <config.h>
-
-#include <string.h>
-#include "file.h"
-#include "optlist.h"
-#include "path.h"
-#include "sect.h"
-#include "xy.h"
-
-char *
-BestShipPath(char *path, int fx, int fy, int tx, int ty, int owner)
-{
-    size_t len;
-
-    if (path_find(fx, fy, tx, ty, owner, MOB_SAIL) < 0)
-       return NULL;
-    len = path_find_route(path, 100, fx, fy, tx, ty);
-    if (len >= 100)
-       return NULL;
-    if (len == 0)
-       strcpy(path, "h");
-    return path;
-}
-
-char *
-BestAirPath(char *path, int fx, int fy, int tx, int ty)
-{
-    size_t len;
-
-    if (path_find(fx, fy, tx, ty, 0, MOB_FLY) < 0)
-       return NULL;
-    len = path_find_route(path, 100, fx, fy, tx, ty);
-    if (len >= 100)
-       return NULL;
-    if (len == 0)
-       strcpy(path, "h");
-    return path;
-}
index 4f50f352bac80e791a017f13229133249f14aff4..dfeaaaf9abcea12abe57712dff1ca05332d14bad 100644 (file)
@@ -29,7 +29,7 @@
  *  Known contributors to this file:
  *     Ken Stevens, 1995
  *     Steve McClure, 1996-2000
- *     Markus Armbruster, 2003-2009
+ *     Markus Armbruster, 2003-2011
  */
 
 #include <config.h>
@@ -615,6 +615,7 @@ perform_mission_bomb(int dam, struct emp_qelem *bombers, coord x, coord y,
        struct airport *air;
        char buf[512];
        char *pp;
+       size_t len;
 
        air = (struct airport *)qp;
        md = mapdist(x, y, air->x, air->y);
@@ -635,7 +636,18 @@ perform_mission_bomb(int dam, struct emp_qelem *bombers, coord x, coord y,
 
        mission_pln_arm(&e, air->x, air->y, 2 * md, 'e', NULL);
 
-       pp = BestAirPath(buf, air->x, air->y, x, y);
+       if (path_find(air->x, air->y, x, y, 0, MOB_FLY) < 0)
+           pp = NULL;
+       else {
+           len = path_find_route(buf, 100, air->x, air->y, x, y);
+           if (len >= 100)
+               pp = NULL;
+           else {
+               if (len == 0)
+                   strcpy(buf, "h");
+               pp = buf;
+           }
+       }
        if (CANT_HAPPEN(!pp))
            continue;
        performed = 1;
index 546d11dd79f459b9e143b40cf01f459f2b2c5b15..f0c100553f1a043906204f286ae222610d59260c 100644 (file)
@@ -94,6 +94,7 @@ getpath(char *buf, char *arg, coord x, coord y, int onlyown,
     char buf2[1024];
     char *p = buf;
     char *bp;
+    size_t len;
     char prompt[128];
     coord dx, dy;
     struct sctstr sect;
@@ -118,10 +119,32 @@ more:
                pr("Destination sectors not allowed here!\n");
                break;
            case P_FLYING:
-               bp = BestAirPath(buf2, x, y, dx, dy);
+               if (path_find(x, y, dx, dy, 0, MOB_FLY) < 0)
+                   bp = NULL;
+               else {
+                   len = path_find_route(buf2, 100, x, y, dx, dy);
+                   if (len >= 100)
+                       bp = NULL;
+                   else {
+                       if (len == 0)
+                           strcpy(buf2, "h");
+                       bp = buf2;
+                   }
+               }
                break;
            case P_SAILING:
-               bp = BestShipPath(buf2, x, y, dx, dy, player->cnum);
+               if (path_find(x, y, dx, dy, player->cnum, MOB_SAIL) < 0)
+                   bp = NULL;
+               else {
+                   len = path_find_route(buf2, 100, x, y, dx, dy);
+                   if (len >= 100)
+                       bp = NULL;
+                   else {
+                       if (len == 0)
+                           strcpy(buf2, "h");
+                       bp = buf2;
+                   }
+               }
                break;
            }
            if (bp && p + strlen(bp) + 1 < buf + MAX_PATH_LEN) {
index fec85c0429fbd5683900ba4a7e5a82b9e954e1b5..4d2d3d99bc6230b3b12f33aa01093fec833e2813 100644 (file)
@@ -157,8 +157,20 @@ unit_path(int together, struct empobj *unit, char *buf)
        return NULL;
     }
     if (unit->ef_type == EF_SHIP) {
-       cp = BestShipPath(buf, unit->x, unit->y,
-                         d_sect.sct_x, d_sect.sct_y, player->cnum);
+       if (path_find(unit->x, unit->y, d_sect.sct_x, d_sect.sct_y,
+                     player->cnum, MOB_SAIL) < 0)
+           cp = NULL;
+       else {
+           len = path_find_route(buf, 100, unit->x, unit->y,
+                                 d_sect.sct_x, d_sect.sct_y);
+           if (len >= 100)
+               cp = NULL;
+           else {
+               if (len == 0)
+                   strcpy(buf, "h");
+               cp = buf;
+           }
+       }
        if (!cp || unit->mobil <= 0) {
            pr("Can't get to '%s' right now.\n",
               xyas(d_sect.sct_x, d_sect.sct_y, player->cnum));
index 972d8b63c893f6b113b886ac5dcd656296ae9147..c8aeb5426e10ffbb5e9d71de0c8b380c46f6ef94 100644 (file)
@@ -29,6 +29,7 @@
  *  Known contributors to this file:
  *     Chad Zabel, 1994
  *     Ken Stevens, 1995
+ *     Markus Armbruster, 2004-2011
  */
 
 #include <config.h>
@@ -242,6 +243,7 @@ int
 nav_ship(struct shpstr *sp)
 {
     char *cp;
+    size_t len;
     int stopping;
     int quit;
     int didsomething = 0;
@@ -274,9 +276,21 @@ nav_ship(struct shpstr *sp)
            if (QEMPTY(&ship_list))
                return 0;
 
-           cp = BestShipPath(buf, sp->shp_x, sp->shp_y,
-                             sp->shp_destx[0], sp->shp_desty[0],
-                             sp->shp_own);
+           if (path_find(sp->shp_x, sp->shp_y,
+                         sp->shp_destx[0], sp->shp_desty[0],
+                         sp->shp_own, MOB_SAIL) < 0)
+               cp = NULL;
+           else {
+               len = path_find_route(buf, 100, sp->shp_x, sp->shp_y,
+                                     sp->shp_destx[0], sp->shp_desty[0]);
+               if (len >= 100)
+                   cp = NULL;
+               else {
+                   if (len == 0)
+                       strcpy(buf, "h");
+                   cp = buf;
+               }
+           }
            if (!cp) {
                wu(0, sp->shp_own,
                   "%s bad path, ship put on standby\n", prship(sp));