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.
This commit is contained in:
Markus Armbruster 2006-05-06 07:20:21 +00:00
parent e86beb9626
commit 2e40a4bb90
16 changed files with 220 additions and 293 deletions

View file

@ -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;
}

View file

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

View file

@ -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,

View file

@ -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])

View file

@ -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, &sect);
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;
}

View file

@ -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, &sect) || !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(&sect))
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(&sect))
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, &sect) || !player->owner) {
pr("You don't own %s\n", xyas(srcx, srcy, player->cnum));
return RET_FAIL;
}
if (!military_control(&sect)) {
pr("Military control required to move nukes.\n");
return RET_FAIL;
}
dam = 0;
mcost = move_ground(&sect, &endsect, (double)ncp->n_weight * moving,
player->argp[5], tran_map, 0, &dam);
mcost = move_ground(&sect, &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, &sect);
getsect(srcx, srcy, &sect);
sect.sct_mobil -= mcost;
if (sect.sct_mobil < 0)
sect.sct_mobil = 0;
putsect(&sect);
/*
* 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;