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 <armbru@pond.sub.org>
This commit is contained in:
parent
196a1292b0
commit
075704276e
1 changed files with 8 additions and 44 deletions
|
@ -145,6 +145,11 @@ multifire(void)
|
||||||
fland.lnd_uid, LAND_MINFIREEFF);
|
fland.lnd_uid, LAND_MINFIREEFF);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (fland.lnd_item[I_GUN] == 0) {
|
||||||
|
pr("%s -- not enough guns\n", prland(&fland));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (fland.lnd_item[I_SHELL] == 0) {
|
if (fland.lnd_item[I_SHELL] == 0) {
|
||||||
pr("%s -- not enough shells\n", prland(&fland));
|
pr("%s -- not enough shells\n", prland(&fland));
|
||||||
continue;
|
continue;
|
||||||
|
@ -254,25 +259,12 @@ multifire(void)
|
||||||
if (type == EF_SHIP) {
|
if (type == EF_SHIP) {
|
||||||
if (!check_ship_ok(&fship))
|
if (!check_ship_ok(&fship))
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
if (fship.shp_own != player->cnum) {
|
|
||||||
pr("Not your ship!\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (target == targ_sub || target == targ_ship) {
|
if (target == targ_sub || target == targ_ship) {
|
||||||
if (fship.shp_uid == vship.shp_uid) {
|
if (fship.shp_uid == vship.shp_uid) {
|
||||||
pr("You can't fire upon yourself!\n");
|
pr("You can't fire upon yourself!\n");
|
||||||
continue;
|
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);
|
range = shp_fire_range(&fship);
|
||||||
range2 = roundrange(range);
|
range2 = roundrange(range);
|
||||||
pr("range is %d.00 (%.2f)\n", range2, range);
|
pr("range is %d.00 (%.2f)\n", range2, range);
|
||||||
|
@ -291,7 +283,7 @@ multifire(void)
|
||||||
dam = shp_fire(&fship);
|
dam = shp_fire(&fship);
|
||||||
}
|
}
|
||||||
putship(fship.shp_uid, &fship);
|
putship(fship.shp_uid, &fship);
|
||||||
if (dam <= 0) {
|
if (dam == 0 || CANT_HAPPEN(dam < 0)) {
|
||||||
pr("Klick! ...\n");
|
pr("Klick! ...\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -302,11 +294,6 @@ multifire(void)
|
||||||
} else if (type == EF_LAND) {
|
} else if (type == EF_LAND) {
|
||||||
if (!check_land_ok(&fland))
|
if (!check_land_ok(&fland))
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
if (fland.lnd_own != player->cnum) {
|
|
||||||
pr("Not your unit!\n");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (target == targ_land) {
|
if (target == targ_land) {
|
||||||
if (fland.lnd_x == vsect.sct_x
|
if (fland.lnd_x == vsect.sct_x
|
||||||
&& fland.lnd_y == vsect.sct_y) {
|
&& 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);
|
range = lnd_fire_range(&fland);
|
||||||
range2 = roundrange(range);
|
range2 = roundrange(range);
|
||||||
pr("range is %d.00 (%.2f)\n", range2, range);
|
pr("range is %d.00 (%.2f)\n", range2, range);
|
||||||
|
@ -334,7 +312,7 @@ multifire(void)
|
||||||
|
|
||||||
dam = lnd_fire(&fland);
|
dam = lnd_fire(&fland);
|
||||||
putland(fland.lnd_uid, &fland);
|
putland(fland.lnd_uid, &fland);
|
||||||
if (dam < 0) {
|
if (CANT_HAPPEN(dam < 0)) {
|
||||||
pr("Klick! ...\n");
|
pr("Klick! ...\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -345,12 +323,6 @@ multifire(void)
|
||||||
} else {
|
} else {
|
||||||
if (!check_sect_ok(&fsect))
|
if (!check_sect_ok(&fsect))
|
||||||
return RET_FAIL;
|
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 (target == targ_land) {
|
||||||
if (fsect.sct_x == vsect.sct_x
|
if (fsect.sct_x == vsect.sct_x
|
||||||
&& fsect.sct_y == vsect.sct_y) {
|
&& fsect.sct_y == vsect.sct_y) {
|
||||||
|
@ -358,17 +330,9 @@ multifire(void)
|
||||||
continue;
|
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);
|
dam = fort_fire(&fsect);
|
||||||
putsect(&fsect);
|
putsect(&fsect);
|
||||||
if (dam < 0) {
|
if (CANT_HAPPEN(dam < 0)) {
|
||||||
pr("Klick! ...\n");
|
pr("Klick! ...\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue