(bomb, drop, fly, para, reco): Use it.
extern void pln_init(int, s_char *);
/* plnsub.c */
extern void count_planes(struct shpstr *);
+extern struct sctstr *get_assembly_point(char *, struct sctstr *, char *);
extern int pln_onewaymission(struct sctstr *, int *, int *);
extern int pln_oneway_to_carrier_ok(struct emp_qelem *,
struct emp_qelem *, int);
s_char flightpath[MAX_PATH_LEN];
struct nstr_item ni_bomb;
struct nstr_item ni_esc;
- coord x, y;
struct sctstr target;
struct emp_qelem bomb_list;
struct emp_qelem esc_list;
mission = *p;
if (strchr("ps", mission) == 0)
return RET_SYN;
- if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0
- || *p == 0)
+ if (!get_assembly_point(player->argp[4], &ap_sect, buf))
return RET_SYN;
- if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
- return RET_SYN;
- if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
- getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
- pr("Assembly point not owned by you or an ally!\n");
- return RET_SYN;
- }
- ax = x;
- ay = y;
+ ax = ap_sect.sct_x;
+ ay = ap_sect.sct_y;
if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING) == 0
|| *flightpath == 0)
return RET_SYN;
int
drop(void)
{
- s_char *p;
int mission_flags;
coord tx, ty;
coord ax, ay;
s_char flightpath[MAX_PATH_LEN];
struct nstr_item ni_bomb;
struct nstr_item ni_esc;
- coord x, y;
struct sctstr target;
struct emp_qelem bomb_list;
struct emp_qelem esc_list;
if (!snxtitem(&ni_esc, EF_PLANE,
getstarg(player->argp[2], "escort(s)? ", buf)))
pr("No escorts...\n");
- if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0
- || *p == 0)
+ if (!get_assembly_point(player->argp[3], &ap_sect, buf))
return RET_SYN;
- if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
- return RET_SYN;
- if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
- getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
- pr("Assembly point not owned by you or an ally!\n");
- return RET_SYN;
- }
- ax = x;
- ay = y;
+ ax = ap_sect.sct_x;
+ ay = ap_sect.sct_y;
if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, P_FLYING) == 0
|| *flightpath == 0)
return RET_SYN;
int
fly(void)
{
- s_char *p;
int mission_flags;
coord tx, ty;
coord ax, ay;
int cno;
struct nstr_item ni_bomb;
struct nstr_item ni_esc;
- coord x, y;
struct sctstr target;
struct emp_qelem bomb_list;
struct emp_qelem esc_list;
if (!snxtitem(&ni_esc, EF_PLANE,
getstarg(player->argp[2], "escort(s)? ", buf)))
pr("No escorts...\n");
- if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0
- || *p == 0)
+ if (!get_assembly_point(player->argp[3], &ap_sect, buf))
return RET_SYN;
- if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
- return RET_SYN;
- if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
- getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
- pr("Assembly point not owned by you or an ally!\n");
- return RET_SYN;
- }
- ax = x;
- ay = y;
+ ax = ap_sect.sct_x;
+ ay = ap_sect.sct_y;
if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, P_FLYING) == 0
|| *flightpath == 0)
return RET_SYN;
int
para(void)
{
- s_char *p;
int mission_flags;
coord tx, ty;
coord ax, ay;
s_char flightpath[MAX_PATH_LEN];
struct nstr_item ni_bomb;
struct nstr_item ni_esc;
- coord x, y;
struct sctstr target;
struct emp_qelem bomb_list;
struct emp_qelem esc_list;
if (!snxtitem(&ni_esc, EF_PLANE,
getstarg(player->argp[2], "escort(s)? ", buf)))
pr("No escorts...\n");
- if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0
- || *p == 0)
+ if (!get_assembly_point(player->argp[3], &ap_sect, buf))
return RET_SYN;
- if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
- return RET_SYN;
- if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
- getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
- pr("Assembly point not owned by you or an ally!\n");
- return RET_SYN;
- }
- ax = x;
- ay = y;
+ ax = ap_sect.sct_x;
+ ay = ap_sect.sct_y;
if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, P_FLYING) == 0
|| *flightpath == 0)
return RET_SYN;
int
reco(void)
{
- s_char *p;
int mission_flags;
coord tx, ty;
coord ax, ay;
int cno;
struct nstr_item ni_bomb;
struct nstr_item ni_esc;
- coord x, y;
struct sctstr target;
struct emp_qelem bomb_list;
struct emp_qelem esc_list;
if (!snxtitem(&ni_esc, EF_PLANE,
getstarg(player->argp[2], "escort(s)? ", buf)))
pr("No escorts...\n");
- if ((p = getstarg(player->argp[3], "assembly point? ", buf)) == 0
- || *p == 0)
+ if (!get_assembly_point(player->argp[3], &ap_sect, buf))
return RET_SYN;
- if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
- return RET_SYN;
- if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
- getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
- pr("Assembly point not owned by you or an ally!\n");
- return RET_SYN;
- }
- ax = x;
- ay = y;
+ ax = ap_sect.sct_x;
+ ay = ap_sect.sct_y;
if (getpath(flightpath, player->argp[4], ax, ay, 0, 0, P_FLYING) == 0
|| *flightpath == 0)
return RET_SYN;
static int pln_equip(struct plist *, struct ichrstr *, int, s_char);
+/*
+ * Get assembly point argument.
+ * If INPUT is not empty, use it, else prompt for more input using PROMPT.
+ * If this yields a valid assembly point, read it into *AP_SECT and
+ * return AP_SECT.
+ * Else complain and return NULL.
+ * *AP_SECT and BUF[1024] may be modified in either case.
+ */
+struct sctstr *
+get_assembly_point(char *input, struct sctstr *ap_sect, char *buf)
+{
+ char *p;
+ coord x, y;
+
+ p = getstarg(input, "assembly point? ", buf);
+ if (!p || *p == 0)
+ return NULL;
+ if (!sarg_xy(p, &x, &y) || !getsect(x, y, ap_sect))
+ return NULL;
+ if (ap_sect->sct_own && ap_sect->sct_own != player->cnum &&
+ getrel(getnatp(ap_sect->sct_own), player->cnum) != ALLIED) {
+ pr("Assembly point not owned by you or an ally!\n");
+ return NULL;
+ }
+ return ap_sect;
+}
+
int
pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
{