]> git.pond.sub.org Git - empserver/commitdiff
Fix MAPWIDTH() for arguments other than 1
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 20 Aug 2008 01:24:51 +0000 (21:24 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 20 Aug 2008 11:40:51 +0000 (07:40 -0400)
MAPWIDTH(x) was (x+2)/2 - 1 too small.  Affected were path and route,
which use MAPWIDTH(3) to size their map buffer: they clobber map rows'
terminating zero when the map spans the whole world in x.  rout() has
a cheesy work-around for that since Chainsaw 2.  path() doesn't, and
duly breaks.

include/map.h

index 8b3ce398f499191bc8d84b2bbaa9162eb6ef4102..b87a21035fcf54812ff4710165d3831ccddf3d5e 100644 (file)
 
 #include "types.h"
 
-#define        MAPWIDTH(persec) ((WORLD_X/2) * ((persec) + 1) + 1)
+/*
+ * Width of the body of a map using PERSEC characters per sector.
+ *
+ * One row shows WORLD_X/2 sectors, separated by one space.  Requires
+ * WORLD_X/2 * (PERSEC+1) - 1 characters.
+ *
+ * Every other row is indented so that the center of the first sector
+ * is aligned with the space separating the first two sectors in the
+ * adjacent rows.  For odd PERSEC, that's (PERSEC+1)/2 additional
+ * characters.  For even PERSEC, it's either PERSEC/2 or PERSEC/2 + 1,
+ * depending on whether we align the character left or right of the
+ * center with the space (the map will look rather odd either way).
+ *
+ * We need one more character for the terminating zero.
+ */
+#define MAPWIDTH(persec) (WORLD_X/2 * ((persec) + 1) + ((persec) + 2) / 2)
 
 /* src/lib/subs/bigmap.c */
 extern int map_set(natid, coord, coord, char, int);