From 075704276e8b27f6e8ffc3c5c4f7b93c1c918d62 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 7 Jan 2014 21:48:37 +0100 Subject: [PATCH] fire: Check land unit guns earlier, drop useless checks We check all necessary conditions for being able to fire before prompting for a target. Except for land unit guns. Clean that up. fort_fire(), shp_fire() or lnd_fire() fail only when the fort, ship or land unit can't fire. If that happens, our checking is incomplete. Oops then. We recheck some of the necessary conditions after getting the target. However, because the command fails when the firing sector, ship or land unit has changed since the first check, these rechecks can't fail. Drop them. Note that the rechecks were just as useless before commit 66165f3 fixed fire to fail on change, because they rechecked the unchanged cached copy instead of the possibly changed original. Signed-off-by: Markus Armbruster --- src/lib/commands/mfir.c | 52 +++++++---------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index f7a63dcec..f6f95d1b8 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -145,6 +145,11 @@ multifire(void) fland.lnd_uid, LAND_MINFIREEFF); continue; } + if (fland.lnd_item[I_GUN] == 0) { + pr("%s -- not enough guns\n", prland(&fland)); + continue; + } + if (fland.lnd_item[I_SHELL] == 0) { pr("%s -- not enough shells\n", prland(&fland)); continue; @@ -254,25 +259,12 @@ multifire(void) if (type == EF_SHIP) { if (!check_ship_ok(&fship)) return RET_FAIL; - if (fship.shp_own != player->cnum) { - pr("Not your ship!\n"); - continue; - } if (target == targ_sub || target == targ_ship) { if (fship.shp_uid == vship.shp_uid) { pr("You can't fire upon yourself!\n"); continue; } } - if (fship.shp_item[I_MILIT] < 1) { - pr("Not enough military for firing crew.\n"); - continue; - } - if (fship.shp_effic < 60) { - pr("Ship #%d is crippled (%d%%)\n", - fship.shp_uid, fship.shp_effic); - continue; - } range = shp_fire_range(&fship); range2 = roundrange(range); pr("range is %d.00 (%.2f)\n", range2, range); @@ -291,7 +283,7 @@ multifire(void) dam = shp_fire(&fship); } putship(fship.shp_uid, &fship); - if (dam <= 0) { + if (dam == 0 || CANT_HAPPEN(dam < 0)) { pr("Klick! ...\n"); continue; } @@ -302,11 +294,6 @@ multifire(void) } else if (type == EF_LAND) { if (!check_land_ok(&fland)) return RET_FAIL; - if (fland.lnd_own != player->cnum) { - pr("Not your unit!\n"); - continue; - } - if (target == targ_land) { if (fland.lnd_x == vsect.sct_x && fland.lnd_y == vsect.sct_y) { @@ -315,15 +302,6 @@ multifire(void) } } - if (lchr[fland.lnd_type].l_dam == 0) { - pr("Unit %d cannot fire!\n", fland.lnd_uid); - continue; - } - if (fland.lnd_item[I_GUN] == 0) { - pr("%s -- not enough guns\n", prland(&fland)); - continue; - } - range = lnd_fire_range(&fland); range2 = roundrange(range); pr("range is %d.00 (%.2f)\n", range2, range); @@ -334,7 +312,7 @@ multifire(void) dam = lnd_fire(&fland); putland(fland.lnd_uid, &fland); - if (dam < 0) { + if (CANT_HAPPEN(dam < 0)) { pr("Klick! ...\n"); continue; } @@ -345,12 +323,6 @@ multifire(void) } else { if (!check_sect_ok(&fsect)) return RET_FAIL; - if (fsect.sct_own != player->cnum || - fsect.sct_type != SCT_FORTR) { - pr("No fortress at %s\n", - xyas(fsect.sct_x, fsect.sct_y, player->cnum)); - continue; - } if (target == targ_land) { if (fsect.sct_x == vsect.sct_x && fsect.sct_y == vsect.sct_y) { @@ -358,17 +330,9 @@ multifire(void) continue; } } - if (fsect.sct_item[I_GUN] == 0) { - pr("Insufficient arms.\n"); - continue; - } - if (fsect.sct_item[I_MILIT] < 5) { - pr("Not enough military for firing crew.\n"); - continue; - } dam = fort_fire(&fsect); putsect(&fsect); - if (dam < 0) { + if (CANT_HAPPEN(dam < 0)) { pr("Klick! ...\n"); continue; } -- 2.43.0