/* Note we will only allocate this once. Afterwards, we just keep
* zeroing it since it's rather small and we don't need to re-allocate
* each time. */
- if (fromhead == (struct as_frompath **)0) {
+ if (fromhead == NULL) {
fromhead = calloc(1, sizeof(struct as_frompath *) * WORLD_Y);
- if (fromhead == (struct as_frompath **)0)
+ if (fromhead == NULL)
return;
}
int i, j;
/* Cache not used yet :) */
- if (fromhead == (struct as_frompath **)0)
+ if (fromhead == NULL)
return;
for (j = 0; j < WORLD_Y; j++) {
return NULL;
/* Do we have any cached? */
- if (fromhead == (struct as_frompath **)0)
+ if (fromhead == NULL)
return NULL;
/* Yes! */
if (s2.sct_own != player->cnum)
continue;
s = BestLandPath(buf, &s1, &s2, &cost, MOB_ROAD);
- if (s != (s_char *)0)
+ if (s)
pr("Best path from %s to %s is %s (cost %1.3f)\n",
xyas(s1.sct_x, s1.sct_y, player->cnum),
xyas(s2.sct_x, s2.sct_y, player->cnum), s, cost);
pr("some %s\n", ip->i_name);
}
for (;;) {
- ip = whatitem((s_char *)0, "commodity to bomb? ");
+ ip = whatitem(NULL, "commodity to bomb? ");
if (player->aborted)
return;
if (!ip)
path = BestDistPath(buf, §, &dsect, &move_cost, MOB_ROAD);
- if (path == (s_char *)0) {
+ if (!path) {
pr("No owned path from %s to %s.\n",
xyas(dsect.sct_x, dsect.sct_y, player->cnum),
xyas(sect.sct_x, sect.sct_y, player->cnum));
int i;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
- static u_char *bitmap = (u_char *)0;
- static s_char *wmapbuf = (s_char *)0;
- static s_char **wmap = (s_char **)0;
+ static u_char *bitmap = NULL;
+ static s_char *wmapbuf = NULL;
+ static s_char **wmap = NULL;
s_char what[64];
int changed = 0;
wmap[i] = &wmapbuf[MAPWIDTH(1) * i];
} else if (wmap) {
free(wmap);
- wmap = (s_char **)0;
+ wmap = NULL;
}
}
if (!bitmap)
s_char *pp, *p;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
- static s_char *mapbuf = (s_char *)0;
- static s_char **map = (s_char **)0;
+ static s_char *mapbuf = NULL;
+ static s_char **map = NULL;
double move_cost;
s_char buf[1024];
}
getsect(sect.sct_dist_x, sect.sct_dist_y, &dsect);
pp = BestDistPath(buf, §, &dsect, &move_cost, MOB_ROAD);
- if (pp == (s_char *)0) {
+ if (!pp) {
pr("No path possible from %s to distribution sector %s\n",
xyas(sect.sct_x, sect.sct_y, player->cnum),
xyas(dsect.sct_x, dsect.sct_y, player->cnum));
map[i] = &mapbuf[MAPWIDTH(3) * i];
} else if (map) {
free(map);
- map = (s_char **)0;
+ map = NULL;
}
}
if (!mapbuf || !map) {
if (player->argp[2] != NULL)
pq = getstarg(player->argp[2], "Retreat path? ", buf1);
else
- pq = (s_char *)0;
+ pq = NULL;
- if (pq != (s_char *)0) {
+ if (pq != NULL) {
fl = getstarg(player->argp[3],
"Retreat conditions [i|t|s|h|b|d|u|c]? ", buf2);
if (!fl)
}
if (rflags == -1)
- pq = (s_char *)0;
+ pq = NULL;
zero = (rflags == -1);
if (zero)
if (zero)
memset(ship.shp_rpath, 0, sizeof(ship.shp_rpath));
- if (pq != (s_char *)0) {
+ if (pq != NULL) {
strncpy(ship.shp_rpath, pq, sizeof(ship.shp_rpath));
putship(ship.shp_uid, &ship);
}
if (player->argp[2] != NULL)
pq = getstarg(player->argp[2], "Retreat path? ", buf1);
else
- pq = (s_char *)0;
- if (pq != (s_char *)0) {
+ pq = NULL;
+ if (pq != NULL) {
fl = getstarg(player->argp[3], "Retreat conditions [i|h|b|c]? ",
buf2);
if (!fl)
}
if (rflags == -1)
- pq = (s_char *)0;
+ pq = NULL;
zero = (rflags == -1);
if (zero)
if (zero)
memset(land.lnd_rpath, 0, sizeof(land.lnd_rpath));
- if (pq != (s_char *)0) {
+ if (pq != NULL) {
strncpy(land.lnd_rpath, pq, sizeof(land.lnd_rpath));
putland(land.lnd_uid, &land);
}
s_char buf1[1024];
/* Note this is not re-entrant anyway, so we keep the buffers
around */
- static s_char *mapbuf = (s_char *)0;
- static s_char **map = (s_char **)0;
- static s_char *buf = (s_char *)0;
+ static s_char *mapbuf = NULL;
+ static s_char **map = NULL;
+ static s_char *buf = NULL;
int i;
if ((ip = whatitem(player->argp[1], "What item? ")) == 0)
map[i] = &mapbuf[MAPWIDTH(3) * i];
} else if (map) {
free(map);
- map = (s_char **)0;
+ map = NULL;
}
}
if (!buf)
s_char buf[1024];
/* Note this is not re-entrant anyway, so we keep the buffers
around */
- static s_char *mapbuf = (s_char *)0;
- static s_char **map = (s_char **)0;
+ static s_char *mapbuf = NULL;
+ static s_char **map = NULL;
nsect = 0;
if (player->argp[1] == NULL) {
map[i] = &mapbuf[MAPWIDTH(1) * i];
} else if (map) {
free(map);
- map = (s_char **)0;
+ map = NULL;
}
}
if (!mapbuf || !map) {
s_char *str;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
- static s_char *mapbuf = (s_char *)0;
- static s_char **map = (s_char **)0;
+ static s_char *mapbuf = NULL;
+ static s_char **map = NULL;
nsect = 0;
if ((ptr = getstarg(player->argp[1], "commodity or variable? ", buf)) == 0)
map[i] = &mapbuf[MAPWIDTH(1) * i];
} else if (map) {
free(map);
- map = (s_char **)0;
+ map = NULL;
}
}
if (!mapbuf || !map) {
sprintf(prompt, "%s %d%% %s territory? ",
xyas(nstr.x, nstr.y, player->cnum),
sect.sct_effic, dchr[sect.sct_type].d_name);
- if ((p = getstarg((s_char *)0, prompt, buf)) == 0)
+ if ((p = getstarg(NULL, prompt, buf)) == 0)
return RET_FAIL;
if (!check_sect_ok(§))
return RET_FAIL;
* would be slow. And, since world size only changes at init
* time, we can do this safely.
*/
-static unsigned int *mapbuf = (unsigned int *)0;
-static unsigned int **mapindex = (unsigned int **)0;
+static unsigned int *mapbuf;
+static unsigned int **mapindex;
s_char *
bestownedpath(s_char *bpath,
int i;
/* Note this is not re-entrant anyway, so we keep the buffers
around */
- static u_char *bitmap = (u_char *)0;
- static s_char *wmapbuf = (s_char *)0;
- static s_char **wmap = (s_char **)0;
+ static u_char *bitmap = NULL;
+ static s_char *wmapbuf = NULL;
+ static s_char **wmap = NULL;
if (!wmapbuf)
wmapbuf = malloc((WORLD_Y * MAPWIDTH(1)) * sizeof(s_char));
wmap[i] = &wmapbuf[MAPWIDTH(1) * i];
} else if (wmap) {
free(wmap);
- wmap = (s_char **)0;
+ wmap = NULL;
}
}
if (!bitmap)
if (bp->adp == NULL)
return NULL;
- if (neighsects == (struct sctstr **)0)
+ if (neighsects == NULL)
neighsects = calloc(((WORLD_X * WORLD_Y) / 2) * 6,
sizeof(struct sctstr *));
offset = (sy * WORLD_X + sx) / 2;
from = §p[offset];
- if (neighsects == (struct sctstr **)0)
+ if (neighsects == NULL)
ssp = (struct sctstr **)&tsp[0];
else
ssp = (struct sctstr **)&neighsects[offset * 6];
for (q = 1; q <= 6; q++, ssp++) {
- if (*ssp == (struct sctstr *)0) {
+ if (*ssp == NULL) {
/* We haven't cached this neighbor yet */
nx = x + diroff[q][0];
ny = y + diroff[q][1];
*path = 0;
*cost = 0.0;
if (best_path(from, to, path, mob_type) < 0)
- return (s_char *)0;
+ return NULL;
*cost = pathcost(from, path, mob_type);
length = strlen(path);
path[length] = 'h';
void
emp_remque(struct emp_qelem *elem)
{
- if (elem == (struct emp_qelem *)0)
+ if (!elem)
return;
- if (elem->q_forw != (struct emp_qelem *)0)
+ if (elem->q_forw)
elem->q_forw->q_back = elem->q_back;
- if (elem->q_back != (struct emp_qelem *)0)
+ if (elem->q_back)
elem->q_back->q_forw = elem->q_forw;
}
* Procedure: find the biggest unit remaining (in
* terms of mil) and give it the casualties.
*/
- biggest = (struct emp_qelem *)0;
+ biggest = NULL;
biggest_mil = -1;
for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) {
llp = (struct llist *)qp;
biggest = qp;
}
}
- if (biggest == (struct emp_qelem *)0)
+ if (biggest == NULL)
return CASUALTY_LUMP - to_take;
llp = (struct llist *)biggest;
pr("Looking for best path to %s\n", path);
path = BestLandPath(buf2, start, &ending_sect, &total_mcost,
MOB_ROAD);
- if (exploring && (path != (s_char *)0)) /* take off the 'h' */
- *(path + strlen(path) - 1) = '\0';
- if (path == (s_char *)0)
+ if (exploring && path) /* take off the 'h' */
+ path[strlen(path) - 1] = '\0';
+ if (!path)
pr("No owned path exists!\n");
else {
pr("Using best path '%s', movement cost %1.3f\n",
for (;;) {
oldx = curx;
oldy = cury;
- if (movstr == 0 || *movstr == 0) {
+ if (!movstr || *movstr == 0) {
if (exploring) {
- map(what, curx, cury, (s_char *)0);
+ map(what, curx, cury, NULL);
} else {
- move_map(what, curx, cury, (s_char *)0);
+ move_map(what, curx, cury, NULL);
}
sprintf(prompt, "<%.1f: %c %s> ", mobility,
dchr[sect.sct_type].d_mnem,
MOB_ROAD);
} else {
pr("Invalid destination sector!\n");
- movstr = (s_char *)0;
+ movstr = NULL;
}
- if (movstr == (s_char *)0) {
+ if (movstr == NULL) {
pr("Can't get to %s from here!\n",
xyas(dx, dy, player->cnum));
- movstr = (s_char *)0;
} else {
if ((mv_cost * weight) > mobility) {
pr("Not enough mobility to go all the way. Nothing moved.\n");
- movstr = (s_char *)0;
+ movstr = NULL;
} else {
pr("Using best path '%s', movement cost %1.3f\n",
movstr, mv_cost);
}
}
}
- if (movstr == 0 || *movstr == 0) {
+ if (!movstr || *movstr == 0) {
buf2[0] = dirch[DIR_STOP];
buf2[1] = 0;
movstr = buf2;
continue;
if (sect.sct_effic < 60)
continue;
- if (BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD) ==
- (s_char *)0)
+ if (!BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD))
continue;
if (!opt_NOFOOD && type == I_FOOD) {
minimum = 2 + ((etu_per_update * eatrate)
continue;
if (sect.sct_effic < 2)
continue;
- if (BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD) ==
- (s_char *)0)
+ if (!BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD))
continue;
if (!opt_NOFOOD && type == I_FOOD)
minimum = 2 + ((etu_per_update * eatrate)
continue;
getsect(land.lnd_x, land.lnd_y, §);
- if (BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD) ==
- (s_char *)0)
+ if (!BestLandPath(buf, &dest, §, &move_cost, MOB_ROAD))
continue;
if ((land.lnd_ship >= 0) && (sect.sct_type != SCT_HARBR))
if ((sp->sct_dist_x == sp->sct_x) && (sp->sct_dist_y == sp->sct_y))
return 0;
- if (path == (s_char *)0) {
+ if (!path) {
if (sp->sct_own != 0) {
if (imex == EXPORT) /* only want this once */
wu(0, sp->sct_own, "No path to dist sector for %s\n",
int n;
struct distinfo *infptr;
- if (g_distptrs == (struct distinfo *)0) {
+ if (g_distptrs == NULL) {
logerror("First update since reboot, allocating buffer\n");
/* Allocate the information buffer */
g_distptrs = (struct distinfo *)(malloc((WORLD_X * WORLD_Y) *
sizeof(struct distinfo)));
- if (g_distptrs == (struct distinfo *)0) {
+ if (g_distptrs == NULL) {
logerror("malloc failed in finish_sects.\n");
return;
}
infptr = &distptrs[XYOFFSET(sp->sct_x, sp->sct_y)];
/* now, get the dist sector */
dist = getsectp(sp->sct_dist_x, sp->sct_dist_y);
- if (dist == (struct sctstr *)0) {
+ if (dist == NULL) {
logerror("Bad dist sect %d,%d for %d,%d !\n", sp->sct_dist_x,
sp->sct_dist_y, sp->sct_x, sp->sct_y);
continue;
path = BestDistPath(buf, dist, sp, &d, MOB_ROAD);
/* Now, we have a path */
- if (path != (s_char *)0) {
+ if (path != NULL) {
#ifdef SAVE_FINISH_PATHS
int len;
/* Here we malloc a buffer and save it */
len = strlen(path);
infptr->path = malloc(len);
- if (infptr->path == (s_char *)0) {
+ if (infptr->path == NULL) {
logerror("malloc failed in assemble_dist_path!\n");
return;
}
static s_char new_path[512];
int ind;
- if (path == (s_char *)0)
- return (s_char *)0;
+ if (path == NULL)
+ return NULL;
ind = strlen(path);
if (ind == 0)
- return (s_char *)0;
+ return NULL;
if (path[ind - 1] == 'h')
ind--;
bp = calloc(WORLD_X * WORLD_Y * 7, sizeof(int));
for (n = 0; n < MAXNOC; n++) {
money[n] = 0;
- if ((np = getnatp(n)) == (struct natstr *)0)
+ if (!(np = getnatp(n)))
continue;
money[n] = np->nat_money;
tpops[n] = count_pop(n);
memset(p_sect, 0, sizeof(p_sect));
mil_dbl_pay = 0;
- if ((np = getnatp(x)) == (struct natstr *)0)
+ if (!(np = getnatp(x)))
continue;
if (np->nat_stat == STAT_SANCT) {
#ifdef DEBUG
np->cur++;
}
gp = ef_ptr(np->type, np->cur);
- if (gp == (struct genitem *)0)
+ if (!gp)
return 0;
selected = 1;
}
onship = 0;
- shp = (struct shpstr *)0;
+ shp = NULL;
if (pp->pln_ship >= 0 && (buildem == 1)) {
if (pp->pln_effic >= 80)
continue;