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.
This commit is contained in:
Markus Armbruster 2008-04-26 10:15:05 +02:00
parent 9e19123abf
commit 61998d2316

View file

@ -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);