From 3ca882714da08866e8d082f9e26ece3dce1ea05e Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 16 Aug 2008 21:56:28 -0400 Subject: [PATCH] Fix computation of map buffer indexes The correct method to compute indexes into a map buffer for a struct range is deltx(), delty(). path() used deltax(), deltay() instead, which yield correct results only for indexes up to half the world size. Pathes spanning larger areas were screwed up. sona(), radmap2(), satmap() also used deltax(), deltay(), but only with arguments where those yield correct results. draw_map() used xnorm(), ynorm() instead, which is correct, but less clear and less efficient. --- src/lib/commands/path.c | 2 +- src/lib/commands/sona.c | 4 ++-- src/lib/subs/maps.c | 4 ++-- src/lib/subs/radmap.c | 10 ++-------- src/lib/subs/satmap.c | 8 +------- 5 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/lib/commands/path.c b/src/lib/commands/path.c index b0b0d208..dbeebbb3 100644 --- a/src/lib/commands/path.c +++ b/src/lib/commands/path.c @@ -100,7 +100,7 @@ path(void) i = diridx(*pp); if (i == DIR_STOP) break; - memcpy(&map[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx) * 2], + memcpy(&map[delty(&ns.range, cy)][deltx(&ns.range, cx) * 2], routech[i][0], 3); cx += diroff[i][0]; diff --git a/src/lib/commands/sona.c b/src/lib/commands/sona.c index 5f3f5bf8..c2e22982 100644 --- a/src/lib/commands/sona.c +++ b/src/lib/commands/sona.c @@ -122,8 +122,8 @@ sona(void) } } snxtsct_dist(&ns, ship.shp_x, ship.shp_y, srange); - cx = deltax(ship.shp_x, ns.range.lx); - cy = deltay(ship.shp_y, ns.range.ly); + cx = deltx(&ns.range, ship.shp_x); + cy = delty(&ns.range, ship.shp_y); while (nxtsct(&ns, §)) { if (!line_of_sight(rad, cx, cy, ns.dx, ns.dy)) { rad[ns.dy][ns.dx] = ' '; diff --git a/src/lib/subs/maps.c b/src/lib/subs/maps.c index 4c3ed229..19974b42 100644 --- a/src/lib/subs/maps.c +++ b/src/lib/subs/maps.c @@ -249,8 +249,8 @@ draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp) if (!xyinrange(unit.gen.x, unit.gen.y, &nsp->range)) continue; - x = xnorm(unit.gen.x - nsp->range.lx); - y = ynorm(unit.gen.y - nsp->range.ly); + x = deltx(&nsp->range, unit.gen.x); + y = delty(&nsp->range, unit.gen.y); if (ef_mappable[i] == EF_NUKE) wmap[y][x] = 'N'; diff --git a/src/lib/subs/radmap.c b/src/lib/subs/radmap.c index 04857823..305976cb 100644 --- a/src/lib/subs/radmap.c +++ b/src/lib/subs/radmap.c @@ -175,15 +175,9 @@ radmap2(int owner, * make the center of the display 0 * so ve et al can find it. */ - rad[deltay(cy, ns.range.ly)][deltax(cx, ns.range.lx)] = '0'; - /* won't work for radar maps > WORLD_Y/2 */ -#ifdef HAY - /* This is not correct for small, hitech worlds. */ - n = deltay(ns.range.hy, ns.range.ly); -#else - /* This is already available, so why not use it. */ + rad[delty(&ns.range, cy)][deltx(&ns.range, cx)] = '0'; + n = ns.range.height; -#endif for (row = 0; row < n; row++) pr("%s\n", rad[row]); pr("\n"); diff --git a/src/lib/subs/satmap.c b/src/lib/subs/satmap.c index 9c812499..15113606 100644 --- a/src/lib/subs/satmap.c +++ b/src/lib/subs/satmap.c @@ -240,16 +240,10 @@ satmap(int x, int y, int eff, int range, int flags, int type) * We have to make the center a '0' for ve * ve needs a garbage line to terminate the map */ - rad[deltay(y, ns.range.ly)][deltax(x, ns.range.lx)] = '0'; + rad[delty(&ns.range, y)][deltx(&ns.range, y)] = '0'; pr("Satellite radar report\n"); -#ifdef HAY - /* This is wrong for small, hitech worlds. */ - n = deltay(ns.range.hy, ns.range.ly); -#else - /* This is already available, so why not use it. */ n = ns.range.height; -#endif for (row = 0; row < n; row++) pr("%s\n", rad[row]); pr("\n(c) 1989 Imaginative Images Inc.\n");