diff --git a/include/prototypes.h b/include/prototypes.h index 6f971530..5e2ee9b6 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -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 *, diff --git a/src/lib/subs/mission.c b/src/lib/subs/mission.c index dd45fea6..d8d67f90 100644 --- a/src/lib/subs/mission.c +++ b/src/lib/subs/mission.c @@ -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,18 +318,9 @@ 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) + if (!in_oparea(gp, x, y)) 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) - continue; - /* Ok, the object can get to where the x,y is */ - if (opt_SLOW_WAR) { if (mission != MI_AIR_DEFENSE) { getsect(x, y, §); @@ -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.