]> git.pond.sub.org Git - empserver/commitdiff
(get_assembly_point): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 1 Oct 2005 14:07:35 +0000 (14:07 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 1 Oct 2005 14:07:35 +0000 (14:07 +0000)
(bomb, drop, fly, para, reco): Use it.

include/prototypes.h
src/lib/commands/bomb.c
src/lib/commands/drop.c
src/lib/commands/fly.c
src/lib/commands/para.c
src/lib/commands/reco.c
src/lib/subs/plnsub.c

index 200a7194496100ef1af39d544252f5f098c5b77e..2aa340b0d326db676b3fb236aac5eeff189b1369 100644 (file)
@@ -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);
index 61937d39f2a8393dce2c9e466f1af448074e3758..81b0e010f2200cc87f419d89b9e1d5f38f5e84c3 100644 (file)
@@ -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;
index 1c319880a7e584ada99d9902a0d800e3ef104953..ed8b7e362ed89a35475d6dda4dd42c85a4d2ca04 100644 (file)
@@ -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;
index 78d2f85cdc796bcc576b6d677299da90172148cf..b450f56ea893cca082051e22c57655ed78b33d21 100644 (file)
@@ -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;
index 804781393155f691ec77cd2acbc42f235d31922b..5016efb01c216b1db85cfc2024beab4a31508779 100644 (file)
@@ -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;
index fdfdc2b3d104dbbd49c73e6d49e85d942a85819d..ca230a4ecc7c2ec22a174820a5079676a37c7d73 100644 (file)
@@ -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;
index cfb9175674c71164516c86a2af2f4841a28b98bd..7371f184ad0548765ab585fe5c225025ecb71954 100644 (file)
 
 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)
 {