]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/laun.c
Fix satellite interception not to break "positioned over" line
[empserver] / src / lib / commands / laun.c
index 2cc523ce830e66434202e04a9b98b5631094e2e6..ead42de464df43259275b50296e976c7e030120c 100644 (file)
@@ -136,39 +136,26 @@ laun(void)
 static int
 launch_as(struct plnstr *pp)
 {
-    coord sx, sy;
     char *cp, buf[1024];
     struct plnstr plane;
-    struct nstr_item ni;
-    int goodtarget;
     int dam, nukedam;
     natid oldown;
 
-    cp = getstarg(player->argp[2], "Target sector? ", buf);
+    cp = getstarg(player->argp[2], "Target satellite? ", buf);
     if (!check_plane_ok(pp))
        return RET_FAIL;
     if (!cp || !*cp)
        return RET_SYN;
-    if (!sarg_xy(cp, &sx, &sy)) {
-       pr("Bad sector designation!\n");
-       return RET_SYN;
-    }
-    if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > pp->pln_range) {
-       pr("Range too great!\n");
+    if (!getplane(atoi(cp), &plane) || !plane.pln_own
+       || !pln_is_in_orbit(&plane)) {
+       pr("No such satellite exists!\n");
        return RET_FAIL;
+       /* Can be abused to find satellite ids.  Tolerable.  */
     }
-    goodtarget = 0;
-    snxtitem_xy(&ni, EF_PLANE, sx, sy);
-    while (!goodtarget && nxtitem(&ni, &plane)) {
-       if (!plane.pln_own)
-           continue;
-       if (!pln_is_in_orbit(&plane))
-           continue;
-       goodtarget = 1;
 
-    }
-    if (!goodtarget) {
-       pr("No satellites there!\n");
+    if (mapdist(pp->pln_x, pp->pln_y, plane.pln_x, plane.pln_y)
+       > pp->pln_range) {
+       pr("Range too great!\n");
        return RET_FAIL;
     }
     if (msl_equip(pp, 'p') < 0) {
@@ -176,10 +163,9 @@ launch_as(struct plnstr *pp)
        return RET_FAIL;
     }
     if (msl_hit(pp, pln_def(&plane), EF_PLANE, N_SAT_KILL, N_SAT_KILL,
-               prplane(&plane), sx, sy, plane.pln_own)) {
-       dam = pln_damage(pp, sx, sy, 'p', &nukedam, 1);
-       if (CANT_HAPPEN(nukedam))
-           return RET_OK;
+               prplane(&plane), plane.pln_x, plane.pln_y, plane.pln_own)) {
+       dam = pln_damage(pp, plane.pln_x, plane.pln_y, 'p', &nukedam, 1);
+       CANT_HAPPEN(nukedam);
        oldown = plane.pln_own;
        planedamage(&plane, dam);
        pr("Hit satellite for %d%% damage!\n", dam);
@@ -222,7 +208,7 @@ launch_missile(struct plnstr *pp, int sublaunch)
        return RET_SYN;
     if (!check_plane_ok(pp))
        return RET_FAIL;
-    if (opt_PINPOINTMISSILE && sarg_type(cp) == NS_LIST) {
+    if (sarg_type(cp) == NS_LIST) {
        if (!(pcp->pl_flags & P_MAR)) {
            pr("Missile not designed to attack ships!\n");
            return RET_FAIL;
@@ -240,17 +226,16 @@ launch_missile(struct plnstr *pp, int sublaunch)
            pr("Bad ship number!\n");
            return RET_FAIL;
        }
-    } /* not PINPOINTMISSILE for ships */
-    else if (!sarg_xy(cp, &sx, &sy)) {
+    } else if (!sarg_xy(cp, &sx, &sy)) {
        pr("Not a sector!\n");
        return RET_FAIL;
-    } else if (opt_PINPOINTMISSILE) {
+    } else {
        if (pcp->pl_flags & P_MAR) {
            pr("Missile designed to attack ships!\n");
            return RET_FAIL;
        }
     }
-    /* end PINPOINTMISSILE */
+
     if (mapdist(pp->pln_x, pp->pln_y, sx, sy) > pp->pln_range) {
        pr("Range too great; try again!\n");
        return RET_FAIL;
@@ -259,7 +244,7 @@ launch_missile(struct plnstr *pp, int sublaunch)
        pr("%s not enough shells!\n", prplane(pp));
        return RET_FAIL;
     }
-    if (opt_PINPOINTMISSILE == 0 || !(pcp->pl_flags & P_MAR)) {
+    if (!(pcp->pl_flags & P_MAR)) {
        getsect(sx, sy, &sect);
        if (opt_SLOW_WAR) {
            natp = getnatp(player->cnum);
@@ -304,8 +289,7 @@ launch_missile(struct plnstr *pp, int sublaunch)
            sectdamage(&sect, dam);
            putsect(&sect);
        }
-    } /* end PINPOINTMISSILE conditional */
-    else if (opt_PINPOINTMISSILE) {    /* else */
+    } else {
        if (!msl_hit(pp, shp_hardtarget(&target_ship), EF_SHIP,
                     N_SHP_MISS, N_SHP_SMISS, prship(&target_ship),
                     target_ship.shp_x, target_ship.shp_y,
@@ -327,7 +311,6 @@ launch_missile(struct plnstr *pp, int sublaunch)
        if (!target_ship.shp_own)
            pr("%s sunk!\n", prship(&target_ship));
     }
-    /* end PINPOINTMISSILE */
     return RET_OK;
 }
 
@@ -363,7 +346,7 @@ launch_sat(struct plnstr *pp, int sublaunch)
        return RET_FAIL;
     }
     p = getstring("Geostationary orbit? ", buf);
-    if (p == 0)
+    if (!p)
        return RET_SYN;
     if (!check_plane_ok(pp))
        return RET_FAIL;
@@ -389,7 +372,6 @@ launch_sat(struct plnstr *pp, int sublaunch)
        pr("Your trajectory was a little off.\n");
     }
     nreport(player->cnum, N_LAUNCH, 0, 1);
-    pr("%s positioned over %s", prplane(pp), xyas(sx, sy, player->cnum));
     if (msl_intercept(sx, sy, pp->pln_own, pcp->pl_def, sublaunch, P_O, 0)) {
        return RET_OK;
     }
@@ -399,7 +381,8 @@ launch_sat(struct plnstr *pp, int sublaunch)
     pp->pln_flags |= PLN_LAUNCHED;
     pp->pln_mobil = pp->pln_mobil > dist ? pp->pln_mobil - dist : 0;
     putplane(pp->pln_uid, pp);
-    pr(", will be ready for use in %d time units\n",
+    pr("%s positioned over %s, will be ready for use in %d time units\n",
+       prplane(pp), xyas(sx, sy, player->cnum),
        plane_mob_max - pp->pln_mobil);
     return RET_OK;
 }