]> git.pond.sub.org Git - empserver/blobdiff - src/lib/subs/landgun.c
Don't unlimber when guns unsuccessfully try to fire
[empserver] / src / lib / subs / landgun.c
index 9654aacef18ed85437a330e929e8720796668d00..160b403d517d35c6bd1442d19b41616b71e1fe3d 100644 (file)
  *
  *  ---
  *
- *  landgun.c: Return values for land and ship gun firing damages
+ *  landgun.c: Fire weapons
  * 
  *  Known contributors to this file:
- *     Markus Armbruster, 2006
+ *     Markus Armbruster, 2006-2008
  */
 
 #include <config.h>
@@ -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;
@@ -198,15 +195,19 @@ lnd_fire(struct lndstr *lp)
        return -1;
     if (lp->lnd_item[I_MILIT] == 0)
        return -1;
-    guns = lp->lnd_dam;
+    guns = lnd_dam(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);
     if (shells == 0)
        return -1;
+    lnd_unlimber(lp);
     d = landunitgun(lp->lnd_effic, guns);
     if (shells < ammo) {
        d *= (double)shells / (double)ammo;
@@ -222,7 +223,7 @@ lnd_fire(struct lndstr *lp)
 int
 shp_usable_guns(struct shpstr *sp)
 {
-    return MIN(sp->shp_glim, sp->shp_item[I_GUN]);
+    return MIN(shp_glim(sp), sp->shp_item[I_GUN]);
 }
 
 /*
@@ -259,7 +260,7 @@ fortrange(struct sctstr *sp)
 double
 shp_fire_range(struct shpstr *sp)
 {
-    return effrange(sp->shp_frnge, sp->shp_tech);
+    return effrange(shp_frnge(sp), sp->shp_tech);
 }
 
 /*
@@ -268,7 +269,7 @@ shp_fire_range(struct shpstr *sp)
 double
 torprange(struct shpstr *sp)
 {
-    return effrange(sp->shp_frnge * 2, sp->shp_tech)
+    return effrange(shp_frnge(sp) * 2, sp->shp_tech)
        * sp->shp_effic / 100.0;
 }
 
@@ -278,7 +279,7 @@ torprange(struct shpstr *sp)
 double
 shp_torp_hitchance(struct shpstr *sp, int range)
 {
-    return DTORP_HITCHANCE(range, sp->shp_visib);
+    return DTORP_HITCHANCE(range, shp_visib(sp));
 }
 
 /*
@@ -287,7 +288,11 @@ shp_torp_hitchance(struct shpstr *sp, int range)
 double
 lnd_fire_range(struct lndstr *lp)
 {
-    return effrange(lp->lnd_frg, lp->lnd_tech);
+    struct sctstr sect;
+
+    getsect(lp->lnd_x, lp->lnd_y, &sect);
+    return effrange(lnd_frg(lp), lp->lnd_tech)
+       + (sect.sct_type == SCT_MOUNT ? 0.5 : 0.0);
 }
 
 int