]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/bomb.c
Update copyright notice
[empserver] / src / lib / commands / bomb.c
index 66a30e1df2c6754c3db21da29ce685a85664f9b4..e17f411c94ba1295d9d7b9c61268aef052c20c9f 100644 (file)
@@ -1,11 +1,11 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2009, Dave Pare, Jeff Bailey, Thomas Ruschak,
- *                           Ken Stevens, Steve McClure
+ *  Copyright (C) 1986-2012, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *                Ken Stevens, Steve McClure, Markus Armbruster
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  Empire is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation, either version 3 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  *  ---
  *
@@ -31,7 +30,7 @@
  *     Dave Pare, 1986
  *     Ken Stevens, 1995
  *     Steve McClure, 1998-2000
- *     Markus Armbruster, 2004-2009
+ *     Markus Armbruster, 2004-2011
  */
 
 #include <config.h>
@@ -85,23 +84,18 @@ bomb(void)
     coord tx, ty;
     coord ax, ay;
     int ap_to_target;
-    struct ichrstr *ip;
     char flightpath[MAX_PATH_LEN];
     struct nstr_item ni_bomb;
     struct nstr_item ni_esc;
     struct sctstr target;
     struct emp_qelem bomb_list;
     struct emp_qelem esc_list;
-    int wantflags;
     struct sctstr ap_sect;
     char mission;
     struct plist *plp;
     struct emp_qelem *qp, *next;
-    int rel;
-    struct natstr *natp;
     char buf[1024];
 
-    wantflags = 0;
     if (get_planes(&ni_bomb, &ni_esc, player->argp[1], player->argp[2]) < 0)
        return RET_SYN;
     p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
@@ -114,7 +108,7 @@ bomb(void)
        return RET_SYN;
     ax = ap_sect.sct_x;
     ay = ap_sect.sct_y;
-    if (!getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING)
+    if (!getpath(flightpath, player->argp[5], ax, ay, 0, 0, MOB_FLY)
        || *flightpath == 0)
        return RET_SYN;
     tx = ax;
@@ -122,7 +116,6 @@ bomb(void)
     (void)pathtoxy(flightpath, &tx, &ty, fcost);
     pr("target sector is %s\n", xyas(tx, ty, player->cnum));
     getsect(tx, ty, &target);
-    ip = NULL;
     ap_to_target = strlen(flightpath);
     if (flightpath[ap_to_target - 1] == 'h')
        ap_to_target--;
@@ -130,14 +123,14 @@ bomb(void)
     /*
      * select planes within range
      */
-    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,
-           2, wantflags | P_F | P_ESC, P_M | P_O);
+    pln_sel(&ni_bomb, &bomb_list, &ap_sect, ap_to_target, 2,
+           P_B | P_T, P_M | P_O);
+    pln_sel(&ni_esc, &esc_list, &ap_sect, ap_to_target, 2,
+           P_ESC | P_F, P_M | P_O);
     /*
      * now arm and equip the bombers, transports, whatever.
      */
-    pln_arm(&bomb_list, 2 * ap_to_target, mission, ip);
+    pln_arm(&bomb_list, 2 * ap_to_target, mission, NULL);
     if (QEMPTY(&bomb_list)) {
        pr("No planes could be equipped for the mission.\n");
        return RET_FAIL;
@@ -164,20 +157,6 @@ bomb(void)
            }
            break;
        case 's':
-           if (opt_SLOW_WAR) {
-               natp = getnatp(player->cnum);
-               if (target.sct_own) {
-                   rel = getrel(natp, target.sct_own);
-                   if ((rel != AT_WAR) && (player->cnum != target.sct_own)
-                       && (target.sct_own) &&
-                       (target.sct_oldown != player->cnum)) {
-                       pr("You're not at war with them!\n");
-                       pln_put(&bomb_list);
-                       pln_put(&esc_list);
-                       return RET_FAIL;
-                   }
-               }
-           }
            nreport(player->cnum, N_SCT_BOMB, target.sct_own, 1);
            strat_bomb(&bomb_list, &target);
            break;
@@ -201,8 +180,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
     char *p;
     int nsubs;
     int nunits;
-    struct natstr *natp;
-    int rel;
     char buf[1024];
     int i;
 
@@ -233,18 +210,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
     }
     switch (*p) {
     case 'l':
-       if (opt_SLOW_WAR) {
-           natp = getnatp(player->cnum);
-           if (target->sct_own) {
-               rel = getrel(natp, target->sct_own);
-               if ((rel != AT_WAR) && (player->cnum != target->sct_own)
-                   && (target->sct_own) &&
-                   (target->sct_oldown != player->cnum)) {
-                   pr("You're not at war with them!\n");
-                   goto retry;
-               }
-           }
-       }
        if (nunits == 0) {
            pr("no units there\n");
            goto retry;
@@ -252,18 +217,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
        land_bomb(list, target);
        break;
     case 'p':
-       if (opt_SLOW_WAR) {
-           natp = getnatp(player->cnum);
-           if (target->sct_own) {
-               rel = getrel(natp, target->sct_own);
-               if ((rel != AT_WAR) && (player->cnum != target->sct_own)
-                   && (target->sct_own) &&
-                   (target->sct_oldown != player->cnum)) {
-                   pr("You're not at war with them!\n");
-                   goto retry;
-               }
-           }
-       }
        if (nplanes == 0) {
            pr("no planes there\n");
            goto retry;
@@ -285,19 +238,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
        ship_bomb(list, target);
        break;
     case 'c':
-       if (opt_SLOW_WAR) {
-           natp = getnatp(player->cnum);
-           if (target->sct_own) {
-               rel = getrel(natp, target->sct_own);
-               if ((rel != AT_WAR) && (player->cnum != target->sct_own)
-                   && (target->sct_own) &&
-                   (target->sct_oldown != player->cnum)) {
-                   pr("You're not at war with them!\n");
-                   goto retry;
-               }
-           }
-       }
-
        for (i = 0; i < nbomb; i++) {
            if (!target->sct_item[bombcomm[i]])
                continue;
@@ -311,18 +251,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
        comm_bomb(list, target);
        break;
     case 'e':
-       if (opt_SLOW_WAR) {
-           natp = getnatp(player->cnum);
-           if (target->sct_own) {
-               rel = getrel(natp, target->sct_own);
-               if ((rel != AT_WAR) && (player->cnum != target->sct_own)
-                   && (target->sct_own) &&
-                   (target->sct_oldown != player->cnum)) {
-                   pr("You're not at war with them!\n");
-                   goto retry;
-               }
-           }
-       }
        eff_bomb(list, target);
        break;
     case 'q':
@@ -341,21 +269,14 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target)
     struct emp_qelem *qp, *next;
     struct sctstr sect;
     int oldeff, dam = 0;
-    int nukedam;
 
     for (qp = list->q_forw; qp != list; qp = next) {
        next = qp->q_forw;
        plp = (struct plist *)qp;
        if (changed_plane_aborts(plp))
            continue;
-       if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
-           continue;
-       if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
-           dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                             'p', &nukedam, 1);
+       dam += pln_damage(&plp->plane, 'p', 1);
     }
-    if (dam <= 0)              /* dam == 0 if only nukes were delivered */
-       return;
     getsect(target->sct_x, target->sct_y, &sect);
     target = &sect;
     oldeff = target->sct_effic;
@@ -388,7 +309,6 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
     struct emp_qelem *qp, *next;
     struct sctstr sect;
     int dam = 0;
-    int nukedam;
 
     for (i = 0; i < nbomb; i++) {
        if (target->sct_item[bombcomm[i]] == 0)
@@ -428,14 +348,8 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if (changed_plane_aborts(plp))
            continue;
-       if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
-           continue;
-       if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
-           dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                             'p', &nukedam, 1);
+       dam += pln_damage(&plp->plane, 'p', 1);
     }
-    if (dam <= 0)              /* dam == 0 if only nukes were delivered */
-       return;
     getsect(target->sct_x, target->sct_y, &sect);
     target = &sect;
     before = target->sct_item[ip->i_uid];
@@ -472,7 +386,6 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
     char buf[1024];
     char prompt[128];
     int hitchance;
-    int nukedam;
     int flak;
     int gun;
 
@@ -482,8 +395,6 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if (changed_plane_aborts(plp))
            continue;
-       if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
-           continue;
        if (plp->pcp->pl_flags & P_A)
            nships = asw_shipsatxy(target->sct_x, target->sct_y, 0, 0,
                                   &plp->plane, &head);
@@ -494,7 +405,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            continue;
        }
        (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
-                     prplane(&plp->plane), plp->bombs);
+                     prplane(&plp->plane), plp->load);
        shipno = -1;
        while (shipno < 0) {
            if (!(q = getstring(prompt, buf)))
@@ -531,13 +442,12 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        mcp = &mchr[(int)ship.shp_type];
        if (gun > 0 && !(mcp->m_flags & M_SUB)) {
            flak = (int)(techfact(ship.shp_tech, gun) * 2.0);
-           PR(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
-              flak, prship(&ship));
+           mpr(ship.shp_own, "Flak! Firing %d guns from ship %s\n",
+               flak, prship(&ship));
            if (pinflak_planedamage(&plp->plane, plp->pcp, ship.shp_own, flak))
                continue;
        }
 
-       dam = 0;
        if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
        else {
@@ -547,18 +457,14 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        }
        if (roll(100) <= hitchance) {
            /* pinbombing is more accurate than normal bombing */
-           dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                                'p', &nukedam, 1);
+           dam = 2 * pln_damage(&plp->plane, 'p', 1);
        } else {
            pr("splash\n");
            /* Bombs that miss have to land somewhere! */
-           dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                            'p', &nukedam, 0);
+           dam = pln_damage(&plp->plane, 'p', 0);
            collateral_damage(target->sct_x, target->sct_y, dam);
-           dam = 0;
-       }
-       if (dam <= 0)           /* dam == 0 if only nukes were delivered */
            continue;
+       }
        if (mcp->m_flags & M_SUB)
            nreport(player->cnum, N_SUB_BOMB, ship.shp_own, 1);
        else
@@ -601,7 +507,6 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
     char prompt[128];
     char buf[1024];
     int hitchance;
-    int nukedam;
     int nplanes;
 
     for (qp = list->q_forw; qp != list; qp = next) {
@@ -609,15 +514,13 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if (changed_plane_aborts(plp))
            continue;
-       if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
-           continue;
        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;
        }
        (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
-                     prplane(&plp->plane), plp->bombs);
+                     prplane(&plp->plane), plp->load);
        planeno = -1;
        while (planeno < 0) {
            if (!(q = getstring(prompt, buf)))
@@ -646,7 +549,6 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
            continue;
        if (changed_plane_aborts(plp))
            continue;
-       dam = 0;
        if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
        else {
@@ -655,18 +557,14 @@ plane_bomb(struct emp_qelem *list, struct sctstr *target)
        }
        if (roll(100) <= hitchance) {
            /* pinbombing is more accurate than normal bombing */
-           dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                                'p', &nukedam, 1);
+           dam = 2 * pln_damage(&plp->plane, 'p', 1);
        } else {
            pr("thud\n");
            /* Bombs that miss have to land somewhere! */
-           dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                            'p', &nukedam, 0);
+           dam = pln_damage(&plp->plane, 'p', 0);
            collateral_damage(target->sct_x, target->sct_y, dam);
-           dam = 0;
-       }
-       if (dam <= 0)           /* dam == 0 if only nukes were delivered */
            continue;
+       }
        if (dam > 100)
            dam = 100;
        own = plane.pln_own;
@@ -707,7 +605,6 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
     int unitno;
     int aaf, flak, hitchance;
     struct plist *plp;
-    int nukedam;
     int nunits;
 
     for (qp = list->q_forw; qp != list; qp = next) {
@@ -715,15 +612,13 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        plp = (struct plist *)qp;
        if (changed_plane_aborts(plp))
            continue;
-       if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
-           continue;
        nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
        if (nunits == 0) {
            pr("%s could not find any units!\n", prplane(&plp->plane));
            continue;
        }
        (void)sprintf(prompt, "%s, %d bombs.  Target ('~' to skip)? ",
-                     prplane(&plp->plane), plp->bombs);
+                     prplane(&plp->plane), plp->load);
        unitno = -1;
        while (unitno < 0) {
            if (!(q = getstring(prompt, buf)))
@@ -755,14 +650,13 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        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);
+           mpr(land.lnd_own,
+               "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;
        }
 
-       dam = 0;
        if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
        else {
@@ -771,18 +665,14 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
            pr("%d%% hitchance...", hitchance);
        }
        if (roll(100) <= hitchance) {
-           dam = 2 * pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                                'p', &nukedam, 1);
+           dam = 2 * pln_damage(&plp->plane, 'p', 1);
        } else {
            pr("thud\n");
            /* Bombs that miss have to land somewhere! */
-           dam = pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                            'p', &nukedam, 0);
+           dam = pln_damage(&plp->plane, 'p', 0);
            collateral_damage(target->sct_x, target->sct_y, dam);
-           dam = 0;
-       }
-       if (dam <= 0)           /* dam == 0 if only nukes were delivered */
            continue;
+       }
        if (dam > 100)
            dam = 100;
        own = land.lnd_own;
@@ -806,17 +696,17 @@ strat_bomb(struct emp_qelem *list, struct sctstr *target)
     int dam = 0;
     struct emp_qelem *qp;
     struct sctstr sect;
-    int nukedam;
+    struct nukstr nuke;
 
     for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
        plp = (struct plist *)qp;
-       if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
-           continue;
-       if (plp->bombs || nuk_on_plane(&plp->plane) >= 0)
-           dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
-                             's', &nukedam, 1);
+       if (getnuke(nuk_on_plane(&plp->plane), &nuke))
+           detonate(&nuke, target->sct_x, target->sct_y,
+                    plp->plane.pln_flags & PLN_AIRBURST);
+       else
+           dam += pln_damage(&plp->plane, 's', 1);
     }
-    if (dam <= 0)              /* dam == 0 if only nukes were delivered */
+    if (dam <= 0)
        return;
     getsect(target->sct_x, target->sct_y, &sect);
     target = &sect;
@@ -847,39 +737,16 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
                    int flak)
 {
     int disp;
-    char dmess[255];
-    int eff;
-    natid plane_owner;
+    char dmess[14];
     int dam;
 
     dam = ac_flak_dam(flak, pln_def(pp), pcp->pl_flags);
-    disp = 0;
-    plane_owner = pp->pln_own;
-    eff = pp->pln_effic;
     if (dam <= 0)
        return 0;
-    memset(dmess, 0, sizeof(dmess));
-    eff -= dam;
-    if (eff < 0)
-       eff = 0;
-    if (eff < PLANE_MINEFF) {
-       sprintf(dmess, " -- shot down");
-       disp = 1;
-    } else if (chance((100 - eff) / 100.0)) {
-       sprintf(dmess, " -- aborted with %d%% damage", 100 - eff);
-       disp = 2;
-    }
-    PR(plane_owner, "    Flak! %s %s takes %d%s.\n",
-       cname(pp->pln_own), prplane(pp), dam, dmess);
+    disp = ac_damage_plane(pp, from, dam, 1, dmess);
+    mpr(pp->pln_own, "    Flak! %s takes %d%s%s.\n",
+       prplane(pp), dam, *dmess ? " --" : "", dmess);
 
-    pp->pln_effic = eff;
-    if (disp == 1) {
-       if (from != 0)
-           nreport(from, N_DOWN_PLANE, pp->pln_own, 1);
-    }
     putplane(pp->pln_uid, pp);
-
-    if (disp > 0)
-       return 1;
-    return 0;
+    return disp > 0;
 }