Clean up display_region_map()

Without ARG1, display_region_map() formats a rectangular area around
CURX,CURY, so it can use do_map().  Ugly, and duplicates some
unit_map() functionality.

Factor snxtsct_around() out of unit_map().  Inline do_map() into
display_region_map(), so we can use snxtsct_around().

Don't mess with player->condarg.  Leftover from when we abused map()
here.
This commit is contained in:
Markus Armbruster 2011-04-10 19:08:11 +02:00
parent 619b3def31
commit 437f16a4d4

View file

@ -77,6 +77,7 @@ static int draw_map(char, int, struct nstr_sect *);
static int bmnxtsct(struct nstr_sect *); static int bmnxtsct(struct nstr_sect *);
static char map_char(int, natid, int); static char map_char(int, natid, int);
static int unit_map(int, int, struct nstr_sect *, char *); static int unit_map(int, int, struct nstr_sect *, char *);
static void snxtsct_around(struct nstr_sect *, coord, coord);
int int
do_map(int bmap, int unit_type, char *arg1, char *arg2) do_map(int bmap, int unit_type, char *arg1, char *arg2)
@ -402,7 +403,6 @@ static int
unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp) unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp)
{ {
union empobj_storage unit; union empobj_storage unit;
struct range range;
char *name; char *name;
if (CANT_HAPPEN((ef_flags(unit_type) & (EFF_OWNER | EFF_XY)) if (CANT_HAPPEN((ef_flags(unit_type) & (EFF_OWNER | EFF_XY))
@ -421,32 +421,48 @@ unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp)
*originp = *name; *originp = *name;
} }
range.lx = xnorm(unit.gen.x - 10); snxtsct_around(nsp, unit.gen.x, unit.gen.y);
range.hx = xnorm(unit.gen.x + 10); return 0;
range.ly = ynorm(unit.gen.y - 5); }
range.hy = ynorm(unit.gen.y + 5);
static void
snxtsct_around(struct nstr_sect *nsp, coord x, coord y)
{
struct range range;
range.lx = xnorm(x - 10);
range.hx = xnorm(x + 10);
range.ly = ynorm(y - 5);
range.hy = ynorm(y + 5);
xysize_range(&range); xysize_range(&range);
snxtsct_area(nsp, &range); snxtsct_area(nsp, &range);
return 0;
} }
int int
display_region_map(int bmap, int unit_type, coord curx, coord cury, display_region_map(int bmap, int unit_type, coord curx, coord cury,
char *arg1, char *arg2) char *arg1, char *arg2)
{ {
char coordinates[80]; struct nstr_sect ns;
char origin;
int res, map_flags;
if (!arg1 || !*arg1) { if (arg1 && *arg1) {
struct natstr *np; res = parse_map_arg(unit_type, arg1, &ns, &origin);
if (res != RET_OK)
return res;
np = getnatp(player->cnum); map_flags = parse_map_flags(bmap, arg2);
sprintf(coordinates, "%d:%d,%d:%d", if (map_flags < 0)
xrel(np, curx - 10), xrel(np, curx + 10), return RET_SYN;
yrel(np, cury - 5), yrel(np, cury + 5)); } else {
arg1 = coordinates; snxtsct_around(&ns, curx, cury);
map_flags = 0;
origin = 0;
} }
player->condarg = NULL;
return do_map(bmap, unit_type, arg1, arg2); if (map_flags & MAP_BMAP_REVERT)
return revert_bmap(&ns);
return draw_map(origin, map_flags, &ns);
} }
int int