From 61998d2316ed30e4fd0d7750ab3f23cd5f9dbeb0 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 26 Apr 2008 10:15:05 +0200 Subject: [PATCH] Fix lnd_fire() ammo sanity check Checking l_ammo before lnd_dam() oopses when something attempts to fire from a land unit type that can't fire (l_dam == 0) and uses no ammo. Such usage is perfectly fine. Move the check to the correct place. --- src/lib/subs/landgun.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/subs/landgun.c b/src/lib/subs/landgun.c index 538009f3..44cea955 100644 --- a/src/lib/subs/landgun.c +++ b/src/lib/subs/landgun.c @@ -25,7 +25,7 @@ * * --- * - * landgun.c: Return values for land and ship gun firing damages + * landgun.c: Fire weapons * * Known contributors to this file: * Markus Armbruster, 2006-2008 @@ -185,12 +185,8 @@ shp_torp(struct shpstr *sp, int usemob) int lnd_fire(struct lndstr *lp) { - int guns, shells; + int guns, ammo, shells; double d; - int ammo = lchr[lp->lnd_type].l_ammo; - - if (CANT_HAPPEN(ammo == 0)) - ammo = 1; if (lp->lnd_effic < LAND_MINFIREEFF) return -1; @@ -202,6 +198,9 @@ lnd_fire(struct lndstr *lp) guns = MIN(guns, lp->lnd_item[I_GUN]); if (guns == 0) return -1; + ammo = lchr[lp->lnd_type].l_ammo; + if (CANT_HAPPEN(ammo == 0)) + ammo = 1; shells = lp->lnd_item[I_SHELL]; shells += supply_commod(lp->lnd_own, lp->lnd_x, lp->lnd_y, I_SHELL, ammo - shells);