Beispiel #1
0
/*
 * 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;
}
Beispiel #2
0
static void
list_realm(int curr, struct natstr *natp)
{
    struct realmstr realm;

    getrealm(curr, natp->nat_cnum, &realm);
    pr("Realm #%d is %d:%d,%d:%d\n", curr,
       xrel(natp, realm.r_xl), xrel(natp, realm.r_xh),
       yrel(natp, realm.r_yl), yrel(natp, realm.r_yh));
}
Beispiel #3
0
int
real(void)
{
    struct realmstr realm;
    struct natstr *natp;
    int curr;
    int lastr;
    struct range abs;
    char *realmp = player->argp[1];

    natp = getnatp(player->cnum);
    if (!realmp) {
	curr = 0;
	lastr = MAXNOR - 1;
    } else {
	if (*realmp == '#')
	    ++realmp;
	if (*realmp && !isdigit(*realmp))
	    return RET_SYN;
	curr = lastr = atoi(realmp);
	if (curr < 0 || curr >= MAXNOR) {
	    pr("Realm number must be in the range 0:%d\n", MAXNOR - 1);
	    return RET_SYN;
	}
    }
    if (!player->argp[2]) {
	while (curr <= lastr) {
	    list_realm(curr, natp);
	    curr++;
	}
    } else {
	if (sarg_type(player->argp[2]) != NS_AREA)
	    return RET_SYN;
	abs.width = 0;
	abs.height = 0;
	if (!sarg_area(player->argp[2], &abs))
	    return RET_SYN;
	getrealm(curr, natp->nat_cnum, &realm);
	realm.r_xl = abs.lx;
	realm.r_xh = abs.hx;
	realm.r_yl = abs.ly;
	realm.r_yh = abs.hy;
	putrealm(&realm);
	list_realm(curr, natp);
    }
    return RET_OK;
}