(bestownedpath, owned_and_navigable): Terrain parameter isn't really
used, remove it. Use null bigmap argument to ignore terrain (flying), non-null for navigation. Callers changed.
This commit is contained in:
parent
abb9ae2338
commit
6fdac645ba
3 changed files with 51 additions and 133 deletions
|
@ -258,8 +258,7 @@ int zdon(void);
|
||||||
* src/lib/common/ *.c
|
* src/lib/common/ *.c
|
||||||
*/
|
*/
|
||||||
/* bestpath.c */
|
/* bestpath.c */
|
||||||
extern s_char *bestownedpath(s_char *, s_char *, int, int, int,
|
extern char *bestownedpath(char *, char *, int, int, int, int, int);
|
||||||
int, s_char *, int);
|
|
||||||
/* bridgefall.c */
|
/* bridgefall.c */
|
||||||
extern void bridgefall(struct sctstr *, struct emp_qelem *);
|
extern void bridgefall(struct sctstr *, struct emp_qelem *);
|
||||||
extern void knockdown(struct sctstr *, struct emp_qelem *);
|
extern void knockdown(struct sctstr *, struct emp_qelem *);
|
||||||
|
|
|
@ -52,59 +52,11 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
|
||||||
static int owned_and_navigable(char *, int, int, char *, int);
|
static int owned_and_navigable(char *, int, int, int);
|
||||||
|
|
||||||
#define MAXROUTE 100 /* return '?' if path longer than this */
|
#define MAXROUTE 100
|
||||||
#define valid(x,y) (((x^y)&1)==0)
|
#define valid(x,y) (((x^y)&1)==0)
|
||||||
|
|
||||||
/* ________________________________________________________________
|
|
||||||
**
|
|
||||||
** bestpath(x1,y1,x2,y2,(s_char *)terrain);
|
|
||||||
**
|
|
||||||
** Calculate routing string to get from sector [x1,y1] to sector [x2,y2]
|
|
||||||
** via a specified type of terrain.
|
|
||||||
**
|
|
||||||
** Specify:
|
|
||||||
**
|
|
||||||
** x1,y1 starting coordinates
|
|
||||||
**
|
|
||||||
** x2,y2 destination coordinates
|
|
||||||
**
|
|
||||||
** terrain ptr to string showing the types of sectors that
|
|
||||||
** we're allowed to pass through:
|
|
||||||
**
|
|
||||||
** A null string enables routing through any kind of
|
|
||||||
** sector (useful for airplanes).
|
|
||||||
**
|
|
||||||
** A string that begins with an 'R' ensures that
|
|
||||||
** the source and destination sectors also match
|
|
||||||
** the specified type of terrain.
|
|
||||||
**
|
|
||||||
** A string that begins with a '~' (after the 'R',
|
|
||||||
** if necessary) specifies that we can pass through
|
|
||||||
** any kind of sector EXCEPT those in the remainder
|
|
||||||
** of the string.
|
|
||||||
**
|
|
||||||
** Examples:
|
|
||||||
**
|
|
||||||
** "R~.^" all sectors along route must be
|
|
||||||
** non-ocean, non-mountain
|
|
||||||
**
|
|
||||||
** "+" all sectors between start and end
|
|
||||||
** must be highway
|
|
||||||
**
|
|
||||||
** "h. " all sectors along route must be
|
|
||||||
** harbor, water, or unmapped
|
|
||||||
**
|
|
||||||
** 'bestpath' returns a pointer to a route string containing either:
|
|
||||||
**
|
|
||||||
** yugjbn - string of normal routing characters if route possible
|
|
||||||
** ? - if route is longer than MAXROUTE characters
|
|
||||||
** \0 - (null string) if no route possible
|
|
||||||
** h - if start and end points are the same sector
|
|
||||||
** ________________________________________________________________
|
|
||||||
*/
|
|
||||||
|
|
||||||
static char *dirchar = "juygbn";
|
static char *dirchar = "juygbn";
|
||||||
int dx[6] = { 2, 1, -1, -2, -1, 1 };
|
int dx[6] = { 2, 1, -1, -2, -1, 1 };
|
||||||
int dy[6] = { 0, -1, -1, 0, 1, 1 };
|
int dy[6] = { 0, -1, -1, 0, 1, 1 };
|
||||||
|
@ -120,18 +72,27 @@ int dy[6] = { 0, -1, -1, 0, 1, 1 };
|
||||||
static unsigned int *mapbuf;
|
static unsigned int *mapbuf;
|
||||||
static unsigned int **mapindex;
|
static unsigned int **mapindex;
|
||||||
|
|
||||||
s_char *
|
/*
|
||||||
bestownedpath(s_char *bpath,
|
* Find passable path from X, Y to EX, EY for nation OWN.
|
||||||
s_char *bigmap,
|
* BPATH is a buffer capable of holding at least MAXROUTE characters.
|
||||||
int x, int y, int ex, int ey, s_char *terrain, int own)
|
* If BIGMAP is null, all sectors are passable (useful for flying).
|
||||||
|
* Else it is taken to be a bmap.
|
||||||
|
* Sectors owned by or allied to OWN are checked according to the
|
||||||
|
* usual rules, and the result is correct.
|
||||||
|
* Other sectors are assumed to be passable when BIGMAP shows '.' or
|
||||||
|
* nothing.
|
||||||
|
* Return path or a null pointer.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
bestownedpath(char *bpath, char *bigmap,
|
||||||
|
int x, int y, int ex, int ey, int own)
|
||||||
{
|
{
|
||||||
int i, j, tx, ty, markedsectors, restr2;
|
int i, j, tx, ty, markedsectors;
|
||||||
int minx, maxx, miny, maxy, scanx, scany;
|
int minx, maxx, miny, maxy, scanx, scany;
|
||||||
unsigned int routelen;
|
unsigned int routelen;
|
||||||
|
|
||||||
if (!mapbuf)
|
if (!mapbuf)
|
||||||
mapbuf = malloc((WORLD_X * WORLD_Y) *
|
mapbuf = malloc(WORLD_X * WORLD_Y * sizeof(unsigned int));
|
||||||
sizeof(unsigned int));
|
|
||||||
if (!mapbuf)
|
if (!mapbuf)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!mapindex) {
|
if (!mapindex) {
|
||||||
|
@ -145,9 +106,6 @@ bestownedpath(s_char *bpath,
|
||||||
if (!mapindex)
|
if (!mapindex)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (0 != (restr2 = (*terrain == 'R')))
|
|
||||||
terrain++;
|
|
||||||
|
|
||||||
x = XNORM(x);
|
x = XNORM(x);
|
||||||
y = YNORM(y);
|
y = YNORM(y);
|
||||||
ex = XNORM(ex);
|
ex = XNORM(ex);
|
||||||
|
@ -159,10 +117,6 @@ bestownedpath(s_char *bpath,
|
||||||
if (!valid(x, y) || !valid(ex, ey))
|
if (!valid(x, y) || !valid(ex, ey))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (restr2 && (!owned_and_navigable(bigmap, x, y, terrain, own) ||
|
|
||||||
!owned_and_navigable(bigmap, ex, ey, terrain, own)))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
for (i = 0; i < WORLD_X; i++)
|
for (i = 0; i < WORLD_X; i++)
|
||||||
for (j = 0; j < WORLD_Y; j++)
|
for (j = 0; j < WORLD_Y; j++)
|
||||||
mapindex[i][j] = 0xFFFF; /* clear the workspace */
|
mapindex[i][j] = 0xFFFF; /* clear the workspace */
|
||||||
|
@ -183,22 +137,20 @@ bestownedpath(s_char *bpath,
|
||||||
x = XNORM(scanx);
|
x = XNORM(scanx);
|
||||||
for (scany = miny; scany <= maxy; scany++) {
|
for (scany = miny; scany <= maxy; scany++) {
|
||||||
y = YNORM(scany);
|
y = YNORM(scany);
|
||||||
if (valid(x, y)) {
|
if (!valid(x, y))
|
||||||
if ((((mapindex[x][y]) & 0x1FFF) == (routelen - 1))) {
|
continue;
|
||||||
|
if (((mapindex[x][y] & 0x1FFF) == routelen - 1)) {
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
tx = x + dx[i];
|
tx = x + dx[i];
|
||||||
ty = y + dy[i];
|
ty = y + dy[i];
|
||||||
tx = XNORM(tx);
|
tx = XNORM(tx);
|
||||||
ty = YNORM(ty);
|
ty = YNORM(ty);
|
||||||
if (mapindex[tx][ty] == 0xFFFF) {
|
if (mapindex[tx][ty] == 0xFFFF) {
|
||||||
if (owned_and_navigable(bigmap, tx, ty,
|
if (owned_and_navigable(bigmap, tx, ty, own)) {
|
||||||
terrain, own)
|
|
||||||
|| (tx == ex && ty == ey && !restr2)) {
|
|
||||||
mapindex[tx][ty] =
|
mapindex[tx][ty] =
|
||||||
((i + 1) << 13) + routelen;
|
((i + 1) << 13) + routelen;
|
||||||
markedsectors++;
|
markedsectors++;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (tx == ex && ty == ey) {
|
if (tx == ex && ty == ey) {
|
||||||
bpath[routelen] = 'h';
|
bpath[routelen] = 'h';
|
||||||
bpath[routelen + 1] = 0;
|
bpath[routelen + 1] = 0;
|
||||||
|
@ -226,18 +178,22 @@ bestownedpath(s_char *bpath,
|
||||||
return NULL; /* no route possible */
|
return NULL; /* no route possible */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return TRUE if sector is passable */
|
/*
|
||||||
|
* Return non-zero if sector X, Y is passable.
|
||||||
|
* If BIGMAP is null, all sectors are passable (useful for flying).
|
||||||
|
* Else it is taken to be a bmap.
|
||||||
|
* Sectors owned by or allied to OWN are checked according to the
|
||||||
|
* usual rules, and the result is correct.
|
||||||
|
* Other sectors are assumed to be passable when BIGMAP shows '.' or
|
||||||
|
* nothing.
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
owned_and_navigable(char *bigmap, int x, int y, char *terrain, int own)
|
owned_and_navigable(char *bigmap, int x, int y, int own)
|
||||||
{
|
{
|
||||||
char *t;
|
char mapspot;
|
||||||
char mapspot; /* What this spot on the bmap is */
|
|
||||||
struct sctstr sect;
|
struct sctstr sect;
|
||||||
int negate;
|
|
||||||
|
|
||||||
/* No terrain to check? Everything is navigable! (this
|
if (!bigmap)
|
||||||
probably means we are flying) */
|
|
||||||
if (!*terrain)
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Owned or allied sector? Check the real sector. */
|
/* Owned or allied sector? Check the real sector. */
|
||||||
|
@ -261,43 +217,6 @@ owned_and_navigable(char *bigmap, int x, int y, char *terrain, int own)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Can only check bigmap */
|
/* Can only check bigmap */
|
||||||
if (bigmap) {
|
|
||||||
/* Do we know what this sector is? If not, we assume it's ok,
|
|
||||||
since otherwise we'll never venture anywhere */
|
|
||||||
mapspot = bigmap[sctoff(x, y)];
|
mapspot = bigmap[sctoff(x, y)];
|
||||||
if (mapspot == ' ' || mapspot == 0)
|
return mapspot == '.' || mapspot == ' ' || mapspot == 0;
|
||||||
return 1;
|
|
||||||
|
|
||||||
/* Now, is it marked with a 'x' or 'X'? If so, avoid it! */
|
|
||||||
if (mapspot == 'x' || mapspot == 'X')
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
/* We don't know what it is since we have no map, so return ok! */
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now, check this bmap entry to see if it is one of the
|
|
||||||
terrain types. */
|
|
||||||
t = terrain;
|
|
||||||
if (*t == '~') {
|
|
||||||
negate = 1;
|
|
||||||
t++;
|
|
||||||
} else
|
|
||||||
negate = 0;
|
|
||||||
|
|
||||||
while (*t) {
|
|
||||||
if (*t == mapspot)
|
|
||||||
break;
|
|
||||||
t++;
|
|
||||||
}
|
|
||||||
if (negate && *t) {
|
|
||||||
/* We found it, so we say it's bad since we are negating */
|
|
||||||
return 0;
|
|
||||||
} else if (!negate && !*t) {
|
|
||||||
/* We didn't find it, so we say it's bad since we aren't negating */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* According to our bmap, this sector is ok. */
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -367,17 +367,17 @@ BestLandPath(s_char *path,
|
||||||
s_char *
|
s_char *
|
||||||
BestShipPath(s_char *path, int fx, int fy, int tx, int ty, int owner)
|
BestShipPath(s_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 */
|
/* need to make sector database available to bestpath */
|
||||||
map = ef_ptr(EF_BMAP, owner);
|
map = ef_ptr(EF_BMAP, owner);
|
||||||
|
if (!map)
|
||||||
return bestownedpath(path, map, fx, fy, tx, ty, ".=h", owner);
|
return NULL;
|
||||||
|
return bestownedpath(path, map, fx, fy, tx, ty, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
s_char *
|
s_char *
|
||||||
BestAirPath(s_char *path, int fx, int fy, int tx, int ty)
|
BestAirPath(s_char *path, int fx, int fy, int tx, int ty)
|
||||||
{
|
{
|
||||||
return bestownedpath(path, 0, fx, fy, tx, ty, "", -1);
|
return bestownedpath(path, 0, fx, fy, tx, ty, -1);
|
||||||
/* return (bestpath(path, fx, fy, tx, ty, "")); */
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue