]> git.pond.sub.org Git - empserver/commitdiff
Fix lnd_fire() ammo sanity check
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Apr 2008 08:15:05 +0000 (10:15 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 26 Apr 2008 08:15:05 +0000 (10:15 +0200)
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

index 538009f3c79443442673e18aca3f7d1a0d1b3b46..44cea9559b3ccdc6e6c20f1325e877df235e87db 100644 (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);