]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/path.c
Update copyright notice
[empserver] / src / lib / common / path.c
index ce1ede1716a753035a1313f503ddc56e8ae3135e..8dd74b945ab9d28e31f4f8f3494d20d570b8537c 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-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -27,7 +27,7 @@
  *
  *  path.c: Empire/A* Interface code.
  *          Define AS_STATS for A* statistics.
- * 
+ *
  *  Known contributors to this file:
  *     Phil Lapsley, 1991
  *     Dave Pare, 1991
 #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"
 
 #define        BP_ASHASHSIZE   128     /* A* queue hash table size */
 #define        BP_NEIGHBORS    6       /* max number of neighbors */
@@ -85,8 +83,7 @@ bp_init(void)
        return NULL;
 
     if (neighsects == NULL)
-       neighsects = calloc(((WORLD_X * WORLD_Y) / 2) * 6,
-                           sizeof(struct sctstr *));
+       neighsects = calloc(WORLD_SZ() * 6, sizeof(struct sctstr *));
 
     return bp;
 }
@@ -182,6 +179,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;
@@ -194,7 +192,7 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp)
     y = c.y;
     sx = XNORM(x);
     sy = YNORM(y);
-    offset = (sy * WORLD_X + sx) / 2;
+    offset = XYOFFSET(sx, sy);
     from = &sectp[offset];
 
     if (neighsects == NULL)
@@ -208,7 +206,7 @@ bp_neighbors(struct as_coord c, struct as_coord *cp, void *pp)
            ny = y + diroff[q][1];
            sx = XNORM(nx);
            sy = YNORM(ny);
-           offset = (sy * WORLD_X + sx) / 2;
+           offset = XYOFFSET(sx, sy);
            sp = &sectp[offset];
            *ssp = sp;
        } else {
@@ -218,7 +216,9 @@ 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 && !SCT_HAS_RAIL(sp))
            continue;
        if (sp->sct_own != from->sct_own)
            continue;
@@ -237,19 +237,15 @@ 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;
     y = to.y;
     sx = XNORM(x);
     sy = YNORM(y);
-    offset = (sy * WORLD_X + sx) / 2;
-    ts = &sectp[offset];
-    cost = sector_mcost(ts, bp->bp_mobtype);
-    return cost;
+    offset = XYOFFSET(sx, sy);
+    return sector_mcost(&sectp[offset], bp->bp_mobtype);
 }
 
 /*
@@ -269,8 +265,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);
 }
 
 /*
@@ -329,7 +325,7 @@ pathcost(struct sctstr *start, char *path, int mob_type)
        cy += diroff[o][1];
        sx = XNORM(cx);
        sy = YNORM(cy);
-       offset = (sy * WORLD_X + sx) / 2;
+       offset = XYOFFSET(sx, sy);
        sp = &sectp[offset];
        cost += sector_mcost(sp, mob_type);
        path++;
@@ -341,9 +337,9 @@ pathcost(struct sctstr *start, char *path, int mob_type)
 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);
 }
 
 char *
@@ -369,7 +365,6 @@ BestShipPath(char *path, int fx, int fy, int tx, int ty, int owner)
 {
     char *map;
 
-    /* need to make sector database available to bestpath */
     map = ef_ptr(EF_BMAP, owner);
     if (!map)
        return NULL;
@@ -379,5 +374,5 @@ BestShipPath(char *path, int fx, int fy, int tx, int ty, int owner)
 char *
 BestAirPath(char *path, int fx, int fy, int tx, int ty)
 {
-    return bestownedpath(path, 0, fx, fy, tx, ty, -1);
+    return bestownedpath(path, NULL, fx, fy, tx, ty, -1);
 }