From 2e40a4bb905b3867c9a606144614df6d39a90171 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 6 May 2006 07:20:21 +0000 Subject: [PATCH] Change nuke storage and commands to match other units: (nukstr): Hold one nuke instead of a stockpile: replace members nuk_n, nuk_types by nuk_type, nuk_plane. Add nuk_land for completeness, like nuk_ship it's not yet used. (nuke_ca): Update accordingly: replace selectors number and types by type and plane. (build_nuke): Update accordingly. (ndump, nuke): Update accordingly. Output is no longer sorted by location, and nukes in same location no longer share id. nuke's extra columns for nuclear plants are repeated for every nuke. (trade_desc): Update accordingly. (cede, grab_sect, check_nuke_ok, detonate, trade_nameof): Talk about nukes instead of nuclear stockpiles. (arm, disarm): Rewrite, split off new disarm(). Don't remove nuke from the nuke file on arm. Allow usual plane syntax, not just plane number. Change second argument from nuke type to nuke number. When plane is already armed, ignore nuke argument and rearm (broken in 4.2.6). (tran_nuke): Update for changed struct nukstr, make as similar as possible to tran_plane. Change syntax to match transport plane. (player_coms): Update arm, disarm and transport accordingly. (prnuke, nuk_on_plane): New. (nuk_add, nuk_delete): Stockpile management, remove. --- include/nuke.h | 9 ++- include/prototypes.h | 5 +- info/arm.t | 2 +- info/transport.t | 6 +- src/lib/commands/arm.c | 142 +++++++++++++++++++++------------------ src/lib/commands/buil.c | 34 ++++++++-- src/lib/commands/cede.c | 4 +- src/lib/commands/ndump.c | 18 ++--- src/lib/commands/nuke.c | 49 ++++++-------- src/lib/commands/tran.c | 131 ++++++++++++++---------------------- src/lib/common/check.c | 2 +- src/lib/global/nsc.c | 4 +- src/lib/player/empmod.c | 8 +-- src/lib/subs/detonate.c | 8 +-- src/lib/subs/nuke.c | 70 ++++--------------- src/lib/subs/trdsub.c | 21 ++---- 16 files changed, 220 insertions(+), 293 deletions(-) diff --git a/include/nuke.h b/include/nuke.h index 84881676..27c3215a 100644 --- a/include/nuke.h +++ b/include/nuke.h @@ -42,13 +42,12 @@ struct nukstr { 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 */ }; diff --git a/include/prototypes.h b/include/prototypes.h index ad63a63f..5e193e66 100644 --- a/include/prototypes.h +++ b/include/prototypes.h @@ -109,6 +109,7 @@ int deli(void); int demo(void); int desi(void); int disa(void); +int disarm(void); int dist(void); int drop(void); int dump(void); @@ -528,11 +529,11 @@ extern void delete_old_news(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 */ diff --git a/info/arm.t b/info/arm.t index 81ab0762..865e3324 100644 --- a/info/arm.t +++ b/info/arm.t @@ -1,7 +1,7 @@ .TH Command ARM .NA arm "Load nuclear weapons onto planes or missiles" .LV Expert -.SY "arm " +.SY "arm " The \*Qarm\*U command loads nuclear devices aboard delivery systems such as planes or missiles. .s1 diff --git a/info/transport.t b/info/transport.t index f03d1ce1..1d3ae114 100644 --- a/info/transport.t +++ b/info/transport.t @@ -2,7 +2,7 @@ .NA transport "Move planes or nuclear devices around" .LV Basic .SY "transport plane " -.SY "transport nuke " +.SY "transport nuke " The transport command is used to move planes and nuclear devices from one sector to another, along the ground. .s1 @@ -11,8 +11,8 @@ one sector to another, along the ground. 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 diff --git a/src/lib/commands/arm.c b/src/lib/commands/arm.c index 69aecb9d..9dd9022d 100644 --- a/src/lib/commands/arm.c +++ b/src/lib/commands/arm.c @@ -52,73 +52,55 @@ arm(void) 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"); + 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 (pl.pln_nuketype == -1) { - if (disarm) { - pr("%s is not carrying any nuclear devices\n", prplane(&pl)); - 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')) @@ -126,26 +108,52 @@ arm(void) 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; } diff --git a/src/lib/commands/buil.c b/src/lib/commands/buil.c index 76706fa3..95a8917c 100644 --- a/src/lib/commands/buil.c +++ b/src/lib/commands/buil.c @@ -639,10 +639,12 @@ build_bridge(struct sctstr *sp, short *vec) } 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"); @@ -681,12 +683,34 @@ build_nuke(struct sctstr *sp, struct nchrstr *np, 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; } @@ -701,7 +725,7 @@ build_plane(struct sctstr *sp, struct plchrstr *pp, 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 */ diff --git a/src/lib/commands/cede.c b/src/lib/commands/cede.c index 0ba9623f..08817061 100644 --- a/src/lib/commands/cede.c +++ b/src/lib/commands/cede.c @@ -231,8 +231,8 @@ grab_sect(struct sctstr *sp, natid to) 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, diff --git a/src/lib/commands/ndump.c b/src/lib/commands/ndump.c index 8bf9570e..8c4dab88 100644 --- a/src/lib/commands/ndump.c +++ b/src/lib/commands/ndump.c @@ -67,17 +67,13 @@ ndump(void) 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]) diff --git a/src/lib/commands/nuke.c b/src/lib/commands/nuke.c index 0c6a9651..0902b77f 100644 --- a/src/lib/commands/nuke.c +++ b/src/lib/commands/nuke.c @@ -47,7 +47,6 @@ int nuke(void) { int first_line = 0; - int first_nuke; int show_comm; int i; struct nstr_item nstr; @@ -68,41 +67,31 @@ nuke(void) 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; } diff --git a/src/lib/commands/tran.c b/src/lib/commands/tran.c index fcf241db..3434e13f 100644 --- a/src/lib/commands/tran.c +++ b/src/lib/commands/tran.c @@ -69,122 +69,89 @@ tran(void) 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))) + weight = 0; + count = 0; + if (!snxtitem(&nstr, EF_NUKE, player->argp[2])) return RET_SYN; - if (!sarg_xy(p, &x, &y)) - 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 (!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)); - 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) - return RET_FAIL; - if (moving > nuke.nuk_types[nuketype]) { - moving = nuke.nuk_types[nuketype]; - if (moving) - pr("only moving %d\n", moving); - else + 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 (count == 0) { + pr("No planes\n"); + return RET_FAIL; + } + if (!getsect(srcx, srcy, §) || !player->owner) { + pr("You don't own %s\n", xyas(srcx, srcy, player->cnum)); + 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; diff --git a/src/lib/common/check.c b/src/lib/common/check.c index af06a80e..a4195124 100644 --- a/src/lib/common/check.c +++ b/src/lib/common/check.c @@ -129,7 +129,7 @@ check_nuke_ok(struct nukstr *nukep) 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; diff --git a/src/lib/global/nsc.c b/src/lib/global/nsc.c index e8f45a4f..674acfcc 100644 --- a/src/lib/global/nsc.c +++ b/src/lib/global/nsc.c @@ -384,8 +384,8 @@ struct castr nuke_ca[] = { {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} diff --git a/src/lib/player/empmod.c b/src/lib/player/empmod.c index ba01ebed..7e0d5e3a 100644 --- a/src/lib/player/empmod.c +++ b/src/lib/player/empmod.c @@ -47,8 +47,7 @@ struct cmndstr player_coms[] = { {"announce {message}", 0, tele, C_MOD, VIS}, {"anti ", 3, anti, C_MOD, NORM + MONEY + CAP}, {"apropos ", 0, apro, 0, VIS}, - {"arm ", 3, arm, C_MOD, - NORM + MONEY + CAP}, + {"arm ", 3, arm, C_MOD, NORM + MONEY + CAP}, {"army ", 0, army, C_MOD, NORM}, {"assault [ ]", 3, assa, C_MOD, NORM + MONEY + CAP}, @@ -90,7 +89,7 @@ struct cmndstr player_coms[] = { NORM + CAP}, {"designate [sure?]", 1, desi, C_MOD, NORM}, {"disable", 0, disa, C_MOD, GOD}, - {"disarm ", 2, arm, C_MOD, NORM + MONEY + CAP}, + {"disarm ", 2, disarm, C_MOD, NORM + MONEY + CAP}, {"distribute ", 1, dist, C_MOD, NORM}, {"drop ", 1, drop, C_MOD, NORM + MONEY + CAP}, {"dump []", 0, dump, 0, NORM}, @@ -253,7 +252,8 @@ struct cmndstr player_coms[] = { {"torpedo ", 3, torp, C_MOD, NORM + MONEY + CAP}, {"trade", 1, trad, C_MOD, NORM + CAP + MONEY}, - {"transport <\"nuke\"|\"plane\"> [ ] ", 1, tran, C_MOD, NORM + CAP}, + {"transport <\"nuke\"|\"plane\"> ", + 1, tran, C_MOD, NORM + CAP}, {"treaty ", 0, trea, 0, NORM + MONEY + CAP}, {"turn <\"on\"|\"off\"|\"mess\">", 0, turn, C_MOD, GOD}, {"unload ", 1, load, diff --git a/src/lib/subs/detonate.c b/src/lib/subs/detonate.c index 9d7d2eb5..e1a34b81 100644 --- a/src/lib/subs/detonate.c +++ b/src/lib/subs/detonate.c @@ -301,12 +301,12 @@ detonate(struct plnstr *pp, int x, int y) 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); } diff --git a/src/lib/subs/nuke.c b/src/lib/subs/nuke.c index 68b0299f..fd460d17 100644 --- a/src/lib/subs/nuke.c +++ b/src/lib/subs/nuke.c @@ -84,68 +84,22 @@ nuk_init(int n, void *ptr) 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; + snxtitem_all(&ni, EF_NUKE); + while (nxtitem(&ni, np)) { + if (np->nuk_plane == pluid) + return np->nuk_uid; } - 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; - } - 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); } diff --git a/src/lib/subs/trdsub.c b/src/lib/subs/trdsub.c index 15d39203..3d9f909a 100644 --- a/src/lib/subs/trdsub.c +++ b/src/lib/subs/trdsub.c @@ -79,7 +79,7 @@ trade_nameof(struct trdstr *tp, union trdgenstr *tgp) { 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: @@ -105,7 +105,6 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp) struct shpstr *sp; struct plnstr *pp; struct lndstr *lp; - struct natstr *natp; int needcomma; struct nstr_item ni; struct plnstr plane; @@ -114,20 +113,10 @@ trade_desc(struct trdstr *tp, union trdgenstr *tgp) 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;