]> git.pond.sub.org Git - empserver/commitdiff
ltend: Reject zero amount more nicely
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 16 Sep 2017 07:30:07 +0000 (09:30 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 5 Jan 2021 06:25:17 +0000 (07:25 +0100)
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 <armbru@pond.sub.org>
src/lib/commands/lten.c
tests/load-tend/05-ltend-1
tests/load-tend/journal.log

index 03eac0354a08eb59fdcb4d5c395142dd6f01271b..86465262a533617a61030f965cadf089c2f2f425 100644 (file)
@@ -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));
index bc0bb0f7fa5aed76064a31d11d477b0e893afa51..d9129700de51b76272fbd7626307ce4fda1b751f 100644 (file)
@@ -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
index 71733323c55b9800dc7fafc872f2dfd30a4958e7..3848c358970dc14160b45c89c5e73b202567f5b1 100644 (file)
     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 <COMM> <tender-SHIPS> <NUM> <UNITS>
+    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
     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