Simplify mission() by separating off clear_mission()
This commit is contained in:
parent
49e8b3c64b
commit
77e3a8fe31
1 changed files with 36 additions and 35 deletions
|
@ -40,6 +40,7 @@
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
||||||
|
static int clear_mission(struct nstr_item *);
|
||||||
static int show_mission(struct nstr_item *);
|
static int show_mission(struct nstr_item *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -57,7 +58,7 @@ mission(void)
|
||||||
struct sctstr opsect;
|
struct sctstr opsect;
|
||||||
union empobj_storage item;
|
union empobj_storage item;
|
||||||
struct empobj *gp;
|
struct empobj *gp;
|
||||||
int num = 0, mobmax, mobused, dist;
|
int num = 0, mobmax, mobused;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
|
@ -107,8 +108,7 @@ mission(void)
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
case 'c':
|
case 'c':
|
||||||
mission = 0;
|
return clear_mission(&ni);
|
||||||
break;
|
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'e':
|
case 'e':
|
||||||
mission = MI_ESCORT;
|
mission = MI_ESCORT;
|
||||||
|
@ -137,7 +137,7 @@ mission(void)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mission && !cando(mission, type)) {
|
if (!cando(mission, type)) {
|
||||||
pr("A %s cannot do that mission!\n", ef_nameof(type));
|
pr("A %s cannot do that mission!\n", ef_nameof(type));
|
||||||
pr("i\tinterdiction (any)\n");
|
pr("i\tinterdiction (any)\n");
|
||||||
pr("s\tsupport (planes only)\n");
|
pr("s\tsupport (planes only)\n");
|
||||||
|
@ -149,7 +149,6 @@ mission(void)
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mission) {
|
|
||||||
if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
|
if ((p = getstarg(player->argp[4], "operations point? ", buf)) == 0
|
||||||
|| *p == 0)
|
|| *p == 0)
|
||||||
return RET_SYN;
|
return RET_SYN;
|
||||||
|
@ -161,10 +160,6 @@ mission(void)
|
||||||
if (!getsect(x, y, &opsect))
|
if (!getsect(x, y, &opsect))
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player->argp[5] != NULL) {
|
if (player->argp[5] != NULL) {
|
||||||
desired_radius = atoi(player->argp[5]);
|
desired_radius = atoi(player->argp[5]);
|
||||||
|
@ -187,7 +182,7 @@ mission(void)
|
||||||
if (!player->owner || gp->own == 0)
|
if (!player->owner || gp->own == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if ((mission && (gp->mobil < mobused)) && mission_mob_cost) {
|
if (gp->mobil < mobused && mission_mob_cost) {
|
||||||
pr("%s: not enough mobility! (needs %d)\n",
|
pr("%s: not enough mobility! (needs %d)\n",
|
||||||
obj_nameof(gp), mobused);
|
obj_nameof(gp), mobused);
|
||||||
continue;
|
continue;
|
||||||
|
@ -204,16 +199,12 @@ mission(void)
|
||||||
return RET_FAIL;
|
return RET_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
dist = mapdist(gp->x, gp->y, x, y);
|
|
||||||
radius = 999;
|
|
||||||
if (mission) {
|
|
||||||
radius = oprange(gp, mission);
|
radius = oprange(gp, mission);
|
||||||
if (radius < dist) {
|
if (radius < 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), radius);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (radius > desired_radius)
|
if (radius > desired_radius)
|
||||||
radius = desired_radius;
|
radius = desired_radius;
|
||||||
|
@ -281,18 +272,15 @@ mission(void)
|
||||||
|
|
||||||
num++; /* good one.. go with it */
|
num++; /* good one.. go with it */
|
||||||
|
|
||||||
if (mission) {
|
|
||||||
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), radius);
|
||||||
gp->mobil -= mobused;
|
gp->mobil -= mobused;
|
||||||
gp->radius = radius;
|
|
||||||
} else
|
|
||||||
gp->radius = 0;
|
|
||||||
|
|
||||||
gp->mission = mission;
|
gp->mission = mission;
|
||||||
gp->opx = x;
|
gp->opx = x;
|
||||||
gp->opy = y;
|
gp->opy = y;
|
||||||
|
gp->radius = radius;
|
||||||
put_empobj(type, gp->uid, gp);
|
put_empobj(type, gp->uid, gp);
|
||||||
}
|
}
|
||||||
if (num == 0) {
|
if (num == 0) {
|
||||||
|
@ -303,6 +291,19 @@ mission(void)
|
||||||
return RET_OK;
|
return RET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
clear_mission(struct nstr_item *np)
|
||||||
|
{
|
||||||
|
union empobj_storage item;
|
||||||
|
|
||||||
|
while (nxtitem(np, &item)) {
|
||||||
|
item.gen.mission = 0;
|
||||||
|
put_empobj(item.gen.ef_type, item.gen.uid, &item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return RET_OK;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
show_mission(struct nstr_item *np)
|
show_mission(struct nstr_item *np)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue