diff --git a/include/prototypes.h b/include/prototypes.h index 200a7194..2aa340b0 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -560,6 +560,7 @@ extern int pln_prewrite(int, s_char *); 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); diff --git a/src/lib/commands/bomb.c b/src/lib/commands/bomb.c index 61937d39..81b0e010 100644 --- a/src/lib/commands/bomb.c +++ b/src/lib/commands/bomb.c @@ -93,7 +93,6 @@ bomb(void) 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; @@ -116,18 +115,10 @@ bomb(void) 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; diff --git a/src/lib/commands/drop.c b/src/lib/commands/drop.c index 1c319880..ed8b7e36 100644 --- a/src/lib/commands/drop.c +++ b/src/lib/commands/drop.c @@ -47,7 +47,6 @@ int drop(void) { - s_char *p; int mission_flags; coord tx, ty; coord ax, ay; @@ -56,7 +55,6 @@ drop(void) 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; @@ -70,18 +68,10 @@ drop(void) 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; diff --git a/src/lib/commands/fly.c b/src/lib/commands/fly.c index 78d2f85c..b450f56e 100644 --- a/src/lib/commands/fly.c +++ b/src/lib/commands/fly.c @@ -48,7 +48,6 @@ int fly(void) { - s_char *p; int mission_flags; coord tx, ty; coord ax, ay; @@ -59,7 +58,6 @@ fly(void) 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; @@ -75,18 +73,10 @@ fly(void) 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; diff --git a/src/lib/commands/para.c b/src/lib/commands/para.c index 80478139..5016efb0 100644 --- a/src/lib/commands/para.c +++ b/src/lib/commands/para.c @@ -53,7 +53,6 @@ static int paradrop(struct emp_qelem *list, coord x, coord y); int para(void) { - s_char *p; int mission_flags; coord tx, ty; coord ax, ay; @@ -61,7 +60,6 @@ para(void) 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; @@ -75,18 +73,10 @@ para(void) 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; diff --git a/src/lib/commands/reco.c b/src/lib/commands/reco.c index fdfdc2b3..ca230a4e 100644 --- a/src/lib/commands/reco.c +++ b/src/lib/commands/reco.c @@ -46,7 +46,6 @@ int reco(void) { - s_char *p; int mission_flags; coord tx, ty; coord ax, ay; @@ -55,7 +54,6 @@ reco(void) 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; @@ -69,18 +67,10 @@ reco(void) 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; diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index cfb91756..7371f184 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -51,6 +51,33 @@ 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) {