]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/landgun.c
Update copyright notice
[empserver] / src / lib / subs / landgun.c
index 538009f3c79443442673e18aca3f7d1a0d1b3b46..0cddbd97a74d84778b577d62c78728d0afab12d9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -25,8 +25,8 @@
  *
  *  ---
  *
- *  landgun.c: Return values for land and ship gun firing damages
- * 
+ *  landgun.c: Fire weapons
+ *
  *  Known contributors to this file:
  *     Markus Armbruster, 2006-2008
  */
@@ -135,7 +135,7 @@ shp_fire(struct shpstr *sp)
 int
 shp_dchrg(struct shpstr *sp)
 {
-    int shells;
+    int shells, dchrgs;
 
     if (sp->shp_effic < 60 || (mchr[sp->shp_type].m_flags & M_DCH) == 0)
        return -1;
@@ -144,10 +144,11 @@ shp_dchrg(struct shpstr *sp)
     shells = sp->shp_item[I_SHELL];
     shells += supply_commod(sp->shp_own, sp->shp_x, sp->shp_y,
                            I_SHELL, 2 - shells);
-    if (shells < 2)
+    if (shells == 0)
        return -1;
-    sp->shp_item[I_SHELL] = shells - 2;
-    return (int)seagun(sp->shp_effic, 3);
+    dchrgs = MIN(2, shells);
+    sp->shp_item[I_SHELL] = shells - dchrgs;
+    return (int)seagun(sp->shp_effic, 2 * dchrgs - 1);
 }
 
 /*
@@ -185,12 +186,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 +199,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);