New shp_mission_interdiction()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 9 Jan 2010 08:39:15 +0000 (09:39 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 19 Jan 2010 07:37:05 +0000 (08:37 +0100)
Factored out of shp_interdict().  No functional change.

src/lib/subs/shpsub.c

index 3ed92344a21e2de684157d08c9b33e4365166ced..eef91a9ea30cfdb6a600c5ca2031896359630903 100644 (file)
@@ -640,6 +640,22 @@ shp_fort_interdiction(struct emp_qelem *list, coord newx, coord newy,
     return 0;
 }
 
+static int
+shp_mission_interdiction(struct emp_qelem *list, coord x, coord y,
+                        natid victim, int subs)
+{
+    char *what = subs ? "subs" : "ships";
+    int wantflags = subs ? M_SUB : 0;
+    int nowantflags = subs ? 0 : M_SUB;
+
+    return shp_damage(list,
+                     unit_interdict(x, y, victim, what,
+                                    shp_easiest_target(list,
+                                               wantflags, nowantflags),
+                                    MI_INTERDICT),
+                     wantflags, nowantflags, x, y);
+}
+
 static int
 shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
 {
@@ -649,23 +665,12 @@ shp_interdict(struct emp_qelem *list, coord newx, coord newy, natid victim)
        stopping |= shp_fort_interdiction(list, newx, newy, victim);
 
        if (shp_contains(list, newx, newy, 0, M_SUB)) {
-           stopping |=
-               shp_damage(list,
-                          unit_interdict(newx, newy, victim, "ships",
-                                         shp_easiest_target(list, 0, M_SUB),
-                                         MI_INTERDICT),
-                          0, M_SUB, newx, newy);
+           stopping |= shp_mission_interdiction(list, newx, newy, victim, 0);
            stopping |= shp_missile_interdiction(list, newx, newy, victim);
        }
     }
-    if (shp_contains(list, newx, newy, M_SUB, 0)) {
-       stopping |=
-           shp_damage(list,
-                      unit_interdict(newx, newy, victim, "subs",
-                                     shp_easiest_target(list, M_SUB, 0),
-                                     MI_SINTERDICT),
-                      M_SUB, 0, newx, newy);
-    }
+    if (shp_contains(list, newx, newy, M_SUB, 0))
+       stopping |= shp_mission_interdiction(list, newx, newy, victim, 1);
     return stopping;
 }