Indented with src/scripts/indent-emp.

This commit is contained in:
Markus Armbruster 2003-09-02 20:48:48 +00:00
parent 5f263a7753
commit 9b7adfbecc
437 changed files with 52211 additions and 51052 deletions

View file

@ -53,9 +53,9 @@
#include "common.h"
#include "optlist.h"
static int owned_and_navigable(s_char * , int , int , s_char * , int );
static int owned_and_navigable(s_char *, int, int, s_char *, int);
#define MAXROUTE 100 /* return '?' if path longer than this */
#define MAXROUTE 100 /* return '?' if path longer than this */
#define valid(x,y) (((x^y)&1)==0)
/* ________________________________________________________________
@ -106,9 +106,9 @@ static int owned_and_navigable(s_char * , int , int , s_char * , int );
** ________________________________________________________________
*/
s_char *dirchar = "juygbn";
int dx[6] = { 2, 1,-1,-2,-1, 1 };
int dy[6] = { 0,-1,-1, 0, 1, 1 };
s_char *dirchar = "juygbn";
int dx[6] = { 2, 1, -1, -2, -1, 1 };
int dy[6] = { 0, -1, -1, 0, 1, 1 };
int tmp;
/*
@ -125,198 +125,196 @@ int tmp;
static unsigned int *mapbuf = (unsigned int *)0;
static unsigned int **mapindex = (unsigned int **)0;
s_char *bestownedpath(s_char *bpath,
s_char *bigmap,
int x,
int y,
int ex,
int ey,
s_char *terrain,
int own)
s_char *
bestownedpath(s_char *bpath,
s_char *bigmap,
int x, int y, int ex, int ey, s_char *terrain, int own)
{
int i, j, tx, ty, markedsectors, restr2;
int minx, maxx, miny, maxy, scanx, scany;
unsigned int routelen;
int i, j, tx, ty, markedsectors, restr2;
int minx, maxx, miny, maxy, scanx, scany;
unsigned int routelen;
if (!mapbuf)
mapbuf = (unsigned int *)malloc((WORLD_X * WORLD_Y) *
sizeof(unsigned int));
if (!mapbuf)
return ((s_char *)0);
if (!mapindex) {
mapindex = (unsigned int **)malloc(WORLD_X * sizeof(unsigned int *));
if (mapindex) {
/* Setup the map pointers */
for (i = 0; i < WORLD_X; i++)
mapindex[i] = &mapbuf[WORLD_Y * i];
}
}
if (!mapindex)
return ((s_char *)0);
bpath[0] = 0;
if (0 != (restr2 = (*terrain == 'R')))
terrain++;
x = XNORM(x);
y = YNORM(y);
ex = XNORM(ex);
ey = YNORM(ey);
if (x == ex && y == ey) {
bpath[0] = 'h';
bpath[1] = 0;
return ((s_char *)bpath);
}
if (!valid(x,y) || !valid(ex,ey))
return((s_char *)0);
if (restr2 && (!owned_and_navigable(bigmap, x, y, terrain, own) ||
!owned_and_navigable(bigmap, x, y, terrain, own)))
return ((s_char *)0);
for (i = 0; i < WORLD_X; i++)
for (j = 0; j < WORLD_Y; j++)
mapindex[i][j] = 0xFFFF; /* clear the workspace */
routelen = 0; /* path length is now 0 */
mapindex[x][y] = 0; /* mark starting spot */
markedsectors = 1; /* source sector marked */
minx = x - 2; /* set X scan bounds */
maxx = x + 2;
miny = y - 1; /* set Y scan bounds */
maxy = y + 1;
do {
if (++routelen == MAXROUTE) {
bpath[0] = '?';
bpath[1] = 0;
return ((s_char *)bpath);
}
markedsectors = 0;
for (scanx = minx; scanx <= maxx; scanx++) {
x = XNORM(scanx);
for (scany = miny; scany <= maxy; scany++) {
y = YNORM(scany);
if (valid(x,y)) {
if ((((mapindex[x][y]) & 0x1FFF) == (routelen - 1))) {
for (i = 0; i < 6; i++) {
tx = x + dx[i];
ty = y + dy[i];
tx = XNORM(tx);
ty = YNORM(ty);
if (mapindex[tx][ty] == 0xFFFF) {
if (owned_and_navigable(bigmap, tx, ty, terrain, own) ||
(tx == ex && ty == ey && !restr2) ) {
mapindex[tx][ty] = ((i + 1) << 13) + routelen;
markedsectors++;
}
}
if (tx == ex && ty == ey) {
bpath[routelen] = 0;
while (routelen--) {
i = ((mapindex[tx][ty]) >> 13) - 1;
bpath[routelen] = dirchar[i];
tx = tx - dx[i];
ty = ty - dy[i];
tx = XNORM(tx);
ty = YNORM(ty);
}
return((s_char *)bpath);
}
}
}
if (!mapbuf)
mapbuf = (unsigned int *)malloc((WORLD_X * WORLD_Y) *
sizeof(unsigned int));
if (!mapbuf)
return ((s_char *)0);
if (!mapindex) {
mapindex =
(unsigned int **)malloc(WORLD_X * sizeof(unsigned int *));
if (mapindex) {
/* Setup the map pointers */
for (i = 0; i < WORLD_X; i++)
mapindex[i] = &mapbuf[WORLD_Y * i];
}
}
}
miny--;
maxy++;
minx -= 2;
maxx += 2;
} while (markedsectors);
if (!mapindex)
return ((s_char *)0);
bpath[0] = 0;
return((s_char *)0); /* no route possible */
bpath[0] = 0;
if (0 != (restr2 = (*terrain == 'R')))
terrain++;
x = XNORM(x);
y = YNORM(y);
ex = XNORM(ex);
ey = YNORM(ey);
if (x == ex && y == ey) {
bpath[0] = 'h';
bpath[1] = 0;
return ((s_char *)bpath);
}
if (!valid(x, y) || !valid(ex, ey))
return ((s_char *)0);
if (restr2 && (!owned_and_navigable(bigmap, x, y, terrain, own) ||
!owned_and_navigable(bigmap, x, y, terrain, own)))
return ((s_char *)0);
for (i = 0; i < WORLD_X; i++)
for (j = 0; j < WORLD_Y; j++)
mapindex[i][j] = 0xFFFF; /* clear the workspace */
routelen = 0; /* path length is now 0 */
mapindex[x][y] = 0; /* mark starting spot */
markedsectors = 1; /* source sector marked */
minx = x - 2; /* set X scan bounds */
maxx = x + 2;
miny = y - 1; /* set Y scan bounds */
maxy = y + 1;
do {
if (++routelen == MAXROUTE) {
bpath[0] = '?';
bpath[1] = 0;
return ((s_char *)bpath);
}
markedsectors = 0;
for (scanx = minx; scanx <= maxx; scanx++) {
x = XNORM(scanx);
for (scany = miny; scany <= maxy; scany++) {
y = YNORM(scany);
if (valid(x, y)) {
if ((((mapindex[x][y]) & 0x1FFF) == (routelen - 1))) {
for (i = 0; i < 6; i++) {
tx = x + dx[i];
ty = y + dy[i];
tx = XNORM(tx);
ty = YNORM(ty);
if (mapindex[tx][ty] == 0xFFFF) {
if (owned_and_navigable
(bigmap, tx, ty, terrain, own)
|| (tx == ex && ty == ey && !restr2)) {
mapindex[tx][ty] =
((i + 1) << 13) + routelen;
markedsectors++;
}
}
if (tx == ex && ty == ey) {
bpath[routelen] = 0;
while (routelen--) {
i = ((mapindex[tx][ty]) >> 13) - 1;
bpath[routelen] = dirchar[i];
tx = tx - dx[i];
ty = ty - dy[i];
tx = XNORM(tx);
ty = YNORM(ty);
}
return ((s_char *)bpath);
}
}
}
}
}
}
miny--;
maxy++;
minx -= 2;
maxx += 2;
} while (markedsectors);
bpath[0] = 0;
return ((s_char *)0); /* no route possible */
}
/* return TRUE if sector is passable */
static int
owned_and_navigable(s_char *map, int x, int y, s_char *terrain, int own)
{
s_char c;
s_char *t;
s_char mapspot; /* What this spot on the bmap is */
int negate;
struct sctstr *sect;
int rel;
s_char c;
s_char *t;
s_char mapspot; /* What this spot on the bmap is */
int negate;
struct sctstr *sect;
int rel;
/* No terrain to check? Everything is navigable! (this
probably means we are flying) */
if (!(*terrain))
return (1);
/* No terrain to check? Everything is navigable! (this
probably means we are flying) */
if (!(*terrain))
return (1);
/* Are we checking this map? */
if (map) {
/* Do we know what this sector is? If not, we assume it's ok,
since otherwise we'll never venture anywhere */
mapspot = map[sctoff(x, y)];
if (mapspot == ' ' || mapspot == 0)
/* Are we checking this map? */
if (map) {
/* Do we know what this sector is? If not, we assume it's ok,
since otherwise we'll never venture anywhere */
mapspot = map[sctoff(x, y)];
if (mapspot == ' ' || mapspot == 0)
return (1);
/* Now, is it marked with a 'x' or 'X'? If so, avoid it! */
if (mapspot == 'x' || mapspot == 'X')
/* 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;
} else {
/* We don't know what it is since we have no map, so return ok! */
return (1);
}
while (*t) {
if (*t == mapspot)
/* 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);
}
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 so far. */
/* According to our bmap, this sector is ok so far. */
/* Ok, we made it this far. Now get the sector */
sect = getsectp(x, y);
c = dchr[sect->sct_type].d_mnem;
/* Ok, now, check the owner if needed */
if (own >= 0) {
if (sect->sct_own != own) {
/* Ok, we made it this far. Now get the sector */
sect = getsectp(x, y);
c = dchr[sect->sct_type].d_mnem;
/* Ok, now, check the owner if needed */
if (own >= 0) {
if (sect->sct_own != own) {
rel = getrel(getnatp(sect->sct_own), own);
/* We can't sail through deity sectors, but we can sail
through any ocean */
if (rel < FRIENDLY && sect->sct_type != SCT_WATER)
return (0);
}
return (0);
}
/* Ok, now, check these two sector types */
/* check for bad harbors. */
if (c == 'h' && sect->sct_effic < 2)
return (0);
/* check for bad bridges */
if (c == '=' && sect->sct_effic < 60)
return (0);
/* Woo-hoo, it's ok! */
return (1);
}
/* Ok, now, check these two sector types */
/* check for bad harbors. */
if (c == 'h' && sect->sct_effic < 2)
return (0);
/* check for bad bridges */
if (c == '=' && sect->sct_effic < 60)
return (0);
/* Woo-hoo, it's ok! */
return (1);
}