(deli): Partial rewrite for clarity, motivated by a `might be used

unitialized' warning.  Funcional change: you can now change direction
without threshold (matches documentation, clarify it anyway).  Change
prompt for the third argument to reflect that.  Also provide context
when prompting for the fourth argument; this is sorely needed we
didn't prompt for the third argument.
This commit is contained in:
Markus Armbruster 2004-02-18 21:00:13 +00:00
parent cb23a7e5b0
commit c5915737b6
2 changed files with 35 additions and 20 deletions

View file

@ -1,7 +1,10 @@
.TH Command DELIVER
.NA deliver "Establish delivery routes for shells, ore, etc"
.LV Expert
.SY "deliver <COMM> <SECTS> [q|<THRESH>] [<DIR>]"
.SY "deliver <COMM> <SECTS> <THRESH> <DIR>"
.SY "deliver <COMM> <SECTS> +<THRESH>"
.SY "deliver <COMM> <SECTS> <DIR>"
.SY "deliver <COMM> <SECTS> q"
.s1
An example of using deliver in addition to distribute is where
you may have a mine which uses distribute to get its food

View file

@ -49,7 +49,7 @@ deli(void)
struct sctstr sect;
register int dir, del;
register struct ichrstr *ich;
register int thresh = -1;
register int thresh;
int i_del;
int sx, sy;
int status;
@ -73,27 +73,37 @@ deli(void)
while (nxtsct(&nstr, &sect) > 0) {
if (!player->owner)
continue;
sprintf(prompt, "%s %s 'query' or %s threshold? ",
del = getvar(i_del, (s_char *)&sect, EF_SECTOR);
thresh = del & ~0x7;
dir = del & 0x7;
sprintf(prompt, "%s %s %s threshold or direction or 'query'? ",
xyas(nstr.x, nstr.y, player->cnum),
dchr[sect.sct_type].d_name, ich->i_name);
if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
return RET_SYN;
del = getvar(i_del, (s_char *)&sect, EF_SECTOR);
if (((*p >= '0') && (*p <= '9')) || *p == '+') {
thresh = atoi(p) & ~0x7;
if (*p == '+'
|| !(p = getstarg(player->argp[4], "Direction? ", buf))
|| !*p)
dir = del & 0x7;
else if ((dir = chkdir(*p, DIR_STOP, DIR_LAST)) < 0)
return RET_SYN;
} else if (*p != 'q')
return RET_SYN;
if (*p != 'q') {
sprintf(prompt, "%s %s %s direction? ",
xyas(nstr.x, nstr.y, player->cnum),
dchr[sect.sct_type].d_name, ich->i_name);
if (((*p >= '0') && (*p <= '9')) || *p == '+') {
thresh = atoi(p) & ~0x7;
if (*p == '+')
p = NULL;
else {
p = getstarg(player->argp[4], prompt, buf);
}
}
if (p && *p) {
dir = chkdir(*p, DIR_STOP, DIR_LAST);
if (dir < 0)
return RET_SYN;
}
if (!check_sect_ok(&sect))
continue;
if (!check_sect_ok(&sect))
continue;
if (thresh >= 0) {
del = thresh + dir;
status = putvar(i_del, del, (s_char *)&sect, EF_SECTOR);
if (status < 0) {
@ -106,9 +116,10 @@ deli(void)
} else
putsect(&sect);
}
if (!del)
continue;
dir = del & 0x7;
sx = diroff[dir][0] + sect.sct_x;
sy = diroff[dir][1] + sect.sct_y;
pr("Deliver %s from %s @ %s to %s",
@ -119,7 +130,8 @@ deli(void)
if (!(del & ~0x7))
pr("\n");
else
pr(" (cutoff %d)\n", del & ~0x7);
pr(" (cutoff %d)\n", thresh);
}
return RET_OK;
}