From 1bde4df2bd69f91b9f4c930a118b4123d64f1e0c Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 13 Sep 2017 18:41:00 +0200 Subject: [PATCH] tend ltend: Reject foreign tenders and land units more nicely We silently ignore foreign ships and land units. This may leave the player guessing why the command did nothing. Report explicitly named ones like this You don't own ship #160! except for tend's target ships. Nice reporting is a bit more involved there, because you can tend to foreign target ships as long as they're friendly. Left for later. Signed-off-by: Markus Armbruster --- src/lib/commands/lten.c | 10 ++++++++-- src/lib/commands/tend.c | 10 ++++++++-- tests/load-tend/03-tend-1 | 2 -- tests/load-tend/05-ltend-1 | 1 - tests/load-tend/journal.log | 14 ++++++++++++++ 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/lib/commands/lten.c b/src/lib/commands/lten.c index a770f4c4..f5df960d 100644 --- a/src/lib/commands/lten.c +++ b/src/lib/commands/lten.c @@ -71,8 +71,11 @@ ltend(void) if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? ")) return RET_SYN; while (nxtitem(&tenders, &tender)) { - if (!player->owner) + if (!player->owner) { + if (tenders.sel == NS_LIST) + pr("You don't own ship #%d!\n", tender.shp_uid); continue; + } if (!(p = getstarg(player->argp[3], "Amount to transfer? ", buf))) return RET_FAIL; if (!check_ship_ok(&tender)) @@ -98,8 +101,11 @@ ltend(void) return RET_FAIL; total = 0; while (nxtitem(&targets, &target)) { - if (!player->owner) + if (!player->owner) { + if (targets.sel == NS_LIST) + pr("You don't own land unit #%d!\n", target.lnd_uid); continue; + } if (target.lnd_ship != tender.shp_uid) { if (targets.sel == NS_LIST) pr("%s is not on %s!\n", diff --git a/src/lib/commands/tend.c b/src/lib/commands/tend.c index a8d9c4b4..25a054dc 100644 --- a/src/lib/commands/tend.c +++ b/src/lib/commands/tend.c @@ -84,8 +84,11 @@ tend(void) return RET_SYN; while (nxtitem(&tenders, &tender)) { - if (!player->owner) + if (!player->owner) { + if (tenders.sel == NS_LIST) + pr("You don't own ship #%d!\n", tender.shp_uid); continue; + } if (type == EF_LAND) { sprintf(prompt, "Land unit(s) to tend from %s? ", prship(&tender)); @@ -214,8 +217,11 @@ tend_land(struct shpstr *tenderp, char *units) return RET_SYN; while (nxtitem(&lni, &land)) { - if (!player->owner) + if (!player->owner) { + if (lni.sel == NS_LIST) + pr("You don't own land unit #%d!\n", land.lnd_uid); continue; + } if (land.lnd_ship != tenderp->shp_uid) { if (lni.sel == NS_LIST) pr("%s is not on %s!\n", prland(&land), prship(tenderp)); diff --git a/tests/load-tend/03-tend-1 b/tests/load-tend/03-tend-1 index 9d012e0f..c51b8d81 100644 --- a/tests/load-tend/03-tend-1 +++ b/tests/load-tend/03-tend-1 @@ -31,7 +31,6 @@ tend f -1 tend f n | foreign tender tend f 160/162/163/164 -| usability: does nothing silently | invalid amount | impossible, as crap is mapped to zero | invalid target @@ -129,7 +128,6 @@ f tend land -1 | foreign tender tend land 160/162/163/164 -| usability: does nothing silently | invalid land tend land 150 -1 | invalid target diff --git a/tests/load-tend/05-ltend-1 b/tests/load-tend/05-ltend-1 index 987a54c4..bc0bb0f7 100644 --- a/tests/load-tend/05-ltend-1 +++ b/tests/load-tend/05-ltend-1 @@ -20,7 +20,6 @@ ltend f -1 ltend f n | foreign tender ltend f 212 -| usability: does nothing silently | invalid amount | impossible, as crap is mapped to zero | invalid target diff --git a/tests/load-tend/journal.log b/tests/load-tend/journal.log index c1d558b3..c5f61807 100644 --- a/tests/load-tend/journal.log +++ b/tests/load-tend/journal.log @@ -2101,6 +2101,10 @@ Play#1 output Play#1 6 0 423 Play#1 input tend f 160/162/163/164 Play#1 command tend + Play#1 output Play#1 1 You don't own ship #160! + Play#1 output Play#1 1 You don't own ship #162! + Play#1 output Play#1 1 You don't own ship #163! + Play#1 output Play#1 1 You don't own ship #164! Play#1 output Play#1 6 0 422 Play#1 input tend f 150 1 -1 Play#1 command tend @@ -2168,6 +2172,10 @@ Play#1 output Play#1 6 0 409 Play#1 input tend f 160/162/163/164 -1 166 Play#1 command tend + Play#1 output Play#1 1 You don't own ship #160! + Play#1 output Play#1 1 You don't own ship #162! + Play#1 output Play#1 1 You don't own ship #163! + Play#1 output Play#1 1 You don't own ship #164! Play#1 output Play#1 6 0 408 Play#1 input tend f 166 -1 160/162/163/164 Play#1 command tend @@ -2283,6 +2291,10 @@ Play#1 output Play#1 6 0 396 Play#1 input tend land 160/162/163/164 Play#1 command tend + Play#1 output Play#1 1 You don't own ship #160! + Play#1 output Play#1 1 You don't own ship #162! + Play#1 output Play#1 1 You don't own ship #163! + Play#1 output Play#1 1 You don't own ship #164! Play#1 output Play#1 6 0 395 Play#1 input tend land 150 -1 Play#1 command tend @@ -2497,6 +2509,7 @@ Play#1 output Play#1 6 0 376 Play#1 input ltend f 212 Play#1 command ltend + Play#1 output Play#1 1 You don't own ship #212! Play#1 output Play#1 6 0 375 Play#1 input tend f 200 1 -1 Play#1 command tend @@ -2508,6 +2521,7 @@ Play#1 output Play#1 6 0 373 Play#1 input ltend f 200 1 26 Play#1 command ltend + Play#1 output Play#1 1 You don't own land unit #26! Play#1 output Play#1 1 0 total food transferred off of cs cargo ship (#200) Play#1 output Play#1 6 0 372 Play#1 input ltend f 200 1 0