]> git.pond.sub.org Git - empserver/blobdiff - src/lib/common/path.c
Update copyright notice
[empserver] / src / lib / common / path.c
index 985e4f770430a33c2e91a2a30ef07e45502930a7..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;
 }
@@ -195,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)
@@ -209,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 {
@@ -219,10 +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
-           && (!intrchr[INT_RAIL].in_enable || sp->sct_rail == 0))
+       if (bp->bp_mobtype == MOB_RAIL && !SCT_HAS_RAIL(sp))
            continue;
        if (sp->sct_own != from->sct_own)
            continue;
@@ -248,7 +244,7 @@ bp_lbcost(struct as_coord from, struct as_coord to, void *pp)
     y = to.y;
     sx = XNORM(x);
     sy = YNORM(y);
-    offset = (sy * WORLD_X + sx) / 2;
+    offset = XYOFFSET(sx, sy);
     return sector_mcost(&sectp[offset], bp->bp_mobtype);
 }
 
@@ -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++;