Get rid of struct plnstr member pln_nuktype

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().
This commit is contained in:
Markus Armbruster 2008-09-06 22:15:41 -04:00
parent 4086c25a15
commit 8b1470e3a8
13 changed files with 40 additions and 56 deletions

View 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 */

View 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);

View 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);
}

View 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);

View 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);

View 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");

View 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");
}

View 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)
{

View 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);

View 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);

View 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;

View 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);

View 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 */
/*