]> git.pond.sub.org Git - empserver/commitdiff
fire: Check land unit guns earlier, drop useless checks
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 7 Jan 2014 20:48:37 +0000 (21:48 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 19 Jan 2014 09:17:00 +0000 (10:17 +0100)
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 <armbru@pond.sub.org>
src/lib/commands/mfir.c

index f7a63dcec76a1a58f315be3f94856a166b5eba55..f6f95d1b8da28ab040e956e73f922007535bde80 100644 (file)
@@ -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;
            }