]> git.pond.sub.org Git - empserver/commitdiff
New in_oparea(), factored out of build_mission_list_type()
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 22 Nov 2008 17:06:54 +0000 (12:06 -0500)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 17 Dec 2008 16:37:55 +0000 (11:37 -0500)
include/prototypes.h
src/lib/subs/mission.c

index 6f971530165e1732f648316edbb0f56e2f3dd0ce..5e2ee9b6dce4490b89ba19fc39b99207de2e44fd 100644 (file)
@@ -485,6 +485,7 @@ extern int unit_interdict(coord, coord, natid, char *, int, int);
 extern int off_support(coord, coord, natid, natid);
 extern int def_support(coord, coord, natid, natid);
 extern int oprange(struct empobj *);
+extern int in_oparea(struct empobj *, coord, coord);
 extern int cando(int, int);
 extern void show_mission(int, struct nstr_item *);
 extern int air_defense(coord, coord, natid, struct emp_qelem *,
index dd45fea642607ca9dac7336b21d0e9e5c0c0adb7..d8d67f90e4c59626d2cf1333cfeb2ad45b35f8d9 100644 (file)
@@ -289,8 +289,6 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
     struct genlist *glp;
     struct empobj *gp;
     union empobj_storage item;
-    int dist;
-    int radius;
     int relat;
     struct sctstr sect;
 
@@ -320,17 +318,8 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
        } else if (relat > HOSTILE)
            continue;
 
-       dist = mapdist(x, y, gp->opx, gp->opy);
-       if (dist > gp->radius)
-           continue;
-
-       /* Ok, it is within the operations range. */
-       /* Now check from where the object actually is */
-       dist = mapdist(x, y, gp->x, gp->y);
-       radius = oprange(gp);
-       if (dist > radius)
+       if (!in_oparea(gp, x, y))
            continue;
-       /* Ok, the object can get to where the x,y is */
 
        if (opt_SLOW_WAR) {
            if (mission != MI_AIR_DEFENSE) {
@@ -831,6 +820,16 @@ oprange(struct empobj *gp)
     return -1;
 }
 
+/*
+ * Does GP's mission op area cover X,Y?
+ */
+int
+in_oparea(struct empobj *gp, coord x, coord y)
+{
+    return mapdist(x, y, gp->opx, gp->opy) <= gp->radius
+       && mapdist(x, y, gp->x, gp->y) <= oprange(gp);
+}
+
 /*
  *  Remove all planes who cannot go on
  *  the mission from the plane list.