(WORLD_SZ): New.
(isok, ef_init, bmaps_intersect, bp_init, player_accept) (finish_sects, main): Use it. (bp_neighbors, bp_lbcost, pathcost): Use XYOFFSET(). No functional change.
This commit is contained in:
parent
e24b608dc6
commit
56de7a2151
8 changed files with 18 additions and 16 deletions
|
@ -36,7 +36,10 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
/* Fast version of sctoff() for normalized arguments: */
|
||||
/* Return the number of sectors in the world */
|
||||
#define WORLD_SZ() (WORLD_X * WORLD_Y / 2)
|
||||
|
||||
/* Fast version of sctoff() for normalized arguments */
|
||||
#define XYOFFSET(x, y) (((y) * WORLD_X + (x)) / 2)
|
||||
|
||||
#define XNORM(x) \
|
||||
|
|
|
@ -203,12 +203,12 @@ isok(int x, int y)
|
|||
|
||||
nmin = ngold = noil = nur = 0;
|
||||
navail = nfree = nowned = 0;
|
||||
if ((map = malloc((WORLD_X * WORLD_Y) / 2)) == 0) {
|
||||
if (!(map = malloc(WORLD_SZ()))) {
|
||||
logerror("malloc failed in isok\n");
|
||||
pr("Memory error. Tell the deity.\n");
|
||||
return 0;
|
||||
}
|
||||
memset(map, 0, (WORLD_X * WORLD_Y) / 2);
|
||||
memset(map, 0, WORLD_SZ());
|
||||
ok(map, x, y);
|
||||
free(map);
|
||||
if (nfree < 5)
|
||||
|
|
|
@ -559,7 +559,7 @@ ef_init(void)
|
|||
struct symbol *lup;
|
||||
int i;
|
||||
|
||||
empfile[EF_MAP].size = empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2;
|
||||
empfile[EF_MAP].size = empfile[EF_BMAP].size = WORLD_SZ();
|
||||
|
||||
ca = (struct castr *)empfile[EF_META].cache;
|
||||
for (i = 0; ca[i].ca_name; i++) ;
|
||||
|
|
|
@ -403,7 +403,7 @@ bmaps_intersect(natid a, natid b)
|
|||
char *mapb = ef_ptr(EF_MAP, b);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < WORLD_X * WORLD_Y / 2; ++i, ++mapa, ++mapb)
|
||||
for (i = 0; i < WORLD_SZ(); ++i, ++mapa, ++mapb)
|
||||
if (*mapa && *mapa != ' ' && *mapb && *mapb != ' ')
|
||||
return 1;
|
||||
return 0;
|
||||
|
|
|
@ -83,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;
|
||||
}
|
||||
|
@ -193,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 = §p[offset];
|
||||
|
||||
if (neighsects == NULL)
|
||||
|
@ -207,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 = §p[offset];
|
||||
*ssp = sp;
|
||||
} else {
|
||||
|
@ -246,7 +245,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(§p[offset], bp->bp_mobtype);
|
||||
}
|
||||
|
||||
|
@ -327,7 +326,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 = §p[offset];
|
||||
cost += sector_mcost(sp, mob_type);
|
||||
path++;
|
||||
|
|
|
@ -219,9 +219,9 @@ player_accept(void *unused)
|
|||
if (NULL != hostp)
|
||||
strcpy(np->hostname, hostp->h_name);
|
||||
#endif /* RESOLVE_IPADDRESS */
|
||||
/* XXX may not be big enough */
|
||||
/* FIXME ancient black magic; figure out true stack need */
|
||||
stacksize = 100000
|
||||
/* budget */ + MAX(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7,
|
||||
/* budget */ + MAX(WORLD_SZ() * sizeof(int) * 7,
|
||||
/* power */ MAXNOC * sizeof(struct powstr));
|
||||
sprintf(buf, "Player (fd #%d)", ns);
|
||||
empth_create(player_login, stacksize, 0, buf, np);
|
||||
|
|
|
@ -77,7 +77,7 @@ finish_sects(int etu)
|
|||
if (g_distptrs == NULL) {
|
||||
logerror("First update since reboot, allocating buffer\n");
|
||||
/* Allocate the information buffer */
|
||||
g_distptrs = malloc((WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs));
|
||||
g_distptrs = malloc(WORLD_SZ() * sizeof(*g_distptrs));
|
||||
if (g_distptrs == NULL) {
|
||||
logerror("malloc failed in finish_sects.\n");
|
||||
return;
|
||||
|
@ -85,7 +85,7 @@ finish_sects(int etu)
|
|||
}
|
||||
|
||||
/* Wipe it clean */
|
||||
memset(g_distptrs, 0, (WORLD_X * WORLD_Y / 2) * sizeof(*g_distptrs));
|
||||
memset(g_distptrs, 0, WORLD_SZ() * sizeof(*g_distptrs));
|
||||
|
||||
logerror("delivering...\n");
|
||||
/* Do deliveries */
|
||||
|
|
|
@ -196,7 +196,7 @@ main(int argc, char *argv[])
|
|||
putsect(&sct);
|
||||
}
|
||||
}
|
||||
map = calloc(WORLD_X * WORLD_Y / 2, sizeof(*map));
|
||||
map = calloc(WORLD_SZ(), sizeof(*map));
|
||||
for (i = 0; i < MAXNOC; i++) {
|
||||
ef_write(EF_MAP, i, map);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue