/*
* 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
*
* 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 */
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;
}
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;
y = c.y;
sx = XNORM(x);
sy = YNORM(y);
- offset = (sy * WORLD_X + sx) / 2;
+ offset = XYOFFSET(sx, sy);
from = §p[offset];
if (neighsects == NULL)
ny = y + diroff[q][1];
sx = XNORM(nx);
sy = YNORM(ny);
- offset = (sy * WORLD_X + sx) / 2;
+ offset = XYOFFSET(sx, sy);
sp = §p[offset];
*ssp = sp;
} else {
}
/* 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;
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 = §p[offset];
- cost = sector_mcost(ts, bp->bp_mobtype);
- return cost;
+ offset = XYOFFSET(sx, sy);
+ return sector_mcost(§p[offset], bp->bp_mobtype);
}
/*
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);
}
/*
cy += diroff[o][1];
sx = XNORM(cx);
sy = YNORM(cy);
- offset = (sy * WORLD_X + sx) / 2;
+ offset = XYOFFSET(sx, sy);
sp = §p[offset];
cost += sector_mcost(sp, mob_type);
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);
}
char *
{
char *map;
- /* need to make sector database available to bestpath */
map = ef_ptr(EF_BMAP, owner);
if (!map)
return NULL;
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);
}