short ef_type;
natid nuk_own;
short nuk_uid;
- coord nuk_x; /* current loc of device */
- coord nuk_y;
+ coord nuk_x, nuk_y; /* current loc of device */
+ signed char nuk_type; /* index in plchr[] */
/* end of part matching struct genitem */
- signed char nuk_n; /* number of nukes in list */
short nuk_ship; /* currently aboard ship (unused) */
- short nuk_trade; /* index into trade file (unused) */
- short nuk_types[N_MAXNUKE]; /* # of nukes in sector of given type */
+ short nuk_plane; /* currently aboard plane */
+ short nuk_land; /* currently aboard land (unused) */
time_t nuk_timestamp; /* Last time this nuke was touched */
};
int demo(void);
int desi(void);
int disa(void);
+int disarm(void);
int dist(void);
int drop(void);
int dump(void);
extern void init_nreport(void);
extern void nreport(natid, int, natid, int);
/* nuke.c */
+extern char *prnuke(struct nukstr *);
extern int nuk_postread(int, void *);
extern int nuk_prewrite(int, void *);
extern void nuk_init(int, void *);
-extern void nuk_add(coord, coord, int, int);
-extern void nuk_delete(struct nukstr *, int, int);
+extern int nuk_on_plane(struct nukstr *, int);
/* nxtitem.c */
extern int nxtitem(struct nstr_item *, void *);
/* nxtsct.c */
.TH Command ARM
.NA arm "Load nuclear weapons onto planes or missiles"
.LV Expert
-.SY "arm <PLANE> <NUKETYPE> <airburst?>"
+.SY "arm <PLANE> <NUKE> <airburst?>"
The \*Qarm\*U command loads nuclear devices
aboard delivery systems such as planes or missiles.
.s1
.NA transport "Move planes or nuclear devices around"
.LV Basic
.SY "transport plane <PLANES> <ROUTE|DESTINATION>"
-.SY "transport nuke <SECT> <NUKETYPE> <number> <ROUTE|DESTINATION>"
+.SY "transport nuke <NUKES> <ROUTE|DESTINATION>"
The transport command is used to move planes and nuclear devices from
one sector to another, along the ground.
.s1
the route, and empire will use the cheapest path (in terms of mobility)
from the current sector to the destination sector.
.s1
-You would move 5 small nukes from 2,0 to 8,0 as follows:
-.EX transport nuke 2,0 small 5 8,0
+You would move nuke #666 to 8,0 as follows:
+.EX transport nuke 666 8,0
.s1
You could move all planes in wing d to -6,0 as follows:
.EX transport plane d -6,0
struct nchrstr *ncp;
struct plchrstr *plc;
struct plnstr pl;
- struct plnstr start; /* Used for sanity checking */
struct nukstr nuke;
char *p;
- int pno;
- int nuketype;
- int found;
+ int pno, nukno;
struct nstr_item ni;
char buf[1024];
- int disarm = **player->argp == 'd';
- char *prompt = disarm ? "Disarm plane: " : "Arm plane: ";
+ char prompt[128];
- if (!(p = getstarg(player->argp[1], prompt, buf)) || !*p)
+ if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
return RET_SYN;
- pno = atoi(p);
- if (pno < 0 || !getplane(pno, &pl) || pl.pln_own != player->cnum)
- return RET_FAIL;
- memcpy(&start, &pl, sizeof(struct plnstr));
- plc = &plchr[(int)pl.pln_type];
- if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) {
- pr("A %s cannot carry nuclear devices!\n", plc->pl_name);
- return RET_FAIL;
- }
- if (opt_MARKET) {
- if (ontradingblock(EF_PLANE, &pl)) {
- pr("You cannot arm/disarm an item on the trading block!\n");
- return RET_FAIL;
- }
- }
- if (pl.pln_nuketype == -1) {
- if (disarm) {
- pr("%s is not carrying any nuclear devices\n", prplane(&pl));
+ while (nxtitem(&ni, &pl)) {
+ if (!player->owner)
+ continue;
+ plc = &plchr[(int)pl.pln_type];
+ if ((plc->pl_flags & (P_O | P_M)) == (P_O | P_M)) {
+ pr("A %s cannot carry nuclear devices!\n", plc->pl_name);
return RET_FAIL;
}
- if ((p = getstarg(player->argp[2], "Device type: ", buf)) == 0)
- return RET_SYN;
- if (!check_plane_ok(&start))
- return RET_FAIL;
- nuketype = typematch(p, EF_NUKE);
- if (nuketype < 0) {
- pr("No such nuke type!\n");
- return RET_SYN;
- }
- ncp = &nchr[nuketype];
- found = 0;
- snxtitem_xy(&ni, EF_NUKE, pl.pln_x, pl.pln_y);
- while (nxtitem(&ni, &nuke)) {
- if (nuke.nuk_own == player->cnum) {
- found = 1;
- break;
+ if (opt_MARKET) {
+ if (ontradingblock(EF_PLANE, &pl)) {
+ pr("You cannot disarm %s while it is on the trading block!\n",
+ prplane(&pl));
+ return RET_FAIL;
}
}
- if (!found) {
- pr("You don't own any nukes in that sector.\n");
- return RET_FAIL;
- }
- if (nuke.nuk_types[nuketype] == 0) {
- pr("No nukes of that type in that sector.\n");
- return RET_FAIL;
+ if (pl.pln_nuketype < 0) {
+ sprintf(prompt, "Nuclear device for %s: ", prplane(&pl));
+ p = getstarg(player->argp[2], prompt, buf);
+ if (!p || !*p)
+ return RET_SYN;
+ if (!check_plane_ok(&pl))
+ return RET_FAIL;
+ nukno = atoi(p);
+ if (!getnuke(nukno, &nuke) || !player->owner)
+ return RET_FAIL;
+ } else {
+ if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
+ CANT_REACH();
+ continue;
+ }
}
+ ncp = &nchr[nuke.nuk_type];
if (pl.pln_load < ncp->n_weight) {
- pr("A %s cannot carry %s devices!\n", plc->pl_name,
- ncp->n_name);
+ pr("A %s cannot carry %s devices!\n",
+ plc->pl_name, ncp->n_name);
return RET_FAIL;
}
p = getstarg(player->argp[3], "Airburst [n]? ", buf);
- if (!check_plane_ok(&start))
+ if (!check_plane_ok(&pl) || !check_nuke_ok(&nuke))
return RET_FAIL;
if (p && (*p == 'y' || *p == 'Y'))
else
pl.pln_flags &= ~PLN_AIRBURST;
- pl.pln_nuketype = nuketype;
- nuk_delete(&nuke, nuketype, 1);
- } else if (!disarm) {
- pr("%s already carrying a warhead.\n", prplane(&pl));
- }
- if (disarm) {
- pr("%s warhead removed from %s and added to %s\n",
- nchr[(int)pl.pln_nuketype].n_name,
- prplane(&pl), xyas(pl.pln_x, pl.pln_y, player->cnum));
- nuk_add(pl.pln_x, pl.pln_y, pl.pln_nuketype, 1);
- pl.pln_nuketype = -1;
- pl.pln_flags &= ~PLN_AIRBURST;
- } else {
- pr("%s armed with a %s warhead.\n", prplane(&pl),
- nchr[(int)pl.pln_nuketype].n_name);
+ pl.pln_nuketype = nuke.nuk_type;
+ nuke.nuk_plane = pl.pln_uid;
+ putplane(pl.pln_uid, &pl);
+ putnuke(nuke.nuk_uid, &nuke);
+ pr("%s armed with %s.\n", prplane(&pl), prnuke(&nuke));
pr("Warhead on %s is programmed to %s\n",
prplane(&pl),
pl.pln_flags & PLN_AIRBURST ? "airburst" : "groundburst");
}
- putplane(pl.pln_uid, &pl);
+ return RET_OK;
+}
+
+int
+disarm(void)
+{
+ struct plnstr pl;
+ struct nukstr nuke;
+ struct nstr_item ni;
+
+ if (!snxtitem(&ni, EF_PLANE, player->argp[1]))
+ return RET_SYN;
+ while (nxtitem(&ni, &pl)) {
+ if (!player->owner)
+ continue;
+ if (pl.pln_nuketype == -1)
+ continue;
+ if (opt_MARKET) {
+ if (ontradingblock(EF_PLANE, &pl)) {
+ pr("You cannot disarm %s while it is on the trading block!\n",
+ prplane(&pl));
+ return RET_FAIL;
+ }
+ }
+ if (nuk_on_plane(&nuke, pl.pln_uid) < 0) {
+ CANT_REACH();
+ continue;
+ }
+ nuke.nuk_plane = -1;
+ pl.pln_nuketype = -1;
+ pl.pln_flags &= ~PLN_AIRBURST;
+ putplane(pl.pln_uid, &pl);
+ putnuke(nuke.nuk_uid, &nuke);
+ pr("%s removed from %s and added to %s\n",
+ prnuke(&nuke), prplane(&pl),
+ xyas(pl.pln_x, pl.pln_y, player->cnum));
+ }
return RET_OK;
}
}
static int
-build_nuke(struct sctstr *sp, struct nchrstr *np,
- short *vec)
+build_nuke(struct sctstr *sp, struct nchrstr *np, short *vec)
{
+ struct nukstr nuke;
+ struct nstr_item nstr;
int avail;
+ int freenuke;
if (sp->sct_type != SCT_NUKE && !player->god) {
pr("Nuclear weapons must be built in nuclear plants.\n");
return 0;
sp->sct_avail -= avail;
player->dolcost += np->n_cost;
- nuk_add(sp->sct_x, sp->sct_y, np - nchr, 1);
+ snxtitem_all(&nstr, EF_NUKE);
+ freenuke = 0;
+ while (nxtitem(&nstr, &nuke)) {
+ if (nuke.nuk_own == 0) {
+ freenuke++;
+ break;
+ }
+ }
+ if (freenuke == 0) {
+ ef_extend(EF_NUKE, 50);
+ }
+ memset(&nuke, 0, sizeof(struct nukstr));
+ nuke.nuk_x = sp->sct_x;
+ nuke.nuk_y = sp->sct_y;
+ nuke.nuk_own = sp->sct_own;
+ nuke.nuk_type = np - nchr;
+ nuke.nuk_ship = nuke.nuk_plane = nuke.nuk_land = -1;
+ nuke.nuk_uid = nstr.cur;
+
vec[I_HCM] -= np->n_hcm;
vec[I_LCM] -= np->n_lcm;
vec[I_OIL] -= np->n_oil;
vec[I_RAD] -= np->n_rad;
- pr("%s warhead created in %s\n", np->n_name,
+
+ makenotlost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid,
+ nuke.nuk_x, nuke.nuk_y);
+ putnuke(nuke.nuk_uid, &nuke);
+ pr("%s created in %s\n", prnuke(&nuke),
xyas(sp->sct_x, sp->sct_y, player->cnum));
return 1;
}
double cost;
float eff = PLANE_MINEFF / 100.0;
int hcm, lcm, mil;
- int freeplane = 0;
+ int freeplane;
mil = roundavg(((double)pp->pl_crew * eff));
/* Always use at least 1 mil to build a plane */
if (np->nuk_own == 0)
continue;
- wu(0, to, "\tnuclear stockpile #%d ceded to you by %s\n",
- np->nuk_uid, cname(player->cnum));
+ wu(0, to, "\t%s ceded to you by %s\n",
+ prnuke(np), cname(player->cnum));
makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
np->nuk_own = to;
makenotlost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x,
if (nuk.nuk_own == 0)
continue;
nnukes++;
- for (i = 0; i < N_MAXNUKE; i++) {
- if (nuk.nuk_types[i] > 0) {
- if (player->god)
- pr("%d ", nuk.nuk_own);
- pr("%d ", nuk.nuk_uid);
- prxy("%d %d", nuk.nuk_x, nuk.nuk_y, player->cnum);
- pr(" %d", nuk.nuk_types[i]);
- pr(" %.5s", nchr[i].n_name);
- pr("\n");
- }
- }
+ if (player->god)
+ pr("%d ", nuk.nuk_own);
+ pr("%d ", nuk.nuk_uid);
+ prxy("%d %d", nuk.nuk_x, nuk.nuk_y, player->cnum);
+ pr(" %d", 1);
+ pr(" %.5s", nchr[(int)nuk.nuk_type].n_name);
+ pr("\n");
}
if (nnukes == 0) {
if (player->argp[1])
nuke(void)
{
int first_line = 0;
- int first_nuke;
int show_comm;
int i;
struct nstr_item nstr;
pr(" sect eff num nuke-type lcm hcm oil rad avail\n");
}
getsect(nuk.nuk_x, nuk.nuk_y, §);
- first_nuke = 1;
show_comm = 0;
if (sect.sct_type == SCT_NUKE && sect.sct_effic >= 60)
show_comm = 1;
- for (i = 0; i < N_MAXNUKE; i++) {
- if (nuk.nuk_types[i] > 0) {
- if (first_nuke) {
- if (player->god)
- pr("%-3d ", nuk.nuk_own);
- prxy("%4d,%-4d", sect.sct_x, sect.sct_y, player->cnum);
- pr(" %c", dchr[sect.sct_type].d_mnem);
- if (sect.sct_newtype != sect.sct_type)
- pr("%c", dchr[sect.sct_newtype].d_mnem);
- else
- pr(" ");
- pr("%4d%%", sect.sct_effic);
- first_nuke = 0;
- } else {
- pr(" ");
- }
+ if (player->god)
+ pr("%-3d ", nuk.nuk_own);
+ prxy("%4d,%-4d", sect.sct_x, sect.sct_y, player->cnum);
+ pr(" %c", dchr[sect.sct_type].d_mnem);
+ if (sect.sct_newtype != sect.sct_type)
+ pr("%c", dchr[sect.sct_newtype].d_mnem);
+ else
+ pr(" ");
+ pr("%4d%%", sect.sct_effic);
- pr("%3d ", nuk.nuk_types[i]);
- pr("%-16.16s ", nchr[i].n_name);
+ pr("%3d ", 1);
+ pr("%-16.16s ", nchr[(int)nuk.nuk_type].n_name);
- if (show_comm) {
- pr("%5d ", sect.sct_item[I_LCM]);
- pr("%5d ", sect.sct_item[I_HCM]);
- pr("%5d ", sect.sct_item[I_OIL]);
- pr("%5d ", sect.sct_item[I_RAD]);
- pr("%5d", sect.sct_avail);
- show_comm = 0;
- }
- pr("\n");
- }
+ if (show_comm) {
+ pr("%5d ", sect.sct_item[I_LCM]);
+ pr("%5d ", sect.sct_item[I_HCM]);
+ pr("%5d ", sect.sct_item[I_OIL]);
+ pr("%5d ", sect.sct_item[I_RAD]);
+ pr("%5d", sect.sct_avail);
+ show_comm = 0;
}
+ pr("\n");
}
return RET_OK;
}
return RET_SYN;
}
-/*
- * Kinda silly; only moves the first nuke.
- * Maybe nukes should be made into commodities?
- */
static int
tran_nuke(void)
{
- struct nchrstr *ncp;
- coord x, y;
+ coord srcx, srcy;
coord dstx, dsty;
- int found;
- char *p;
- int nuketype;
- int moving;
+ int mcost;
+ int weight, count;
+ int type, dam;
+ struct nstr_item nstr;
struct nukstr nuke;
struct sctstr sect;
struct sctstr endsect;
- int mcost, dam;
- struct nstr_item nstr;
- char buf[1024];
- if (!(p = getstarg(player->argp[2], "from sector : ", buf)))
- return RET_SYN;
- if (!sarg_xy(p, &x, &y))
+ weight = 0;
+ count = 0;
+ if (!snxtitem(&nstr, EF_NUKE, player->argp[2]))
return RET_SYN;
- if (!getsect(x, y, §) || !player->owner) {
- pr("Not yours\n");
- return RET_FAIL;
- }
- snxtitem_xy(&nstr, EF_NUKE, sect.sct_x, sect.sct_y);
- found = 0;
while (nxtitem(&nstr, &nuke)) {
- if (player->owner) {
- found = 1;
- break;
+ if (!player->owner)
+ continue;
+ type = nuke.nuk_type;
+ if (nuke.nuk_plane >= 0) {
+ pr("%s is armed and can't be transported\n", prnuke(&nuke));
+ return RET_FAIL;
}
+ if (count == 0) {
+ srcx = nuke.nuk_x;
+ srcy = nuke.nuk_y;
+ } else {
+ if (nuke.nuk_x != srcx || nuke.nuk_y != srcy) {
+ pr("All nukes must be in the same sector.\n");
+ return RET_FAIL;
+ }
+ }
+ weight += nchr[type].n_weight;
+ ++count;
}
- if (!found) {
- pr("There are no nukes in %s\n",
- xyas(sect.sct_x, sect.sct_y, player->cnum));
- return RET_FAIL;
- }
- if (!(p = getstarg(player->argp[3], "warhead type : ", buf)))
- return RET_SYN;
- if (!check_sect_ok(§))
- return RET_FAIL;
- nuketype = typematch(p, EF_NUKE);
- if (nuketype < 0) {
- pr("No such nuke type!\n");
- return RET_SYN;
- }
- ncp = &nchr[nuketype];
- if (!nuke.nuk_types[nuketype]) {
- pr("No %s nukes in %s\n",
- ncp->n_name, xyas(sect.sct_x, sect.sct_y, player->cnum));
+ if (count == 0) {
+ pr("No planes\n");
return RET_FAIL;
}
- p = getstarg(player->argp[4], "number of warheads : ", buf);
- if (!check_sect_ok(§))
- return RET_FAIL;
- if (p == 0 || *p == 0 || (moving = atoi(p)) < 0)
+ if (!getsect(srcx, srcy, §) || !player->owner) {
+ pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
return RET_FAIL;
- if (moving > nuke.nuk_types[nuketype]) {
- moving = nuke.nuk_types[nuketype];
- if (moving)
- pr("only moving %d\n", moving);
- else
- return RET_FAIL;
}
if (!military_control(§)) {
pr("Military control required to move nukes.\n");
return RET_FAIL;
}
dam = 0;
- mcost = move_ground(§, &endsect, (double)ncp->n_weight * moving,
- player->argp[5], tran_map, 0, &dam);
-
+ mcost = move_ground(§, &endsect, weight,
+ player->argp[3], tran_map, 0, &dam);
if (mcost < 0)
return 0;
+ dstx = endsect.sct_x;
+ dsty = endsect.sct_y;
+ snxtitem_rewind(&nstr);
+ while (nxtitem(&nstr, &nuke)) {
+ if (!player->owner)
+ continue;
+ /* TODO apply dam */
+ nuke.nuk_x = dstx;
+ nuke.nuk_y = dsty;
+ putnuke(nuke.nuk_uid, &nuke);
+ }
if (mcost > 0)
pr("Total movement cost = %d\n", mcost);
else
pr("No mobility used\n");
-
- dstx = endsect.sct_x;
- dsty = endsect.sct_y;
- /*
- * decrement mobility from src sector
- */
- getsect(nuke.nuk_x, nuke.nuk_y, §);
+ getsect(srcx, srcy, §);
sect.sct_mobil -= mcost;
if (sect.sct_mobil < 0)
sect.sct_mobil = 0;
putsect(§);
- /*
- * update old nuke
- */
- if (!getnuke(nuke.nuk_uid, &nuke)) {
- pr("Could not find that stockpile again.\n");
- return RET_FAIL;
- }
- if (nuke.nuk_types[nuketype] < moving || nuke.nuk_own != player->cnum) {
- pr("Stockpile changed!\n");
- return RET_FAIL;
- }
- nuk_delete(&nuke, nuketype, moving);
- nuk_add(dstx, dsty, nuketype, moving);
return RET_OK;
}
static int
tran_plane(void)
{
- int srcx, srcy;
- int dstx, dsty;
+ coord srcx, srcy;
+ coord dstx, dsty;
int mcost;
int weight, count;
int type, dam;
memcpy(&tnuke, nukep, sizeof(struct nukstr));
tnuke.nuk_timestamp = chknuke.nuk_timestamp = 0;
if (memcmp(&tnuke, &chknuke, sizeof(struct nukstr))) {
- pr("Nuclear stockpile %d has changed!\n", nukep->nuk_uid);
+ pr("Nuke %d has changed!\n", nukep->nuk_uid);
return 0;
}
return 1;
{NSC_NATID, 0, 0, fldoff(nukstr, nuk_own), "owner", EF_NATION},
{NSC_XCOORD, 0, 0, fldoff(nukstr, nuk_x), "xloc", EF_BAD},
{NSC_YCOORD, 0, 0, fldoff(nukstr, nuk_y), "yloc", EF_BAD},
- {NSC_CHAR, 0, 0, fldoff(nukstr, nuk_n), "number", EF_BAD},
- {NSC_SHORT, 0, N_MAXNUKE, fldoff(nukstr, nuk_types), "types", EF_BAD},
+ {NSC_TYPEID, 0, 0, fldoff(nukstr, nuk_type), "type", EF_NUKE_CHR},
+ {NSC_SHORT, 0, 0, fldoff(nukstr, nuk_plane), "plane", EF_BAD},
{NSC_TIME, NSC_EXTRA, 0, fldoff(nukstr, nuk_timestamp), "timestamp",
EF_BAD},
{NSC_NOTYPE, 0, 0, 0, NULL, EF_BAD}
{"announce {message}", 0, tele, C_MOD, VIS},
{"anti <SECT>", 3, anti, C_MOD, NORM + MONEY + CAP},
{"apropos <topic>", 0, apro, 0, VIS},
- {"arm <PLANE> <NUKETYPE> <airburst?>", 3, arm, C_MOD,
- NORM + MONEY + CAP},
+ {"arm <PLANE> <NUKE> <airburst?>", 3, arm, C_MOD, NORM + MONEY + CAP},
{"army <ARMY> <UNITS>", 0, army, C_MOD, NORM},
{"assault <to-SECT> <from-SHIP> [<forts?> <ships?> <arty?> <planes?>]",
3, assa, C_MOD, NORM + MONEY + CAP},
NORM + CAP},
{"designate <SECTS> <type> [sure?]", 1, desi, C_MOD, NORM},
{"disable", 0, disa, C_MOD, GOD},
- {"disarm <PLANE>", 2, arm, C_MOD, NORM + MONEY + CAP},
+ {"disarm <PLANE>", 2, disarm, C_MOD, NORM + MONEY + CAP},
{"distribute <SECTS> <DISTSECT|.|h>", 1, dist, C_MOD, NORM},
{"drop <cargo-PLANES> <fighter-PLANES> <ap-SECT> <PATH|DESTINATION> <COMM>", 1, drop, C_MOD, NORM + MONEY + CAP},
{"dump <SECTS> [<fields>]", 0, dump, 0, NORM},
{"torpedo <submarine-SHIPS> <target-SHIP>", 3, torp, C_MOD,
NORM + MONEY + CAP},
{"trade", 1, trad, C_MOD, NORM + CAP + MONEY},
- {"transport <\"nuke\"|\"plane\"> <SECT|PLANES> [<NUKETYPE> <number>] <PATH|DESTINATION>", 1, tran, C_MOD, NORM + CAP},
+ {"transport <\"nuke\"|\"plane\"> <NUKES|PLANES> <PATH|DESTINATION>",
+ 1, tran, C_MOD, NORM + CAP},
{"treaty <TREATIES>", 0, trea, 0, NORM + MONEY + CAP},
{"turn <\"on\"|\"off\"|\"mess\">", 0, turn, C_MOD, GOD},
{"unload <COMM|\"land\"|\"plane\"> <SHIPS> <NUM|UNIT|PLANE>", 1, load,
nuke.nuk_y);
nuke.nuk_own = 0;
if (own == bombown) {
- mpr(bombown, "nuclear stockpile #%d at %s destroyed\n",
- ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own));
+ mpr(bombown, "%s at %s destroyed\n",
+ prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
} else {
if (own != 0)
- mpr(own, "nuclear stockpile #%d at %s destroyed\n",
- ni.cur, xyas(nuke.nuk_x, nuke.nuk_y, own));
+ mpr(own, "%s at %s destroyed\n",
+ prnuke(&nuke), xyas(nuke.nuk_x, nuke.nuk_y, own));
}
putnuke(ni.cur, &nuke);
}
np->nuk_own = 0;
}
-void
-nuk_add(coord x, coord y, int type, int num)
+int
+nuk_on_plane(struct nukstr *np, int pluid)
{
- struct nukstr nuke;
- struct sctstr sect;
- int nuk_uid;
- natid own;
- int n;
+ struct nstr_item ni;
- /* getsect in case of world wraparound */
- getsect(x, y, §);
- if (!(own = sect.sct_own))
- return;
- x = sect.sct_x;
- y = sect.sct_y;
-
- /*
- * either find a stockpile in x,y or add a new one
- */
- nuk_uid = -1;
- for (n = 0; getnuke(n, &nuke); n++) {
- if (nuke.nuk_own == own) {
- if (nuke.nuk_x == x && nuke.nuk_y == y) {
- nuk_uid = n;
- break;
- }
- } else if (nuke.nuk_own == 0 && nuk_uid == -1)
- nuk_uid = n;
- }
- if (nuk_uid == -1)
- nuk_uid = n;
- if (getnuke(nuk_uid, &nuke) == 0) {
- ef_extend(EF_NUKE, 10);
- memset(&nuke, 0, sizeof(struct nukstr));
- nuke.nuk_uid = nuk_uid;
+ snxtitem_all(&ni, EF_NUKE);
+ while (nxtitem(&ni, np)) {
+ if (np->nuk_plane == pluid)
+ return np->nuk_uid;
}
- if (nuke.nuk_own == 0) {
- nuke.nuk_ship = -1;
- nuke.nuk_x = x;
- nuke.nuk_y = y;
- nuke.nuk_own = own;
- makenotlost(EF_NUKE, nuke.nuk_own, nuke.nuk_uid, nuke.nuk_x,
- nuke.nuk_y);
- }
- nuke.nuk_types[type] += num;
- nuke.nuk_n += num;
-
- if (!putnuke(nuke.nuk_uid, &nuke))
- pr("Problem with the nuclear stockpiles, tell the deity.\n");
-
+ return -1;
}
-void
-nuk_delete(struct nukstr *np, int type, int num)
+char *
+prnuke(struct nukstr *np)
{
- if (np->nuk_types[type] < num)
- num = np->nuk_types[type];
- np->nuk_types[type] -= num;
- np->nuk_n -= num;
- if (np->nuk_n <= 0) {
- makelost(EF_NUKE, np->nuk_own, np->nuk_uid, np->nuk_x, np->nuk_y);
- np->nuk_own = 0;
- }
- putnuke(np->nuk_uid, np);
+ return prbuf("%s warhead #%d",
+ nchr[(int)np->nuk_type].n_name, np->nuk_uid);
}
{
switch (tp->trd_type) {
case EF_NUKE:
- return "nuclear stockpile";
+ return nchr[(int)tgp->nuk.nuk_type].n_name;
case EF_PLANE:
return plchr[(int)tgp->pln.pln_type].pl_name;
case EF_SHIP:
struct shpstr *sp;
struct plnstr *pp;
struct lndstr *lp;
- struct natstr *natp;
int needcomma;
struct nstr_item ni;
struct plnstr plane;
switch (tp->trd_type) {
case EF_NUKE:
np = &tgp->nuk;
- if (!getsect(np->nuk_x, np->nuk_y, §))
- return 0;
- tp->trd_owner = sect.sct_own;
- natp = getnatp(tp->trd_owner);
- pr("(%3d) ", sect.sct_own);
- needcomma = 0;
- for (i = 0; i < N_MAXNUKE; i++) {
- if (np->nuk_types[i]) {
- if (needcomma)
- pr(",");
- pr("%dx%s", np->nuk_types[i], nchr[i].n_name);
- needcomma = 1;
- }
- }
+ tp->trd_owner = np->nuk_own;
+ pr("(%3d) %s #%d",
+ tp->trd_owner,
+ nchr[(int)np->nuk_type].n_name, tp->trd_unitid);
break;
case EF_SHIP:
sp = &tgp->shp;