]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/bomb.c
commands: Rename the command functions
[empserver] / src / lib / commands / bomb.c
index 1de00905f3f24352c07dd8e16ab81c02eb396606..ad0ecf24c051de96c3505aff13c0a5ea9a0aea0c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2016, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2021, 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-2016
+ *     Markus Armbruster, 2004-2021
  */
 
 #include <config.h>
@@ -60,26 +60,8 @@ 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)
+c_bomb(void)
 {
     char *p;
     coord tx, ty;
@@ -236,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;
@@ -308,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? ");
@@ -322,17 +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);
-       else
-           break;
+           continue;
+       }
+       break;
     }
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
@@ -444,15 +418,15 @@ 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");
            /* Bombs that miss have to land somewhere! */
-           dam = pln_damage(&plp->plane, 'p', 0);
+           dam = pln_damage(&plp->plane, 'p', NULL);
            collateral_damage(target->sct_x, target->sct_y, dam);
            continue;
        }
@@ -472,9 +446,9 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
               prship(&ship),
               xyas(target->sct_x, target->sct_y, player->cnum));
        if (dam && (ship.shp_rflags & RET_INJURED))
-           retreat_ship(&ship, ship.shp_own, 'i');
+           retreat_ship(&ship, ship.shp_own);
        else if (ship.shp_rflags & RET_BOMBED)
-           retreat_ship(&ship, ship.shp_own, 'b');
+           retreat_ship(&ship, ship.shp_own);
        putship(ship.shp_uid, &ship);
        collateral_damage(target->sct_x, target->sct_y, dam / 2);
     }
@@ -542,15 +516,15 @@ 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");
            /* Bombs that miss have to land somewhere! */
-           dam = pln_damage(&plp->plane, 'p', 0);
+           dam = pln_damage(&plp->plane, 'p', NULL);
            collateral_damage(target->sct_x, target->sct_y, dam);
            continue;
        }
@@ -632,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;
@@ -643,14 +617,14 @@ 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', "");
        } else {
            pr("thud\n");
            /* Bombs that miss have to land somewhere! */
-           dam = pln_damage(&plp->plane, 'p', 0);
+           dam = pln_damage(&plp->plane, 'p', NULL);
            collateral_damage(target->sct_x, target->sct_y, dam);
            continue;
        }
@@ -663,9 +637,9 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
                xyas(target->sct_x, target->sct_y, own));
        landdamage(&land, dam);
        if (dam && (land.lnd_rflags & RET_INJURED))
-           retreat_land(&land, own, 'i');
+           retreat_land(&land, own);
        else if (land.lnd_rflags & RET_BOMBED)
-           retreat_land(&land, own, 'b');
+           retreat_land(&land, own);
        nreport(player->cnum, N_UNIT_BOMB, own, 1);
        putland(land.lnd_uid, &land);
        collateral_damage(target->sct_x, target->sct_y, dam);