/* * translate #1 or lx:ly,hx:hy into a result range struct * returns absolute coords */ int sarg_area(char *str, struct range *rp) { long rlm; struct natstr *np; struct realmstr realm; char *end; if (*str == '#') { /* * realm #X where (X > 0 && X < MAXNOR) * Assumes realms are in abs coordinates */ if (*++str) { rlm = strtol(str, &end, 10); if (end == str || (*end != 0 && !isspace(*end)) || rlm < 0 || MAXNOR <= rlm) return 0; } else rlm = 0; getrealm(rlm, player->cnum, &realm); rp->lx = realm.r_xl; rp->hx = realm.r_xh; rp->ly = realm.r_yl; rp->hy = realm.r_yh; } else { /* * full map specification * LX:LY,HX:HY where * ly, hy are optional. */ rp->lx = rp->hx = strtox(str, &str); if (rp->lx < 0) return 0; if (*str == ':') { rp->hx = strtox(str + 1, &str); if (rp->hx < 0) return 0; } if (*str++ != ',') return 0; rp->ly = rp->hy = strtoy(str, &str); if (rp->ly < 0) return 0; if (*str == ':') { rp->hy = strtoy(str + 1, &str); if (rp->hy < 0) return 0; } if (*str != 0 && !isspace(*str)) return 0; np = getnatp(player->cnum); rp->lx = xabs(np, rp->lx); rp->hx = xabs(np, rp->hx); rp->ly = yabs(np, rp->ly); rp->hy = yabs(np, rp->hy); } xysize_range(rp); return 1; }
void snxtsct_all(struct nstr_sect *np) { struct range worldrange; worldrange.lx = 0; worldrange.ly = 0; worldrange.hx = WORLD_X - 1; worldrange.hy = WORLD_Y - 1; xysize_range(&worldrange); snxtsct_area(np, &worldrange); }
/* * setup the nstr_sect structure for sector selection. * can select on either NS_ALL, NS_AREA, or NS_DIST * iterate thru the "condarg" string looking * for arguments to compile into the nstr. * Using this function for anything but command arguments is usually * incorrect, because it respects conditionals. Use the snxtsct_FOO() * instead. */ int snxtsct(struct nstr_sect *np, char *str) { struct range range; struct natstr *natp; coord cx, cy; int dist; char buf[1024]; if (!str || !*str) { if (!(str = getstring("(sects)? ", buf))) return 0; } else make_stale_if_command_arg(str); switch (sarg_type(str)) { case NS_AREA: if (!sarg_area(str, &range)) return 0; snxtsct_area(np, &range); break; case NS_DIST: if (!sarg_range(str, &cx, &cy, &dist)) return 0; snxtsct_dist(np, cx, cy, dist); break; case NS_ALL: /* * Can't use snxtsct_all(), as it would disclose the real * origin. Use a world-sized area instead. */ natp = getnatp(player->cnum); range.lx = xabs(natp, -WORLD_X / 2); range.ly = yabs(natp, -WORLD_Y / 2); range.hx = xnorm(range.lx + WORLD_X - 1); range.hy = ynorm(range.ly + WORLD_Y - 1); xysize_range(&range); snxtsct_area(np, &range); break; default: return 0; } return snxtsct_use_condarg(np); }