]> git.pond.sub.org Git - empserver/commitdiff
(ac_flak_dam): Redesign so that code common to all its callers ends up
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 24 Jun 2006 14:24:23 +0000 (14:24 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 24 Jun 2006 14:24:23 +0000 (14:24 +0000)
in this function.

include/plane.h
src/lib/commands/bomb.c
src/lib/subs/aircombat.c

index a0bb2f96bac545ad12daeeb907f7364a7deb6ee4..76b32b00f5bf3d68798c60b5dcf7bc8850f4e327 100644 (file)
@@ -157,7 +157,7 @@ struct shiplist {
 /* src/lib/subs/aircombat.c */
 extern void ac_combat_headers(natid, natid);
 extern void ac_airtoair(struct emp_qelem *, struct emp_qelem *);
-extern int ac_flak_dam(int);
+extern int ac_flak_dam(int, int, int);
 extern void ac_encounter(struct emp_qelem *, struct emp_qelem *, coord,
                         coord, char *, int, int,
                         struct emp_qelem *, struct emp_qelem *);
index c10dfb06eee5be36ad99b2e43ecdab3fab3cbe95..62257ec379e36e6954db644fcb4a278bd7e5c9ae 100644 (file)
@@ -864,14 +864,7 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
     natid plane_owner;
     int dam;
 
-    flak -= pp->pln_def;
-    if ((pcp->pl_flags & P_T) == 0)
-       flak--;
-    if (pcp->pl_flags & P_X)
-       flak -= 2;
-    if (pcp->pl_flags & P_H)
-       flak -= 1;
-    dam = ac_flak_dam(flak);
+    dam = ac_flak_dam(flak, pp->pln_def, pcp->pl_flags);
     disp = 0;
     plane_owner = pp->pln_own;
     eff = pp->pln_effic;
index 81353bde572af7ffc94902cf3a06208efcea8aba..95ec82fa164a9dc3bff1250c227bd9eeb4276f3f 100644 (file)
@@ -958,22 +958,9 @@ ac_fireflak(struct emp_qelem *list, natid from, int guns)
     plp = (struct plist *)list->q_forw;
 
     for (qp = list->q_forw; qp != list; qp = next) {
-       /*
-        * fighters don't get shot at by flak
-        * non-tactical bombers are harder to hit with flak.
-        * ('Cause they're not dive-bombing?)
-        */
        next = qp->q_forw;
        plp = (struct plist *)qp;
-       pp = &plp->plane;
-       diff = guns - pp->pln_def;
-       if ((plp->pcp->pl_flags & P_T) == 0)
-           diff--;
-       if (plp->pcp->pl_flags & P_X)
-           diff -= 2;
-       if (plp->pcp->pl_flags & P_H)
-           diff -= 1;
-       n = ac_flak_dam(diff);
+       n = ac_flak_dam(guns, plp->plane.pln_def, plp->pcp->pl_flags);
        ac_planedamage(plp, from, n, 0, 2, 1, msg);
     }
 }
@@ -982,9 +969,9 @@ ac_fireflak(struct emp_qelem *list, natid from, int guns)
  * Calculate flak damage
  */
 int
-ac_flak_dam(int flak)
+ac_flak_dam(int guns, int def, int pl_flags)
 {
-    int dam;
+    int flak, dam;
     float mult;
     /*                            <-7      -7     -6     -5     -4 */
     static float flaktable[18] = { 0.132f, 0.20f, 0.20f, 0.25f, 0.30f,
@@ -994,6 +981,14 @@ ac_flak_dam(int flak)
         0.70f,0.75f, 0.80f, 0.85f, 1.1305f };
     enum { FLAK_MAX = sizeof(flaktable)/sizeof(flaktable[0]) - 1 };
 
+    flak = guns - def;
+    if ((pl_flags & P_T) == 0)
+       flak--;
+    if (pl_flags & P_X)
+       flak -= 2;
+    if (pl_flags & P_H)
+       flak -= 1;
+
     if (flak > 8)
        mult = flaktable[FLAK_MAX];
     else if (flak < -7)