From 7d2c09668c1d418abeef1ea661a02d0bb78a1abf Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 16 Sep 2017 09:30:07 +0200 Subject: [PATCH] ltend: Reject zero amount more nicely Unlike tend, ltend does nothing silently when asked to tend zero commodities. This may leave the player guessing why the command did nothing. Report the reason and fail the command, just like tend does. While there, improve the prompt to match tend's. Signed-off-by: Markus Armbruster --- src/lib/commands/lten.c | 14 +++++++++++--- tests/load-tend/05-ltend-1 | 2 +- tests/load-tend/journal.log | 9 +++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/lib/commands/lten.c b/src/lib/commands/lten.c index 03eac035..86465262 100644 --- a/src/lib/commands/lten.c +++ b/src/lib/commands/lten.c @@ -63,6 +63,7 @@ ltend(void) int transfer; int total; char *p; + char prompt[512]; char buf[1024]; if (!(ip = whatitem(player->argp[1], "Transfer what commodity? "))) @@ -76,12 +77,19 @@ ltend(void) pr("You don't own ship #%d!\n", tender.shp_uid); continue; } - if (!(p = getstarg(player->argp[3], "Amount to transfer? ", buf))) + sprintf(prompt, "Number of %s to tend from %s? ", + ip->i_name, prship(&tender)); + if (!(p = getstarg(player->argp[3], prompt, buf))) return RET_FAIL; + if (!*p) + continue; if (!check_ship_ok(&tender)) return RET_FAIL; - if ((amt = atoi(p)) == 0) - break; + amt = atoi(p); + if (!amt) { + pr("Amount must be non-zero!\n"); + return RET_SYN; + } ontender = tender.shp_item[ip->i_uid]; if (ontender == 0 && amt > 0) { pr("No %s on %s\n", ip->i_name, prship(&tender)); diff --git a/tests/load-tend/05-ltend-1 b/tests/load-tend/05-ltend-1 index bc0bb0f7..d9129700 100644 --- a/tests/load-tend/05-ltend-1 +++ b/tests/load-tend/05-ltend-1 @@ -41,7 +41,7 @@ ltend c 200/201 1 350/352 ltend h 200/201 1 350/352 | zero amount: ltend f 200/201 0 350/351//352 -| usability: does nothing silently +__cmd added 0 -1 0 | more than the ship has ltend s 200/201 5 350/351/352 | more than the land can hold diff --git a/tests/load-tend/journal.log b/tests/load-tend/journal.log index 71733323..3848c358 100644 --- a/tests/load-tend/journal.log +++ b/tests/load-tend/journal.log @@ -2572,6 +2572,11 @@ Play#1 output Play#1 6 0 368 Play#1 input ltend f 200/201 0 350/351//352 Play#1 command ltend + Play#1 output Play#1 1 Amount must be non-zero! + Play#1 output Play#1 1 Usage: ltend + Play#1 output Play#1 6 0 368 + Play#1 input __cmd added 0 -1 0 + Play#1 command __cmd Play#1 output Play#1 6 0 367 Play#1 input ltend s 200/201 5 350/351/352 Play#1 command ltend @@ -2647,12 +2652,12 @@ Play#1 input f Play#1 output Play#1 4 Tender(s)? Play#1 input 200/201 - Play#1 output Play#1 4 Amount to transfer? + Play#1 output Play#1 4 Number of food to tend from cs cargo ship (#200)? Play#1 input 1 Play#1 output Play#1 4 Units to be tended? Play#1 input 350/351 Play#1 output Play#1 1 2 total food transferred off of cs cargo ship (#200) - Play#1 output Play#1 4 Amount to transfer? + Play#1 output Play#1 4 Number of food to tend from cs cargo ship (#201)? Play#1 input -1 Play#1 output Play#1 4 Units to be tended? Play#1 input 350