]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/bomb.c
Update copyright notice
[empserver] / src / lib / commands / bomb.c
index d44d7d7d61144f3d02c4edf7cc1dffbc2d6cc4d7..eb46f3917b42532b1a44011cde870209503d6998 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2015, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2020, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                Ken Stevens, Steve McClure, Markus Armbruster
  *
  *  Empire is free software: you can redistribute it and/or modify
@@ -30,7 +30,7 @@
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2015
+ *     Markus Armbruster, 2004-2016
  */
 
 #include <config.h>
@@ -60,24 +60,6 @@ static int changed_plane_aborts(struct plist *);
 static int pinflak_planedamage(struct plnstr *, struct plchrstr *,
                               natid, int);
 
-static i_type bombcomm[] = {
-    I_CIVIL,
-    I_MILIT,
-    I_SHELL,
-    I_GUN,
-    I_PETROL,
-    I_IRON,
-    I_DUST,
-    I_BAR,
-    I_FOOD,
-    I_OIL,
-    I_LCM,
-    I_HCM,
-    I_UW,
-    I_RAD
-};
-static int nbomb = sizeof(bombcomm) / sizeof(*bombcomm);
-
 int
 bomb(void)
 {
@@ -117,8 +99,6 @@ bomb(void)
     pr("target sector is %s\n", xyas(tx, ty, player->cnum));
     getsect(tx, ty, &target);
     ap_to_target = strlen(flightpath);
-    if (flightpath[ap_to_target - 1] == 'h')
-       ap_to_target--;
     pr("range to target is %d\n", ap_to_target);
     /*
      * select planes within range
@@ -196,7 +176,7 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
            pr("Some subs are present in the sector.\n");
     }
     nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0);
-    nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0, 0);
+    nunits = unitsatxy(target->sct_x, target->sct_y, 0, L_SPY);
   retry:
     p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
                  buf);
@@ -238,12 +218,11 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
        ship_bomb(list, target);
        break;
     case 'c':
-       for (i = 0; i < nbomb; i++) {
-           if (!target->sct_item[bombcomm[i]])
-               continue;
-           break;
+       for (i = I_NONE + 1; i <= I_MAX; i++) {
+           if (target->sct_item[i])
+               break;
        }
-       if (i >= nbomb) {
+       if (i > I_MAX) {
            pr("No bombable commodities in %s\n",
               xyas(target->sct_x, target->sct_y, player->cnum));
            goto retry;
@@ -310,13 +289,12 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
     struct sctstr sect;
     int dam = 0;
 
-    for (i = 0; i < nbomb; i++) {
-       if (target->sct_item[bombcomm[i]] == 0)
+    for (i = I_NONE + 1; i <= I_MAX; i++) {
+       if (!target->sct_item[i])
            continue;
-       if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
+       if (opt_SUPER_BARS && i == I_BAR)
            continue;
-       ip = &ichr[bombcomm[i]];
-       pr("some %s\n", ip->i_name);
+       pr("some %s\n", ichr[i].i_name);
     }
     for (;;) {
        ip = whatitem(NULL, "commodity to bomb? ");
@@ -324,24 +302,11 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
            return;
        if (!ip)
            continue;
-
-       for (i = 0; i < nbomb; i++) {
-           if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
-               continue;
-           if (&ichr[bombcomm[i]] == ip)
-               break;
-       }
-       if (i == nbomb) {
+       if (opt_SUPER_BARS && ip->i_uid == I_BAR) {
            pr("You can't bomb %s!\n", ip->i_name);
-           for (i = 0; i < nbomb; i++) {
-               if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
-                   continue;
-               pr("%s%s", i == 0 ? "Bombable: " : ", ",
-                  ichr[bombcomm[i]].i_name);
-           }
-           pr("\n");
-       } else
-           break;
+           continue;
+       }
+       break;
     }
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
@@ -453,10 +418,10 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        else {
            hitchance = pln_hitchance(&plp->plane,
                                      shp_hardtarget(&ship), EF_SHIP);
-           pr("%d%% hitchance...", hitchance);
+           pr("%d%% hit chance...", hitchance);
        }
        if (pct_chance(hitchance)) {
-           /* pinbombing is more accurate than normal bombing */
+           /* pin-bombing is more accurate than normal bombing */
            dam = 2 * pln_damage(&plp->plane, 'p', "");
        } else {
            pr("splash\n");
@@ -480,11 +445,11 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            pr("%s at %s sunk!\n",
               prship(&ship),
               xyas(target->sct_x, target->sct_y, player->cnum));
-       putship(ship.shp_uid, &ship);
        if (dam && (ship.shp_rflags & RET_INJURED))
            retreat_ship(&ship, ship.shp_own, 'i');
        else if (ship.shp_rflags & RET_BOMBED)
            retreat_ship(&ship, ship.shp_own, 'b');
+       putship(ship.shp_uid, &ship);
        collateral_damage(target->sct_x, target->sct_y, dam / 2);
     }
 out:
@@ -551,10 +516,10 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
            hitchance = 100;
        else {
            hitchance = pln_hitchance(&plp->plane, 0, EF_PLANE);
-           pr("%d%% hitchance...", hitchance);
+           pr("%d%% hit chance...", hitchance);
        }
        if (pct_chance(hitchance)) {
-           /* pinbombing is more accurate than normal bombing */
+           /* pin-bombing is more accurate than normal bombing */
            dam = 2 * pln_damage(&plp->plane, 'p', "");
        } else {
            pr("thud\n");
@@ -601,7 +566,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if (changed_plane_aborts(plp))
            continue;
-       nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0, 0);
+       nunits = unitsatxy(target->sct_x, target->sct_y, 0, L_SPY);
        if (nunits == 0) {
            pr("%s could not find any units!\n", prplane(&plp->plane));
            continue;
@@ -617,7 +582,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
            if (*q == '~')
                break;
            if (*q == '?') {
-               unitsatxy(target->sct_x, target->sct_y, 0, 0, 0);
+               unitsatxy(target->sct_x, target->sct_y, 0, L_SPY);
                continue;
            }
            n = atoi(q);
@@ -625,6 +590,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
                continue;
            if (getland(n, &land) && land.lnd_own &&
                land.lnd_ship < 0 && land.lnd_land < 0 &&
+               !(lchr[land.lnd_type].l_flags & L_SPY) &&
                land.lnd_x == target->sct_x && land.lnd_y == target->sct_y)
                unitno = n;
            else
@@ -640,7 +606,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
            flak = roundavg(techfact(land.lnd_tech,
                                     aaf * 3.0 * land.lnd_effic / 100.0));
            mpr(land.lnd_own,
-               "Flak! Firing flak guns from unit %s (aa rating %d)\n",
+               "Flak! Firing flak guns from unit %s (AA rating %d)\n",
                prland(&land), aaf);
            if (pinflak_planedamage(&plp->plane, plp->pcp, land.lnd_own, flak))
                continue;
@@ -651,7 +617,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        else {
            hitchance = pln_hitchance(&plp->plane,
                                      lnd_hardtarget(&land), EF_LAND);
-           pr("%d%% hitchance...", hitchance);
+           pr("%d%% hit chance...", hitchance);
        }
        if (pct_chance(hitchance)) {
            dam = 2 * pln_damage(&plp->plane, 'p', "");
@@ -670,12 +636,12 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
                cname(player->cnum), dam, prland(&land),
                xyas(target->sct_x, target->sct_y, own));
        landdamage(&land, dam);
-       putland(land.lnd_uid, &land);
        if (dam && (land.lnd_rflags & RET_INJURED))
            retreat_land(&land, own, 'i');
        else if (land.lnd_rflags & RET_BOMBED)
            retreat_land(&land, own, 'b');
        nreport(player->cnum, N_UNIT_BOMB, own, 1);
+       putland(land.lnd_uid, &land);
        collateral_damage(target->sct_x, target->sct_y, dam);
     }
 }