]> git.pond.sub.org Git - empserver/blobdiff - src/lib/commands/bomb.c
COPYING duplicates information from README. Remove. Move GPL from
[empserver] / src / lib / commands / bomb.c
index f2fefd811f7909ad1bb28d7ab059b0231de5059a..ba456860793b79bc660b997cc86e8038cb6ff42c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Empire - A multi-player, client/server Internet based war game.
- *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ *  Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
  *                           Ken Stevens, Steve McClure
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -19,9 +19,9 @@
  *
  *  ---
  *
- *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
- *  related information and legal notices. It is expected that any future
- *  projects/authors will amend these files as needed.
+ *  See files README, COPYING and CREDITS in the root of the source
+ *  tree for related information and legal notices.  It is expected
+ *  that future projects/authors will amend these files as needed.
  *
  *  ---
  *
  *     Steve McClure, 1998-2000
  */
 
+#include <config.h>
+
 #include <ctype.h>
 #include <string.h>
 #include "misc.h"
 #include "player.h"
-#include "var.h"
 #include "sect.h"
 #include "ship.h"
 #include "land.h"
 #include "item.h"
 #include "plane.h"
-#include "nuke.h"
 #include "retreat.h"
 #include "xy.h"
 #include "nsc.h"
@@ -65,7 +65,7 @@ static void plane_bomb(struct emp_qelem *list, struct sctstr *target);
 static void land_bomb(struct emp_qelem *list, struct sctstr *target);
 static void ship_bomb(struct emp_qelem *list, struct sctstr *target);
 
-static int bombcomm[] = {
+static i_type bombcomm[] = {
     I_CIVIL,
     I_MILIT,
     I_SHELL,
@@ -81,14 +81,13 @@ static int bombcomm[] = {
     I_UW,
     I_RAD
 };
-static int nbomb = sizeof(bombcomm) / sizeof(int);
+static int nbomb = sizeof(bombcomm) / sizeof(*bombcomm);
 
 int
 bomb(void)
 {
     s_char *p;
     int mission_flags;
-    int tech;
     coord tx, ty;
     coord ax, ay;
     int ap_to_target;
@@ -96,7 +95,6 @@ bomb(void)
     s_char flightpath[MAX_PATH_LEN];
     struct nstr_item ni_bomb;
     struct nstr_item ni_esc;
-    coord x, y;
     struct sctstr target;
     struct emp_qelem bomb_list;
     struct emp_qelem esc_list;
@@ -113,36 +111,24 @@ bomb(void)
     if (!snxtitem(&ni_esc, EF_PLANE,
                  getstarg(player->argp[2], "escort(s)? ", buf)))
        pr("No escorts...\n");
-    if ((p =
-        getstarg(player->argp[3], "pinpoint, or strategic? ", buf)) == 0)
+    p = getstarg(player->argp[3], "pinpoint, or strategic? ", buf);
+    if (!p)
        return RET_SYN;
     mission = *p;
     if (strchr("ps", mission) == 0)
        return RET_SYN;
-    if ((p = getstarg(player->argp[4], "assembly point? ", buf)) == 0
-       || *p == 0)
-       return RET_SYN;
-    if (!sarg_xy(p, &x, &y) || !getsect(x, y, &ap_sect))
-       return RET_SYN;
-    if (ap_sect.sct_own && ap_sect.sct_own != player->cnum &&
-       getrel(getnatp(ap_sect.sct_own), player->cnum) != ALLIED) {
-       pr("Assembly point not owned by you or an ally!\n");
+    if (!get_assembly_point(player->argp[4], &ap_sect, buf))
        return RET_SYN;
-    }
-    ax = x;
-    ay = y;
-    if (getpath(flightpath, player->argp[5], ax, ay, 0, 0,
-               0, P_FLYING) == 0 || *flightpath == 0)
+    ax = ap_sect.sct_x;
+    ay = ap_sect.sct_y;
+    if (getpath(flightpath, player->argp[5], ax, ay, 0, 0, P_FLYING) == 0
+       || *flightpath == 0)
        return RET_SYN;
     tx = ax;
     ty = ay;
     (void)pathtoxy(flightpath, &tx, &ty, fcost);
     pr("target sector is %s\n", xyas(tx, ty, player->cnum));
     getsect(tx, ty, &target);
-    if (target.sct_type == SCT_SANCT) {
-       pr("You can't bomb that sector!\n");
-       return RET_SYN;
-    }
     ip = 0;
     ap_to_target = strlen(flightpath);
     if (*(flightpath + strlen(flightpath) - 1) == 'h')
@@ -158,26 +144,23 @@ bomb(void)
            2, wantflags | P_F | P_ESC, P_M | P_O);
     /*
      * now arm and equip the bombers, transports, whatever.
-     * tech is stored in high 16 bits of mission_flags.
-     * yuck.
      */
-    tech = 0;
     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, &tech);
+    mission_flags = pln_arm(&bomb_list, 2 * ap_to_target, mission,
+                           ip, 0, mission_flags);
     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, &tech);
+    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);
     if (QEMPTY(&bomb_list)) {
        pr("No planes got through fighter defenses\n");
+    } else if (target.sct_type == SCT_SANCT) {
+       pr("You can't bomb that sector!\n");
     } else {
        switch (mission) {
        case 'p':
@@ -220,10 +203,7 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
     int type;
     int bad;
     s_char *p;
-    int vec[I_MAX + 1];
     struct plist *plp;
-    struct emp_qelem *qp;
-    int bestacc;
     int nsubs;
     int nunits;
     struct natstr *natp;
@@ -239,11 +219,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
     nsubs = 0;
     plp = (struct plist *)list->q_forw;
     if (plp->pcp->pl_flags & P_A) {
-       bestacc = 0;
-       for (qp = list->q_forw; qp != list; qp = qp->q_forw)
-           plp = (struct plist *)qp;
-       if (plp->plane.pln_acc < bestacc)
-           bestacc = plp->plane.pln_acc;
        nships = num_shipsatxy(target->sct_x, target->sct_y, 0, 0);
        nsubs = nships - shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
        if (nsubs > 0)
@@ -253,7 +228,6 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
     }
     nplanes = planesatxy(target->sct_x, target->sct_y, 0, 0, list);
     nunits = unitsatxy(target->sct_x, target->sct_y, 0, 0);
-    getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
   retry:
     p = getstring("Bomb what? (ship, plane, land unit, efficiency, commodities) ",
                  buf);
@@ -333,7 +307,7 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
        }
 
        for (i = 0; i < nbomb; i++) {
-           if (!vec[bombcomm[i]])
+           if (!target->sct_item[bombcomm[i]])
                continue;
            break;
        }
@@ -371,7 +345,7 @@ pin_bomb(struct emp_qelem *list, struct sctstr *target)
 static void
 eff_bomb(struct emp_qelem *list, struct sctstr *target)
 {
-    register struct plist *plp;
+    struct plist *plp;
     struct emp_qelem *qp;
     struct sctstr sect;
     int oldeff, dam = 0;
@@ -382,9 +356,8 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target)
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
            continue;
        if (plp->bombs || plp->plane.pln_nuketype != -1)
-           dam +=
-               pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
-                          &nukedam, 1);
+           dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
+                             'p', &nukedam, 1);
     }
     if (dam <= 0)              /* dam == 0 if only nukes were delivered */
        return;
@@ -392,6 +365,7 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target)
     target = &sect;
     oldeff = target->sct_effic;
     target->sct_effic = effdamage(target->sct_effic, dam);
+    target->sct_avail = effdamage(target->sct_avail, dam);
     target->sct_road = effdamage(target->sct_road, dam);
     target->sct_rail = effdamage(target->sct_rail, dam);
     target->sct_defense = effdamage(target->sct_defense, dam);
@@ -405,7 +379,7 @@ 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));
-    if (target->sct_effic < 20) {
+    if (target->sct_effic < SCT_MINEFF) {
        if (target->sct_type == SCT_BSPAN)
            knockdown(target, list);
        else if (target->sct_type == SCT_BTOWER) {
@@ -420,20 +394,18 @@ eff_bomb(struct emp_qelem *list, struct sctstr *target)
 static void
 comm_bomb(struct emp_qelem *list, struct sctstr *target)
 {
-    register struct plist *plp;
+    struct plist *plp;
     float b;
     int i;
     int amt, before;
     struct ichrstr *ip;
-    int vec[I_MAX + 1];
     struct emp_qelem *qp;
     struct sctstr sect;
     int dam = 0;
     int nukedam;
 
-    getvec(VT_ITEM, vec, (s_char *)target, EF_SECTOR);
     for (i = 0; i < nbomb; i++) {
-       if (vec[bombcomm[i]] == 0)
+       if (target->sct_item[bombcomm[i]] == 0)
            continue;
        if (opt_SUPER_BARS && bombcomm[i] == I_BAR)
            continue;
@@ -470,9 +442,8 @@ comm_bomb(struct emp_qelem *list, struct sctstr *target)
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
            continue;
        if (plp->bombs || plp->plane.pln_nuketype != -1)
-           dam +=
-               pln_damage(&plp->plane, target->sct_x, target->sct_y, 'p',
-                          &nukedam, 1);
+           dam += pln_damage(&plp->plane, target->sct_x, target->sct_y,
+                             'p', &nukedam, 1);
     }
     if (dam <= 0)              /* dam == 0 if only nukes were delivered */
        return;
@@ -500,7 +471,6 @@ static void
 ship_bomb(struct emp_qelem *list, struct sctstr *target)
 {
     struct plist *plp;
-    int onsea;
     struct mchrstr *mcp;
     int dam;
     s_char *q;
@@ -510,7 +480,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
     int ignore;
     struct shpstr ship;
     int nships = 0;
-    struct shiplook head, *s, *s2;
+    struct shiplist *head = NULL;
     s_char buf[1024];
     s_char prompt[128];
     s_char msg[128];
@@ -520,21 +490,9 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
     int gun;
     int shell;
 
-    memset(&head, 0, sizeof(struct shiplook));
-    head.uid = -1;
-    onsea = (target->sct_type == SCT_WATER) ? 1 : 0;
     for (qp = list->q_forw; qp != list && !player->aborted;
         qp = qp->q_forw) {
-       if (head.uid != -1) {
-           s = head.next;
-           while (s != (struct shiplook *)0) {
-               s2 = s;
-               s = s->next;
-               free(s2);
-           }
-       }
-       memset(&head, 0, sizeof(struct shiplook));
-       head.uid = -1;
+       free_shiplist(&head);
        plp = (struct plist *)qp;
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
            continue;
@@ -560,7 +518,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            }
            if (*q == '?') {
                if (plp->pcp->pl_flags & P_A)
-                   print_found(&head);
+                   print_shiplist(head);
                else
                    shipsatxy(target->sct_x, target->sct_y, 0, M_SUB);
                continue;
@@ -572,15 +530,19 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            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)
                shipno = n;
        }
        if (shipno < 0)
            continue;
+       if ((plp->pcp->pl_flags & P_A) && !on_shiplist(shipno, head))
+           continue;
 
        shell = gun = 0;
-       gun = min(ship.shp_item[I_GUN], ship.shp_glim);
+       gun = MIN(ship.shp_item[I_GUN], ship.shp_glim);
        if (gun > 0) {
            shell = ship.shp_item[I_SHELL];
            if (shell <= 0)
@@ -603,21 +565,19 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
        if (plp->plane.pln_nuketype != -1)
            hitchance = 100;
        else {
-           hitchance =
-               pln_hitchance(&plp->plane, shp_hardtarget(&ship), EF_SHIP);
+           hitchance = pln_hitchance(&plp->plane,
+                                     shp_hardtarget(&ship), EF_SHIP);
            pr("%d%% hitchance...", hitchance);
        }
        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, target->sct_x, target->sct_y,
+                                'p', &nukedam, 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, target->sct_x, target->sct_y, 'p',
+                            &nukedam, 0);
            collateral_damage(target->sct_x, target->sct_y, dam, list);
            dam = 0;
        }
@@ -639,7 +599,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
            if (((ship.shp_rflags & RET_INJURED) == 0) || !dam)
                retreat_ship(&ship, 'b');
        putship(ship.shp_uid, &ship);
-       getship(n, &ship);
+       getship(ship.shp_uid, &ship);
        if (!ship.shp_own) {
            pr("%s at %s sunk!\n",
               prship(&ship),
@@ -649,12 +609,7 @@ ship_bomb(struct emp_qelem *list, struct sctstr *target)
       next:
        ;
     }
-    s = head.next;
-    while (s != (struct shiplook *)0) {
-       s2 = s;
-       s = s->next;
-       free(s2);
-    }
+    free_shiplist(&head);
 }
 
 static void
@@ -724,15 +679,13 @@ 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, target->sct_x, target->sct_y,
+                                'p', &nukedam, 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, target->sct_x, target->sct_y,
+                            'p', &nukedam, 0);
            collateral_damage(target->sct_x, target->sct_y, dam, list);
            dam = 0;
        }
@@ -763,7 +716,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(plane.pln_x, plane.pln_y, dam, list);
+       collateral_damage(target->sct_x, target->sct_y, dam, list);
       next:
        ;
     }
@@ -780,7 +733,6 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
     s_char buf[1024];
     s_char msg[128];
     struct lndstr land;
-    struct lchrstr *lcp;
     struct emp_qelem *qp;
     int unitno;
     int ignore, flak, hitchance;
@@ -826,8 +778,6 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        if (unitno < 0)
            continue;
 
-       lcp = &lchr[(int)land.lnd_type];
-
        flak = (int)(techfact(land.lnd_tech, (double)land.lnd_aaf) * 3.0);
        if (flak) {
            sprintf(msg,
@@ -842,20 +792,18 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
        if (plp->plane.pln_nuketype != -1)
            hitchance = 100;
        else {
-           hitchance =
-               pln_hitchance(&plp->plane, lnd_hardtarget(&land), EF_LAND);
+           hitchance = pln_hitchance(&plp->plane,
+                                     lnd_hardtarget(&land), EF_LAND);
            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, target->sct_x, target->sct_y,
+                                'p', &nukedam, 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, target->sct_x, target->sct_y, 'p',
+                            &nukedam, 0);
            collateral_damage(target->sct_x, target->sct_y, dam, list);
            dam = 0;
        }
@@ -875,7 +823,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(land.lnd_x, land.lnd_y, dam, list);
+       collateral_damage(target->sct_x, target->sct_y, dam, list);
       next:
        ;
     }
@@ -884,7 +832,7 @@ land_bomb(struct emp_qelem *list, struct sctstr *target)
 static void
 strat_bomb(struct emp_qelem *list, struct sctstr *target)
 {
-    register struct plist *plp;
+    struct plist *plp;
     int dam = 0;
     struct emp_qelem *qp;
     struct sctstr sect;
@@ -895,9 +843,8 @@ strat_bomb(struct emp_qelem *list, struct sctstr *target)
        if ((plp->pcp->pl_flags & P_C) && (!(plp->pcp->pl_flags & P_T)))
            continue;
        if (plp->bombs || plp->plane.pln_nuketype != -1)
-           dam +=
-               pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
-                          &nukedam, 1);
+           dam += pln_damage(&plp->plane, target->sct_x, target->sct_y, 's',
+                             &nukedam, 1);
     }
     if (dam <= 0)              /* dam == 0 if only nukes were delivered */
        return;
@@ -915,11 +862,6 @@ strat_bomb(struct emp_qelem *list, struct sctstr *target)
     putsect(&sect);
 }
 
-#define FLAK_MAX 15
-float lflaktable[16] = { 0.20, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
-    0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85,
-};
-
 static int
 pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
                    int flak)
@@ -932,26 +874,13 @@ pinflak_planedamage(struct plnstr *pp, struct plchrstr *pcp, natid from,
     struct lndstr land;
     natid plane_owner;
     int dam;
-    float mult;
 
     flak -= (pp->pln_def + 1);
     if (pcp->pl_flags & P_X)
        flak -= 2;
     if (pcp->pl_flags & P_H)
        flak -= 1;
-    if (flak > 8)
-       mult = lflaktable[FLAK_MAX] * 1.33;
-    else if (flak < -7)
-       mult = lflaktable[0] * 0.66;
-    else {
-       flak += 7;
-       mult = lflaktable[flak];
-    }
-    mult *= flakscale;
-    dam = (int)((roll(8) + 2) * mult);
-    if (dam > 100)
-       dam = 100;
-
+    dam = ac_flak_dam(flak);
     disp = 0;
     plane_owner = pp->pln_own;
     eff = pp->pln_effic;