]> git.pond.sub.org Git - empserver/commitdiff
Get rid of struct plnstr member pln_nuktype
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 7 Sep 2008 02:15:41 +0000 (22:15 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 9 Sep 2008 01:32:53 +0000 (21:32 -0400)
pln_nuktype is redundant; it can be computed from the nuke's
nuk_plane.

Make plane selector nuketype virtual and NSC_EXTRA.  It should have
been NSC_EXTRA all along.  This changes xdump plane.

Don't set it in arm(), disarm(), build_plane(), pln_damage() and
nuk_fixup().  The latter no longer does anything, remove it.

Deprecate edit key 'n' in doplane(), and don't show it in pr_plane().
The key never made much sense.

eff_bomb(), comm_bomb(), ship_bomb(), plane_bomb(), land_bomb(),
strat_bomb(), mission_pln_equip(), air_damage(), msl_hit(),
pln_equip() tested pln_nuketype to check whether a plane carries a
nuke.  Test nuk_on_plane() instead.

pdump(), plan(), trade_desc() print whether and what kind of nuke a
plane carries.  Adapt that to use nuk_on_plane().

13 files changed:
include/plane.h
src/lib/commands/arm.c
src/lib/commands/bomb.c
src/lib/commands/buil.c
src/lib/commands/edit.c
src/lib/commands/pdump.c
src/lib/commands/plan.c
src/lib/common/nsc.c
src/lib/subs/mission.c
src/lib/subs/mslsub.c
src/lib/subs/plnsub.c
src/lib/subs/trdsub.c
src/util/empdump.c

index 6fb735f0fb84c18067d09d752bc334f0f3e1bcb3..d15289044af8589b2a82e3c05f34f3cb6b4ff0da 100644 (file)
@@ -68,7 +68,6 @@ struct plnstr {
     short pln_ship;            /* pointer to carrier */
     short pln_land;            /* pointer to carrier */
     signed char pln_harden;    /* for missiles */
-    signed char pln_nuketype;  /* type of nuclear armament (if any) */
     signed char pln_flags;     /* State of the plane */
     short pln_access;          /* Last tick mob was updated (MOB_ACCESS) */
     float pln_theta;           /* position in orbital sine wave */
index 8a443caa7f926180edf49530415934e4c5147882..bb4a6a08670cea21d4c36e7bc56f733e63a8bb08 100644 (file)
@@ -111,7 +111,6 @@ arm(void)
        snprintf(buf, sizeof(buf), "armed on your %s in %s",
                 prplane(&pl), xyas(pl.pln_x, pl.pln_y, pl.pln_own));
        gift(pl.pln_own, player->cnum, &nuke, buf);
-       pl.pln_nuketype = nuke.nuk_type;
        nuke.nuk_plane = pl.pln_uid;
        putplane(pl.pln_uid, &pl);
        putnuke(nuke.nuk_uid, &nuke);
@@ -159,7 +158,6 @@ disarm(void)
                 xyas(sect.sct_x, sect.sct_y, sect.sct_own));
        gift(sect.sct_own, player->cnum, &nuke, buf);
        nuke.nuk_plane = -1;
-       pl.pln_nuketype = -1;
        pl.pln_flags &= ~PLN_AIRBURST;
        putplane(pl.pln_uid, &pl);
        putnuke(nuke.nuk_uid, &nuke);
index 9140936a53f765a28f64abf6e4970869ce12b59d..583079f3ee50f83e4a0f1f3c93ba518ea3b1d36c 100644 (file)
@@ -42,6 +42,7 @@
 #include "item.h"
 #include "land.h"
 #include "news.h"
+#include "nuke.h"
 #include "optlist.h"
 #include "path.h"
 #include "plane.h"
@@ -342,7 +343,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);
     }
@@ -419,7 +420,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);
     }
@@ -532,7 +533,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,
@@ -636,7 +637,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);
@@ -747,7 +748,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,
@@ -796,7 +797,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);
     }
index 6a80a3ab1f5898da4c60f9abdb2b4ea7778164c8..cce2f01968e854cc250a482a6582b1b665605830 100644 (file)
@@ -778,7 +778,6 @@ build_plane(struct sctstr *sp, struct plchrstr *pp, short *vec, int tlev)
     plane.pln_wing = 0;
     plane.pln_ship = -1;
     plane.pln_land = -1;
-    plane.pln_nuketype = -1;
     plane.pln_harden = 0;
     plane.pln_flags = 0;
     pln_set_tech(&plane, tlev);
index 55695414b438730526fa4ce3e2466d5b57cab4b1..7e4c8ecf04583fa5394328584967f39e176a7663 100644 (file)
@@ -332,7 +332,6 @@ pr_plane(struct plnstr *plane)
     pr("Flags <f>: %d\n", plane->pln_flags);
     pr("Ship <s>: %d\t\t", plane->pln_ship);
     pr("Land Unit <y>: %d\t", plane->pln_land);
-    pr("Nuke Type <n>: %d\n", plane->pln_nuketype);
 }
 
 static void
@@ -981,7 +980,7 @@ doplane(char op, int arg, char *p, struct plnstr *plane)
 
     switch (op) {
     case 'n':
-       plane->pln_nuketype = arg;
+       warn_deprecated(op);
        break;
     case 'U':
        ef_set_uid(EF_PLANE, plane, arg);
index 5465e4885373b9794af5e681fd954de893e2162d..c97ea98b1277199f130811fce4a292ef7a797f0b 100644 (file)
@@ -45,6 +45,7 @@ pdump(void)
     int nplanes;
     struct nstr_item np;
     struct plnstr plane;
+    struct nukstr nuke;
     int field[128];
     struct natstr *natp;
     int n, i;
@@ -266,8 +267,8 @@ pdump(void)
                    ? " Y" : " N");
                break;
            case 20:
-               if (plane.pln_nuketype != -1) {
-                   pr(" %.5s", nchr[(int)plane.pln_nuketype].n_name);
+               if (getnuke(nuk_on_plane(&plane), &nuke)) {
+                   pr(" %.5s", nchr[nuke.nuk_type].n_name);
                    break;
                } else
                    pr(" N/A");
index b841573cbfa62c918bc0ecf1a188bed6b93e58a8..fdc079006ea70aa6b485fc7ac4ec2b8714de8930 100644 (file)
@@ -46,6 +46,7 @@ plan(void)
     int nplanes, noff;
     struct nstr_item np;
     struct plnstr plane;
+    struct nukstr nuke;
 
     if (!snxtitem(&np, EF_PLANE, player->argp[1], NULL))
        return RET_SYN;
@@ -76,9 +77,9 @@ plan(void)
            pr("      ");
        if (pln_is_in_orbit(&plane))
            pr((plane.pln_flags & PLN_SYNCHRONOUS) ? " geosync" : " orbit");
-       else if (plane.pln_nuketype >= 0)
+       else if (getnuke(nuk_on_plane(&plane), &nuke))
            pr(" %-5.5s %c",
-              nchr[(int)plane.pln_nuketype].n_name,
+              nchr[nuke.nuk_type].n_name,
               plane.pln_flags & PLN_AIRBURST ? 'A' : 'G');
        pr("\n");
     }
index f01207e0ccc027cd17ed7e347524b38a319f6674..733e2c5d863acb5f935d288d8589cf68f2cb64a0 100644 (file)
@@ -50,6 +50,7 @@ static void *nsc_ver_maxnoc(struct valstr *, struct natstr *, void *);
 static void *nsc_sct_terr(struct valstr *, struct natstr *, void *);
 static void *nsc_pln_att(struct valstr *, struct natstr *, void *);
 static void *nsc_pln_def(struct valstr *, struct natstr *, void *);
+static void *nsc_pln_nuketype(struct valstr *, struct natstr *, void *);
 static void *nsc_lnd_att(struct valstr *, struct natstr *, void *);
 static void *nsc_lnd_def(struct valstr *, struct natstr *, void *);
 static void *nsc_lnd_vul(struct valstr *, struct natstr *, void *);
@@ -294,13 +295,13 @@ struct castr plane_ca[] = {
     {"ship", fldoff(pln_ship), NSC_SHORT, 0, NULL, EF_BAD, 0},
     {"land", fldoff(pln_land), NSC_SHORT, 0, NULL, EF_BAD, 0},
     {"harden", fldoff(pln_harden), NSC_CHAR, 0, NULL, EF_BAD, 0},
-    {"nuketype", fldoff(pln_nuketype), NSC_CHAR, 0, NULL, EF_BAD, 0},
     {"flags", fldoff(pln_flags), NSC_CHAR, 0, NULL,
      EF_PLANE_FLAGS, NSC_BITS},
     {"access", fldoff(pln_access), NSC_SHORT, 0, NULL, EF_BAD, 0},
     {"theta", fldoff(pln_theta), NSC_FLOAT, 0, NULL, EF_BAD, 0},
     {"att", 0, NSC_LONG, 0, nsc_pln_att, EF_BAD, NSC_EXTRA},
     {"def", 0, NSC_LONG, 0, nsc_pln_def, EF_BAD, NSC_EXTRA},
+    {"nuketype", 0, NSC_LONG, 0, nsc_pln_nuketype, EF_BAD, NSC_EXTRA},
     {NULL, 0, NSC_NOTYPE, 0, NULL, EF_BAD, 0}
 #undef CURSTR
 };
@@ -782,6 +783,14 @@ nsc_pln_att(struct valstr *val, struct natstr *np, void *ptr)
     return NULL;
 }
 
+static void *
+nsc_pln_nuketype(struct valstr *val, struct natstr *np, void *ptr)
+{
+    struct nukstr *nukp = getnukep(nuk_on_plane(ptr));
+    val->val_as.lng = nukp ? nukp->nuk_type : -1;
+    return NULL;
+}
+
 static void *
 nsc_lnd_att(struct valstr *val, struct natstr *np, void *ptr)
 {
index 6bacf228d2630d6268170f7e72b729e4246fd51a..9a252ad3143091d7d453936caee48104e217b787 100644 (file)
@@ -1008,7 +1008,7 @@ mission_pln_equip(struct plist *plp, struct ichrstr *ip, int flags,
        switch (mission) {
        case 's':               /* strategic bomb */
        case 'p':               /* pinpoint bomb */
-           if (pp->pln_nuketype == -1) {
+           if (nuk_on_plane(pp) < 0) {
                itype = I_SHELL;
                needed = load;
            }
@@ -1168,7 +1168,7 @@ air_damage(struct emp_qelem *bombers, coord x, coord y, int mission,
               prplane(pp), cname(victim), s, xyas(x, y, pp->pln_own));
        }
        hitchance = pln_hitchance(pp, hardtarget, EF_SHIP);
-       if (plp->plane.pln_nuketype != -1)
+       if (nuk_on_plane(&plp->plane) >= 0)
            hitchance = 100;
        else if (hardtarget != SECT_HARDTARGET)
            wu(0, pp->pln_own, "\t\t%d%% hitchance...", hitchance);
index 8ab1694b9334067741652de10be7c3d54f808bb1..89dbc22e745c3d8827563c8f34b49becfeda5969 100644 (file)
@@ -42,6 +42,7 @@
 #include "nat.h"
 #include "news.h"
 #include "nsc.h"
+#include "nuke.h"
 #include "optlist.h"
 #include "path.h"
 #include "plane.h"
@@ -129,8 +130,10 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
     putplane(pp->pln_uid, pp);
     mpr(pp->pln_own, "\tSHWOOOOOSH!  Missile launched!\n");
 
-    if (pp->pln_nuketype != -1)
+    if (nuk_on_plane(pp) >= 0) {
        mpr(pp->pln_own, "\tArming nuclear warheads...\n");
+       hitchance = 100;
+    }
 
     if (pcp->pl_flags & P_T)
        mpr(victim, "Incoming %s missile sighted at %s...\n",
@@ -150,9 +153,6 @@ msl_hit(struct plnstr *pp, int hardtarget, int type, int news_item,
        }
     }
 
-    if (pp->pln_nuketype != -1)
-       hitchance = 100;
-
     mpr(pp->pln_own, "\t%d%% hitchance...", hitchance);
     hit = (roll(100) <= hitchance);
 
index d4a9564832825b5dea04b787547058eaf9d363a8..e5adeaa2941430a904964283437b72e71fbbfdd6 100644 (file)
@@ -666,7 +666,7 @@ pln_equip(struct plist *plp, struct ichrstr *ip, int flags, char mission)
        switch (mission) {
        case 's':               /* strategic bomb */
        case 'p':               /* pinpoint bomb */
-           if (pp->pln_nuketype == -1) {
+           if (nuk_on_plane(pp) < 0) {
                itype = I_SHELL;
                needed = load;
            }
@@ -1138,7 +1138,6 @@ pln_damage(struct plnstr *pp, coord x, coord y, char type, int *nukedamp,
     if (getnuke(nuk_on_plane(pp), &nuke)) {
        mpr(pp->pln_own, "Releasing RV's for %s detonation...\n",
            pp->pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
-       pp->pln_nuketype = -1;
        *nukedamp = detonate(&nuke, x, y,
                             pp->pln_flags & PLN_AIRBURST);
        return 0;
index 12f9bda1d190a0abcdf3ce5e4a018efb2be09a25..f7121404b08668310bd18908bdcf6c743ef0a20c 100644 (file)
@@ -108,6 +108,7 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
     struct nstr_item ni;
     struct plnstr plane;
     struct lndstr land;
+    struct nukstr nuke;
 
     switch (tp->trd_type) {
     case EF_NUKE:
@@ -136,9 +137,8 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
                       plane.pln_tech,
                       plane.pln_effic,
                       plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
-                   if (plane.pln_nuketype != -1) {
-                       pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
-                   }
+                   if (getnuke(nuk_on_plane(&plane), &nuke))
+                       pr("(%s)", nchr[nuke.nuk_type].n_name);
                }
            }
            snxtitem_all(&ni, EF_LAND);
@@ -157,10 +157,8 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
                                   plane.pln_effic,
                                   plchr[(int)plane.pln_type].pl_name,
                                   plane.pln_uid);
-                               if (plane.pln_nuketype != -1) {
-                                   pr("(%s)",
-                                      nchr[(int)plane.pln_nuketype].n_name);
-                               }
+                               if (getnuke(nuk_on_plane(&plane), &nuke))
+                                   pr("(%s)", nchr[nuke.nuk_type].n_name);
                            }
                        }
                    }
@@ -193,9 +191,8 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
                       plane.pln_tech,
                       plane.pln_effic,
                       plchr[(int)plane.pln_type].pl_name, plane.pln_uid);
-                   if (plane.pln_nuketype != -1) {
-                       pr("(%s)", nchr[(int)plane.pln_nuketype].n_name);
-                   }
+                   if (getnuke(nuk_on_plane(&plane), &nuke))
+                       pr("(%s)", nchr[nuke.nuk_type].n_name);
                }
            }
        }
@@ -209,9 +206,8 @@ trade_desc(struct trdstr *tp, union empobj_storage *tgp)
           pp->pln_tech,
           pp->pln_effic,
           plchr[(int)pp->pln_type].pl_name, tp->trd_unitid);
-       if (pp->pln_nuketype != -1) {
-           pr("(%s)", nchr[(int)pp->pln_nuketype].n_name);
-       }
+       if (getnuke(nuk_on_plane(pp), &nuke))
+           pr("(%s)", nchr[nuke.nuk_type].n_name);
        break;
     default:
        pr("flaky unit type %d", tp->trd_type);
index ae0a589fa49966aa398418f90bbc2219f398b4f4..9d6b32676b6979f963c0a62946679f21d95b4b3a 100644 (file)
@@ -50,7 +50,6 @@ static void exit_bad_arg(char *, ...)
 static void dump_table(int, int);
 static void pln_fixup(void);
 static void lnd_fixup(void);
-static void nuk_fixup(void);
 
 int
 main(int argc, char *argv[])
@@ -151,7 +150,6 @@ main(int argc, char *argv[])
            exit(1);
        pln_fixup();
        lnd_fixup();
-       nuk_fixup();
     }
 
     if (ef_verify() < 0)
@@ -282,22 +280,6 @@ lnd_fixup(void)
     }
 }
 
-static void
-nuk_fixup(void)
-{
-    int i;
-    struct nukstr *np;
-    struct plnstr *cpp;
-
-    for (i = 0; (np = ef_ptr(EF_NUKE, i)); i++) {
-       if (!np->nuk_own)
-           continue;
-       cpp = ef_ptr(EF_PLANE, np->nuk_plane);
-       if (cpp)
-           cpp->pln_nuketype = np->nuk_type;
-    }
-}
-
 /* Temporarily copied from src/lib/subs/???sub.c */
 
 /*