]> git.pond.sub.org Git - empserver/commitdiff
Get rid of msl_launch_mindam()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 10 Oct 2009 20:32:18 +0000 (16:32 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 13 Dec 2009 07:04:07 +0000 (08:04 +0100)
It's awkward, especially in shp_missile_interdiction().  Inline into
callers and simplify.

include/prototypes.h
src/lib/subs/lndsub.c
src/lib/subs/mission.c
src/lib/subs/mslsub.c
src/lib/subs/shpsub.c

index 4b3cc52298ed35daa66d312be5e12efb28196d00..3e9705d02f9b357eab09ca29f9c4fa7ec24f53c0 100644 (file)
@@ -497,8 +497,6 @@ extern int msl_hit(struct plnstr *, int, int, int, int, char *,
                   coord, coord, int);
 extern void msl_sel(struct emp_qelem *, coord, coord, natid, int,
                    int, int);
                   coord, coord, int);
 extern void msl_sel(struct emp_qelem *, coord, coord, natid, int,
                    int, int);
-extern int msl_launch_mindam(struct emp_qelem *, coord, coord, int,
-                            int, int, char *, int);
 /* mtch.c */
 extern int comtch(char *, struct cmndstr *, int);
 /* natarg.c */
 /* mtch.c */
 extern int comtch(char *, struct cmndstr *, int);
 /* natarg.c */
index 04301045fd1b2b687062eed04dedbe501b4cacf7..98fb636cdcf9d8b8a842ecc6898f39dd41e4ccfd 100644 (file)
@@ -718,25 +718,47 @@ static int
 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
                         natid victim)
 {
 lnd_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
                         natid victim)
 {
-    int dam;
+    int mindam = lnd_count(list) * 20;
+    int hardtarget = lnd_easiest_target(list);
+    int dam, newdam;
+    struct plist *plp;
     struct emp_qelem msl_list, *qp, *newqp;
 
     msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
 
     struct emp_qelem msl_list, *qp, *newqp;
 
     msl_sel(&msl_list, newx, newy, victim, P_T, P_MAR, MI_INTERDICT);
 
-    dam = msl_launch_mindam(&msl_list, newx, newy,
-                           lnd_easiest_target(list), EF_LAND,
-                           lnd_count(list) * 20, "troops", victim);
+    dam = 0;
+    for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
+       newqp = qp->q_back;
+       plp = (struct plist *)qp;
+
+       if (dam < mindam && mission_pln_equip(plp, NULL, 'p') >= 0) {
+           if (msl_hit(&plp->plane, hardtarget, EF_LAND,
+                       N_LND_MISS, N_LND_SMISS,
+                       "troops", newx, newy, victim)) {
+               newdam = pln_damage(&plp->plane, 'p', 1);
+               dam += newdam;
+#if 0
+           /*
+            * FIXME want collateral damage on miss, but we get here
+            * too when launch fails or missile is intercepted
+            */
+           } else {
+               /* Missiles that miss have to hit somewhere! */
+               newdam = pln_damage(&plp->plane, 'p', 0);
+               collateral_damage(newx, newy, newdam);
+#endif
+           }
+           plp->plane.pln_effic = 0;
+           putplane(plp->plane.pln_uid, &plp->plane);
+       }
+       emp_remque(qp);
+       free(qp);
+    }
+
     if (dam) {
        mpr(victim, "missile interdiction mission does %d damage!\n", dam);
        collateral_damage(newx, newy, dam);
     }
     if (dam) {
        mpr(victim, "missile interdiction mission does %d damage!\n", dam);
        collateral_damage(newx, newy, dam);
     }
-    qp = msl_list.q_forw;
-    while (qp != msl_list.q_forw) {
-       newqp = qp->q_forw;
-       emp_remque(qp);
-       free(qp);
-       qp = newqp;
-    }
     return dam;
 }
 
     return dam;
 }
 
index cab8182b0b5c73c0f24f00d695eb0cdb5d02c855..b6188472531179a23eee32aba51109f772fd266d 100644 (file)
@@ -389,7 +389,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
     struct plchrstr *pcp;
     int dam = 0, dam2;
     natid plane_owner = 0;
     struct plchrstr *pcp;
     int dam = 0, dam2;
     natid plane_owner = 0;
-    int md, range, air_dam = 0;
+    int md, range, air_dam;
     double hitchance, vrange;
     int targeting_ships = *s == 's'; /* "subs" or "ships" FIXME gross! */
 
     double hitchance, vrange;
     int targeting_ships = *s == 's'; /* "subs" or "ships" FIXME gross! */
 
@@ -547,19 +547,36 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
            break;
        }
     }
            break;
        }
     }
-    if (!QEMPTY(&missiles)) {
-       /* I arbitrarily chose 100 mindam -KHS */
-       dam +=
-           msl_launch_mindam(&missiles, x, y, hardtarget, EF_SECTOR, 100,
-                             "sector", victim);
-       qp = missiles.q_forw;
-       while (qp != (&missiles)) {
-           newqp = qp->q_forw;
-           emp_remque(qp);
-           free(qp);
-           qp = newqp;
+
+    air_dam = 0;
+    for (qp = missiles.q_back; qp != &missiles; qp = newqp) {
+       newqp = qp->q_back;
+       plp = (struct plist *)qp;
+
+       if (air_dam < 100 && mission_pln_equip(plp, NULL, 'p') >= 0) {
+           if (msl_hit(&plp->plane, hardtarget, EF_SECTOR,
+                       N_SCT_MISS, N_SCT_SMISS,
+                       "sector", x, y, victim)) {
+               dam2 = pln_damage(&plp->plane, 'p', 1);
+               air_dam += dam2;
+#if 0
+           /*
+            * FIXME want collateral damage on miss, but we get here
+            * too when launch fails or missile is intercepted
+            */
+           } else {
+               /* Missiles that miss have to hit somewhere! */
+               dam2 = pln_damage(&plp->plane, 'p', 0);
+               collateral_damage(x, y, dam2);
+#endif
+           }
+           plp->plane.pln_effic = 0;
+           putplane(plp->plane.pln_uid, &plp->plane);
        }
        }
+       emp_remque(qp);
+       free(qp);
     }
     }
+    dam += air_dam;
 
     if (QEMPTY(&bombers)) {
        qp = list->q_forw;
 
     if (QEMPTY(&bombers)) {
        qp = list->q_forw;
@@ -593,6 +610,7 @@ perform_mission(coord x, coord y, natid victim, struct emp_qelem *list,
            add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y);
     }
 
            add_airport(&airp, plp->plane.pln_x, plp->plane.pln_y);
     }
 
+    air_dam = 0;
     for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) {
        struct airport *air;
        char buf[512];
     for (qp = airp.q_forw; qp != (&airp); qp = qp->q_forw) {
        struct airport *air;
        char buf[512];
index 6c779d7e93c346eec14f9b042ac17886852c0f5e..8e48692ec2aa035c41efb90b74c2dd3c7028616a 100644 (file)
@@ -353,57 +353,3 @@ msl_intercept(coord x, coord y, natid bombown, int hardtarget,
     }
     return 0;
 }
     }
     return 0;
 }
-
-/* Keep launching missiles on list until mindam damage has been done */
-int
-msl_launch_mindam(struct emp_qelem *list, coord x, coord y, int hardtarget,
-                 int type, int mindam, char *whatp, int victim)
-{
-    struct emp_qelem *qp;
-    struct emp_qelem *next;
-    struct plist *plp;
-    int newdam, dam = 0;
-    int news_item;
-    int snews_item;
-
-    if (type == EF_SHIP) {
-       news_item = N_SHP_MISS;
-       snews_item = N_SHP_SMISS;
-    } else if (type == EF_LAND) {
-       news_item = N_LND_MISS;
-       snews_item = N_LND_SMISS;
-    } else {
-       news_item = N_SCT_MISS;
-       snews_item = N_SCT_SMISS;
-    }
-
-    for (qp = list->q_back; qp != list && dam < mindam;
-        qp = next) {
-       next = qp->q_back;
-       plp = (struct plist *)qp;
-
-       if (mission_pln_equip(plp, NULL, 'p') >= 0) {
-           if (msl_hit(&plp->plane,
-                       hardtarget, type, news_item, snews_item,
-                       whatp, x, y, victim)) {
-               newdam = pln_damage(&plp->plane, 'p', 1);
-               dam += newdam;
-#if 0
-           /*
-            * FIXME want collateral damage on miss, but we get here
-            * too when launch fails or missile is intercepted
-            */
-           } else {
-               /* Missiles that miss have to hit somewhere! */
-               newdam = pln_damage(&plp->plane, 'p', 0);
-               collateral_damage(x, y, newdam);
-#endif
-           }
-           plp->plane.pln_effic = 0;
-           putplane(plp->plane.pln_uid, &plp->plane);
-           emp_remque(qp);
-           free(qp);
-       }
-    }
-    return dam;
-}
index 746dc411131ba8b9748fed29c37655ab4f922a8c..3580e022ec0dd8cd8d142c5c9d26ff56a344643d 100644 (file)
@@ -479,37 +479,48 @@ shp_missile_interdiction(struct emp_qelem *list, coord newx, coord newy,
                         natid victim)
 {
     int dam;
                         natid victim)
 {
     int dam;
-    int twotries;
     int stopping = 0;
     struct emp_qelem msl_list, *qp, *newqp;
     int stopping = 0;
     struct emp_qelem msl_list, *qp, *newqp;
+    struct plist *plp;
     struct ulist *mvs;
     struct ulist *mvs;
-    char what[512];
 
     msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
 
 
     msl_sel(&msl_list, newx, newy, victim, P_T | P_MAR, 0, MI_INTERDICT);
 
-    twotries = 0;
-    while (!QEMPTY(&msl_list) && (mvs = most_valuable_ship(list))) {
-       sprintf(what, "%s", prship(&mvs->unit.ship));
-       dam = msl_launch_mindam(&msl_list, newx, newy,
-                               shp_hardtarget(&mvs->unit.ship),
-                               EF_SHIP, 1, what, victim);
-       if (dam) {
-           mpr(victim,
-               "missile interdiction mission does %d damage to %s!\n",
-               dam, what);
-           shp_damage_one(mvs, dam);
-           twotries = 0;
-           stopping |= 1;
-       } else if (++twotries >= 2) {
-           break;
+    for (qp = msl_list.q_back; qp != &msl_list; qp = newqp) {
+       newqp = qp->q_back;
+       plp = (struct plist *)qp;
+
+       mvs = most_valuable_ship(list);
+       if (mvs && mission_pln_equip(plp, NULL, 'p') >= 0) {
+           if (msl_hit(&plp->plane,
+                       shp_hardtarget(&mvs->unit.ship),
+                       EF_SHIP, N_SHP_MISS, N_SHP_SMISS,
+                       prship(&mvs->unit.ship),
+                       newx, newy, victim)) {
+               dam = pln_damage(&plp->plane, 'p', 1);
+               if (dam) {
+                   mpr(victim,
+                       "missile interdiction mission does %d damage to %s!\n",
+                       dam, prship(&mvs->unit.ship));
+                   shp_damage_one(mvs, dam);
+                   stopping = 1;
+               }
+#if 0
+           /*
+            * FIXME want collateral damage on miss, but we get here
+            * too when launch fails or missile is intercepted
+            */
+           } else {
+               /* Missiles that miss have to hit somewhere! */
+               dam = pln_damage(&plp->plane, 'p', 0);
+               collateral_damage(newx, newy, dam);
+#endif
+           }
+           plp->plane.pln_effic = 0;
+           putplane(plp->plane.pln_uid, &plp->plane);
        }
        }
-    }
-    qp = msl_list.q_forw;
-    while (qp != msl_list.q_forw) {
-       newqp = qp->q_forw;
        emp_remque(qp);
        free(qp);
        emp_remque(qp);
        free(qp);
-       qp = newqp;
     }
 
     return stopping;
     }
 
     return stopping;