]> git.pond.sub.org Git - empserver/commitdiff
Factor out ship firing range calculation into shp_fire_range()
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 3 Mar 2008 19:20:39 +0000 (20:20 +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/fortdef.c
src/lib/subs/landgun.c
src/lib/subs/mission.c

index ea323c1f742535de35276aea04f660c99af0518b..6e5c46a3c5ab1a46dcbc698e2e1ed01aa3ec2703 100644 (file)
@@ -186,5 +186,6 @@ extern int m_glim(struct mchrstr *, int);
 extern int shp_dchrg(struct shpstr *);
 extern int shp_fire(struct shpstr *);
 extern int shp_torp(struct shpstr *, int);
+extern double shp_fire_range(struct shpstr *);
 
 #endif
index ca52e15aa1b2232acd787e0bae91a27d994fcc83..b65e59de1369f89d37f29c457ac9b699874fafc3 100644 (file)
@@ -306,7 +306,7 @@ multifire(void)
                   fshipno, fship.shp_effic);
                continue;
            }
-           range = effrange(fship.shp_frnge, fship.shp_tech);
+           range = shp_fire_range(&fship);
            range2 = roundrange(range);
            pr("range is %d.00 (%.2f)\n", range2, range);
            if (target == targ_sub
@@ -746,7 +746,7 @@ quiet_bigdef(int attacker, struct emp_qelem *list, natid own, natid aown,
                continue;
            dam += dam2;
        } else {
-           erange = effrange(ship.shp_frnge, ship.shp_tech);
+           erange = shp_fire_range(&ship);
            if (roundrange(erange) < ni.curdist)
                continue;
            dam2 = shp_fire(&ship);
index 829c719ec4b13567e71dd9e08ab44e0b8d8d8545..a33368d2422191bf0cf009462abf426d6f709f76 100644 (file)
@@ -241,7 +241,7 @@ fire_dchrg(struct shpstr *sp, struct shpstr *targ, int ntargets)
 {
     int range, erange, dam;
 
-    erange = roundrange(effrange(sp->shp_frnge, sp->shp_tech));
+    erange = roundrange(shp_fire_range(sp));
     range = mapdist(sp->shp_x, sp->shp_y, targ->shp_x, targ->shp_y);
     if (range > erange)
        return;
index 591fc0f2ba87f4c9d3a7f258e2329d9a6b500256..5e931c779cce53d3a95725088c3af8ff53e8d69a 100644 (file)
@@ -91,7 +91,7 @@ sd(natid att, natid own, coord x, coord y, int noisy, int defending,
            continue;
        if ((mchr[(int)ship.shp_type].m_flags & M_SUB) && !usesubs)
            continue;
-       range = roundrange(effrange(ship.shp_frnge, ship.shp_tech));
+       range = roundrange(shp_fire_range(&ship));
        if (range < ni.curdist)
            continue;
        dam = shp_fire(&ship);
index fbaed6c50be7a52f834ba6bbe372ebad30c25325..73210903cc0ac165e6c728e06b558ac623b51e82 100644 (file)
@@ -255,6 +255,15 @@ fortrange(struct sctstr *sp)
     return rng;
 }
 
+/*
+ * Return firing range for ship SP.
+ */
+double
+shp_fire_range(struct shpstr *sp)
+{
+    return effrange(sp->shp_frnge, sp->shp_tech);
+}
+
 int
 roundrange(double r)
 {
index 1e92f77c2ac4276b04c9f49ac496a4608bfac903..a889a7694075d5e90003e7aa3fb0935d0ec30308 100644 (file)
@@ -530,7 +530,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
                    "Incoming torpedo sighted @ %s hits and does %d damage!\n",
                    xyas(x, y, victim), dam2);
            } else {
-               range = roundrange(effrange(sp->shp_frnge, sp->shp_tech));
+               range = roundrange(shp_fire_range(sp));
                if (md > range)
                    continue;
                if (mission == MI_SINTERDICT)
@@ -835,8 +835,7 @@ oprange(struct empobj *gp, int *radius)
 
     switch (gp->ef_type) {
     case EF_SHIP:
-       range = ldround(effrange(((struct shpstr *)gp)->shp_frnge,
-                                ((struct shpstr *)gp)->shp_tech), 1);
+       range = ldround(shp_fire_range((struct shpstr *)gp), 1);
        break;
     case EF_LAND:
        range = ldround(effrange(((struct lndstr *)gp)->lnd_frg,