New in_oparea(), factored out of build_mission_list_type()

This commit is contained in:
Markus Armbruster 2008-11-22 12:06:54 -05:00
parent 439fa2eadc
commit 40d8357746
2 changed files with 12 additions and 12 deletions

View 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 off_support(coord, coord, natid, natid);
extern int def_support(coord, coord, natid, natid); extern int def_support(coord, coord, natid, natid);
extern int oprange(struct empobj *); extern int oprange(struct empobj *);
extern int in_oparea(struct empobj *, coord, coord);
extern int cando(int, int); extern int cando(int, int);
extern void show_mission(int, struct nstr_item *); extern void show_mission(int, struct nstr_item *);
extern int air_defense(coord, coord, natid, struct emp_qelem *, extern int air_defense(coord, coord, natid, struct emp_qelem *,

View file

@ -289,8 +289,6 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
struct genlist *glp; struct genlist *glp;
struct empobj *gp; struct empobj *gp;
union empobj_storage item; union empobj_storage item;
int dist;
int radius;
int relat; int relat;
struct sctstr sect; struct sctstr sect;
@ -320,18 +318,9 @@ build_mission_list_type(struct genlist *mi, coord x, coord y, int mission,
} else if (relat > HOSTILE) } else if (relat > HOSTILE)
continue; continue;
dist = mapdist(x, y, gp->opx, gp->opy); if (!in_oparea(gp, x, y))
if (dist > gp->radius)
continue; 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 (opt_SLOW_WAR) {
if (mission != MI_AIR_DEFENSE) { if (mission != MI_AIR_DEFENSE) {
getsect(x, y, &sect); getsect(x, y, &sect);
@ -831,6 +820,16 @@ oprange(struct empobj *gp)
return -1; 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 * Remove all planes who cannot go on
* the mission from the plane list. * the mission from the plane list.