]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/bomb.c
Fix trailing whitespace
[empserver] / src / lib / commands / bomb.c
index 13991377944eb416c89ce28a3adeabdd32404847..59b19373740aa744cb09814cb7c2762565747968 100644 (file)
@@ -26,7 +26,7 @@
  *  ---
  *
  *  bomb.c: Fly bombing missions
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
@@ -42,6 +42,7 @@
 #include "item.h"
 #include "land.h"
 #include "news.h"
+#include "nuke.h"
 #include "optlist.h"
 #include "path.h"
 #include "plane.h"
@@ -342,7 +343,7 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
            continue;
-       if (plp->bombs || plp->plane.pln_nuketype != -1)
+       if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
            dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
                              'p', &nukedam, 1);
     }
@@ -419,7 +420,7 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
            continue;
-       if (plp->bombs || plp->plane.pln_nuketype != -1)
+       if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
            dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
                              'p', &nukedam, 1);
     }
@@ -455,7 +456,6 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
     int n;
     struct emp_qelem *qp;
     int shipno;
-    int ignore;
     struct shpstr ship;
     int nships = 0;
     struct shiplist *head = NULL;
@@ -467,8 +467,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
     int gun;
     int shell;
 
-    for (qp = list->q_forw; qp != list && !player->aborted;
-        qp = qp->q_forw) {
+    for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
        free_shiplist(&head);
        plp = (struct plist *)qp;
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
@@ -484,15 +483,14 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        }
        (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
                      prplane(&plp->plane), plp->bombs);
-       ignore = 0;
        shipno = -1;
-       while (shipno < 0 && !player->aborted && !ignore) {
-           if ((q = getstring(prompt, buf)) == 0 || *q == 0)
+       while (shipno < 0) {
+           if ((q = getstring(prompt, buf)) == 0)
+               goto out;
+           if (*q == 0)
                continue;
-           if (*q == '~') {
-               ignore = 1;
-               continue;
-           }
+           if (*q == '~')
+               break;
            if (*q == '?') {
                if (plp->pcp->pl_flags & P_A)
                    print_shiplist(head);
@@ -500,16 +498,15 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
                    shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
                continue;
            }
-           if (!isdigit(*q))
-               continue;
            n = atoi(q);
            if (n < 0)
                continue;
-           if ((plp->pcp->pl_flags & P_A) && !on_shiplist(n, head))
-               continue;
-           if (getship(n, &ship) && ship.shp_own &&
+           if ((!(plp->pcp->pl_flags & P_A) || on_shiplist(n, head)) &&
+               getship(n, &ship) && ship.shp_own &&
                ship.shp_x == target->sct_x && ship.shp_y == target->sct_y)
                shipno = n;
+           else
+               pr("Ship #%d not spotted\n", n);
        }
        if (shipno < 0)
            continue;
@@ -536,7 +533,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        }
 
        dam = 0;
-       if (plp->plane.pln_nuketype != -1)
+       if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
        else {
            hitchance = pln_hitchance(&plp->plane,
@@ -581,6 +578,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        }
        collateral_damage(target->sct_x, target->sct_y, dam / 2);
     }
+out:
     free_shiplist(&head);
 }
 
@@ -594,7 +592,6 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
     struct plnstr plane;
     struct emp_qelem *qp;
     int planeno;
-    int ignore;
     struct plist *plp;
     char prompt[128];
     char buf[1024];
@@ -614,14 +611,13 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
        (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
                      prplane(&plp->plane), plp->bombs);
        planeno = -1;
-       ignore = 0;
-       while (planeno < 0 && !player->aborted && !ignore) {
-           if ((q = getstring(prompt, buf)) == 0 || *q == 0)
-               continue;
-           if (*q == '~') {
-               ignore = 1;
+       while (planeno < 0) {
+           if ((q = getstring(prompt, buf)) == 0)
+               return;
+           if (*q == 0)
                continue;
-           }
+           if (*q == '~')
+               break;
            if (*q == '?') {
                planesatxy(target->sct_x, target->sct_y, 0, 0);
                continue;
@@ -641,7 +637,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
        if (planeno < 0)
            continue;
        dam = 0;
-       if (plp->plane.pln_nuketype != -1)
+       if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
        else {
            hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
@@ -699,7 +695,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
     struct lndstr land;
     struct emp_qelem *qp;
     int unitno;
-    int ignore, aaf, flak, hitchance;
+    int aaf, flak, hitchance;
     struct plist *plp;
     int nukedam;
     int nunits;
@@ -716,14 +712,13 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
                      prplane(&plp->plane), plp->bombs);
        unitno = -1;
-       ignore = 0;
-       while (unitno < 0 && !player->aborted && !ignore) {
-           if ((q = getstring(prompt, buf)) == 0 || *q == 0)
+       while (unitno < 0) {
+           if ((q = getstring(prompt, buf)) == 0)
+               return;
+           if (*q == 0)
                continue;
-           if (*q == '~') {
-               ignore = 1;
-               continue;
-           }
+           if (*q == '~')
+               break;
            if (*q == '?') {
                unitsatxy(target->sct_x, target->sct_y, 0, 0);
                continue;
@@ -753,7 +748,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        }
 
        dam = 0;
-       if (plp->plane.pln_nuketype != -1)
+       if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
        else {
            hitchance = pln_hitchance(&plp->plane,
@@ -802,7 +797,7 @@ strat_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
            continue;
-       if (plp->bombs || plp->plane.pln_nuketype != -1)
+       if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
            dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
                              's', &nukedam, 1);
     }