/*
* 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 */
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 *);
* 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;
* 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;
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;
}
/* 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;
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;
sx = XNORM(x);
sy = YNORM(y);
offset = (sy * WORLD_X + sx) / 2;
- ts = §p[offset];
- cost = sector_mcost(ts, bp->bp_mobtype);
- return cost;
+ 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);
}
/*
}
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;
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)
{
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);
}