]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/bomb.c
Update copyright notice
[empserver] / src / lib / commands / bomb.c
index 7d5653c55d91fd6f92b4302ef9170be96e8b6949..ef8582dedf489059c809a5240232e5071d525eef 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
  *  ---
  *
  *  bomb.c: Fly bombing missions
- * 
+ *
  *  Known contributors to this file:
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
+ *     Markus Armbruster, 2004-2008
  */
 
 #include <config.h>
@@ -41,6 +42,7 @@
 #include "item.h"
 #include "land.h"
 #include "news.h"
+#include "nuke.h"
 #include "optlist.h"
 #include "path.h"
 #include "plane.h"
@@ -79,7 +81,6 @@ int
 bomb(void)
 {
     char *p;
-    int mission_flags;
     coord tx, ty;
     coord ax, ay;
     int ap_to_target;
@@ -98,13 +99,10 @@ bomb(void)
     char buf[1024];
 
     wantflags = 0;
-    if (!snxtitem(&ni_bomb, EF_PLANE, player->argp[1]))
+    if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0)
        return RET_SYN;
-    if (!snxtitem(&ni_esc, EF_PLANE,
-                 getstarg(player->argp[2], "escort(s)? ", buf)))
-       pr("No escorts...\n");
     p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
-    if (!p)
+    if (!p || !*p)
        return RET_SYN;
     mission = *p;
     if (strchr("ps", mission) == 0)
@@ -129,7 +127,6 @@ bomb(void)
     /*
      * select planes within range
      */
-    mission_flags = 0;
     pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target,
            2, wantflags, P_M | P_O);
     pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target,
@@ -137,18 +134,13 @@ bomb(void)
     /*
      * now arm and equip the bombers, transports, whatever.
      */
-    mission_flags |= P_X;      /* stealth (shhh) */
-    mission_flags |= P_H;      /* gets turned off if not all choppers */
-    mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
-                           ip, 0, mission_flags);
+    pln_arm(&bomb_list, 2 * ap_to_target, mission, ip, 0);
     if (QEMPTY(&bomb_list)) {
        pr("No planes could be equipped for the mission.\n");
        return RET_FAIL;
     }
-    mission_flags = pln_arm(&esc_list, 2 * ap_to_target, mission,
-                           ip, P_F | P_ESC, mission_flags);
-    ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, mission_flags,
-                0, 0, 0);
+    pln_arm(&esc_list, 2 * ap_to_target, mission, ip, P_F | P_ESC);
+    ac_encounter(&bomb_list, &esc_list, ax, ay, flightpath, 0);
     if (QEMPTY(&bomb_list)) {
        pr("No planes got through fighter defenses\n");
     } else if (target.sct_type == SCT_SANCT) {
@@ -177,8 +169,7 @@ bomb(void)
            strat_bomb(&bomb_list, &target);
            break;
        default:
-           pr("Bad mission %c\n", mission);
-           break;
+           CANT_REACH();
        }
     }
     pln_put(&bomb_list);
@@ -210,22 +201,20 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
        effadv((int)target->sct_effic), dcp->d_name);
     nsubs = 0;
     plp = (struct plist *)list->q_forw;
+    nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
     if (plp->pcp->pl_flags & P_A) {
-       nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
-       nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
+       nsubs = shipsatxy(target->sct_x, target->sct_y, M_SUB, 0, 1);
        if (nsubs > 0)
            pr("Some subs are present in the sector.\n");
-    } else {
-       nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
     }
-    nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
+    nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
     nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
   retry:
     p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
                  buf);
-    if (p == 0 || *p == 0) {
-       if (player->aborted)
-           return;
+    if (!p)
+       return;
+    if (!*p) {
        bad++;
        if (bad > 2)
            return;
@@ -347,7 +336,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);
     }
@@ -369,9 +358,9 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target)
           "%s bombing raid did %d%% damage in %s\n",
           cname(player->cnum), oldeff - target->sct_effic,
           xyas(target->sct_x, target->sct_y, target->sct_own));
-    bridge_damaged(target, list);
+    bridge_damaged(target);
     putsect(&sect);
-    collateral_damage(target->sct_x, target->sct_y, dam, list);
+    collateral_damage(target->sct_x, target->sct_y, dam);
 }
 
 static void
@@ -424,7 +413,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);
     }
@@ -447,7 +436,7 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
           cname(player->cnum), b, ip->i_name,
           xyas(target->sct_x, target->sct_y, target->sct_own));
     putsect(&sect);
-    collateral_damage(target->sct_x, target->sct_y, dam, list);
+    collateral_damage(target->sct_x, target->sct_y, dam);
 }
 
 static void
@@ -460,7 +449,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;
@@ -472,8 +460,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)))
@@ -482,41 +469,37 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
                                   &plp->plane, &head);
        else
-           nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
+           nships = shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
        if (nships == 0) {
            pr("%s could not find any ships!\n", prplane(&plp->plane));
            continue;
        }
        (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)
-               continue;
-           if (*q == '~') {
-               ignore = 1;
+       while (shipno < 0) {
+           if ((q = getstring(prompt, buf)) == 0)
+               goto out;
+           if (*q == 0)
                continue;
-           }
+           if (*q == '~')
+               break;
            if (*q == '?') {
                if (plp->pcp->pl_flags & P_A)
                    print_shiplist(head);
                else
-                   shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
+                   shipsatxy(target->sct_x, target->sct_y, 0, M_SUB, 0);
                continue;
            }
-           if (*q == 'd')
-               goto next;
-           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_x == target->sct_x &&
-               ship.shp_y == target->sct_y)
+           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;
@@ -543,7 +526,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,
@@ -559,7 +542,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            /* Bombs that miss have to land somewhere! */
            dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
                             'p', &nukedam, 0);
-           collateral_damage(target->sct_x, target->sct_y, dam, list);
+           collateral_damage(target->sct_x, target->sct_y, dam);
            dam = 0;
        }
        if (dam <= 0)           /* dam == 0 if only nukes were delivered */
@@ -586,10 +569,9 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
               prship(&ship),
               xyas(target->sct_x, target->sct_y, player->cnum));
        }
-       collateral_damage(target->sct_x, target->sct_y, dam / 2, list);
-      next:
-       ;
+       collateral_damage(target->sct_x, target->sct_y, dam / 2);
     }
+out:
     free_shiplist(&head);
 }
 
@@ -603,7 +585,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];
@@ -615,7 +596,7 @@ plane_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;
-       nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
+       nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
        if (nplanes == 0) {
            pr("%s could not find any planes!\n", prplane(&plp->plane));
            continue;
@@ -623,28 +604,25 @@ 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, list);
+               planesatxy(target->sct_x, target->sct_y, 0, 0);
                continue;
            }
-           if (*q == 'd')
-               goto next;
            n = atoi(q);
            if (n < 0)
                continue;
            if (getplane(n, &plane) &&
                plane.pln_x == target->sct_x &&
                plane.pln_y == target->sct_y &&
-               ((plane.pln_flags & PLN_LAUNCHED) == 0) &&
-               (!ac_isflying(&plane, list)))
+               plane.pln_ship < 0 && plane.pln_land < 0 &&
+               !(plane.pln_flags & PLN_LAUNCHED))
                planeno = n;
            else
                pr("Plane #%d not spotted\n", n);
@@ -652,7 +630,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);
@@ -667,7 +645,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
            /* Bombs that miss have to land somewhere! */
            dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
                             'p', &nukedam, 0);
-           collateral_damage(target->sct_x, target->sct_y, dam, list);
+           collateral_damage(target->sct_x, target->sct_y, dam);
            dam = 0;
        }
        if (dam <= 0)           /* dam == 0 if only nukes were delivered */
@@ -694,9 +672,7 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
               cname(player->cnum), dam, prplane(&plane),
               xyas(target->sct_x, target->sct_y, own));
        putplane(plane.pln_uid, &plane);
-       collateral_damage(target->sct_x, target->sct_y, dam, list);
-      next:
-       ;
+       collateral_damage(target->sct_x, target->sct_y, dam);
     }
 }
 
@@ -712,7 +688,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;
@@ -729,24 +705,22 @@ 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)
-               continue;
-           if (*q == '~') {
-               ignore = 1;
+       while (unitno < 0) {
+           if ((q = getstring(prompt, buf)) == 0)
+               return;
+           if (*q == 0)
                continue;
-           }
+           if (*q == '~')
+               break;
            if (*q == '?') {
                unitsatxy(target->sct_x, target->sct_y, 0, 0);
                continue;
            }
-           if (*q == 'd')
-               goto next;
            n = atoi(q);
            if (n < 0)
                continue;
-           if (getland(n, &land) &&
+           if (getland(n, &land) && land.lnd_own &&
+               land.lnd_ship < 0 && land.lnd_land < 0 &&
                land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
                unitno = n;
            else
@@ -756,8 +730,9 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
            continue;
 
        aaf = lnd_aaf(&land);
-       flak = (int)(techfact(land.lnd_tech, aaf) * 3.0);
-       if (flak) {
+       if (aaf) {
+           flak = roundavg(techfact(land.lnd_tech,
+                                    aaf * 3.0 * land.lnd_effic / 100.0));
            PR(land.lnd_own,
               "Flak! Firing flak guns from unit %s (aa rating %d)\n",
               prland(&land), aaf);
@@ -766,7 +741,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,
@@ -781,7 +756,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
            /* Bombs that miss have to land somewhere! */
            dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
                             'p', &nukedam, 0);
-           collateral_damage(target->sct_x, target->sct_y, dam, list);
+           collateral_damage(target->sct_x, target->sct_y, dam);
            dam = 0;
        }
        if (dam <= 0)           /* dam == 0 if only nukes were delivered */
@@ -789,9 +764,8 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        if (dam > 100)
            dam = 100;
        own = land.lnd_own;
-       if (own != 0)
-           mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
-               cname(player->cnum), dam, prland(&land));
+       mpr(own, "%s pinpoint bombing raid did %d damage to %s\n",
+           cname(player->cnum), dam, prland(&land));
        check_retreat_and_do_landdamage(&land, dam);
 
        if (land.lnd_rflags & RET_BOMBED)
@@ -799,9 +773,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
                retreat_land(&land, 'b');
        nreport(player->cnum, N_UNIT_BOMB, own, 1);
        putland(land.lnd_uid, &land);
-       collateral_damage(target->sct_x, target->sct_y, dam, list);
-      next:
-       ;
+       collateral_damage(target->sct_x, target->sct_y, dam);
     }
 }
 
@@ -818,7 +790,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);
     }
@@ -831,7 +803,7 @@ strat_bomb(struct emp_qelem *list, struct sctstr *target)
           cname(player->cnum), PERCENT_DAMAGE(dam),
           xyas(target->sct_x, target->sct_y, target->sct_own));
 
-    sectdamage(target, dam, list);
+    sectdamage(target, dam);
 
     pr("did %d damage in %s\n", PERCENT_DAMAGE(dam),
        xyas(target->sct_x, target->sct_y, player->cnum));
@@ -845,8 +817,6 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
     int disp;
     char dmess[255];
     int eff;
-    struct shpstr ship;
-    struct lndstr land;
     natid plane_owner;
     int dam;
 
@@ -874,14 +844,6 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
     if (disp == 1) {
        if (from != 0)
            nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
-       if (pp->pln_ship >= 0) {
-           getship(pp->pln_ship, &ship);
-           take_plane_off_ship(pp, &ship);
-       }
-       if (pp->pln_land >= 0) {
-           getland(pp->pln_land, &land);
-           take_plane_off_land(pp, &land);
-       }
     }
     putplane(pp->pln_uid, pp);