]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/path.c
Update copyright notice.
[empserver] / src / lib / common / path.c
index d2ad3f4b790144c23bf73fa6f7e2cf5b7ed97189..4553ec1a7c3b03d08c16041720b08f7bed160713 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
 
 #include <config.h>
 
-#include <stdio.h>
-#include <stdlib.h>
 #include "../as/as.h"
+#include "file.h"
 #include "misc.h"
+#include "optlist.h"
 #include "path.h"
-#include "xy.h"
+#include "prototypes.h"
 #include "sect.h"
-#include "file.h"
-#include "common.h"
-#include "gen.h"
-#include "optlist.h"
+#include "xy.h"
+#include <stdio.h>
 
 #define        BP_ASHASHSIZE   128     /* A* queue hash table size */
 #define        BP_NEIGHBORS    6       /* max number of neighbors */
@@ -59,7 +57,7 @@ struct bestp {
     struct as_data *adp;
 };
 
-static int bp_path(struct as_path *pp, s_char *buf);
+static int bp_path(struct as_path *pp, char *buf);
 static int bp_neighbors(struct as_coord c, struct as_coord *cp, void *);
 static double bp_lbcost(struct as_coord from, struct as_coord to, void *);
 static double bp_realcost(struct as_coord from, struct as_coord to, void *);
@@ -96,7 +94,7 @@ bp_init(void)
  * string in path.  Return 0 on success, -1 on error.
  */
 static int
-best_path(struct sctstr *from, struct sctstr *to, s_char *path,
+best_path(struct sctstr *from, struct sctstr *to, char *path,
          int mob_type)
 {
     static struct bestp *mybestpath;
@@ -138,10 +136,10 @@ best_path(struct sctstr *from, struct sctstr *to, s_char *path,
  * success, -1 on failure.
  */
 static int
-bp_path(struct as_path *pp, s_char *buf)
+bp_path(struct as_path *pp, char *buf)
 {
     struct as_path *np;
-    s_char *cp = buf;
+    char *cp = buf;
     int dx, dy;
     int n;
 
@@ -182,6 +180,7 @@ static int
 bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp)
 {
     struct sctstr *sectp = (void *)empfile[EF_SECTOR].cache;
+    struct bestp *bp = pp;
     coord x, y;
     coord nx, ny;
     int n = 0, q;
@@ -218,7 +217,10 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp)
        }
        /* No need to calculate cost each time, just make sure we can
           move through it.  We calculate it later. */
-       if (dchr[sp->sct_type].d_mcst == 0)
+       if (dchr[sp->sct_type].d_mob0 < 0)
+           continue;
+       if (bp->bp_mobtype == MOB_RAIL
+           && (!intrchr[INT_RAIL].in_enable || sp->sct_rail == 0))
            continue;
        if (sp->sct_own != from->sct_own)
            continue;
@@ -237,9 +239,7 @@ static double
 bp_lbcost(struct as_coord from, struct as_coord to, void *pp)
 {
     struct sctstr *sectp = (void *)empfile[EF_SECTOR].cache;
-    struct bestp *bp = (struct bestp *)pp;
-    struct sctstr *ts;
-    float cost;
+    struct bestp *bp = pp;
     int x, y, sx, sy, offset;
 
     x = to.x;
@@ -247,9 +247,7 @@ bp_lbcost(struct as_coord from, struct as_coord to, void *pp)
     sx = XNORM(x);
     sy = YNORM(y);
     offset = (sy * WORLD_X + sx) / 2;
-    ts = &sectp[offset];
-    cost = sector_mcost(ts, bp->bp_mobtype);
-    return cost;
+    return sector_mcost(&sectp[offset], bp->bp_mobtype);
 }
 
 /*
@@ -269,8 +267,8 @@ bp_realcost(struct as_coord from, struct as_coord to, void *pp)
 static double
 bp_seccost(struct as_coord from, struct as_coord to, void *pp)
 {
-    return (double)mapdist((coord)from.x, (coord)from.y,
-                          (coord)to.x, (coord)to.y);
+    return mapdist((coord)from.x, (coord)from.y,
+                  (coord)to.x, (coord)to.y);
 }
 
 /*
@@ -301,7 +299,7 @@ bp_clear_cachepath(void)
 }
 
 double
-pathcost(struct sctstr *start, s_char *path, int mob_type)
+pathcost(struct sctstr *start, char *path, int mob_type)
 {
     struct sctstr *sectp = (void *)empfile[EF_SECTOR].cache;
     unsigned i;
@@ -338,16 +336,16 @@ pathcost(struct sctstr *start, s_char *path, int mob_type)
     return cost;
 }
 
-s_char *
-BestDistPath(s_char *path,
+char *
+BestDistPath(char *path,
             struct sctstr *from,
-            struct sctstr *to, double *cost, int mob_type)
+            struct sctstr *to, double *cost)
 {
-    return BestLandPath(path, from, to, cost, mob_type);
+    return BestLandPath(path, from, to, cost, MOB_MOVE);
 }
 
-s_char *
-BestLandPath(s_char *path,
+char *
+BestLandPath(char *path,
             struct sctstr *from,
             struct sctstr *to, double *cost, int mob_type)
 {
@@ -364,20 +362,19 @@ BestLandPath(s_char *path,
     return path;
 }
 
-s_char *
-BestShipPath(s_char *path, int fx, int fy, int tx, int ty, int owner)
+char *
+BestShipPath(char *path, int fx, int fy, int tx, int ty, int owner)
 {
-    s_char *map;
+    char *map;
 
-    /* need to make sector database available to bestpath */
     map = ef_ptr(EF_BMAP, owner);
-
-    return bestownedpath(path, map, fx, fy, tx, ty, ".=h", owner);
+    if (!map)
+       return NULL;
+    return bestownedpath(path, map, fx, fy, tx, ty, owner);
 }
 
-s_char *
-BestAirPath(s_char *path, int fx, int fy, int tx, int ty)
+char *
+BestAirPath(char *path, int fx, int fy, int tx, int ty)
 {
-    return bestownedpath(path, 0, fx, fy, tx, ty, "", -1);
-    /*    return (bestpath(path, fx, fy, tx, ty, "")); */
+    return bestownedpath(path, NULL, fx, fy, tx, ty, -1);
 }