Remove oprange()'s mission parameter
Use the current mission instead. Make mission() set it before calling oprange(), and clean up somewhat.
This commit is contained in:
parent
ca9af92523
commit
d5f371cc1d
3 changed files with 27 additions and 26 deletions
|
@ -483,7 +483,7 @@ extern int ground_interdict(coord, coord, natid, char *);
|
||||||
extern int unit_interdict(coord, coord, natid, char *, int, int);
|
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 *, int);
|
extern int oprange(struct empobj *);
|
||||||
extern int in_oparea(struct empobj *, coord, coord);
|
extern int in_oparea(struct empobj *, coord, coord);
|
||||||
extern int cando(int, int);
|
extern int cando(int, int);
|
||||||
extern int air_defense(coord, coord, natid, struct emp_qelem *,
|
extern int air_defense(coord, coord, natid, struct emp_qelem *,
|
||||||
|
|
|
@ -54,7 +54,7 @@ mission(void)
|
||||||
int type;
|
int type;
|
||||||
int mission;
|
int mission;
|
||||||
coord x, y;
|
coord x, y;
|
||||||
int desired_radius, radius;
|
int radius, range;
|
||||||
union empobj_storage item;
|
union empobj_storage item;
|
||||||
struct empobj *gp;
|
struct empobj *gp;
|
||||||
int num = 0, mobmax, mobused;
|
int num = 0, mobmax, mobused;
|
||||||
|
@ -158,14 +158,13 @@ mission(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->argp[5] != NULL) {
|
if (player->argp[5] != NULL) {
|
||||||
desired_radius = atoi(player->argp[5]);
|
radius = atoi(player->argp[5]);
|
||||||
if (desired_radius < 0) {
|
if (radius < 0) {
|
||||||
pr("Radius must be greater than zero!\n");
|
pr("Radius can't be negative!\n");
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
} else {
|
} else
|
||||||
desired_radius = 9999;
|
radius = 9999;
|
||||||
}
|
|
||||||
|
|
||||||
if ((mobmax = get_empobj_mob_max(type)) == -1)
|
if ((mobmax = get_empobj_mob_max(type)) == -1)
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
|
@ -255,27 +254,23 @@ mission(void)
|
||||||
y = gp->y;
|
y = gp->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
radius = oprange(gp, mission);
|
gp->mobil -= mobused;
|
||||||
if (radius < mapdist(gp->x, gp->y, x, y)) {
|
gp->mission = mission;
|
||||||
|
range = oprange(gp);
|
||||||
|
if (range < mapdist(gp->x, gp->y, x, y)) {
|
||||||
pr("%s: out of range! (range %d)\n",
|
pr("%s: out of range! (range %d)\n",
|
||||||
obj_nameof(gp), radius);
|
obj_nameof(gp), range);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
gp->opx = x;
|
||||||
if (radius > desired_radius)
|
gp->opy = y;
|
||||||
radius = desired_radius;
|
gp->radius = MIN(range, radius);
|
||||||
num++; /* good one.. go with it */
|
put_empobj(type, gp->uid, gp);
|
||||||
|
num++;
|
||||||
|
|
||||||
pr("%s on %s mission, centered on %s, radius %d\n",
|
pr("%s on %s mission, centered on %s, radius %d\n",
|
||||||
obj_nameof(gp), mission_name(mission),
|
obj_nameof(gp), mission_name(mission),
|
||||||
xyas(x, y, player->cnum), radius);
|
xyas(x, y, player->cnum), gp->radius);
|
||||||
gp->mobil -= mobused;
|
|
||||||
|
|
||||||
gp->mission = mission;
|
|
||||||
gp->opx = x;
|
|
||||||
gp->opy = y;
|
|
||||||
gp->radius = radius;
|
|
||||||
put_empobj(type, gp->uid, gp);
|
|
||||||
}
|
}
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
pr("No %s%s\n", ef_nameof(type), splur(num));
|
pr("No %s%s\n", ef_nameof(type), splur(num));
|
||||||
|
|
|
@ -741,14 +741,20 @@ mission_name(short mission)
|
||||||
return "a mysterious";
|
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
|
int
|
||||||
oprange(struct empobj *gp, int mission)
|
oprange(struct empobj *gp)
|
||||||
{
|
{
|
||||||
switch (gp->ef_type) {
|
switch (gp->ef_type) {
|
||||||
case EF_SHIP:
|
case EF_SHIP:
|
||||||
return ldround(shp_fire_range((struct shpstr *)gp), 1);
|
return ldround(shp_fire_range((struct shpstr *)gp), 1);
|
||||||
case EF_LAND:
|
case EF_LAND:
|
||||||
if (mission == MI_RESERVE)
|
if (gp->mission == MI_RESERVE)
|
||||||
return lnd_reaction_range((struct lndstr *)gp);
|
return lnd_reaction_range((struct lndstr *)gp);
|
||||||
return ldround(lnd_fire_range((struct lndstr *)gp), 1);
|
return ldround(lnd_fire_range((struct lndstr *)gp), 1);
|
||||||
case EF_PLANE:
|
case EF_PLANE:
|
||||||
|
@ -768,7 +774,7 @@ int
|
||||||
in_oparea(struct empobj *gp, coord x, coord y)
|
in_oparea(struct empobj *gp, coord x, coord y)
|
||||||
{
|
{
|
||||||
return mapdist(x, y, gp->opx, gp->opy) <= gp->radius
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue