]> git.pond.sub.org Git - empserver/commitdiff
Factor out torpedo hit chance into shp_torp_hitchance()
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 3 Mar 2008 19:59:39 +0000 (20:59 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Fri, 14 Mar 2008 19:25:39 +0000 (20:25 +0100)
include/ship.h
src/lib/commands/mfir.c
src/lib/commands/torp.c
src/lib/subs/landgun.c
src/lib/subs/mission.c

index db6054d138a3244d0488a0bd5d9c07f4ecf1cdaa..923865843bfd9e9e55319613f9a9caa742d7f406 100644 (file)
@@ -188,5 +188,6 @@ extern int shp_fire(struct shpstr *);
 extern int shp_torp(struct shpstr *, int);
 extern double shp_fire_range(struct shpstr *);
 extern int shp_usable_guns(struct shpstr *);
+extern double shp_torp_hitchance(struct shpstr *, int);
 
 #endif
index b0b9345961bf368de0670aebf59cfb368d44a6a0..c9ba7b453f2265c65e4b0c524ea6af2238ad06c8 100644 (file)
@@ -34,7 +34,6 @@
 #include <config.h>
 
 #include "commands.h"
-#include "damage.h"
 #include "empobj.h"
 #include "optlist.h"
 #include "retreat.h"
@@ -742,7 +741,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
            fp->type = targ_ship;
            fp->uid = ship.shp_uid;
            add_to_fired_queue(&fp->queue, list);
-           if (!chance(DTORP_HITCHANCE(range, ship.shp_visib)))
+           if (!chance(shp_torp_hitchance(&ship, range)))
                continue;
            dam += dam2;
        } else {
index a33368d2422191bf0cf009462abf426d6f709f76..590be2b96841437f11168fa98e1de2878812ccaf 100644 (file)
@@ -37,7 +37,6 @@
 #include <config.h>
 
 #include "commands.h"
-#include "damage.h"
 #include "news.h"
 #include "optlist.h"
 #include "retreat.h"
@@ -159,7 +158,7 @@ torp(void)
        getship(victno, &vship);
        vshipown = vship.shp_own;
        range = mapdist(sub.shp_x, sub.shp_y, vship.shp_x, vship.shp_y);
-       hitchance = DTORP_HITCHANCE(range, sub.shp_visib);
+       hitchance = shp_torp_hitchance(&sub, range);
        if (range <= erange) {
            pr("Hitchance = %d%%\n", (int)(hitchance * 100));
        }
@@ -307,7 +306,7 @@ fire_torp(struct shpstr *sp, struct shpstr *targ, int ntargets)
 
     pr("Captain! Torpedoes sighted!\n");
 
-    if (chance(DTORP_HITCHANCE(range, sp->shp_visib))) {
+    if (chance(shp_torp_hitchance(sp, range))) {
        pr("BOOM!...\n");
        if (sp->shp_own != 0)
            wu(0, sp->shp_own, "%s @ %s torpedoed %s\n",
index 4f0c018d60cc7dd903b350c7c159f53a8be0dad6..9654aacef18ed85437a330e929e8720796668d00 100644 (file)
@@ -235,16 +235,6 @@ effrange(int rng, double tlev)
     return techfact((int)tlev, rng / 2.0);
 }
 
-/*
- * Return torpedo range for ship SP.
- */
-double
-torprange(struct shpstr *sp)
-{
-    return effrange(sp->shp_frnge * 2, sp->shp_tech)
-       * sp->shp_effic / 100.0;
-}
-
 /*
  * Return firing range for sector SP.
  */
@@ -272,6 +262,25 @@ shp_fire_range(struct shpstr *sp)
     return effrange(sp->shp_frnge, sp->shp_tech);
 }
 
+/*
+ * Return torpedo range for ship SP.
+ */
+double
+torprange(struct shpstr *sp)
+{
+    return effrange(sp->shp_frnge * 2, sp->shp_tech)
+       * sp->shp_effic / 100.0;
+}
+
+/*
+ * Return hit chance for torpedo from ship SP at range RANGE.
+ */
+double
+shp_torp_hitchance(struct shpstr *sp, int range)
+{
+    return DTORP_HITCHANCE(range, sp->shp_visib);
+}
+
 /*
  * Return firing range for land unit SP.
  */
index 4de50a73f690bbfd8c28d4d36a4335de0d6c8ced..362b15f409ab637904000f9f204686ab37cf94ca 100644 (file)
@@ -35,7 +35,6 @@
 #include <config.h>
 
 #include <stdlib.h>
-#include "damage.h"
 #include "empobj.h"
 #include "file.h"
 #include "item.h"
@@ -501,7 +500,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
                putship(sp->shp_uid, sp);
                if (dam2 < 0)
                    continue;
-               hitchance = DTORP_HITCHANCE(md, sp->shp_visib);
+               hitchance = shp_torp_hitchance(sp, md);
 
                wu(0, sp->shp_own,
                   "%s locking on %s %s in %s\n",