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 *, int);
+extern int oprange(struct empobj *);
extern int in_oparea(struct empobj *, coord, coord);
extern int cando(int, int);
extern int air_defense(coord, coord, natid, struct emp_qelem *,
int type;
int mission;
coord x, y;
- int desired_radius, radius;
+ int radius, range;
union empobj_storage item;
struct empobj *gp;
int num = 0, mobmax, mobused;
}
if (player->argp[5] != NULL) {
- desired_radius = atoi(player->argp[5]);
- if (desired_radius < 0) {
- pr("Radius must be greater than zero!\n");
+ radius = atoi(player->argp[5]);
+ if (radius < 0) {
+ pr("Radius can't be negative!\n");
return RET_FAIL;
}
- } else {
- desired_radius = 9999;
- }
+ } else
+ radius = 9999;
if ((mobmax = get_empobj_mob_max(type)) == -1)
return RET_FAIL;
y = gp->y;
}
- radius = oprange(gp, mission);
- if (radius < mapdist(gp->x, gp->y, x, y)) {
+ gp->mobil -= mobused;
+ gp->mission = mission;
+ range = oprange(gp);
+ if (range < mapdist(gp->x, gp->y, x, y)) {
pr("%s: out of range! (range %d)\n",
- obj_nameof(gp), radius);
+ obj_nameof(gp), range);
continue;
}
-
- if (radius > desired_radius)
- radius = desired_radius;
- num++; /* good one.. go with it */
-
- pr("%s on %s mission, centered on %s, radius %d\n",
- obj_nameof(gp), mission_name(mission),
- xyas(x, y, player->cnum), radius);
- gp->mobil -= mobused;
-
- gp->mission = mission;
gp->opx = x;
gp->opy = y;
- gp->radius = radius;
+ gp->radius = MIN(range, radius);
put_empobj(type, gp->uid, gp);
+ num++;
+
+ pr("%s on %s mission, centered on %s, radius %d\n",
+ obj_nameof(gp), mission_name(mission),
+ xyas(x, y, player->cnum), gp->radius);
}
if (num == 0) {
pr("No %s%s\n", ef_nameof(type), splur(num));
return "a mysterious";
}
+/*
+ * Maximum distance GP can perform its mission.
+ * Note: this has nothing to do with the radius of the op-area.
+ * oprange() governs where the unit *can* strike, the op-area governs
+ * where the player wants it to strike.
+ */
int
-oprange(struct empobj *gp, int mission)
+oprange(struct empobj *gp)
{
switch (gp->ef_type) {
case EF_SHIP:
return ldround(shp_fire_range((struct shpstr *)gp), 1);
case EF_LAND:
- if (mission == MI_RESERVE)
+ if (gp->mission == MI_RESERVE)
return lnd_reaction_range((struct lndstr *)gp);
return ldround(lnd_fire_range((struct lndstr *)gp), 1);
case EF_PLANE:
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, gp->mission);
+ && mapdist(x, y, gp->x, gp->y) <= oprange(gp);
}
/*