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 <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2017-09-13 18:41:00 +02:00
parent eb5ed8802a
commit 1bde4df2bd
5 changed files with 30 additions and 7 deletions

View file

@ -71,8 +71,11 @@ ltend(void)
if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? ")) if (!snxtitem(&tenders, EF_SHIP, player->argp[2], "Tender(s)? "))
return RET_SYN; return RET_SYN;
while (nxtitem(&tenders, &tender)) { 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; continue;
}
if (!(p = getstarg(player->argp[3], "Amount to transfer? ", buf))) if (!(p = getstarg(player->argp[3], "Amount to transfer? ", buf)))
return RET_FAIL; return RET_FAIL;
if (!check_ship_ok(&tender)) if (!check_ship_ok(&tender))
@ -98,8 +101,11 @@ ltend(void)
return RET_FAIL; return RET_FAIL;
total = 0; total = 0;
while (nxtitem(&targets, &target)) { 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; continue;
}
if (target.lnd_ship != tender.shp_uid) { if (target.lnd_ship != tender.shp_uid) {
if (targets.sel == NS_LIST) if (targets.sel == NS_LIST)
pr("%s is not on %s!\n", pr("%s is not on %s!\n",

View file

@ -84,8 +84,11 @@ tend(void)
return RET_SYN; return RET_SYN;
while (nxtitem(&tenders, &tender)) { 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; continue;
}
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));
@ -214,8 +217,11 @@ tend_land(struct shpstr *tenderp, char *units)
return RET_SYN; return RET_SYN;
while (nxtitem(&lni, &land)) { 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; continue;
}
if (land.lnd_ship != tenderp->shp_uid) { if (land.lnd_ship != tenderp->shp_uid) {
if (lni.sel == NS_LIST) if (lni.sel == NS_LIST)
pr("%s is not on %s!\n", prland(&land), prship(tenderp)); pr("%s is not on %s!\n", prland(&land), prship(tenderp));

View file

@ -31,7 +31,6 @@ tend f -1
tend f n tend f n
| foreign tender | foreign tender
tend f 160/162/163/164 tend f 160/162/163/164
| usability: does nothing silently
| invalid amount | invalid amount
| impossible, as crap is mapped to zero | impossible, as crap is mapped to zero
| invalid target | invalid target
@ -129,7 +128,6 @@ f
tend land -1 tend land -1
| foreign tender | foreign tender
tend land 160/162/163/164 tend land 160/162/163/164
| usability: does nothing silently
| invalid land | invalid land
tend land 150 -1 tend land 150 -1
| invalid target | invalid target

View file

@ -20,7 +20,6 @@ ltend f -1
ltend f n ltend f n
| foreign tender | foreign tender
ltend f 212 ltend f 212
| usability: does nothing silently
| invalid amount | invalid amount
| impossible, as crap is mapped to zero | impossible, as crap is mapped to zero
| invalid target | invalid target

View file

@ -2101,6 +2101,10 @@
Play#1 output Play#1 6 0 423 Play#1 output Play#1 6 0 423
Play#1 input tend f 160/162/163/164 Play#1 input tend f 160/162/163/164
Play#1 command tend 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 output Play#1 6 0 422
Play#1 input tend f 150 1 -1 Play#1 input tend f 150 1 -1
Play#1 command tend Play#1 command tend
@ -2168,6 +2172,10 @@
Play#1 output Play#1 6 0 409 Play#1 output Play#1 6 0 409
Play#1 input tend f 160/162/163/164 -1 166 Play#1 input tend f 160/162/163/164 -1 166
Play#1 command tend 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 output Play#1 6 0 408
Play#1 input tend f 166 -1 160/162/163/164 Play#1 input tend f 166 -1 160/162/163/164
Play#1 command tend Play#1 command tend
@ -2283,6 +2291,10 @@
Play#1 output Play#1 6 0 396 Play#1 output Play#1 6 0 396
Play#1 input tend land 160/162/163/164 Play#1 input tend land 160/162/163/164
Play#1 command tend 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 output Play#1 6 0 395
Play#1 input tend land 150 -1 Play#1 input tend land 150 -1
Play#1 command tend Play#1 command tend
@ -2497,6 +2509,7 @@
Play#1 output Play#1 6 0 376 Play#1 output Play#1 6 0 376
Play#1 input ltend f 212 Play#1 input ltend f 212
Play#1 command ltend 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 output Play#1 6 0 375
Play#1 input tend f 200 1 -1 Play#1 input tend f 200 1 -1
Play#1 command tend Play#1 command tend
@ -2508,6 +2521,7 @@
Play#1 output Play#1 6 0 373 Play#1 output Play#1 6 0 373
Play#1 input ltend f 200 1 26 Play#1 input ltend f 200 1 26
Play#1 command ltend 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 1 0 total food transferred off of cs cargo ship (#200)
Play#1 output Play#1 6 0 372 Play#1 output Play#1 6 0 372
Play#1 input ltend f 200 1 0 Play#1 input ltend f 200 1 0