Fix command abortion after getting player input

The old code didn't honor command abortion at the following prompts:

* arm third argument

* deliver fourth argument (also simplify)

* fire third argument

* fly and recon prompt for carrier to land on: pln_onewaymission()
  treated abort like empty input, which made planes attempt landing in
  the sector.

* lmine second argument

* order d fourth argument

* power c nat(s) argument

* range second argument

* sail second argument

* shutdown both arguments (first one was broken in commit 84cfd670,
  v4.3.10, second one never worked).

* tend third argument
This commit is contained in:
Markus Armbruster 2008-07-15 07:55:42 -04:00
parent b3a7a8ee11
commit 9eda5f87b8
11 changed files with 51 additions and 32 deletions

View file

@ -96,6 +96,8 @@ arm(void)
return RET_FAIL; return RET_FAIL;
} }
p = getstarg(player->argp[3], "Airburst [n]? ", buf); p = getstarg(player->argp[3], "Airburst [n]? ", buf);
if (!p)
return RET_SYN;
if (!check_plane_ok(&pl) || !check_nuke_ok(&nuke)) if (!check_plane_ok(&pl) || !check_nuke_ok(&nuke))
return RET_FAIL; return RET_FAIL;
@ -106,7 +108,7 @@ arm(void)
return RET_FAIL; return RET_FAIL;
} }
if (p && (*p == 'y' || *p == 'Y')) if (*p == 'y' || *p == 'Y')
pl.pln_flags |= PLN_AIRBURST; pl.pln_flags |= PLN_AIRBURST;
else else
pl.pln_flags &= ~PLN_AIRBURST; pl.pln_flags &= ~PLN_AIRBURST;

View file

@ -55,7 +55,7 @@ deli(void)
if (!snxtsct(&nstr, player->argp[2])) if (!snxtsct(&nstr, player->argp[2]))
return RET_SYN; return RET_SYN;
while (!player->aborted && nxtsct(&nstr, &sect) > 0) { while (nxtsct(&nstr, &sect) > 0) {
if (!player->owner) if (!player->owner)
continue; continue;
@ -69,15 +69,17 @@ deli(void)
if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
return RET_SYN; return RET_SYN;
if (*p != 'q') { 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 == '+') { if (((*p >= '0') && (*p <= '9')) || *p == '+') {
thresh = atoi(p) & ~0x7; thresh = atoi(p) & ~0x7;
if (*p == '+') if (*p == '+')
p = NULL; p = NULL;
else { else {
sprintf(prompt, "%s %s %s direction? ",
xyas(nstr.x, nstr.y, player->cnum),
dchr[sect.sct_type].d_name, ich->i_name);
p = getstarg(player->argp[4], prompt, buf); p = getstarg(player->argp[4], prompt, buf);
if (!p)
return RET_SYN;
} }
} }
if (p && *p) { if (p && *p) {

View file

@ -118,10 +118,6 @@ multifire(void)
if (!snxtitem(&nbst, type, ptr)) if (!snxtitem(&nbst, type, ptr))
return RET_SYN; return RET_SYN;
if (player->aborted) {
pr("Fire aborted.\n");
return RET_OK;
}
while (nxtitem(&nbst, &item)) { while (nxtitem(&nbst, &item)) {
if (type == EF_LAND) { if (type == EF_LAND) {
if (!getland(item.land.lnd_uid, &fland)) if (!getland(item.land.lnd_uid, &fland))
@ -220,13 +216,11 @@ multifire(void)
fy = fsect.sct_y; fy = fsect.sct_y;
} }
if ((ptr = getstarg(player->argp[3], "Firing at? ", buf)) == 0 ptr = getstarg(player->argp[3], "Firing at? ", buf);
|| *ptr == '\0') if (!ptr)
return RET_SYN;
if (!*ptr)
continue; continue;
if (player->aborted) {
pr("Fire aborted.\n");
continue;
}
if (!issector(ptr)) { if (!issector(ptr)) {
vshipno = atoi(ptr); vshipno = atoi(ptr);
if (vshipno < 0 || !getship(vshipno, &vship) || if (vshipno < 0 || !getship(vshipno, &vship) ||

View file

@ -128,9 +128,11 @@ landmine(void)
sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum)); sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum));
sprintf(prompt, "Drop how many mines from %s? ", prland(&land)); sprintf(prompt, "Drop how many mines from %s? ", prland(&land));
mines_wanted = onearg(player->argp[2], prompt); mines_wanted = onearg(player->argp[2], prompt);
if (!check_land_ok(&land)) if (mines_wanted < 0)
return RET_SYN;
if (mines_wanted == 0)
continue; continue;
if (mines_wanted <= 0) if (!check_land_ok(&land))
continue; continue;
land.lnd_mission = 0; land.lnd_mission = 0;
total_mines_laid = 0; total_mines_laid = 0;

View file

@ -136,7 +136,9 @@ orde(void)
if (!orders) { if (!orders) {
p = getstarg(player->argp[4], "Second dest? ", buf); p = getstarg(player->argp[4], "Second dest? ", buf);
if (!p || !*p || !strcmp(p, "-")) { if (!p)
return RET_SYN;
if (!*p || !strcmp(p, "-")) {
orders = 1; orders = 1;
pr("A one-way order has been accepted.\n"); pr("A one-way order has been accepted.\n");
} else if (!strncmp(p, "s", 1)) { } else if (!strncmp(p, "s", 1)) {

View file

@ -94,7 +94,8 @@ powe(void)
if (player->argp[i]) { if (player->argp[i]) {
if (player->argp[i][0] == 'c') { if (player->argp[i][0] == 'c') {
snxtitem(&ni, EF_NATION, player->argp[i + 1]); if (!snxtitem(&ni, EF_NATION, player->argp[i + 1]))
return RET_SYN;
while (nxtitem(&ni, &nat)) { while (nxtitem(&ni, &nat)) {
if (nat.nat_stat == STAT_UNUSED) if (nat.nat_stat == STAT_UNUSED)
continue; continue;

View file

@ -52,9 +52,11 @@ range(void)
if (!player->owner || plane.pln_own == 0) if (!player->owner || plane.pln_own == 0)
continue; continue;
p = getstarg(player->argp[2], "New range? ", buf); p = getstarg(player->argp[2], "New range? ", buf);
if (!p)
return RET_SYN;
if (!check_plane_ok(&plane)) if (!check_plane_ok(&plane))
return RET_SYN; return RET_SYN;
if (!p || (i = atoi(p)) < 0) if ((i = atoi(p)) < 0)
continue; continue;
rmax = pln_range_max(&plane); rmax = pln_range_max(&plane);
plane.pln_range = MIN(rmax, i); plane.pln_range = MIN(rmax, i);

View file

@ -110,7 +110,7 @@ cmd_sail_ship(struct nstr_item *nstr)
struct shpstr ship; struct shpstr ship;
char navpath[MAX_PATH_LEN]; char navpath[MAX_PATH_LEN];
while (!player->aborted && nxtitem(nstr, &ship)) { while (nxtitem(nstr, &ship)) {
if (!player->owner || ship.shp_own == 0) if (!player->owner || ship.shp_own == 0)
continue; continue;
if ((ship.shp_autonav & AN_AUTONAV) && if ((ship.shp_autonav & AN_AUTONAV) &&
@ -123,14 +123,14 @@ cmd_sail_ship(struct nstr_item *nstr)
xyas(ship.shp_x, ship.shp_y, ship.shp_own)); xyas(ship.shp_x, ship.shp_y, ship.shp_own));
cp = getpath(navpath, player->argp[2], cp = getpath(navpath, player->argp[2],
ship.shp_x, ship.shp_y, 0, 0, P_SAILING); ship.shp_x, ship.shp_y, 0, 0, P_SAILING);
if (!cp)
return RET_SYN;
if (!check_ship_ok(&ship)) if (!check_ship_ok(&ship))
continue; continue;
if (!player->aborted) {
strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 2); strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 2);
ship.shp_mission = 0; ship.shp_mission = 0;
putship(ship.shp_uid, &ship); putship(ship.shp_uid, &ship);
} }
}
return RET_OK; return RET_OK;
} }

View file

@ -50,10 +50,15 @@ shut(void)
shutdown_minutes = shutdown_minutes =
onearg(player->argp[1], onearg(player->argp[1],
"Time until shutdown in minutes (-1 to abort shutdown sequence)? "); "Time until shutdown in minutes (-1 to abort shutdown sequence)? ");
if (!updates_disabled()) if (player->aborted)
if (!(p = getstarg(player->argp[2], "Disable update [y]? ", buf)) return RET_SYN;
|| *p != 'n') if (!updates_disabled()) {
p = getstarg(player->argp[2], "Disable update [y]? ", buf);
if (!p)
return RET_SYN;
if (*p != 'n')
disa(); disa();
}
shutdown_was_pending = shutdown_initiate(shutdown_minutes); shutdown_was_pending = shutdown_initiate(shutdown_minutes);
if (shutdown_was_pending < 0) if (shutdown_was_pending < 0)

View file

@ -90,7 +90,10 @@ tend(void)
if (type == EF_LAND) { if (type == EF_LAND) {
sprintf(prompt, "Land unit(s) to tend from %s? ", sprintf(prompt, "Land unit(s) to tend from %s? ",
prship(&tender)); prship(&tender));
if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) p = getstarg(player->argp[3], prompt, buf);
if (!p)
return RET_SYN;
if (!*p)
continue; continue;
if (!check_ship_ok(&tender)) if (!check_ship_ok(&tender))
return RET_SYN; return RET_SYN;
@ -100,7 +103,10 @@ tend(void)
} }
sprintf(prompt, "Number of %s to tend from %s? ", sprintf(prompt, "Number of %s to tend from %s? ",
ip->i_name, prship(&tender)); ip->i_name, prship(&tender));
if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p) p = getstarg(player->argp[3], prompt, buf);
if (!p)
return RET_SYN;
if (!*p)
continue; continue;
if (!check_ship_ok(&tender)) if (!check_ship_ok(&tender))
return RET_SYN; return RET_SYN;

View file

@ -114,7 +114,10 @@ pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
nships = carriersatxy(target->sct_x, target->sct_y, player->cnum); nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
if (nships) { if (nships) {
for (;;) { for (;;) {
if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p) p = getstring("Carrier #? ", buf);
if (!p)
return -1;
if (!*p)
break; break;
cno = atoi(p); cno = atoi(p);
if (cno < 0 if (cno < 0